Type the evaluator stubs as variadic mocks

tsc rejects spreading unknown[] into a zero-parameter vi.fn; give the
context-evaluator stubs a variadic signature and cast the recorded call
tuples where the tests read them back.
This commit is contained in:
Marc-André Bombeck committed 2026-08-14 02:07:42 +02:00
1 parent db6465c17d
commit 4e12aef5fd
4 files changed
+18 -11

No files matched your search

@@ -52,8 +52,9 @@ describe("nudge-status — NEXT_APP_OPEN hook", () => {
await (GET as unknown as () => Promise<unknown>)();
expect(evaluateContext).toHaveBeenCalledTimes(1);
const [prismaArg, userId, trigger] = evaluateContext.mock.calls[0]!;
expect((prismaArg as { __tag: string }).__tag).toBe("prisma");
const [prismaArg, userId, trigger] = evaluateContext.mock
.calls[0] as unknown as [{ __tag: string }, string, string];
expect(prismaArg.__tag).toBe("prisma");
expect(userId).toBe("u1");
expect(trigger).toBe("app-open");
// Ordering: the surfaced message must be visible to this very read.
@@ -137,9 +137,11 @@ describe("evaluateCoachContextReminders — measurement cues", () => {
"measurement",
NOW,
);
const where = prisma.coachReminder.findMany.mock.calls[0]![0]!.where as {
contextCue: { in: string[] };
};
const where = (
prisma.coachReminder.findMany.mock.calls[0] as unknown as [
{ where: { contextCue: { in: string[] } } },
]
)[0].where;
expect(where.contextCue.in).not.toContain("NEXT_APP_OPEN");
});
});
@@ -21,10 +21,12 @@ vi.mock("@/lib/ai/coach/bytes-codec", () => ({
// The context-cue backstop delegates to the shared evaluator; its own
// behaviour is pinned in `ai/coach/__tests__/context-reminders.test.ts`.
const contextEvaluateMock = vi.fn(async () => ({ surfaced: 0, errored: 0 }));
const contextEvaluateMock = vi.fn(async (..._args: unknown[]) => ({
surfaced: 0,
errored: 0,
}));
vi.mock("@/lib/ai/coach/context-reminders", () => ({
evaluateCoachContextReminders: (...args: unknown[]) =>
contextEvaluateMock(...args),
evaluateCoachContextReminders: contextEvaluateMock,
}));
import { runCoachReminderSweep } from "../coach-reminder-sweep";
@@ -21,10 +21,12 @@ vi.mock("@/lib/jobs/boss-instance", () => ({
// the Vorsorge assertions stay isolated; one test below pins that the hook
// actually fires (watched red: removing the call site in
// `runReminderSatisfyForUser` fails it).
const evaluateContextMock = vi.fn(async () => ({ surfaced: 0, errored: 0 }));
const evaluateContextMock = vi.fn(async (..._args: unknown[]) => ({
surfaced: 0,
errored: 0,
}));
vi.mock("@/lib/ai/coach/context-reminders", () => ({
evaluateCoachContextReminders: (...args: unknown[]) =>
evaluateContextMock(...args),
evaluateCoachContextReminders: evaluateContextMock,
}));
import {