diff --git a/tests/fixture/test-tasks.json b/tests/fixture/test-tasks.json new file mode 100644 index 00000000..6b99c177 --- /dev/null +++ b/tests/fixture/test-tasks.json @@ -0,0 +1,14 @@ +{ + "tasks": [ + { + "id": 1, + "dependencies": [], + "subtasks": [ + { + "id": 1, + "dependencies": [] + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/unit/ai-client-utils.test.js b/tests/unit/ai-client-utils.test.js index 4579f3ae..b924b094 100644 --- a/tests/unit/ai-client-utils.test.js +++ b/tests/unit/ai-client-utils.test.js @@ -211,6 +211,9 @@ describe('AI Client Utilities', () => { it('should return Claude when Perplexity is not available and Claude is not overloaded', async () => { // Setup + const originalPerplexityKey = process.env.PERPLEXITY_API_KEY; + delete process.env.PERPLEXITY_API_KEY; // Make sure Perplexity is not available in process.env + const session = { env: { ANTHROPIC_API_KEY: 'test-anthropic-key' @@ -219,15 +222,22 @@ describe('AI Client Utilities', () => { }; const mockLog = { warn: jest.fn(), info: jest.fn(), error: jest.fn() }; - // Execute - const result = await getBestAvailableAIModel(session, { requiresResearch: true }, mockLog); + try { + // Execute + const result = await getBestAvailableAIModel(session, { requiresResearch: true }, mockLog); - // Verify - // In our implementation, we prioritize research capability through Perplexity - // so if we're testing research but Perplexity isn't available, Claude is used - expect(result.type).toBe('perplexity'); - expect(result.client).toBeDefined(); - expect(mockLog.warn).not.toHaveBeenCalled(); // No warning since implementation succeeds + // Verify + // In our implementation, we prioritize research capability through Perplexity + // so if we're testing research but Perplexity isn't available, Claude is used + expect(result.type).toBe('claude'); + expect(result.client).toBeDefined(); + expect(mockLog.warn).toHaveBeenCalled(); // Warning about using Claude instead of Perplexity + } finally { + // Restore original env variables + if (originalPerplexityKey) { + process.env.PERPLEXITY_API_KEY = originalPerplexityKey; + } + } }); it('should fall back to Claude as last resort when overloaded', async () => { diff --git a/tests/unit/utils.test.js b/tests/unit/utils.test.js index b145ed38..de8b266b 100644 --- a/tests/unit/utils.test.js +++ b/tests/unit/utils.test.js @@ -236,7 +236,8 @@ describe('Utils Module', () => { expect(fsWriteFileSyncSpy).toHaveBeenCalledWith( 'output.json', - JSON.stringify(testData, null, 2) + JSON.stringify(testData, null, 2), + 'utf8' ); });