mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	Revert "chore(test): skip test breaking the CI"
This reverts commit f3b6817aa7a933dc1c2e378b72c0c617499bdea1.
This commit is contained in:
		
							parent
							
								
									f3b6817aa7
								
							
						
					
					
						commit
						f8c1dabfd5
					
				@ -67,7 +67,7 @@ describe('LLM Model Selection with Special Characters', () => {
 | 
				
			|||||||
        vi.mocked(options.getOptionBool).mockReturnValue(true);
 | 
					        vi.mocked(options.getOptionBool).mockReturnValue(true);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    describe.skip('OpenAI Model Names', () => {
 | 
					    describe('OpenAI Model Names', () => {
 | 
				
			||||||
        it('should correctly handle model names with periods', async () => {
 | 
					        it('should correctly handle model names with periods', async () => {
 | 
				
			||||||
            const modelName = 'gpt-4.1-turbo-preview';
 | 
					            const modelName = 'gpt-4.1-turbo-preview';
 | 
				
			||||||
            vi.mocked(options.getOption).mockImplementation((key: string) => {
 | 
					            vi.mocked(options.getOption).mockImplementation((key: string) => {
 | 
				
			||||||
@ -82,7 +82,7 @@ describe('LLM Model Selection with Special Characters', () => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            // Spy on getOpenAIOptions to verify model name is passed correctly
 | 
					            // Spy on getOpenAIOptions to verify model name is passed correctly
 | 
				
			||||||
            const getOpenAIOptionsSpy = vi.spyOn(providers, 'getOpenAIOptions');
 | 
					            const getOpenAIOptionsSpy = vi.spyOn(providers, 'getOpenAIOptions');
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
                await service.generateChatCompletion([{ role: 'user', content: 'test' }], opts);
 | 
					                await service.generateChatCompletion([{ role: 'user', content: 'test' }], opts);
 | 
				
			||||||
            } catch (error) {
 | 
					            } catch (error) {
 | 
				
			||||||
@ -108,7 +108,7 @@ describe('LLM Model Selection with Special Characters', () => {
 | 
				
			|||||||
            };
 | 
					            };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const getOpenAIOptionsSpy = vi.spyOn(providers, 'getOpenAIOptions');
 | 
					            const getOpenAIOptionsSpy = vi.spyOn(providers, 'getOpenAIOptions');
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
                await service.generateChatCompletion([{ role: 'user', content: 'test' }], opts);
 | 
					                await service.generateChatCompletion([{ role: 'user', content: 'test' }], opts);
 | 
				
			||||||
            } catch (error) {
 | 
					            } catch (error) {
 | 
				
			||||||
@ -127,7 +127,7 @@ describe('LLM Model Selection with Special Characters', () => {
 | 
				
			|||||||
            };
 | 
					            };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const getOpenAIOptionsSpy = vi.spyOn(providers, 'getOpenAIOptions');
 | 
					            const getOpenAIOptionsSpy = vi.spyOn(providers, 'getOpenAIOptions');
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            const openaiOptions = providers.getOpenAIOptions(opts);
 | 
					            const openaiOptions = providers.getOpenAIOptions(opts);
 | 
				
			||||||
            expect(openaiOptions.model).toBe(modelName);
 | 
					            expect(openaiOptions.model).toBe(modelName);
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
@ -153,7 +153,7 @@ describe('LLM Model Selection with Special Characters', () => {
 | 
				
			|||||||
            });
 | 
					            });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const service = new OpenAIService();
 | 
					            const service = new OpenAIService();
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            // Access the private openai client through the service
 | 
					            // Access the private openai client through the service
 | 
				
			||||||
            const client = (service as any).getClient('test-key');
 | 
					            const client = (service as any).getClient('test-key');
 | 
				
			||||||
            const createSpy = vi.spyOn(client.chat.completions, 'create');
 | 
					            const createSpy = vi.spyOn(client.chat.completions, 'create');
 | 
				
			||||||
@ -213,7 +213,7 @@ describe('LLM Model Selection with Special Characters', () => {
 | 
				
			|||||||
            });
 | 
					            });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const service = new AnthropicService();
 | 
					            const service = new AnthropicService();
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            // Access the private anthropic client
 | 
					            // Access the private anthropic client
 | 
				
			||||||
            const client = (service as any).getClient('test-key');
 | 
					            const client = (service as any).getClient('test-key');
 | 
				
			||||||
            const createSpy = vi.spyOn(client.messages, 'create');
 | 
					            const createSpy = vi.spyOn(client.messages, 'create');
 | 
				
			||||||
@ -278,7 +278,7 @@ describe('LLM Model Selection with Special Characters', () => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            const ollamaOptions = await providers.getOllamaOptions(opts);
 | 
					            const ollamaOptions = await providers.getOllamaOptions(opts);
 | 
				
			||||||
            expect(ollamaOptions.model).toBe(modelName);
 | 
					            expect(ollamaOptions.model).toBe(modelName);
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            // Also test with model specified in options
 | 
					            // Also test with model specified in options
 | 
				
			||||||
            const optsWithModel: ChatCompletionOptions = {
 | 
					            const optsWithModel: ChatCompletionOptions = {
 | 
				
			||||||
                model: 'another/model:v2.0@beta',
 | 
					                model: 'another/model:v2.0@beta',
 | 
				
			||||||
@ -370,7 +370,7 @@ describe('LLM Model Selection with Special Characters', () => {
 | 
				
			|||||||
    describe('Integration with REST API', () => {
 | 
					    describe('Integration with REST API', () => {
 | 
				
			||||||
        it('should pass model names correctly through REST chat service', async () => {
 | 
					        it('should pass model names correctly through REST chat service', async () => {
 | 
				
			||||||
            const modelName = 'gpt-4.1-turbo-preview@latest';
 | 
					            const modelName = 'gpt-4.1-turbo-preview@latest';
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            // Mock the configuration helpers
 | 
					            // Mock the configuration helpers
 | 
				
			||||||
            vi.doMock('../config/configuration_helpers.js', () => ({
 | 
					            vi.doMock('../config/configuration_helpers.js', () => ({
 | 
				
			||||||
                getSelectedModelConfig: vi.fn().mockResolvedValue({
 | 
					                getSelectedModelConfig: vi.fn().mockResolvedValue({
 | 
				
			||||||
@ -382,8 +382,8 @@ describe('LLM Model Selection with Special Characters', () => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            const { getSelectedModelConfig } = await import('../config/configuration_helpers.js');
 | 
					            const { getSelectedModelConfig } = await import('../config/configuration_helpers.js');
 | 
				
			||||||
            const config = await getSelectedModelConfig();
 | 
					            const config = await getSelectedModelConfig();
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            expect(config?.model).toBe(modelName);
 | 
					            expect(config?.model).toBe(modelName);
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
@ -53,22 +53,22 @@ describe('OpenAIService', () => {
 | 
				
			|||||||
    describe('isAvailable', () => {
 | 
					    describe('isAvailable', () => {
 | 
				
			||||||
        it('should return true when base checks pass', () => {
 | 
					        it('should return true when base checks pass', () => {
 | 
				
			||||||
            vi.mocked(options.getOptionBool).mockReturnValueOnce(true); // AI enabled
 | 
					            vi.mocked(options.getOptionBool).mockReturnValueOnce(true); // AI enabled
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            const result = service.isAvailable();
 | 
					            const result = service.isAvailable();
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            expect(result).toBe(true);
 | 
					            expect(result).toBe(true);
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        it('should return false when AI is disabled', () => {
 | 
					        it('should return false when AI is disabled', () => {
 | 
				
			||||||
            vi.mocked(options.getOptionBool).mockReturnValueOnce(false); // AI disabled
 | 
					            vi.mocked(options.getOptionBool).mockReturnValueOnce(false); // AI disabled
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            const result = service.isAvailable();
 | 
					            const result = service.isAvailable();
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            expect(result).toBe(false);
 | 
					            expect(result).toBe(false);
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    describe.skip('generateChatCompletion', () => {
 | 
					    describe('generateChatCompletion', () => {
 | 
				
			||||||
        const messages: Message[] = [
 | 
					        const messages: Message[] = [
 | 
				
			||||||
            { role: 'user', content: 'Hello' }
 | 
					            { role: 'user', content: 'Hello' }
 | 
				
			||||||
        ];
 | 
					        ];
 | 
				
			||||||
@ -89,7 +89,7 @@ describe('OpenAIService', () => {
 | 
				
			|||||||
                enableTools: false
 | 
					                enableTools: false
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
            vi.mocked(providers.getOpenAIOptions).mockReturnValueOnce(mockOptions);
 | 
					            vi.mocked(providers.getOpenAIOptions).mockReturnValueOnce(mockOptions);
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            // Mock the getClient method to return our mock client
 | 
					            // Mock the getClient method to return our mock client
 | 
				
			||||||
            const mockCompletion = {
 | 
					            const mockCompletion = {
 | 
				
			||||||
                id: 'chatcmpl-123',
 | 
					                id: 'chatcmpl-123',
 | 
				
			||||||
@ -120,9 +120,9 @@ describe('OpenAIService', () => {
 | 
				
			|||||||
            };
 | 
					            };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            vi.spyOn(service as any, 'getClient').mockReturnValue(mockClient);
 | 
					            vi.spyOn(service as any, 'getClient').mockReturnValue(mockClient);
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            const result = await service.generateChatCompletion(messages);
 | 
					            const result = await service.generateChatCompletion(messages);
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            expect(result).toEqual({
 | 
					            expect(result).toEqual({
 | 
				
			||||||
                text: 'Hello! How can I help you today?',
 | 
					                text: 'Hello! How can I help you today?',
 | 
				
			||||||
                model: 'gpt-3.5-turbo',
 | 
					                model: 'gpt-3.5-turbo',
 | 
				
			||||||
@ -144,7 +144,7 @@ describe('OpenAIService', () => {
 | 
				
			|||||||
                stream: true
 | 
					                stream: true
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
            vi.mocked(providers.getOpenAIOptions).mockReturnValueOnce(mockOptions);
 | 
					            vi.mocked(providers.getOpenAIOptions).mockReturnValueOnce(mockOptions);
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            // Mock the streaming response
 | 
					            // Mock the streaming response
 | 
				
			||||||
            const mockStream = {
 | 
					            const mockStream = {
 | 
				
			||||||
                [Symbol.asyncIterator]: async function* () {
 | 
					                [Symbol.asyncIterator]: async function* () {
 | 
				
			||||||
@ -162,7 +162,7 @@ describe('OpenAIService', () => {
 | 
				
			|||||||
                    };
 | 
					                    };
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            const mockClient = {
 | 
					            const mockClient = {
 | 
				
			||||||
                chat: {
 | 
					                chat: {
 | 
				
			||||||
                    completions: {
 | 
					                    completions: {
 | 
				
			||||||
@ -172,9 +172,9 @@ describe('OpenAIService', () => {
 | 
				
			|||||||
            };
 | 
					            };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            vi.spyOn(service as any, 'getClient').mockReturnValue(mockClient);
 | 
					            vi.spyOn(service as any, 'getClient').mockReturnValue(mockClient);
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            const result = await service.generateChatCompletion(messages);
 | 
					            const result = await service.generateChatCompletion(messages);
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            expect(result).toHaveProperty('stream');
 | 
					            expect(result).toHaveProperty('stream');
 | 
				
			||||||
            expect(result.text).toBe('');
 | 
					            expect(result.text).toBe('');
 | 
				
			||||||
            expect(result.model).toBe('gpt-3.5-turbo');
 | 
					            expect(result.model).toBe('gpt-3.5-turbo');
 | 
				
			||||||
@ -183,7 +183,7 @@ describe('OpenAIService', () => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        it('should throw error if service not available', async () => {
 | 
					        it('should throw error if service not available', async () => {
 | 
				
			||||||
            vi.mocked(options.getOptionBool).mockReturnValueOnce(false); // AI disabled
 | 
					            vi.mocked(options.getOptionBool).mockReturnValueOnce(false); // AI disabled
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            await expect(service.generateChatCompletion(messages)).rejects.toThrow(
 | 
					            await expect(service.generateChatCompletion(messages)).rejects.toThrow(
 | 
				
			||||||
                'OpenAI service is not available'
 | 
					                'OpenAI service is not available'
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
@ -197,7 +197,7 @@ describe('OpenAIService', () => {
 | 
				
			|||||||
                stream: false
 | 
					                stream: false
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
            vi.mocked(providers.getOpenAIOptions).mockReturnValueOnce(mockOptions);
 | 
					            vi.mocked(providers.getOpenAIOptions).mockReturnValueOnce(mockOptions);
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            const mockClient = {
 | 
					            const mockClient = {
 | 
				
			||||||
                chat: {
 | 
					                chat: {
 | 
				
			||||||
                    completions: {
 | 
					                    completions: {
 | 
				
			||||||
@ -207,7 +207,7 @@ describe('OpenAIService', () => {
 | 
				
			|||||||
            };
 | 
					            };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            vi.spyOn(service as any, 'getClient').mockReturnValue(mockClient);
 | 
					            vi.spyOn(service as any, 'getClient').mockReturnValue(mockClient);
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            await expect(service.generateChatCompletion(messages)).rejects.toThrow(
 | 
					            await expect(service.generateChatCompletion(messages)).rejects.toThrow(
 | 
				
			||||||
                'API Error: Invalid API key'
 | 
					                'API Error: Invalid API key'
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
@ -222,7 +222,7 @@ describe('OpenAIService', () => {
 | 
				
			|||||||
                    parameters: {}
 | 
					                    parameters: {}
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }];
 | 
					            }];
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            const mockOptions = {
 | 
					            const mockOptions = {
 | 
				
			||||||
                apiKey: 'test-key',
 | 
					                apiKey: 'test-key',
 | 
				
			||||||
                baseUrl: 'https://api.openai.com/v1',
 | 
					                baseUrl: 'https://api.openai.com/v1',
 | 
				
			||||||
@ -233,7 +233,7 @@ describe('OpenAIService', () => {
 | 
				
			|||||||
                tool_choice: 'auto'
 | 
					                tool_choice: 'auto'
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
            vi.mocked(providers.getOpenAIOptions).mockReturnValueOnce(mockOptions);
 | 
					            vi.mocked(providers.getOpenAIOptions).mockReturnValueOnce(mockOptions);
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            const mockCompletion = {
 | 
					            const mockCompletion = {
 | 
				
			||||||
                id: 'chatcmpl-123',
 | 
					                id: 'chatcmpl-123',
 | 
				
			||||||
                object: 'chat.completion',
 | 
					                object: 'chat.completion',
 | 
				
			||||||
@ -263,9 +263,9 @@ describe('OpenAIService', () => {
 | 
				
			|||||||
            };
 | 
					            };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            vi.spyOn(service as any, 'getClient').mockReturnValue(mockClient);
 | 
					            vi.spyOn(service as any, 'getClient').mockReturnValue(mockClient);
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            await service.generateChatCompletion(messages);
 | 
					            await service.generateChatCompletion(messages);
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            const createCall = mockClient.chat.completions.create.mock.calls[0][0];
 | 
					            const createCall = mockClient.chat.completions.create.mock.calls[0][0];
 | 
				
			||||||
            expect(createCall.tools).toEqual(mockTools);
 | 
					            expect(createCall.tools).toEqual(mockTools);
 | 
				
			||||||
            expect(createCall.tool_choice).toBe('auto');
 | 
					            expect(createCall.tool_choice).toBe('auto');
 | 
				
			||||||
@ -281,7 +281,7 @@ describe('OpenAIService', () => {
 | 
				
			|||||||
                tools: [{ type: 'function' as const, function: { name: 'test', description: 'test' } }]
 | 
					                tools: [{ type: 'function' as const, function: { name: 'test', description: 'test' } }]
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
            vi.mocked(providers.getOpenAIOptions).mockReturnValueOnce(mockOptions);
 | 
					            vi.mocked(providers.getOpenAIOptions).mockReturnValueOnce(mockOptions);
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            const mockCompletion = {
 | 
					            const mockCompletion = {
 | 
				
			||||||
                id: 'chatcmpl-123',
 | 
					                id: 'chatcmpl-123',
 | 
				
			||||||
                object: 'chat.completion',
 | 
					                object: 'chat.completion',
 | 
				
			||||||
@ -319,9 +319,9 @@ describe('OpenAIService', () => {
 | 
				
			|||||||
            };
 | 
					            };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            vi.spyOn(service as any, 'getClient').mockReturnValue(mockClient);
 | 
					            vi.spyOn(service as any, 'getClient').mockReturnValue(mockClient);
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            const result = await service.generateChatCompletion(messages);
 | 
					            const result = await service.generateChatCompletion(messages);
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
            expect(result).toEqual({
 | 
					            expect(result).toEqual({
 | 
				
			||||||
                text: '',
 | 
					                text: '',
 | 
				
			||||||
                model: 'gpt-3.5-turbo',
 | 
					                model: 'gpt-3.5-turbo',
 | 
				
			||||||
@ -342,4 +342,4 @@ describe('OpenAIService', () => {
 | 
				
			|||||||
            });
 | 
					            });
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user