From 27b57db3ea341deaf1c2fbbf123b1be435e4bf74 Mon Sep 17 00:00:00 2001 From: senke Date: Mon, 27 Apr 2026 14:24:42 +0200 Subject: [PATCH] fix(test): exclude Invalid Date from fc.date arbitrary in validation property test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CI run 461 (frontend ci.yml) hit a true property-test flake: FAIL src/schemas/__tests__/validation.property.test.ts > property: isoDateSchema > accepts valid ISO 8601 datetime strings RangeError: Invalid time value at MapArbitrary.mapper validation.property.test.ts:73:12 (d) => d.toISOString() `fc.date({ min, max })` from fast-check can occasionally generate the `new Date(NaN)` sentinel ("Invalid Date") even with min/max bounds. The .map((d) => d.toISOString()) step then throws RangeError, failing the property and the whole vitest run. Fast-check 3.13+ exposes `noInvalidDate: true` as a generator option that skips the NaN-Date sentinel; we're on 4.7, so the option is available. Adding it makes the arbitrary deterministic-ish and removes the flake. Verified locally — 39/39 property tests pass repeatedly. SKIP_TESTS=1 — single-file test fix already verified by hand. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../__tests__/validation.property.test.ts | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/apps/web/src/schemas/__tests__/validation.property.test.ts b/apps/web/src/schemas/__tests__/validation.property.test.ts index 06cef929d..44cc99a56 100644 --- a/apps/web/src/schemas/__tests__/validation.property.test.ts +++ b/apps/web/src/schemas/__tests__/validation.property.test.ts @@ -68,10 +68,24 @@ function safeChatContent(min: number, max: number) { /** Arbitrary that generates valid UUIDs */ const validUuid = fc.uuid(); -/** Arbitrary that generates valid ISO 8601 datetime strings */ -const validIsoDate = fc.date({ min: new Date('2000-01-01'), max: new Date('2099-12-31') }).map( - (d) => d.toISOString(), -); +/** + * Arbitrary that generates valid ISO 8601 datetime strings. + * + * `noInvalidDate: true` excludes the `new Date(NaN)` "Invalid Date" + * sentinel that fast-check's `fc.date()` would otherwise produce + * occasionally. Without it, a sporadic CI run hits + * RangeError: Invalid time value + * inside `.toISOString()` and fails the whole property suite — a + * non-deterministic flake that has nothing to do with the property + * being asserted. + */ +const validIsoDate = fc + .date({ + min: new Date('2000-01-01'), + max: new Date('2099-12-31'), + noInvalidDate: true, + }) + .map((d) => d.toISOString()); /** Arbitrary that generates valid email-shaped strings */ const validEmail = fc