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