test(audit): make the page list earn it, instead of asking it to (#818)

responsive-audit.mjs opens with the argument this enforces — "a rule enforced
on the pages that happened to be reachable is a rule with holes exactly where
nobody looked, so the list has to earn it". It could not earn it alone,
because nothing ever compared the list to the app. Twenty-four static page
routes were in neither list.

Comparing them found four that matter:

  /my-feedback  the REPORTER's view — the one feedback surface whose reader
                may be a stranger on someone else's site, and one AGENTS.md
                already records as having been forgotten ("the three-line
                clamp shipped to the operator inbox never reached it").
  /license      public, 200, and already missed once: the MIT relicense fixed
                LICENSE, README and Terms and left this page telling readers
                they "may not" host or repackage (loki#802).
  /privacy      the other two pages a stranger is entitled to read, neither
  /terms        of them ever measured.

Plus /unlock, /releases, /setup and the two /docs guides. All twenty new
checks pass, so the gap was not hiding broken layouts here — but it was
hiding /feedback's, which clipped its own stats mid-word on a phone until
#813, and it would hide the next one.

The rest are excluded BY NAME WITH A REASON in NOT_MEASURED: retired redirect
stubs that render nothing (/agents, /atlas, /duet, /digests, /decisions,
/history, /blog), an action rather than a page (/sign-out), and flows that
need state a headless run cannot mint — a claim token, a verification token,
a connected Fleet Runner.

scripts/test/audit-covers-every-page.ts then fails when a page.tsx is in
neither, so adding a page becomes a decision about whether it is measured
rather than a silent omission. It also fails on an exclusion whose page no
longer exists — a stale reason is one nobody re-examines — and refuses a route
listed in both.

It asserts its own parse first. If the regex that reads those lists ever stops
matching, every other check would pass vacuously, which is precisely the
failure this file exists to prevent.

Mutation, both ways: removing /my-feedback from the audit fails it, and
excluding a route with no page fails it.

verify: format:check, tsc, lint (0 errors, 2 pre-existing warnings),
check:design (11), check:desktop, test:home 130/130. test:unit 226/228 —
activity-time-zone-stable and telegram-allowlist need a live local server and
fail identically on pristine origin/main.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
CatoandClaude Opus 5 authored and GitHub committed 2026-09-20 14:09:32 -07:00
1 parent 7d5bedb942
commit cdff69e3c2
2 files changed
+168

No files matched your search

+120
View File
@@ -0,0 +1,120 @@
/**
* Every page in the app is measured, or deliberately excluded with a reason.
*
* responsive-audit.mjs opens with the argument this enforces: "a rule enforced
* on the pages that happened to be reachable is a rule with holes exactly
* where nobody looked — so the list has to earn it." It could not earn it on
* its own, because nothing compared the list to the app.
*
* What was missing when this was written, found by that comparison:
*
* /feedback where the operator spends the triage half of their day, with
* the densest control cluster in the app. Unmeasured, and it
* was clipping its own stats mid-word on a phone.
* /my-feedback the REPORTER's view — the one feedback surface whose reader
* may be a stranger on someone else's site, and one AGENTS.md
* already records as having been forgotten once.
* /license public, and already missed once: the MIT relicense fixed
* LICENSE, README and Terms and left this page telling readers
* they "may not" host or repackage (loki#802).
* /privacy /terms the other two pages a stranger is entitled to read.
*
* A new page now has to be a decision — measured, or excluded and why.
*
* Run: npx tsx scripts/test/audit-covers-every-page.ts
*/
import { readdirSync, statSync, readFileSync } from "node:fs";
import { join, relative, sep } from "node:path";
const ROOT = new URL("../..", import.meta.url).pathname;
const APP = join(ROOT, "src", "app");
const AUDIT = join(ROOT, "scripts", "test", "responsive-audit.mjs");
let failures = 0;
function check(name: string, fn: () => void) {
try {
fn();
console.log(` ✓ ${name}`);
} catch (err) {
failures++;
console.log(` ✗ ${name}`);
console.log(` ${err instanceof Error ? err.message : String(err)}`);
}
}
function assert(cond: boolean, msg: string) {
if (!cond) throw new Error(msg);
}
/** Every `page.tsx` in the app router, as the URL it serves. */
function pageRoutes(dir: string, out: string[] = []): string[] {
for (const entry of readdirSync(dir)) {
const p = join(dir, entry);
if (statSync(p).isDirectory()) pageRoutes(p, out);
else if (entry === "page.tsx" || entry === "page.ts") {
const rel = relative(APP, dir);
if (rel === "") {
out.push("/");
continue;
}
// Route groups — (app), (private) — are organisation, not URL.
const segs = rel.split(sep).filter((s) => !(s.startsWith("(") && s.endsWith(")")));
out.push("/" + segs.join("/"));
}
}
return out;
}
/** The three lists in the audit, read from its source so they cannot drift. */
function auditLists(): { measured: Set<string>; excluded: Set<string> } {
const src = readFileSync(AUDIT, "utf8");
const arrayOf = (name: string) => {
const m = new RegExp(`const ${name}\\s*=\\s*\\[([\\s\\S]*?)\\]`).exec(src);
return m ? [...m[1].matchAll(/"(\/[^"]*)"/g)].map((x) => x[1]) : [];
};
const excludedBlock = /export const NOT_MEASURED\s*=\s*\{([\s\S]*?)\n\};/.exec(src);
const excluded = excludedBlock
? [...excludedBlock[1].matchAll(/"(\/[^"]*)"\s*:\s*"([^"]+)"/g)].map((m) => m[1])
: [];
return {
measured: new Set([...arrayOf("PAGES"), ...arrayOf("PUBLIC_PAGES")]),
excluded: new Set(excluded),
};
}
console.log("audit-covers-every-page:");
const routes = pageRoutes(APP);
const { measured, excluded } = auditLists();
check("the audit's own lists parse", () => {
// If this regex ever stops matching, every check below passes vacuously —
// which is the failure mode the audit itself exists to prevent.
assert(measured.size > 20, `expected the page lists, parsed ${measured.size}`);
assert(excluded.size > 5, `expected exclusions, parsed ${excluded.size}`);
});
check("every static page route is measured or excluded with a reason", () => {
// Dynamic segments need a real id to render and are out of scope.
const statics = [...new Set(routes.filter((r) => !r.includes("[")))].sort();
const orphans = statics.filter((r) => !measured.has(r) && !excluded.has(r));
assert(
orphans.length === 0,
`page routes in neither the audit nor NOT_MEASURED:\n ${orphans.join("\n ")}\n` +
` Add each to PAGES / PUBLIC_PAGES, or to NOT_MEASURED with the reason.`,
);
});
check("nothing is excluded that no longer exists", () => {
// An exclusion for a deleted page is a stale reason nobody will re-examine.
const statics = new Set(routes.filter((r) => !r.includes("[")));
const ghosts = [...excluded].filter((r) => !statics.has(r));
assert(ghosts.length === 0, `excluded routes with no page: ${ghosts.join(", ")}`);
});
check("a route is not in both lists", () => {
const both = [...excluded].filter((r) => measured.has(r));
assert(both.length === 0, `measured AND excluded: ${both.join(", ")}`);
});
console.log(failures === 0 ? "\nall passed" : `\n${failures} failed`);
process.exit(failures === 0 ? 0 : 1);
+48
View File
@@ -126,6 +126,14 @@ const PAGES = [
// per-row action cluster is the densest control group in the app.
"/feedback",
"/robots",
// Authenticated, and both were reachable and unmeasured. /my-feedback is
// the REPORTER's view — the one feedback surface whose reader may be a
// stranger on someone else's site, and the one AGENTS.md records as having
// been forgotten before ("the three-line clamp shipped to the operator
// inbox never reached it"). /unlock is the PIN gate, which is a real
// rendered form, not a redirect.
"/my-feedback",
"/unlock",
"/terminal",
"/prompts",
"/activity",
@@ -167,8 +175,48 @@ const PUBLIC_PAGES = [
"/docs",
"/sign-in",
"/sign-up",
// All render 200 to a signed-out stranger and none were measured. The legal
// three are the point: /license has already been missed once by a change
// that touched everything around it — the MIT relicense fixed LICENSE,
// README and Terms and left this page telling readers they "may not" host
// or repackage (loki#802).
"/license",
"/privacy",
"/terms",
"/releases",
"/setup",
"/docs/quickstart",
"/docs/feedback-widget",
];
/**
* Page routes deliberately NOT measured, each with the reason.
*
* This list is the other half of the paragraph above PAGES: a rule enforced on
* the pages that happened to be reachable is a rule with holes. So every
* `page.tsx` in the app must be in PAGES, in PUBLIC_PAGES, or here — and
* scripts/test/audit-covers-every-page.ts fails when a new one is in none of
* them. Adding a page then becomes a decision about whether it is measured,
* rather than a silent omission.
*/
export const NOT_MEASURED = {
"/agents": "retired — 308 to /control, renders nothing",
"/atlas": "retired — 308 to /projects, renders nothing",
"/duet": "retired — redirect stub",
"/digests": "retired — redirect stub onto /activity",
"/decisions": "retired — redirect stub onto /activity",
"/history": "retired — redirect stub onto /activity",
"/blog": "307 to /thoughts, renders nothing",
"/sign-out": "an action, not a page",
"/onboarding": "first-run flow: needs a brand-new account to render its real state",
"/control/workspace": "needs a selected workspace in session state",
"/control/import-local": "needs a local Fleet Runner connected",
"/claim-feedback": "needs a one-time claim token from a widget report",
"/verify-email": "needs a live verification token",
"/forgot-password": "needs a live reset token",
"/x-login/complete": "OAuth callback landing, not a page anyone navigates to",
};
const isPublicPage = (p) => PUBLIC_PAGES.includes(p);
const MIN_TOUCH_PX = 44;