From 6ad5eb25e92a7243d0f767a601080fada5dbdf9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Sun, 17 May 2026 14:52:22 +0200 Subject: [PATCH] test(insights): raise timeout on the 5 MB payload guard test The features-payload-too-large guard constructs a ~5.6 MB rollup payload and runs the whole serialiser pipeline to confirm the ceiling fires. Local hardware completes the assertion well inside the default 5 s budget, but the GitHub-Actions Ubuntu runners crossed it and timed out on the v1.4.36 push. Pin a 30 s budget on this single case (Vitest 4's two-arg `it(name, opts, fn)` form, the deprecated three-arg form was removed) and leave the rest of the suite on the default; the runtime is dominated by the giant allocation, so the wider window only matters for the slowest runners. --- src/lib/insights/__tests__/features.test.ts | 48 +++++++++++++-------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/src/lib/insights/__tests__/features.test.ts b/src/lib/insights/__tests__/features.test.ts index 87abb3fb0..04b52411c 100644 --- a/src/lib/insights/__tests__/features.test.ts +++ b/src/lib/insights/__tests__/features.test.ts @@ -126,26 +126,36 @@ describe("extractFeatures — v1.4.36 W3 bucketed payload", () => { expect(features.context.ageYears).toBeGreaterThan(40); }); - it("throws FeaturesPayloadTooLargeError when the serialised payload exceeds the 5 MB cap", async () => { - // Fabricate an absurdly long bucket list so the JSON dump crosses - // the ceiling. ~200 KB per series × 28 series ≈ ~5.6 MB. - const giant = new Array(200_000).fill(null).map((_, i) => ({ - bucketStart: new Date(Date.now() - i * dayMs), - count: i, - mean: i, - minValue: i, - maxValue: i, - sd: 0, - slope: 0, - r2: 0, - computedAt: new Date(), - })); - prismaMock.measurementRollup.findMany.mockResolvedValue(giant); + // Constructs a ~5.6 MB rollup payload and runs the whole serialiser + // pipeline; the slower GitHub-Actions runners cross the default 5 s + // budget. Raise this single test only — the rest of the suite stays + // on the default timeout. Vitest 4 takes the timeout as a numeric + // second argument (the old `it(name, fn, options)` signature was + // removed in v4). + it( + "throws FeaturesPayloadTooLargeError when the serialised payload exceeds the 5 MB cap", + { timeout: 30_000 }, + async () => { + // Fabricate an absurdly long bucket list so the JSON dump crosses + // the ceiling. ~200 KB per series × 28 series ≈ ~5.6 MB. + const giant = new Array(200_000).fill(null).map((_, i) => ({ + bucketStart: new Date(Date.now() - i * dayMs), + count: i, + mean: i, + minValue: i, + maxValue: i, + sd: 0, + slope: 0, + r2: 0, + computedAt: new Date(), + })); + prismaMock.measurementRollup.findMany.mockResolvedValue(giant); - await expect(extractFeatures("user-1", true)).rejects.toThrow( - FeaturesPayloadTooLargeError, - ); - }); + await expect(extractFeatures("user-1", true)).rejects.toThrow( + FeaturesPayloadTooLargeError, + ); + }, + ); it("exposes the size cap as a public constant", () => { expect(FEATURES_MAX_BYTES).toBe(5 * 1024 * 1024);