/** * CLI Command Integration Tests */ import { OllamaClient, ConversationManager } from '@fsfalmansour/neohub-core'; // Mock @fsfalmansour/neohub-core jest.mock('@fsfalmansour/neohub-core'); const mockOllamaClient = OllamaClient as jest.MockedClass; const mockConversationManager = ConversationManager as jest.MockedClass< typeof ConversationManager >; describe('CLI Command Integration', () => { describe('OllamaClient Integration', () => { let mockOllama: jest.Mocked; beforeEach(() => { jest.clearAllMocks(); mockOllama = { healthCheck: jest.fn().mockResolvedValue(true), getConfig: jest.fn().mockReturnValue({ baseUrl: 'http://localhost:11434', model: 'deepseek-coder:33b', timeout: 60000, }), chat: jest.fn().mockResolvedValue({ message: { content: 'AI response' }, }), setModel: jest.fn(), complete: jest.fn().mockResolvedValue('completion result'), listModels: jest.fn().mockResolvedValue({ models: [ { name: 'deepseek-coder:33b', size: 19000000000 }, { name: 'codellama:34b', size: 20000000000 }, ], }), } as any; mockOllamaClient.mockImplementation(() => mockOllama); }); it('should check Ollama health', async () => { const client = new OllamaClient({ baseUrl: 'http://localhost:11434' }); const isHealthy = await client.healthCheck(); expect(isHealthy).toBe(true); }); it('should get model configuration', () => { const client = new OllamaClient({ baseUrl: 'http://localhost:11434' }); const config = client.getConfig(); expect(config.model).toBe('deepseek-coder:33b'); }); it('should list available models', async () => { const client = new OllamaClient({ baseUrl: 'http://localhost:11434' }); const response = await client.listModels(); expect(response.models).toHaveLength(2); expect(response.models[0].name).toBe('deepseek-coder:33b'); }); it('should send chat messages', async () => { const client = new OllamaClient({ baseUrl: 'http://localhost:11434' }); const response = await client.chat([ { role: 'user', content: 'Hello' }, ] as any); expect(response.message.content).toBe('AI response'); }); it('should complete prompts', async () => { const client = new OllamaClient({ baseUrl: 'http://localhost:11434' }); const result = await client.complete('test prompt', {}); expect(result).toBe('completion result'); }); it('should change model', () => { const client = new OllamaClient({ baseUrl: 'http://localhost:11434' }); client.setModel('codellama:34b'); expect(client.setModel).toHaveBeenCalledWith('codellama:34b'); }); }); describe('ConversationManager Integration', () => { let mockConversation: jest.Mocked; beforeEach(() => { jest.clearAllMocks(); mockConversation = { addUserMessage: jest.fn(), addAssistantMessage: jest.fn(), getMessages: jest.fn().mockReturnValue([]), clear: jest.fn(), getHistory: jest.fn().mockReturnValue([]), export: jest.fn().mockReturnValue('exported-data'), } as any; mockConversationManager.mockImplementation(() => mockConversation); }); it('should add user messages', () => { const manager = new ConversationManager(); manager.addUserMessage('Hello'); expect(manager.addUserMessage).toHaveBeenCalledWith('Hello'); }); it('should add assistant messages', () => { const manager = new ConversationManager(); manager.addAssistantMessage('Hi'); expect(manager.addAssistantMessage).toHaveBeenCalledWith('Hi'); }); it('should get message list', () => { const manager = new ConversationManager(); const messages = manager.getMessages(); expect(Array.isArray(messages)).toBe(true); }); it('should clear conversation', () => { const manager = new ConversationManager(); manager.clear(); expect(manager.clear).toHaveBeenCalled(); }); it('should export conversation', () => { const manager = new ConversationManager(); const exported = manager.export(); expect(exported).toBe('exported-data'); }); it('should get conversation history', () => { const manager = new ConversationManager(); const history = manager.getHistory(); expect(Array.isArray(history)).toBe(true); }); }); });