diff --git a/pm-stack/aggregator/src/dns.ts b/pm-stack/aggregator/src/dns.ts index 4d82bc9323..a678ab4293 100644 --- a/pm-stack/aggregator/src/dns.ts +++ b/pm-stack/aggregator/src/dns.ts @@ -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( @@ -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" || diff --git a/pm-stack/aggregator/test/slice3.test.ts b/pm-stack/aggregator/test/slice3.test.ts index 91ee8c0234..f7f9fc0986 100644 --- a/pm-stack/aggregator/test/slice3.test.ts +++ b/pm-stack/aggregator/test/slice3.test.ts @@ -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();