From bd00595ded0923902c874705ef668e966405f684 Mon Sep 17 00:00:00 2001 From: Giancarmine Salucci Date: Tue, 12 May 2026 22:13:20 +0200 Subject: [PATCH] fix(test): mock $env/dynamic/private in llm-logging spec Tests passed locally because .env provided OPENAI_BASE_URL and OPENAI_API_KEY. In the Docker build stage there is no .env, so createLLM() threw 'OPENAI_BASE_URL environment variable is not set' before the mocked OpenAI client ever ran, causing 3 test failures. Add vi.mock('$env/dynamic/private', ...) with stub values so the tests are self-contained and environment-independent. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/tests/llm-logging.spec.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/tests/llm-logging.spec.ts b/src/tests/llm-logging.spec.ts index e71c1d2..0bfc0f9 100644 --- a/src/tests/llm-logging.spec.ts +++ b/src/tests/llm-logging.spec.ts @@ -13,6 +13,16 @@ vi.mock('openai', () => ({ } })); +// Mock env so tests pass in environments without .env (e.g. Docker CI builds) +vi.mock('$env/dynamic/private', () => ({ + env: { + OPENAI_BASE_URL: 'http://localhost:11434/v1', + OPENAI_API_KEY: 'test-key', + LLM_MODEL: 'test-model', + LLM_REQUEST_TIMEOUT_MS: undefined + } +})); + // Import AFTER mocking import { checkLLMHealth, checkModelAvailability } from '$lib/server/llm';