mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 20:42:43 +00:00
tests/integration/query-counter.ts counts the statements the app sends while a function runs, by wrapping Client.prototype.query on the copy of pg the Prisma adapter itself resolves (so a second pg in node_modules cannot leave it reading zero; a window with no statement throws). Background tasks are settled before the window closes, so fire-and-forget writes count with the request that started them. query-budget-hot-routes.test.ts seeds a small account (four months of the main types with overlapping sources, stats rows, sleep, glucose, a medication, workouts and mood), warms each route once, evicts the user's caches and counts the next call. Budgets, measured on this fixture: /api/auth/me 18, dashboard summary 86, dashboard snapshot 103, pulse series 30/365/3650 days 6 each, day view 48, insights health status 60, correlations 44, a 500-row batch ingest 31. A failure prints every statement grouped by text. Proof: one extra `SELECT 1` before every handler in apiHandler failed all ten budgets by exactly one (18 → 19, 86 → 87, … 31 → 32), which also shows the counts are deterministic; with the probe removed all ten pass.