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
13 changes: 13 additions & 0 deletions pm-stack/aggregator/src/dns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ export interface DnsSummary {
unused: DnsEntry[];
/** Entries renewing within `days` of `now` (spend horizon). */
renewingSoon: DnsEntry[];
/** Counts derived from the register's per-entry auto-renew values. */
autoRenew: { on: number; off: number; unknown: number };
}

export function summarizeDns(section: DnsSection, now = new Date(), soonDays = 45): DnsSummary {
Expand All @@ -123,11 +125,22 @@ export function summarizeDns(section: DnsSection, now = new Date(), soonDays = 4
// vanished from nextRenewal and renewingSoon (#1684).
const today = chicagoYmd(now);
const cutoff = addDaysYmd(today, soonDays);
const autoRenew = entries.reduce(
(counts, entry) => {
const value = typeof entry.autoRenew === "string" ? entry.autoRenew.trim().toLowerCase() : "";
if (value === "on") counts.on++;
else if (value === "off") counts.off++;
else counts.unknown++;
return counts;
},
{ on: 0, off: 0, unknown: 0 },
);
return {
nextRenewal: entries.find((e) => e.renewal >= today) ?? entries[0] ?? null,
active: entries.filter((e) => e.status === "active"),
earmarked: entries.filter((e) => e.status === "earmarked"),
unused: entries.filter((e) => e.status === "unused"),
renewingSoon: entries.filter((e) => e.renewal >= today && e.renewal <= cutoff),
autoRenew,
};
}
69 changes: 58 additions & 11 deletions pm-stack/aggregator/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3467,16 +3467,50 @@ export function renderOverviewShell(provenance: Provenance, detail?: ProvenanceD

// --- DNS register page (#906 §1, data from #902) -----------------------------

function dnsTable(entries: DnsEntry[]): string {
function dnsTable(entries: DnsEntry[], renewingSoon: Set<DnsEntry>, nextRenewal?: DnsEntry | null): string {
const rows = entries
.map(
(e) =>
`<tr><td><strong>${esc(e.domain)}</strong></td><td>${esc(e.renewal)}</td><td>${e.priceUsd != null ? `$${e.priceUsd.toFixed(2)}` : "—"}</td><td>${esc(e.autoRenew)}</td><td>${esc(e.plan)}</td><td>${esc(e.review)}</td></tr>`,
`<tr${e === nextRenewal ? ' id="dns-next-renewal"' : ""} data-dns-row data-dns-status="${esc(e.status)}" data-dns-renewing-soon="${renewingSoon.has(e)}"><td><strong>${esc(e.domain)}</strong></td><td>${esc(e.renewal)}</td><td>${e.priceUsd != null ? `$${e.priceUsd.toFixed(2)}` : "—"}</td><td>${esc(e.autoRenew)}</td><td>${esc(e.plan)}</td><td>${esc(e.review)}</td></tr>`,
)
.join("");
return `<div class="tblwrap"><table><caption>Domain register</caption><tr><th scope="col">Domain</th><th scope="col">Next renewal</th><th scope="col">Price (list)</th><th scope="col">Auto-renew</th><th scope="col">Plan / status</th><th scope="col">Review?</th></tr>${rows || '<tr><td colspan="6" class="muted">none</td></tr>'}</table></div>`;
return `<div class="tblwrap"><table id="dns-register-table"><caption>Domain register</caption><thead><tr><th scope="col">Domain</th><th scope="col">Next renewal</th><th scope="col">Price (list)</th><th scope="col">Auto-renew</th><th scope="col">Plan / status</th><th scope="col">Review?</th></tr></thead><tbody>${rows || '<tr><td colspan="6" class="muted">none</td></tr>'}</tbody></table></div>`;
}

const DNS_FILTER_SCRIPT = `<script>
(function () {
var buttons = document.querySelectorAll("[data-dns-filter]");
var rows = document.querySelectorAll("[data-dns-row]");
buttons.forEach(function (button) {
button.addEventListener("click", function () {
var filter = button.getAttribute("data-dns-filter");
buttons.forEach(function (candidate) {
var selected = candidate === button;
candidate.classList.toggle("primary", selected);
candidate.setAttribute("aria-pressed", String(selected));
});
rows.forEach(function (row) {
var matches = filter === "all" || (filter === "renewing-soon"
? row.getAttribute("data-dns-renewing-soon") === "true"
: row.getAttribute("data-dns-status") === filter);
row.hidden = !matches;
});
});
});
var nextLink = document.querySelector("[data-dns-next-link]");
if (nextLink) {
nextLink.addEventListener("click", function () {
buttons.forEach(function (candidate) {
var selected = candidate.getAttribute("data-dns-filter") === "all";
candidate.classList.toggle("primary", selected);
candidate.setAttribute("aria-pressed", String(selected));
});
rows.forEach(function (row) { row.hidden = false; });
});
}
})();
</script>`;

export function renderDns(section: DnsSection | null, provenance: Provenance, detail?: ProvenanceDetail): string {
const chips = detail ? freshnessChips(detail, ["dns"]) : "";
if (!section) {
Expand All @@ -3492,23 +3526,36 @@ export function renderDns(section: DnsSection | null, provenance: Provenance, de
const s = summarizeDns(section);
const next = s.nextRenewal;
const soonTotal = Math.round(s.renewingSoon.reduce((sum, e) => sum + (e.priceUsd ?? 0), 0) * 100) / 100;
const renewingSoon = new Set(s.renewingSoon);
const filters = [
["all", "All", section.entries.length],
["active", "Active", s.active.length],
["earmarked", "Earmarked", s.earmarked.length],
["unused", "Unused", s.unused.length],
["renewing-soon", "Renewing soon", s.renewingSoon.length],
] as const;
const filterChips = filters
.map(
([filter, label, count], index) =>
`<button type="button" class="qchip dns-filter${index === 0 ? " primary" : ""}" data-dns-filter="${filter}" aria-pressed="${index === 0}">${label} (${count})</button>`,
)
.join("");
const body = `<h1>DNS / domain register</h1>
<p class="muted">${section.entries.length} domains · $${section.totalAnnualListUsd.toFixed(2)}/yr at list renewal prices · register parsed ${fmtDate(section.generatedAt)} (${esc(section.source)}). The register is maintained by the #902 pipeline — this page renders it, never edits it. Machine-first: <a href="/api/dns.json">/api/dns.json</a>.</p>
<div class="board">
<div class="card"><strong>Next renewal</strong><br>${
next
? `<strong>${esc(next.domain)}</strong> — ${esc(next.renewal)}${next.priceUsd != null ? ` ($${next.priceUsd.toFixed(2)})` : ""}<br><span class="muted">${esc(next.plan)}</span>`
? `${esc(next.renewal)}${next.priceUsd != null ? ` · $${next.priceUsd.toFixed(2)}` : ""}<br><span class="muted">See <a href="#dns-next-renewal" data-dns-next-link>its row in the renewal-sorted register</a>.</span>`
: "—"
}</div>
<div class="card"><strong>Renewing in 45 days</strong><br>${s.renewingSoon.length} domain${s.renewingSoon.length === 1 ? "" : "s"} · $${soonTotal.toFixed(2)}<br><span class="muted">Auto-renew is ON across the account portfolio — this is upcoming spend, not lapse risk.</span></div>
<div class="card"><strong>Renewing in 45 days</strong><br>${s.renewingSoon.length} domain${s.renewingSoon.length === 1 ? "" : "s"} · $${soonTotal.toFixed(2)} at list price</div>
<div class="card"><strong>Auto-renew</strong><br>${s.autoRenew.on} ON · ${s.autoRenew.off} OFF · ${s.autoRenew.unknown} unknown</div>
<div class="card"><strong>Portfolio shape</strong><br>${s.active.length} in use · ${s.earmarked.length} unused but earmarked · ${s.unused.length} completely unused</div>
</div>
<h2>Next renewals</h2>${dnsTable(section.entries.slice(0, 10))}
<h2>In use (${s.active.length})</h2>${dnsTable(s.active)}
<h2>Unused but earmarked (${s.earmarked.length})</h2><p class="muted">No public-facing use, but the name or plan ties them to a project family (earmark as recorded in the register).</p>${dnsTable(s.earmarked)}
<h2>Completely unused (${s.unused.length})</h2><p class="muted">Nothing but registrar defaults — each still auto-renews until someone decides otherwise.</p>${dnsTable(s.unused)}
<details><summary>Full register (${section.entries.length})</summary>${dnsTable(section.entries)}</details>`;
return layout("DNS register", body, provenance, "/dns", "", chips);
<h2>Domain register (${section.entries.length})</h2>
<div class="chips" role="group" aria-label="Filter domains by status">${filterChips}</div>
${dnsTable(section.entries, renewingSoon, next)}`;
return layout("DNS register", body, provenance, "/dns", DNS_FILTER_SCRIPT, chips);
}

// --- AA cost explorer page (ainventory import data via the fleet feed) -----
Expand Down
44 changes: 38 additions & 6 deletions pm-stack/aggregator/test/slice3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@ describe("dns register parser", () => {
expect(summary.renewingSoon.map((e) => e.domain)).toEqual(["first.de"]);
});

test("auto-renew summary counts ON, OFF, and unknown values from entries", () => {
const missingAutoRenew = {
...FIXTURE_DNS.entries[0],
autoRenew: undefined as unknown as string,
};
const entries = [
{ ...FIXTURE_DNS.entries[0], autoRenew: "ON" },
{ ...FIXTURE_DNS.entries[1], autoRenew: "OFF" },
{ ...FIXTURE_DNS.entries[2], autoRenew: "unknown" },
missingAutoRenew,
];
const summary = summarizeDns({ ...FIXTURE_DNS, entries }, new Date("2026-12-28T00:00:00Z"));
expect(summary.autoRenew).toEqual({ on: 1, off: 1, unknown: 2 });
});

test("summary ages renewals by the Chicago day, not UTC (#1684)", () => {
// 2026-10-31T01:30:00Z is 20:30 CDT on 2026-10-30 in Chicago:
// the UTC day has already rolled over, the Chicago day has not.
Expand Down Expand Up @@ -419,14 +434,31 @@ describe("pages manifest + slice-3 renders", () => {
expect(html).toContain("DNS register");
});

test("dns page renders the three views + next renewal", () => {
test("dns page renders each domain once with status filters and data-derived auto-renew counts", () => {
const html = renderDns(FIXTURE_DNS, fixtureSource().provenance());
expect(html).toContain("Next renewal");
expect(html).toContain("1110x.de");
expect(html).toContain("Unused but earmarked");
expect(html).toContain("Completely unused");
expect(html).toContain("grandnag.us");
expect(html).toContain("security.cab");
for (const entry of FIXTURE_DNS.entries) {
expect(html.split(entry.domain).length - 1).toBe(1);
}
expect(html).toContain('data-dns-filter="active"');
expect(html).toContain('data-dns-filter="earmarked"');
expect(html).toContain('data-dns-filter="unused"');
expect(html).toContain('data-dns-filter="renewing-soon"');
expect(html).toContain("Auto-renew</strong><br>3 ON · 0 OFF · 1 unknown");
expect(html).not.toContain("Auto-renew is ON across the account portfolio");
expect(html).not.toContain("<details><summary>Full register");
});

test("dns next-renewal card links to the actual next-renewal row, not the first row", () => {
const past = { ...FIXTURE_DNS.entries[0], domain: "past.example", renewal: "2020-01-01" };
const upcoming = { ...FIXTURE_DNS.entries[0], domain: "upcoming.example", renewal: "2999-01-01" };
const section = { ...FIXTURE_DNS, entries: [past, upcoming] };
const html = renderDns(section, fixtureSource().provenance());
expect(html).not.toContain("See the first row");
expect(html).toContain('href="#dns-next-renewal"');
const rowStart = html.indexOf('id="dns-next-renewal"');
expect(rowStart).toBeGreaterThan(-1);
expect(html.slice(rowStart, rowStart + 500)).toContain("upcoming.example");
});

test("dns page without a section says so honestly", () => {
Expand Down
Loading