From 4dfc9d56c8213b211d62d030c18ab7d6699ee650 Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Thu, 12 Nov 2026 15:21:42 -0600 Subject: [PATCH] fix(aggregator): gate pool-item updatedAt with isIsoDate (#5202) --- pm-stack/aggregator/src/projects.ts | 8 ++++++-- pm-stack/aggregator/test/projects.test.ts | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/pm-stack/aggregator/src/projects.ts b/pm-stack/aggregator/src/projects.ts index 2aa51bd1b..e9eccbee5 100644 --- a/pm-stack/aggregator/src/projects.ts +++ b/pm-stack/aggregator/src/projects.ts @@ -11,7 +11,7 @@ // the live source so the wire shape is parsed exactly once. import type { GhItem, OrchestrationSection, ProjectAudit, ProjectPoolItem, RefKey } from "./model.ts"; import { isValidRef, refKey } from "./model.ts"; -import { isRecord, isTimestampNotFuture } from "./validate.ts"; +import { isIsoDate, isRecord, isTimestampNotFuture } from "./validate.ts"; import { workItemRefSet } from "./work-items.ts"; export const PROJECT_ID = "PVT_kwDOAZNvF84Bouay"; @@ -468,7 +468,11 @@ export function isProjectPoolItem(v: unknown): v is ProjectPoolItem { (p.draft === undefined || typeof p.draft === "boolean") && (p.labels === undefined || (Array.isArray(p.labels) && p.labels.every((x) => typeof x === "string"))) && (p.author === undefined || typeof p.author === "string") && - (p.updatedAt === undefined || typeof p.updatedAt === "string") && + // updatedAt feeds derive.ts momentum/recency math, which Date.parse's + // it: a bare string check lets impossible dates roll into fabricated + // activity (#5202). A present non-empty stamp must be a real ISO date; + // '' is the collector's missing-stamp form and counts as absent. + (p.updatedAt === undefined || p.updatedAt === "" || isIsoDate(p.updatedAt)) && (p.closedAt === undefined || typeof p.closedAt === "string") && (p.mergedAt === undefined || typeof p.mergedAt === "string") && (p.state === "open" || p.state === "closed" || p.state === "merged") && diff --git a/pm-stack/aggregator/test/projects.test.ts b/pm-stack/aggregator/test/projects.test.ts index 989b6e8ba..137aeb275 100644 --- a/pm-stack/aggregator/test/projects.test.ts +++ b/pm-stack/aggregator/test/projects.test.ts @@ -192,6 +192,25 @@ describe("collector projects parsing (GraphQL -> feed section)", () => { expect(isProjectPoolItem(pool[0])).toBe(true); }); + test("the pool gate refuses impossible updatedAt stamps (#5202)", () => { + const item = parseProjectItems(GQL)[0]; + // Control: the collector's own stamp passes, and the missing-stamp + // forms (absent field, '') stay valid. + expect(isProjectPoolItem(item)).toBe(true); + expect(isProjectPoolItem({ ...item, updatedAt: "" })).toBe(true); + const { updatedAt: _dropped, ...withoutStamp } = item; + expect(isProjectPoolItem(withoutStamp)).toBe(true); + // Impossible calendar days and non-ISO strings are refused: before + // the gate they rolled over in Date.parse and fabricated this-week + // activity in derive.ts momentum math. + for (const bad of ["2026-02-29", "2026-02-30", "2026-04-31", "March 2, 2026", "not-a-date"]) { + expect(isProjectPoolItem({ ...item, updatedAt: bad })).toBe(false); + } + // A real leap day and a full ISO datetime still pass. + expect(isProjectPoolItem({ ...item, updatedAt: "2024-02-29" })).toBe(true); + expect(isProjectPoolItem({ ...item, updatedAt: "2026-03-01T12:00:00Z" })).toBe(true); + }); + test("derived state + disagreement", () => { const pool = parseProjectItems(GQL); // Open, no orchestration presence -> Todo, which disagrees with In Progress.