From e818178be8d0c46352a254b86ae0052ca72ce09a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Fri, 26 Jun 2026 14:17:36 +0200 Subject: [PATCH] test(coach): seed the budget-refusal integration test at the user-plan cap The daily cap is now provider-aware; the seeded chain resolves to a user-egress provider, so the refusal must be seeded at USER_PLAN_CAP rather than the smaller operator cap to trip the gate. --- tests/integration/coach-chat.test.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/integration/coach-chat.test.ts b/tests/integration/coach-chat.test.ts index c0fd6c4e2..3a26d5c22 100644 --- a/tests/integration/coach-chat.test.ts +++ b/tests/integration/coach-chat.test.ts @@ -24,7 +24,7 @@ process.env.ENCRYPTION_KEY ??= import { cookieJar, headerJar } from "./mock-next-headers"; import { getPrismaClient, truncateAllTables } from "./setup"; -import { OPERATOR_COST_CAP } from "@/lib/ai/coach/budget"; +import { USER_PLAN_CAP } from "@/lib/ai/coach/budget"; vi.mock("next/headers", async () => { const { cookieJar, headerJar } = await import("./mock-next-headers"); @@ -223,11 +223,15 @@ describe("POST /api/insights/chat — integration", () => { const { userId } = await seedUserWithSession(); const prisma = getPrismaClient(); const dateKey = new Date().toISOString().slice(0, 10); + // v1.21.0 — the daily cap is now provider-aware: the seeded user resolves + // to a user-egress chain, so the applicable ceiling is USER_PLAN_CAP. Seed + // the spend at that ceiling so the reservation trips the gate. (Seeding the + // smaller operator cap would no longer refuse on this chain.) await prisma.coachUsage.create({ data: { userId, dateKey, - totalTokens: OPERATOR_COST_CAP, + totalTokens: USER_PLAN_CAP, messageCount: 50, }, }); @@ -251,7 +255,7 @@ describe("POST /api/insights/chat — integration", () => { const usage = await prisma.coachUsage.findUnique({ where: { userId_dateKey: { userId, dateKey } }, }); - expect(usage?.totalTokens).toBe(OPERATOR_COST_CAP); + expect(usage?.totalTokens).toBe(USER_PLAN_CAP); }); it("returns 404 (not 403) when conversationId belongs to another user", async () => {