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
7 changes: 3 additions & 4 deletions pm-stack/aggregator/src/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
import { dirname } from "node:path";
import type { DashAuthor } from "./model.ts";
import { isIsoDate } from "./validate.ts";

/** The cross-cutting filter dimensions a saved view pins (#1276). */
export interface ViewFilters {
Expand Down Expand Up @@ -96,10 +97,8 @@ function isSavedView(value: unknown): value is SavedView {
view.owner.length > 0 &&
validateViewFilters(view.filters).ok &&
typeof view.isDefault === "boolean" &&
typeof view.createdAt === "string" &&
Number.isFinite(Date.parse(view.createdAt)) &&
typeof view.updatedAt === "string" &&
Number.isFinite(Date.parse(view.updatedAt))
isIsoDate(view.createdAt) &&
isIsoDate(view.updatedAt)
);
}

Expand Down
55 changes: 55 additions & 0 deletions pm-stack/aggregator/test/views.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,61 @@ describe("views store (#1276)", () => {
expect(quarantined).toHaveLength(1);
expect(readFileSync(join(dir, quarantined[0]), "utf8")).toBe(raw);
});

// #4979: Date.parse rolled day-overflow stamps over (2026-02-30 ->
// 2026-03-02) and accepted non-ISO strings; the store gate now uses
// the shared isIsoDate contract like every sibling store gate.
test.each([
["impossible createdAt", { createdAt: "2026-02-30T10:00:00.000Z", updatedAt: "2026-03-01T10:00:00.000Z" }],
["impossible updatedAt", { createdAt: "2026-03-01T10:00:00.000Z", updatedAt: "2026-04-31T10:00:00.000Z" }],
["non-ISO createdAt", { createdAt: "March 2, 2026", updatedAt: "2026-03-01T10:00:00.000Z" }],
["non-leap Feb 29 createdAt", { createdAt: "2026-02-29T10:00:00.000Z", updatedAt: "2026-03-01T10:00:00.000Z" }],
])("a view with an %s stamp is quarantined on load", async (_label, stamps) => {
const { dir, file, store } = tmpStore();
const raw = JSON.stringify({
version: 1,
views: [
{
id: "vw-1",
name: "Stamped",
owner: drewKey,
filters: { repo: "a/b" },
isDefault: false,
...stamps,
},
],
});
writeFileSync(file, raw);

expect(await store.all()).toEqual([]);
const quarantined = readdirSync(dir).filter((f) => f.startsWith("views.json.corrupt-"));
expect(quarantined).toHaveLength(1);
expect(readFileSync(join(dir, quarantined[0]), "utf8")).toBe(raw);
});

test("a view with a leap-date stamp loads normally", async () => {
const { dir, file, store } = tmpStore();
const raw = JSON.stringify({
version: 1,
views: [
{
id: "vw-1",
name: "Leap",
owner: drewKey,
filters: { repo: "a/b" },
isDefault: false,
createdAt: "2024-02-29T10:00:00.000Z",
updatedAt: "2024-02-29T10:00:00.000Z",
},
],
});
writeFileSync(file, raw);

const all = await store.all();
expect(all).toHaveLength(1);
expect(all[0].createdAt).toBe("2024-02-29T10:00:00.000Z");
expect(readdirSync(dir).filter((f) => f.startsWith("views.json.corrupt-"))).toHaveLength(0);
});
});

const items: ViewItemLike[] = [
Expand Down