From 40cf10ba20e1fd33393f70b5d4643da29efe8e90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Tue, 20 Oct 2026 06:06:25 +0200 Subject: [PATCH] test: bring fixtures in line with the nap rule and the recovery read Correlation fixtures wrote minute-long midday sleeps, which the nap rule now reads as naps; they write nights. The analytics test mocks the user read the empty recovery reason makes, and the control-byte guard asserts the size of its sweep. --- src/__tests__/api/analytics/since-cap.test.ts | 2 ++ src/__tests__/no-control-bytes-guard.test.ts | 2 ++ src/lib/ai/coach/__tests__/correlations-read.test.ts | 10 ++++++---- src/lib/clinician-share/__tests__/exif-strip.test.ts | 5 ++++- .../derived/__tests__/derived-assessment.test.ts | 1 + 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/__tests__/api/analytics/since-cap.test.ts b/src/__tests__/api/analytics/since-cap.test.ts index 221f1342e..f38bf6bc9 100644 --- a/src/__tests__/api/analytics/since-cap.test.ts +++ b/src/__tests__/api/analytics/since-cap.test.ts @@ -35,6 +35,8 @@ import { describe, it, expect, vi, beforeEach } from "vitest"; vi.mock("@/lib/db", () => ({ prisma: { measurement: { findMany: vi.fn() }, + // The empty recovery page reads the Oura fields for its reason. + user: { findUnique: vi.fn().mockResolvedValue(null) }, }, })); diff --git a/src/__tests__/no-control-bytes-guard.test.ts b/src/__tests__/no-control-bytes-guard.test.ts index 25982880d..aefe05080 100644 --- a/src/__tests__/no-control-bytes-guard.test.ts +++ b/src/__tests__/no-control-bytes-guard.test.ts @@ -24,6 +24,8 @@ describe("source files carry no raw control bytes", () => { floor: 3000, extensions: [".ts", ".tsx", ".js", ".mjs", ".css", ".json", ".md"], }).filter((file) => !file.startsWith("generated/")); + // A sweep that read nothing would agree with any tree. + expect(files.length).toBeGreaterThan(3000); const offenders: string[] = []; for (const file of files) { const lines = readFileSync(join(src, file), "utf8").split("\n"); diff --git a/src/lib/ai/coach/__tests__/correlations-read.test.ts b/src/lib/ai/coach/__tests__/correlations-read.test.ts index 153f4db6b..ea621035c 100644 --- a/src/lib/ai/coach/__tests__/correlations-read.test.ts +++ b/src/lib/ai/coach/__tests__/correlations-read.test.ts @@ -250,8 +250,9 @@ describe("readCoachCorrelations", () => { // Next-day sleep falls as today's burden rises (8h baseline − burden). measurements.push({ type: "SLEEP_DURATION", - value: 8 - burden, - measuredAt: new Date(base + (i + 1) * 86_400_000), + // A night of hours waking at 07:00, not a midday minute-long nap. + value: (8 - burden) * 60, + measuredAt: new Date(base + (i + 1) * 86_400_000 - 5 * 3_600_000), }); } @@ -346,8 +347,9 @@ describe("readCoachCorrelations", () => { // Higher pressure today → shorter sleep tomorrow (a clean negative r). measurements.push({ type: "SLEEP_DURATION", - value: 8 - swing * 0.5, - measuredAt: new Date(base + (i + 1) * 86_400_000), + // A night of hours waking at 07:00, not a midday minute-long nap. + value: (8 - swing * 0.5) * 60, + measuredAt: new Date(base + (i + 1) * 86_400_000 - 5 * 3_600_000), }); } diff --git a/src/lib/clinician-share/__tests__/exif-strip.test.ts b/src/lib/clinician-share/__tests__/exif-strip.test.ts index e03a86e21..f20f38f52 100644 --- a/src/lib/clinician-share/__tests__/exif-strip.test.ts +++ b/src/lib/clinician-share/__tests__/exif-strip.test.ts @@ -53,7 +53,10 @@ describe("stripImageMetadata — passthrough", () => { describe("stripImageMetadata — JPEG", () => { // SOI + APP0(JFIF) + APP1(Exif w/ GPS) + APP2(ICC) + COM + DQT + SOS + scan. const soi = Buffer.from([0xff, 0xd8]); - const app0 = jpegSegment(0xe0, Buffer.from("JFIF\0\x01\x01\0\0\x01\0\x01\0\0")); + const app0 = jpegSegment( + 0xe0, + Buffer.from("JFIF\0\x01\x01\0\0\x01\0\x01\0\0"), + ); const exifPayload = Buffer.concat([ Buffer.from("Exif\0\0"), // A recognisable GPS marker string we can assert is gone. diff --git a/src/lib/insights/derived/__tests__/derived-assessment.test.ts b/src/lib/insights/derived/__tests__/derived-assessment.test.ts index 317551cb2..cd8d00ebf 100644 --- a/src/lib/insights/derived/__tests__/derived-assessment.test.ts +++ b/src/lib/insights/derived/__tests__/derived-assessment.test.ts @@ -76,6 +76,7 @@ const sleepScore: SleepScoreValue = { ], windowNights: 20, rhythmNights: 20, + rhythmMinNights: 3, series: [78, 82], };