From 85828371a616c52f52164ff24a01c91343a67ffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Sun, 21 Jun 2026 01:02:44 +0200 Subject: [PATCH] test(insights): stub briefing illness/cycle context in generate route test The v1.18.11 briefing now folds illness-episode and cycle state into the prompt via buildBriefingIllnessCycleContext, which resolves module gates through memoizePerRequest and queries cycleProfile. The generate route test mocks neither getEvent nor the cycle/illness models, so every case threw once the new call path ran. Stub the context module to no output and add the getEvent export to the logging-context mock so these cases stay scoped to the provider and cache behaviour they assert. --- .../api/insights/generate/__tests__/route.test.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/app/api/insights/generate/__tests__/route.test.ts b/src/app/api/insights/generate/__tests__/route.test.ts index ff58846b8..355250d4a 100644 --- a/src/app/api/insights/generate/__tests__/route.test.ts +++ b/src/app/api/insights/generate/__tests__/route.test.ts @@ -103,6 +103,20 @@ vi.mock("@/lib/insights/comprehensive-generate", () => ({ vi.mock("@/lib/logging/context", () => ({ annotate: vi.fn(), + // The briefing illness/cycle context resolves module gates through + // `memoizePerRequest`, which reads the active wide-event via `getEvent`. + // Returning no event makes the per-request cache fall through to the + // factory, exercising the real gate path without a request scope. + getEvent: vi.fn(() => undefined), +})); + +// The briefing's illness/cycle context (v1.18.11 P5) is module-gated and +// server-authoritative with its own gate tests; these cases exercise the +// provider/cache path, so stub it to no context to keep the route isolated +// from the cycle/illness DB queries. +vi.mock("@/lib/insights/illness-cycle-briefing", () => ({ + buildBriefingIllnessCycleContext: vi.fn(async () => null), + buildBriefingIllnessCyclePrompt: vi.fn(() => ""), })); vi.mock("@/lib/insights/features", async () => {