@@ -4,7 +4,7 @@ import { mkdtempSync, renameSync, rmSync, writeFileSync } from "node:fs"; |
4 | 4 | import { tmpdir } from "node:os"; |
5 | 5 | import { join } from "node:path"; |
6 | 6 | import { CommentsStore, validateNewComment } from "../src/comments.ts"; |
7 | | -import { dnsSectionFromRegister, parseDnsRegister, summarizeDns } from "../src/dns.ts"; |
| 7 | +import { dnsSectionFromRegister, isDnsSection, parseDnsRegister, summarizeDns } from "../src/dns.ts"; |
8 | 8 | import type { SessionFeedEntry } from "../src/model.ts"; |
9 | 9 | import { PAGES } from "../src/pages.ts"; |
10 | 10 | import { agentIdentityOf, mergeRecords, parseLaunchRecords, recordFromSessionEntry } from "../src/registry.ts"; |
@@ -117,6 +117,36 @@ describe("dns register parser", () => { |
117 | 117 | expect(parseDnsRegister("# nothing here\n")).toEqual([]); |
118 | 118 | expect(dnsSectionFromRegister("# nothing\n", "2026-10-25T00:00:00Z", "test")).toBeNull(); |
119 | 119 | }); |
| 120 | + |
| 121 | + test("isDnsSection owns the finite-number + status rules (#2412)", () => { |
| 122 | + const good = dnsSectionFromRegister(REGISTER_MD, "2026-10-25T00:00:00Z", "test"); |
| 123 | + expect(good).not.toBeNull(); |
| 124 | + expect(isDnsSection(good)).toBe(true); |
| 125 | + const noTotal = { ...good! } as Record<string, unknown>; |
| 126 | + delete noTotal.totalAnnualListUsd; |
| 127 | + expect(isDnsSection(noTotal)).toBe(false); |
| 128 | + expect(isDnsSection({ ...good, totalAnnualListUsd: "46.29" })).toBe(false); |
| 129 | + expect(isDnsSection({ ...good, totalAnnualListUsd: null })).toBe(false); |
| 130 | + expect(isDnsSection({ ...good, totalAnnualListUsd: Number.NaN })).toBe(false); |
| 131 | + expect(isDnsSection({ ...good, totalAnnualListUsd: Number.POSITIVE_INFINITY })).toBe(false); |
| 132 | + const withEntry = (priceUsd: unknown) => ({ |
| 133 | + ...good, |
| 134 | + entries: good!.entries.map((e, i) => (i === 0 ? { ...e, priceUsd } : e)), |
| 135 | + }); |
| 136 | + expect(isDnsSection(withEntry("4.07"))).toBe(false); |
| 137 | + expect(isDnsSection(withEntry(Number.NaN))).toBe(false); |
| 138 | + expect(isDnsSection(withEntry(null))).toBe(true); |
| 139 | + const withStatus = (status: unknown) => ({ |
| 140 | + ...good, |
| 141 | + entries: good!.entries.map((e, i) => (i === 0 ? { ...e, status } : e)), |
| 142 | + }); |
| 143 | + expect(isDnsSection(withStatus("bogus"))).toBe(false); |
| 144 | + expect(isDnsSection(withStatus(undefined))).toBe(false); |
| 145 | + expect(isDnsSection(withStatus("active"))).toBe(true); |
| 146 | + expect(isDnsSection(withStatus("earmarked"))).toBe(true); |
| 147 | + expect(isDnsSection(withStatus("unused"))).toBe(true); |
| 148 | + }); |
| 149 | + |
120 | 150 | }); |
121 | 151 |
|
122 | 152 | // --- Identity registry (#906 §3) --------------------------------------------- |
|