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: 8 additions & 1 deletion pm-stack/aggregator/src/dns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ export function isDnsSection(v: unknown): v is DnsSection {
// renderers cannot render.
typeof s.totalAnnualListUsd === "number" &&
Number.isFinite(s.totalAnnualListUsd) &&
// Money is bounded below as well as finite (#4226): a negative
// total renders as negative spend and records a negative
// snapshot value downstream.
s.totalAnnualListUsd >= 0 &&
Array.isArray(s.entries) &&
s.entries.length > 0 &&
s.entries.every(
Expand All @@ -176,7 +180,10 @@ export function isDnsSection(v: unknown): v is DnsSection {
// 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))) &&
(typeof (e as DnsEntry).priceUsd === "number" &&
Number.isFinite((e as DnsEntry).priceUsd) &&
// A present price must also be non-negative (#4226).
(e as DnsEntry).priceUsd >= 0)) &&
// status feeds summarizeDns buckets; an unknown/missing status
// under-counts silently, so the gate owns the enum (#2412).
((e as DnsEntry).status === "active" ||
Expand Down
19 changes: 19 additions & 0 deletions pm-stack/aggregator/test/slice3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,25 @@ describe("dns register parser", () => {
expect(isDnsSection(withStatus("unused"))).toBe(true);
});

test("isDnsSection rejects negative money, allows zero (#4226)", () => {
const good = dnsSectionFromRegister(REGISTER_MD, "2026-10-25T00:00:00Z", "test");
expect(good).not.toBeNull();
// Negative finite money passed the #2412 finiteness gate: a negative
// total renders as negative spend and records a negative snapshot.
expect(isDnsSection({ ...good, totalAnnualListUsd: -999 })).toBe(false);
expect(isDnsSection({ ...good, totalAnnualListUsd: -0.01 })).toBe(false);
// Zero is the control: a free tier totals 0 and stays valid.
expect(isDnsSection({ ...good, totalAnnualListUsd: 0 })).toBe(true);
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(-0.01))).toBe(false);
expect(isDnsSection(withEntry(0))).toBe(true);
expect(isDnsSection(withEntry(null))).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();
Expand Down
Loading