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
18 changes: 17 additions & 1 deletion pm-stack/aggregator/src/dns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,30 @@ export function isDnsSection(v: unknown): v is DnsSection {
return (
typeof s.generatedAt === "string" &&
Number.isFinite(Date.parse(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
// renderers cannot render.
typeof s.totalAnnualListUsd === "number" &&
Number.isFinite(s.totalAnnualListUsd) &&
Array.isArray(s.entries) &&
s.entries.length > 0 &&
s.entries.every(
(e) =>
typeof e === "object" &&
e !== null &&
typeof (e as DnsEntry).domain === "string" &&
typeof (e as DnsEntry).renewal === "string",
typeof (e as DnsEntry).renewal === "string" &&
// priceUsd is number|null in the model: null/absent stays valid,
// but a present value must be a finite number (#2412).
((e as DnsEntry).priceUsd === null ||
(e as DnsEntry).priceUsd === undefined ||
(typeof (e as DnsEntry).priceUsd === "number" && Number.isFinite((e as DnsEntry).priceUsd))) &&
// status feeds summarizeDns buckets; an unknown/missing status
// under-counts silently, so the gate owns the enum (#2412).
((e as DnsEntry).status === "active" ||
(e as DnsEntry).status === "earmarked" ||
(e as DnsEntry).status === "unused"),
)
);
}
Expand Down
32 changes: 31 additions & 1 deletion pm-stack/aggregator/test/slice3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { tmpdir } from "node:os";
import { join } from "node:path";
import { CommentsStore, validateNewComment } from "../src/comments.ts";
import { dnsSectionFromRegister, parseDnsRegister, summarizeDns } from "../src/dns.ts";
import { dnsSectionFromRegister, isDnsSection, parseDnsRegister, summarizeDns } from "../src/dns.ts";
import type { SessionFeedEntry } from "../src/model.ts";
import { PAGES } from "../src/pages.ts";
import { agentIdentityOf, mergeRecords, parseLaunchRecords, recordFromSessionEntry } from "../src/registry.ts";
Expand Down Expand Up @@ -117,6 +117,36 @@
expect(parseDnsRegister("# nothing here\n")).toEqual([]);
expect(dnsSectionFromRegister("# nothing\n", "2026-10-25T00:00:00Z", "test")).toBeNull();
});

test("isDnsSection owns the finite-number + status rules (#2412)", () => {
const good = dnsSectionFromRegister(REGISTER_MD, "2026-10-25T00:00:00Z", "test");
expect(good).not.toBeNull();
expect(isDnsSection(good)).toBe(true);
const noTotal = { ...good! } as Record<string, unknown>;
delete noTotal.totalAnnualListUsd;
expect(isDnsSection(noTotal)).toBe(false);
expect(isDnsSection({ ...good, totalAnnualListUsd: "46.29" })).toBe(false);
expect(isDnsSection({ ...good, totalAnnualListUsd: null })).toBe(false);
expect(isDnsSection({ ...good, totalAnnualListUsd: Number.NaN })).toBe(false);
expect(isDnsSection({ ...good, totalAnnualListUsd: Number.POSITIVE_INFINITY })).toBe(false);
const withEntry = (priceUsd: unknown) => ({
...good,
entries: good!.entries.map((e, i) => (i === 0 ? { ...e, priceUsd } : e)),
});
expect(isDnsSection(withEntry("4.07"))).toBe(false);
expect(isDnsSection(withEntry(Number.NaN))).toBe(false);
expect(isDnsSection(withEntry(null))).toBe(true);
const withStatus = (status: unknown) => ({
...good,
entries: good!.entries.map((e, i) => (i === 0 ? { ...e, status } : e)),
});
expect(isDnsSection(withStatus("bogus"))).toBe(false);
expect(isDnsSection(withStatus(undefined))).toBe(false);
expect(isDnsSection(withStatus("active"))).toBe(true);
expect(isDnsSection(withStatus("earmarked"))).toBe(true);
expect(isDnsSection(withStatus("unused"))).toBe(true);
});

});

// --- Identity registry (#906 §3) ---------------------------------------------
Expand Down Expand Up @@ -505,7 +535,7 @@
records: { source: string }[];
identities: { kind: string }[];
};
expect(registry.records.some((r) => r.source === "claude-code")).toBe(true);

Check failure on line 538 in pm-stack/aggregator/test/slice3.test.ts

View workflow job for this annotation

GitHub Actions / test

error: expect(received).toBe(expected)

Expected: true Received: false at <anonymous> (/home/runner/work/code/code/pm-stack/aggregator/test/slice3.test.ts:538:70)
expect(registry.identities.some((i) => i.kind === "drew")).toBe(true);
const pages = await (await fetch(`http://127.0.0.1:${port}/pages`)).text();
expect(pages).toContain("All pages");
Expand Down
Loading