Program
Twelve weeks.
90-Tage-Programm#!/usr/bin/env node /** * Self-test for render-sweep.mjs. Run: node scripts/ci/test-render-sweep.mjs * * Every check is pinned on BOTH sides — the defect fires, correct markup stays * silent — because a detector that has quietly stopped firing reports a clean * fleet, and a detector that fires on everything is read once and ignored. * Mutation-proven when written: disabling each check's core condition in * RENDER_MEASURE fails its positive fixture here (see the PR). * * Fixtures render in real Chromium via page.setContent — no network, no fleet. * The pure halves (apps.conf parsing, DENY, merge, tally, ratchet) run first * and need no browser. */ import { CHECKS, DENY, RENDER_MEASURE, findingsOf, formatBaseline, improvements, mergeFindings, parseAppsConf, readBaseline, regressions, renderWithRecovery, resolveSites, tally, } from "./render-sweep.mjs"; import { MEASURE, loadPlaywright } from "./ui-defect-audit.mjs"; let pass = 0; let fail = 0; const ok = (cond, label) => { if (cond) pass++; else { fail++; console.error(`✗ ${label}`); } }; // ── pure ───────────────────────────────────────────────────────────────────── { // A dead context (newPage throws) is rebuilt and the page retried once; a // second loss is UNMEASURED, never a crash of the whole sweep and never clean. const deadCtx = { newPage: async () => { throw new Error("Target page, context or browser has been closed"); } }; const goodCtx = { newPage: async () => ({ on() {}, goto: async () => ({ status: () => 404 }), url: () => "https://x.test/", close: async () => {}, }) }; let rebuilt = 0; const env = { ctx: deadCtx, rebuild: async () => { rebuilt++; env.ctx = goodCtx; } }; const r1 = await renderWithRecovery(env, "https://x.test/"); ok(rebuilt === 1 && r1.why === "HTTP 404", `a lost browser is rebuilt and the page retried, got ${JSON.stringify(r1)} after ${rebuilt} rebuild(s)`); const env2 = { ctx: deadCtx, rebuild: async () => { env2.ctx = deadCtx; } }; const r2 = await renderWithRecovery(env2, "https://x.test/"); ok(/browser lost twice/.test(r2.why ?? ""), `a second loss is reported unmeasured, got ${JSON.stringify(r2)}`); } { const conf = [ "# comment", "kivvi|4005|kivvi.orangecat.ch|/x|.|kivvi|RevampIT|client-app|live|favour|0|-", "gone|4099|gone.orangecat.ch|/x|.|-|bitbaum|product|archived|-|-|-", "evig|4004|evig.orangecat.ch,revampit.orangecat.ch|/x|.|r|bitbaum|product|live|-|-|-", ].join("\n"); const rows = parseAppsConf(conf); ok(rows.length === 2, "apps.conf: archived rows are not swept"); ok(rows.find((r) => r.name === "evig")?.url === "https://evig.orangecat.ch", "apps.conf: first domain is the site"); const sites = resolveSites(conf, { extraSites: { loki: { url: "https://loki.orangecat.ch", kind: "product" } }, pages: { kivvi: ["/", "/api/health", "/admin", "/cron/run", "/how-it-works"] }, }); ok(sites.some((s) => s.name === "loki"), "extraSites are swept too"); const kivvi = sites.find((s) => s.name === "kivvi"); ok(kivvi.client === true, "a client-app row is marked client (report only, never fixed)"); ok( JSON.stringify(kivvi.paths) === JSON.stringify(["/", "/how-it-works"]), `DENY strips api/admin/cron paths even when configured, got ${JSON.stringify(kivvi.paths)}`, ); ok(sites.find((s) => s.name === "evig").paths.join() === "/", "a site without pages gets / only"); for (const p of ["/api/x", "/admin", "/auth/signin", "/cron", "/jobs/1", "/account", "/settings", "/login?next=/"]) { ok(DENY.test(p), `DENY refuses ${p}`); } for (const p of ["/", "/atlas?view=world", "/blog", "/jobsearch-tips", "/about"]) { ok(!DENY.test(p), `DENY allows ${p}`); } ok(resolveSites(conf, {}, ["kivvi"]).length === 1, "SITES narrows the sweep"); // merge + ratchet const f = { tag: "p", text: "EXTRACT", kicker: true, next: "x" }; const merged = mergeFindings([ { site: "a", path: "/", width: "390", findings: [{ check: "empty-heading", f }] }, { site: "a", path: "/", width: "1440", findings: [{ check: "empty-heading", f }] }, { site: "a", path: "/b", width: "390", findings: [{ check: "empty-heading", f }] }, ]); const counts = tally(merged); ok(counts.a["empty-heading"] === 2, "one finding at two widths counts once; another page counts again"); ok(merged.get("a").values().next().value.widths.join() === "390,1440", "widths are recorded"); const base = readBaseline("# c\na empty-heading 2\na split-number 3\n"); ok(regressions(counts, base).length === 0, "equal to baseline: no regression"); ok(regressions({ a: { ...counts.a, "empty-heading": 3 } }, base).length === 1, "a rise is a regression"); ok(regressions({ z: { "fixed-overlap": 1 } }, base).length === 1, "a new site x check starts from 0"); ok(improvements(counts, base).some((r) => r.check === "split-number"), "a fall is reported as an improvement"); ok(regressions({}, base).length === 0, "an unmeasured site is not judged (and not read as clean)"); const round = readBaseline(formatBaseline({ a: { "empty-heading": 2, "split-number": 0 } })); ok(round.a["empty-heading"] === 2 && round.a["split-number"] === undefined, "baseline round-trips, zeros omitted"); ok( findingsOf({ pageOverflow: 12, navSmallTargets: [{}], navOffViewport: [] }, {}, ["boom"]).map((x) => x.check).join() === "rule3-small-target,rule8-sideways,page-errors", "MEASURE's rule 3/8 results and page errors map onto checks", ); ok(CHECKS.length === 8, "eight ratcheted checks"); } // ── rendered ───────────────────────────────────────────────────────────────── const doc = (body) => `
${body}`; const FIX = { // substrata's country panel: a roles label, then a new section's heading. orphanLabel: `extract
Ordered by share of world output.
South Asia · IN
Body.
Twelve weeks.
90-Tage-ProgrammOnly details has content.
Text.
Next.
Content under sub.
Real content.
| 282,000 (+10%) |
| Total 1,234,567,890 units |
| 282,000 (+10%) | A long label that wraps across several lines in this narrow cell is fine |