From 8fac38a0b7fb5103f8888989a51d08a91979bd58 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 2 Nov 2026 09:34:51 -0600 Subject: [PATCH] fix(aggregator): reject impossible generatedAt in AA/DNS gates via isIsoDate (#3441) --- pm-stack/aggregator/src/aa.ts | 8 +++----- pm-stack/aggregator/src/dns.ts | 4 ++-- pm-stack/aggregator/test/aa-gate-2415.test.ts | 8 ++++++++ pm-stack/aggregator/test/aa.test.ts | 7 +++++++ pm-stack/aggregator/test/slice3.test.ts | 9 +++++++++ 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/pm-stack/aggregator/src/aa.ts b/pm-stack/aggregator/src/aa.ts index e691fb03d0..c00b0c8f0b 100644 --- a/pm-stack/aggregator/src/aa.ts +++ b/pm-stack/aggregator/src/aa.ts @@ -21,6 +21,7 @@ import type { AaTestRun, AaThreshold, } from "./model.ts"; +import { isIsoDate } from "./validate.ts"; // --- scalar coercion --------------------------------------------------------- // The Supabase Management API serializes numeric columns as JSON @@ -1097,13 +1098,10 @@ export function isAaSection(v: unknown): v is AaFeedSection { if (typeof v !== "object" || v === null) return false; const s = v as Partial & Partial; if (s.status === "absent") - return ( - typeof s.reason === "string" && typeof s.generatedAt === "string" && Number.isFinite(Date.parse(s.generatedAt)) - ); + return typeof s.reason === "string" && isIsoDate(s.generatedAt); if (s.status !== "ok") return false; return ( - typeof s.generatedAt === "string" && - Number.isFinite(Date.parse(s.generatedAt)) && + isIsoDate(s.generatedAt) && typeof s.batch === "string" && Array.isArray(s.rankings) && s.rankings.length > 0 && diff --git a/pm-stack/aggregator/src/dns.ts b/pm-stack/aggregator/src/dns.ts index 1c4e4fd7e2..4f4e38f620 100644 --- a/pm-stack/aggregator/src/dns.ts +++ b/pm-stack/aggregator/src/dns.ts @@ -8,6 +8,7 @@ // not the competitor. import { addDaysYmd, chicagoYmd } from "./derive.ts"; import type { DnsEntry, DnsSection } from "./model.ts"; +import { isIsoDate } from "./validate.ts"; /** Classification from the register's "Plan / status" cell. */ export function classifyDnsStatus(plan: string): DnsEntry["status"] { @@ -75,8 +76,7 @@ export function isDnsSection(v: unknown): v is DnsSection { if (typeof v !== "object" || v === null) return false; const s = v as Partial; return ( - typeof s.generatedAt === "string" && - Number.isFinite(Date.parse(s.generatedAt)) && + isIsoDate(s.generatedAt) && // totalAnnualListUsd is dereferenced with .toFixed on the /dns and // usage render paths, so the gate must guarantee a finite number // (#2412) — a missing/string/null/NaN total certifies a section the diff --git a/pm-stack/aggregator/test/aa-gate-2415.test.ts b/pm-stack/aggregator/test/aa-gate-2415.test.ts index 9d6816e6ac..25aac021d1 100644 --- a/pm-stack/aggregator/test/aa-gate-2415.test.ts +++ b/pm-stack/aggregator/test/aa-gate-2415.test.ts @@ -86,4 +86,12 @@ describe("isAaSection gate depth (#2415)", () => { undefDate.testRuns = [{ testRunKey: "run-1" }]; expect(isAaSection(undefDate)).toBe(false); }); + + test("rejects impossible generatedAt dates Date.parse rolls over (#3441)", () => { + for (const generatedAt of ["2026-02-30T00:00:00Z", "2026-02-29T00:00:00Z", "2026-04-31T00:00:00Z"]) { + const s = completeSection(); + s.generatedAt = generatedAt; + expect(isAaSection(s)).toBe(false); + } + }); }); diff --git a/pm-stack/aggregator/test/aa.test.ts b/pm-stack/aggregator/test/aa.test.ts index 339e8f71c5..a3da27e962 100644 --- a/pm-stack/aggregator/test/aa.test.ts +++ b/pm-stack/aggregator/test/aa.test.ts @@ -294,6 +294,13 @@ describe("payload assembly + section shape", () => { expect(isAaSection({ generatedAt: "x", batch: "y", rankings: [] })).toBe(false); }); + test("isAaSection rejects the absent form with impossible generatedAt dates (#3441)", () => { + expect(isAaSection(aaAbsent("Supabase unreachable", "2026-10-26T18:05:00Z"))).toBe(true); + for (const generatedAt of ["2026-02-30T00:00:00Z", "2026-02-29T00:00:00Z", "2026-04-31T00:00:00Z"]) { + expect(isAaSection(aaAbsent("Supabase unreachable", generatedAt))).toBe(false); + } + }); + test("summarizeAa: usable-up-to + snapshot vintage", () => { const summary = summarizeAa(FIXTURE_AA); const lunaKey = FIXTURE_AA.testRuns[0].testRunKey; diff --git a/pm-stack/aggregator/test/slice3.test.ts b/pm-stack/aggregator/test/slice3.test.ts index 508d095914..e02836473a 100644 --- a/pm-stack/aggregator/test/slice3.test.ts +++ b/pm-stack/aggregator/test/slice3.test.ts @@ -162,6 +162,15 @@ describe("dns register parser", () => { expect(isDnsSection(withStatus("unused"))).toBe(true); }); + test("isDnsSection rejects impossible generatedAt dates Date.parse rolls over (#3441)", () => { + const good = dnsSectionFromRegister(REGISTER_MD, "2026-10-25T00:00:00Z", "test"); + expect(good).not.toBeNull(); + expect(isDnsSection(good)).toBe(true); + for (const generatedAt of ["2026-02-30T00:00:00Z", "2026-02-29T00:00:00Z", "2026-04-31T00:00:00Z"]) { + expect(isDnsSection({ ...good, generatedAt })).toBe(false); + } + }); + }); // --- Identity registry (#906 §3) ---------------------------------------------