// tests/ollama_provider_reasoning.test.mjs import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; let originalFetch; let originalEnv; beforeEach(() => { originalFetch = globalThis.fetch; // shallow clone is fine for test mutations originalEnv = { ...process.env }; }); afterEach(() => { globalThis.fetch = originalFetch; process.env = originalEnv; }); describe('OllamaProvider reasoning flag', () => { it('adds options.reasoning=true when OLLAMA_REASONING is enabled', async () => { // Arrange env *before* importing the module (ENABLE_REASONING is computed at import time) process.env.OLLAMA_REASONING = 'true'; process.env.OLLAMA_URL = 'http://ollama.local'; process.env.GENERATOR_MODEL = 'test-model'; const fetchMock = vi.fn(async () => ({ ok: true, json: async () => ({ response: 'ok' }), })); globalThis.fetch = fetchMock; // Dynamic import so env is read fresh for this test const { OllamaProvider } = await import( '../src/providers/ollama_provider.mjs' ); const provider = new OllamaProvider({ model: 'test-model' }); // Act await provider.generate('Hello, world'); // Assert expect(fetchMock).toHaveBeenCalledTimes(1); const [url, options] = fetchMock.mock.calls[0]; expect(url).toMatch(/\/api\/generate$/); const body = JSON.parse(options.body); expect(body).toHaveProperty('model', 'test-model'); expect(body).toHaveProperty('prompt'); expect(body).toHaveProperty('options'); expect(body.options).toHaveProperty('reasoning', true); }); });