Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pm-stack/aggregator/src/item-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import { appendFile, mkdir, readFile } from "node:fs/promises";
import { dirname, join } from "node:path";
import type { GhState, ProjectPoolItem, RefKey } from "./model.ts";
import { isIsoDate } from "./validate.ts";

export const ITEM_HISTORY_SCHEMA_VERSION = 1;

Expand Down Expand Up @@ -141,10 +142,14 @@ export function isItemHistoryCutoff(v: unknown): v is ItemHistoryCutoff {
if (!v || typeof v !== "object") return false;
const c = v as Record<string, unknown>;
if (c.schemaVersion !== ITEM_HISTORY_SCHEMA_VERSION) return false;
if (typeof c.cutoffAt !== "string" || Number.isNaN(Date.parse(c.cutoffAt))) return false;
// Real calendar dates only (#5172): Date.parse rolls impossible dates
// over (2026-02-30 -> Mar 2) and parses non-ISO strings in a
// timezone-dependent way, so gate with isIsoDate like the sibling
// gates (snapshots.ts, #2264/#2483).
if (!isIsoDate(c.cutoffAt)) return false;
const coverage = c.coverage as Record<string, unknown> | undefined;
if (!coverage || typeof coverage !== "object") return false;
if (typeof coverage.source !== "string" || typeof coverage.fetchedAt !== "string") return false;
if (typeof coverage.source !== "string" || !isIsoDate(coverage.fetchedAt)) return false;
if (typeof coverage.complete !== "boolean" || typeof coverage.unavailable !== "boolean") {
return false;
}
Expand Down
28 changes: 28 additions & 0 deletions pm-stack/aggregator/test/item-history.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,34 @@ describe("captureItemHistory", () => {
});
});

describe("isItemHistoryCutoff date gates (#5172)", () => {
const valid = () => cutoff(W1, [poolItem(7)]);

test("valid ISO cutoff and coverage stamps pass (control)", () => {
expect(isItemHistoryCutoff(valid())).toBe(true);
});

test("impossible and non-ISO cutoffAt stamps are refused", () => {
for (const stamp of [
"2026-02-30T00:00:00Z",
"2026-04-31T00:00:00Z",
"March 2, 2026",
"03/02/2026",
]) {
expect(isItemHistoryCutoff({ ...valid(), cutoffAt: stamp })).toBe(false);
}
});

test("impossible and non-ISO coverage.fetchedAt stamps are refused", () => {
for (const stamp of ["not-a-date", "2026-02-30T00:00:00Z"]) {
const c = valid();
expect(
isItemHistoryCutoff({ ...c, coverage: { ...c.coverage, fetchedAt: stamp } }),
).toBe(false);
}
});
});

describe("weeklyTransitions / weeklyCompletions", () => {
test("close counts once; a reopen leaves the completed count until re-closed", () => {
const cutoffs = [
Expand Down