chore(deps): adapt most of the tests
Some checks failed
Checks / main (push) Has been cancelled

This commit is contained in:
Elian Doran 2025-11-01 19:21:57 +02:00
parent fa30bfc04b
commit 35f244cf50
No known key found for this signature in database
7 changed files with 77 additions and 71 deletions

View File

@ -52,9 +52,9 @@ vi.mock("../../services/llm/ai_service_manager.js", () => ({
// Mock chat pipeline // Mock chat pipeline
const mockChatPipelineExecute = vi.fn(); const mockChatPipelineExecute = vi.fn();
const MockChatPipeline = vi.fn().mockImplementation(() => ({ const MockChatPipeline = vi.fn().mockImplementation(function () {
execute: mockChatPipelineExecute this.execute = mockChatPipelineExecute;
})); });
vi.mock("../../services/llm/pipeline/chat_pipeline.js", () => ({ vi.mock("../../services/llm/pipeline/chat_pipeline.js", () => ({
ChatPipeline: MockChatPipeline ChatPipeline: MockChatPipeline
})); }));

View File

@ -35,24 +35,24 @@ vi.mock('../log.js', () => ({
})); }));
vi.mock('./providers/anthropic_service.js', () => ({ vi.mock('./providers/anthropic_service.js', () => ({
AnthropicService: vi.fn().mockImplementation(() => ({ AnthropicService: vi.fn().mockImplementation(function () {
isAvailable: vi.fn().mockReturnValue(true), this.isAvailable = vi.fn().mockReturnValue(true);
generateChatCompletion: vi.fn() this.generateChatCompletion = vi.fn();
})) })
})); }));
vi.mock('./providers/openai_service.js', () => ({ vi.mock('./providers/openai_service.js', () => ({
OpenAIService: vi.fn().mockImplementation(() => ({ OpenAIService: vi.fn().mockImplementation(function () {
isAvailable: vi.fn().mockReturnValue(true), this.isAvailable = vi.fn().mockReturnValue(true);
generateChatCompletion: vi.fn() this.generateChatCompletion = vi.fn();
})) };
})); }));
vi.mock('./providers/ollama_service.js', () => ({ vi.mock('./providers/ollama_service.js', () => ({
OllamaService: vi.fn().mockImplementation(() => ({ OllamaService: vi.fn().mockImplementation(function () {
isAvailable: vi.fn().mockReturnValue(true), this.isAvailable = vi.fn().mockReturnValue(true);
generateChatCompletion: vi.fn() this.generateChatCompletion = vi.fn();
})) })
})); }));
vi.mock('./config/configuration_helpers.js', () => ({ vi.mock('./config/configuration_helpers.js', () => ({
@ -65,7 +65,7 @@ vi.mock('./config/configuration_helpers.js', () => ({
})); }));
vi.mock('./context/index.js', () => ({ vi.mock('./context/index.js', () => ({
ContextExtractor: vi.fn().mockImplementation(() => ({})) ContextExtractor: vi.fn().mockImplementation(function () {})
})); }));
vi.mock('./context_extractors/index.js', () => ({ vi.mock('./context_extractors/index.js', () => ({

View File

@ -39,9 +39,9 @@ vi.mock('../pipeline/chat_pipeline.js', () => ({
})); }));
vi.mock('./handlers/tool_handler.js', () => ({ vi.mock('./handlers/tool_handler.js', () => ({
ToolHandler: vi.fn().mockImplementation(() => ({ ToolHandler: vi.fn().mockImplementation(function () {
handleToolCalls: vi.fn() this.handleToolCalls = vi.fn()
})) })
})); }));
vi.mock('../chat_storage_service.js', () => ({ vi.mock('../chat_storage_service.js', () => ({

View File

@ -36,20 +36,22 @@ vi.mock('./constants/llm_prompt_constants.js', () => ({
})); }));
vi.mock('./pipeline/chat_pipeline.js', () => ({ vi.mock('./pipeline/chat_pipeline.js', () => ({
ChatPipeline: vi.fn().mockImplementation((config) => ({ ChatPipeline: vi.fn().mockImplementation(function (config) {
config, Object.assign(this, {
execute: vi.fn(), config,
getMetrics: vi.fn(), execute: vi.fn(),
resetMetrics: vi.fn(), getMetrics: vi.fn(),
stages: { resetMetrics: vi.fn(),
contextExtraction: { stages: {
execute: vi.fn() contextExtraction: {
}, execute: vi.fn()
semanticContextExtraction: { },
execute: vi.fn() semanticContextExtraction: {
execute: vi.fn()
}
} }
} });
})) });
})); }));
vi.mock('./ai_service_manager.js', () => ({ vi.mock('./ai_service_manager.js', () => ({
@ -67,12 +69,12 @@ describe('ChatService', () => {
beforeEach(async () => { beforeEach(async () => {
vi.clearAllMocks(); vi.clearAllMocks();
// Get mocked modules // Get mocked modules
mockChatStorageService = (await import('./chat_storage_service.js')).default; mockChatStorageService = (await import('./chat_storage_service.js')).default;
mockAiServiceManager = (await import('./ai_service_manager.js')).default; mockAiServiceManager = (await import('./ai_service_manager.js')).default;
mockLog = (await import('../log.js')).default; mockLog = (await import('../log.js')).default;
// Setup pipeline mock // Setup pipeline mock
mockChatPipeline = { mockChatPipeline = {
execute: vi.fn(), execute: vi.fn(),
@ -87,10 +89,10 @@ describe('ChatService', () => {
} }
} }
}; };
// Create a new ChatService instance // Create a new ChatService instance
chatService = new ChatService(); chatService = new ChatService();
// Replace the internal pipelines with our mock // Replace the internal pipelines with our mock
(chatService as any).pipelines.set('default', mockChatPipeline); (chatService as any).pipelines.set('default', mockChatPipeline);
(chatService as any).pipelines.set('agent', mockChatPipeline); (chatService as any).pipelines.set('agent', mockChatPipeline);
@ -228,7 +230,7 @@ describe('ChatService', () => {
it('should create new session if not found', async () => { it('should create new session if not found', async () => {
mockChatStorageService.getChat.mockResolvedValueOnce(null); mockChatStorageService.getChat.mockResolvedValueOnce(null);
const mockNewChat = { const mockNewChat = {
id: 'chat-new', id: 'chat-new',
title: 'New Chat', title: 'New Chat',
@ -301,7 +303,7 @@ describe('ChatService', () => {
mockChatStorageService.getChat.mockResolvedValue(mockChat); mockChatStorageService.getChat.mockResolvedValue(mockChat);
mockChatStorageService.updateChat.mockResolvedValue(mockChat); mockChatStorageService.updateChat.mockResolvedValue(mockChat);
mockChatPipeline.execute.mockResolvedValue({ mockChatPipeline.execute.mockResolvedValue({
text: 'Hello! How can I help you?', text: 'Hello! How can I help you?',
model: 'gpt-3.5-turbo', model: 'gpt-3.5-turbo',
@ -435,7 +437,7 @@ describe('ChatService', () => {
mockChatStorageService.getChat.mockResolvedValue(mockChat); mockChatStorageService.getChat.mockResolvedValue(mockChat);
mockChatStorageService.updateChat.mockResolvedValue(mockChat); mockChatStorageService.updateChat.mockResolvedValue(mockChat);
mockChatPipeline.execute.mockResolvedValue({ mockChatPipeline.execute.mockResolvedValue({
text: 'Based on the context, here is my response.', text: 'Based on the context, here is my response.',
model: 'gpt-4', model: 'gpt-4',
@ -841,7 +843,7 @@ describe('ChatService', () => {
it('should return default title for empty or invalid messages', () => { it('should return default title for empty or invalid messages', () => {
const generateTitle = (chatService as any).generateTitleFromMessages.bind(chatService); const generateTitle = (chatService as any).generateTitleFromMessages.bind(chatService);
expect(generateTitle([])).toBe('New Chat'); expect(generateTitle([])).toBe('New Chat');
expect(generateTitle([{ role: 'assistant', content: 'Hello' }])).toBe('New Chat'); expect(generateTitle([{ role: 'assistant', content: 'Hello' }])).toBe('New Chat');
}); });
@ -858,4 +860,4 @@ describe('ChatService', () => {
expect(title).toBe('First line'); expect(title).toBe('First line');
}); });
}); });
}); });

View File

@ -47,9 +47,9 @@ vi.mock('../../ai_service_manager.js', () => ({
})); }));
vi.mock('../index.js', () => ({ vi.mock('../index.js', () => ({
ContextExtractor: vi.fn().mockImplementation(() => ({ ContextExtractor: vi.fn().mockImplementation(function () {
findRelevantNotes: vi.fn().mockResolvedValue([]) this.findRelevantNotes = vi.fn().mockResolvedValue([])
})) });
})); }));
describe('ContextService', () => { describe('ContextService', () => {
@ -59,7 +59,7 @@ describe('ContextService', () => {
beforeEach(() => { beforeEach(() => {
vi.clearAllMocks(); vi.clearAllMocks();
service = new ContextService(); service = new ContextService();
mockLLMService = { mockLLMService = {
generateChatCompletion: vi.fn().mockResolvedValue({ generateChatCompletion: vi.fn().mockResolvedValue({
content: 'Mock LLM response', content: 'Mock LLM response',
@ -84,7 +84,7 @@ describe('ContextService', () => {
describe('initialize', () => { describe('initialize', () => {
it('should initialize successfully', async () => { it('should initialize successfully', async () => {
const result = await service.initialize(); const result = await service.initialize();
expect(result).toBeUndefined(); // initialize returns void expect(result).toBeUndefined(); // initialize returns void
expect((service as any).initialized).toBe(true); expect((service as any).initialized).toBe(true);
}); });
@ -92,7 +92,7 @@ describe('ContextService', () => {
it('should not initialize twice', async () => { it('should not initialize twice', async () => {
await service.initialize(); await service.initialize();
await service.initialize(); // Second call should be a no-op await service.initialize(); // Second call should be a no-op
expect((service as any).initialized).toBe(true); expect((service as any).initialized).toBe(true);
}); });
@ -102,9 +102,9 @@ describe('ContextService', () => {
service.initialize(), service.initialize(),
service.initialize() service.initialize()
]; ];
await Promise.all(promises); await Promise.all(promises);
expect((service as any).initialized).toBe(true); expect((service as any).initialized).toBe(true);
}); });
}); });
@ -186,11 +186,11 @@ describe('ContextService', () => {
describe('error handling', () => { describe('error handling', () => {
it('should handle service operations', async () => { it('should handle service operations', async () => {
await service.initialize(); await service.initialize();
// These operations should not throw // These operations should not throw
const result1 = await service.processQuery('test', mockLLMService); const result1 = await service.processQuery('test', mockLLMService);
const result2 = await service.findRelevantNotes('test', null, {}); const result2 = await service.findRelevantNotes('test', null, {});
expect(result1).toBeDefined(); expect(result1).toBeDefined();
expect(result2).toBeDefined(); expect(result2).toBeDefined();
}); });
@ -224,4 +224,4 @@ describe('ContextService', () => {
}); });
}); });
}); });
}); });

View File

@ -48,8 +48,8 @@ vi.mock('@anthropic-ai/sdk', () => {
} }
}; };
const mockAnthropic = vi.fn().mockImplementation(() => ({ const mockAnthropic = vi.fn().mockImplementation(function () {
messages: { this.messages = {
create: vi.fn().mockImplementation((params) => { create: vi.fn().mockImplementation((params) => {
if (params.stream) { if (params.stream) {
return Promise.resolve(mockStream); return Promise.resolve(mockStream);
@ -71,8 +71,8 @@ vi.mock('@anthropic-ai/sdk', () => {
} }
}); });
}) })
} };
})); });
return { default: mockAnthropic }; return { default: mockAnthropic };
}); });
@ -127,7 +127,9 @@ describe('AnthropicService', () => {
} }
}; };
AnthropicMock.mockImplementation(() => mockAnthropicInstance); AnthropicMock.mockImplementation(function () {
Object.assign(this, mockAnthropicInstance);
});
service = new AnthropicService(); service = new AnthropicService();
}); });

View File

@ -30,11 +30,11 @@ vi.mock('./providers.js', () => ({
})); }));
vi.mock('../formatters/ollama_formatter.js', () => ({ vi.mock('../formatters/ollama_formatter.js', () => ({
OllamaMessageFormatter: vi.fn().mockImplementation(() => ({ OllamaMessageFormatter: vi.fn().mockImplementation(function () {
formatMessages: vi.fn().mockReturnValue([ this.formatMessages = vi.fn().mockReturnValue([
{ role: 'user', content: 'Hello' } { role: 'user', content: 'Hello' }
]), ]);
formatResponse: vi.fn().mockReturnValue({ this.formatResponse = vi.fn().mockReturnValue({
text: 'Hello! How can I help you today?', text: 'Hello! How can I help you today?',
provider: 'Ollama', provider: 'Ollama',
model: 'llama2', model: 'llama2',
@ -44,8 +44,8 @@ vi.mock('../formatters/ollama_formatter.js', () => ({
totalTokens: 15 totalTokens: 15
}, },
tool_calls: null tool_calls: null
}) });
})) })
})); }));
vi.mock('../tools/tool_registry.js', () => ({ vi.mock('../tools/tool_registry.js', () => ({
@ -83,8 +83,8 @@ vi.mock('ollama', () => {
} }
}; };
const mockOllama = vi.fn().mockImplementation(() => ({ const mockOllama = vi.fn().mockImplementation(function () {
chat: vi.fn().mockImplementation((params) => { this.chat = vi.fn().mockImplementation((params) => {
if (params.stream) { if (params.stream) {
return Promise.resolve(mockStream); return Promise.resolve(mockStream);
} }
@ -97,8 +97,8 @@ vi.mock('ollama', () => {
model: 'llama2', model: 'llama2',
done: true done: true
}); });
}), });
show: vi.fn().mockResolvedValue({ this.show = vi.fn().mockResolvedValue({
modelfile: 'FROM llama2', modelfile: 'FROM llama2',
parameters: {}, parameters: {},
template: '', template: '',
@ -109,8 +109,8 @@ vi.mock('ollama', () => {
parameter_size: '7B', parameter_size: '7B',
quantization_level: 'Q4_0' quantization_level: 'Q4_0'
} }
}), });
list: vi.fn().mockResolvedValue({ this.list = vi.fn().mockResolvedValue({
models: [ models: [
{ {
name: 'llama2:latest', name: 'llama2:latest',
@ -119,7 +119,7 @@ vi.mock('ollama', () => {
} }
] ]
}) })
})); });
return { Ollama: mockOllama }; return { Ollama: mockOllama };
}); });
@ -196,7 +196,9 @@ describe('OllamaService', () => {
}) })
}; };
OllamaMock.mockImplementation(() => mockOllamaInstance); OllamaMock.mockImplementation(function () {
Object.assign(this, mockOllamaInstance);
});
service = new OllamaService(); service = new OllamaService();