/** * Responsive audit — the automated check behind "every page works at 320px+". * Run: npm run audit:responsive (all pages, default viewports) * npm run audit:responsive -- /loki (one page) * * WHY THIS EXISTS * * CLAUDE.md states the rule — "All pages must work at 320px+ without horizontal * scroll" — and nothing enforced it for AUTHENTICATED pages. Every existing * check either runs unauthenticated (smoke) or at a single desktop width * (dogfood). So the rule was a promise, and layout regressions on the pages the * operator actually uses could ship green. * * It surfaced concretely: a Loki layout change could not be verified across * viewports at all, because `resize_window` in the interactive browser does not * take effect under a tiling window manager (outerWidth stays put), and the * repo's headless tooling needs a session token that needs the database. * Reasoning about breakpoints from CSS is not verification. * * WHAT IT CHECKS, per page per viewport: * 1. No horizontal overflow — scrollWidth must not exceed the viewport. This * is the stated rule, and the one that makes a phone unusable. * 2. Which element overflowed, when one does. A bare "320 fails" costs an * hour of bisecting; the offender's tag + classes costs nothing to report. * 3. Touch targets >= 44px on coarse-pointer widths. Also a stated rule, and * invisible in a screenshot. * 4. No word drawn across two lines. A word may wrap; it may never be cut * ("Te / rm", "Di / re / ct / or / y" — Substrata's answer table at 390, * 2026-10-22). `word-break: break-all` or `overflow-wrap: anywhere` on a * wide ancestor does this, and reading the CSS finds none of it; only * laying the words out does. The measure is chatkit's * (`@bitbaum/chatkit/audit`), the one its own browser test and the widget * test (widget-host-avoid-browser.ts) run, so "cut" has one definition. * 5. A screenshot per page/viewport under .tmp/responsive-audit/ for eyeballs. * * AUTH * * Needs a session: LOKI_SESSION_TOKEN, or AUDIT_DATABASE_URL + AUTH_SECRET to * mint one. Shared with the ship report in ./lib/session-cookie.mjs, which * says why it does not reuse print-session-token.ts. */ import fs from "node:fs"; import path from "node:path"; import { chromium } from "playwright"; import { config } from "dotenv"; import { BROKEN_WORDS_SOURCE } from "@bitbaum/chatkit/audit"; import { mintSessionToken, sessionCookies } from "./lib/session-cookie.mjs"; config({ path: ".env.local", quiet: true }); const BASE = (process.env.AUDIT_BASE ?? "https://loki.orangecat.ch").replace(/\/$/, ""); const OUT = ".tmp/responsive-audit"; /** Optional CSS injected into every page before measuring — see the call site. */ const EXTRA_CSS = process.env.AUDIT_EXTRA_CSS ? fs.readFileSync(process.env.AUDIT_EXTRA_CSS, "utf8") : null; /** * React's hydration failures, in both shapes. * Production ships minified errors, so #418/#423/#425 is all you get and the * number IS the message; dev builds print prose instead. Matching only one form * means the check works in exactly the environment you are not auditing. */ const HYDRATION_ERROR = /Minified React error #(418|419|421|422|423|425)|[Hh]ydration failed|did not match the server|Text content does not match/; /** * Widths that represent real failure classes, not a sweep. * 320 is the narrowest phone still in use and the stated floor; 390 is a modern * iPhone; 768 is the tablet/sidebar boundary; 1440 is the laptop most of this * gets designed on. Each is a breakpoint where THIS app changes behaviour. */ const VIEWPORTS = [ { name: "320", width: 320, height: 720, touch: true }, { name: "390", width: 390, height: 844, touch: true }, { name: "768", width: 768, height: 1024, touch: true }, { name: "1440", width: 1440, height: 900, touch: false }, ]; /** * Every authenticated surface reachable from the nav, plus the sub-routes that * carry their own layout. Auditing five pages proved the harness; auditing the * whole app is what actually protects it — a rule enforced on a sample is a rule * with holes exactly where nobody looked. * * Public/marketing routes USED to be excluded here, deferred to `npm run smoke` * "which already covers them". It does not: smoke curls each route and asserts * a 2xx/3xx status. A status code says nothing about a layout, so the pages * every stranger sees FIRST were the only ones in the product with no * responsive coverage at all — the exact hole this file's own comment warns * about, in the one place nobody was looking. Measured when finally audited: * 19 sub-44px tap targets on /fleet, every one of them the site address that * is the whole point of the row. They are in PUBLIC_PAGES below now, and they * need no session, so they cost nothing to keep honest. */ /** * FIVE of the twenty entries that used to be here were `redirect()` stubs: * /agents and /atlas (retired, → /control and /projects), /digests, /decisions * and /history (→ /activity). So a "20 route" report was really 15 pages, four * of them measured twice under a name they no longer own — a 25% coverage * overstatement that nothing surfaced, because a redirect renders a real page * and passes. Two of them did worse than lie: the redirect raced the * measurement, and one run hung while another reported the context destroyed. * * The `landed elsewhere` note in the report is the detector, so the next * retirement shows up as a line of output instead of silent double-counting. */ /** * The private-zone pages (/people, /money, /habits, /events, /goals, /memory) * were missing from this list, and from the smoke's probes, and from the UI * dogfood's flows. One cause behind all three: they sit behind the PIN, so * measuring them without an unlock measures a lock screen, and each check quietly * dropped them instead. A rule enforced on the pages that happened to be * reachable is a rule with holes exactly where nobody looked — which is the * comment above this list, so the list has to earn it. * * LOKI_PRIVATE_ZONE_COOKIE (scripts/test/print-private-zone-cookie.ts) * supplies the unlock. Without it these pages still render — as their lock * screen — so the audit degrades to what it measured before rather than failing. */ const PAGES = [ "/today", "/loki", "/voice", "/control", "/projects", "/missions", // Package rows carry a name, a version and up to four tags that wrap; a // long package name must break, not push the row sideways. The detail // sample is a package every fleet register lists (it is the AI layer). "/packages", "/packages/ai-kit", "/approvals", // Where a form hand-off starts, and it is opened on a PHONE more than // anywhere — the point of it is filling a form from the device in hand. // Measured with a real recipe so the value chips are on the page. "/fill?recipe=npm-trusted-publisher&package=%40bitbaum%2Fchatkit&owner=bitbaum&repo=chatkit&workflow=publish.yml", // Six avenues of cards plus a filter strip: a page built to be thumbed // through on a phone, so it is measured from the day it ships. "/suggestions", // /feedback and /robots were reachable from the sidebar and audited by // neither list — the same hole the paragraph above describes, still open. // /feedback is where an operator spends the triage half of their day, and its // per-row action cluster is the densest control group in the app. "/feedback", "/feedback/studio", "/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", "/system", "/thoughts", "/settings", "/models", "/integrations/orangecat/build", "/control/import", "/control/new-from-scratch", "/people", "/crew", "/money", "/habits", "/events", "/goals", "/memory", ]; /** * Unauthenticated routes. Audited with NO session — that is the point: this is * what a stranger gets, so measuring it while signed in would measure a * different page (the landing redirects a signed-in operator straight to the * app). Kept separate from PAGES for that reason, not for tidiness. */ const PUBLIC_PAGES = [ "/", "/change", "/take", "/build", "/fleet", "/pricing", "/pricing/personal", "/download", "/why", "/how-it-works", "/no-screen", "/compare", "/roadmap", "/investors", "/whitepaper", "/thoughts", "/changelog", "/support", "/docs", "/sign-in", "/sign-in/error", "/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", // A studio partner's OrangeCat pages: signed out they are a one-button card // (and /studio/connect without its token, the expired-link message) — the // first thing a stranger from the studio site sees here. "/studio/connect", "/studio/partner", /** * DYNAMIC routes, measured through one real instance each. * * These were not "missed" — they were excluded by construction: * audit-covers-every-page skipped every route containing "[", so a template * was out of scope however many pages it served. /fleet/[slug] serves the * public build profile of all 36 projects and every "via Loki" link on an * OrangeCat wall should land on it, and it had never been driven through a * viewport. It was clipping 47% of every roadmap line at 390px. * * A sample that stops resolving now FAILS (see the 404 guard in the loop) * rather than quietly measuring a not-found page, because a rotted sample * looks exactly like a covered route. */ "/fleet/heidi", "/thoughts/shipped-is-not-witnessed", "/u/cato", ]; /** * 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", "/frontier": "retired — 308 to /thoughts, renders nothing", "/mission": "308 to /why, renders nothing", "/commission": "308 to /change, renders nothing", "/philosophy": "308 to /why, 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", // Dynamic routes whose parameter cannot be known from the repo. Each names // what it would take, so "needs an id" is a decision on record rather than // the silent exclusion every "[" used to get. "/change/requests/[id]": "needs a build request filed by the audited account (one per brief, signed in); checked at 390px by hand on 2026-10-19 with no horizontal scroll", "/projects/[id]": "needs a project id from the audited environment's database", "/missions/[id]": "needs an accessible project id from the audited environment; rendered from the same owner-scoped project dossier", "/projects/[id]/review": "needs an owned project id; actual review component and styles are measured at four widths in inspection-workspace-browser.ts", "/projects/[id]/watch": "needs a project id (with a run) from the audited environment's database", "/projects/[id]/workbench": "needs an owned project id from the audited environment's database; checked by hand at 390, 720, 1000, 1440 and 1920px on 2026-10-30 with no horizontal scroll, and at 900px as a one-pane window", "/atlas/[projectId]": "needs a project id from the audited environment's database", "/people/[id]": "needs a person id from the private zone", "/goals/[id]": "needs a goal id from the private zone", "/robots/[id]": "needs an agent id from the audited environment", "/a/[token]": "needs a live action token from a dispatched approval", "/invite/[token]": "needs a live invitation token", "/invite/project/[token]": "needs a live project invitation token — only its sha-256 is stored, so no fixture can be derived from the DB", "/reset-password/[token]": "needs a live password-reset token", "/verify-email/[token]": "needs a live email-verification token", "/share/project/[token]": "needs a share token minted for one project", "/share/task/[token]": "needs a share token minted for one task", }; const isPublicPage = (p) => PUBLIC_PAGES.includes(p); const MIN_TOUCH_PX = 44; /** * Measure one rendered page. Runs in the browser: reports overflow with the * culprit, and undersized touch targets. * * `scrollWidth > clientWidth + 1` — the 1px slack absorbs sub-pixel rounding at * fractional device ratios, which otherwise reports a phantom overflow on every * page and trains everyone to ignore the check. * * A real function, not a string: Playwright does not bind arguments to a string * pageFunction, so the string form silently received `undefined` for minTouch * and returned nothing at all. */ function measurePage(minTouch) { const de = document.documentElement; const vw = de.clientWidth; const offenders = [...document.querySelectorAll("body *")] .filter((el) => { const r = el.getBoundingClientRect(); if (r.width === 0 || r.height === 0) return false; const cs = getComputedStyle(el); if (cs.position === "fixed" || cs.visibility === "hidden") return false; return r.right > vw + 1; }) .map((el) => ({ tag: el.tagName.toLowerCase(), cls: (el.className || "").toString().slice(0, 80), right: Math.round(el.getBoundingClientRect().right), width: Math.round(el.getBoundingClientRect().width), })) .sort((a, b) => b.right - a.right) .slice(0, 5); // What the FINGER hits, which is repeatedly NOT the control's own box: // • a 14px checkbox inside a 60px