mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 05:57:09 +01:00
* feat(workbench): one project side by side, on one screen or two A project's session and Loki as columns of one window, and its site in a window of its own — beside this one or on the other screen. Nothing in it is new UI: the columns are TerminalSurface and LokiWorkspace mounted as they are; the site is the live page with the owner's pass, where pointing and "Fix it now" already live. What the workbench adds is the arrangement. - /projects/[id]/workbench, a Workbench row on the project page, and the pane SSOT in config/workbench.ts (session, loki). - The site is a window, not a pane, on purpose: every fleet site sends frame-ancestors 'none' and Cross-Origin-Opener-Policy same-origin, so it can be neither framed nor reached as an opener. The workbench says only what it knows. docs/architecture/workbench.md. - Windows open the best way the platform offers: Fleet Runner places them from the real display list (new IPC open-workbench-window, v0.8.60, caller tiled left / new window right, or the other display whole, an open window brought forward); a Chromium browser places a popup on the other screen once allowed; any browser gets a half-screen popup. - Any pane in its own window (?pane=): a solo window hides the shell chrome at every width; the windows of one project on one machine keep each other honest over a BroadcastChannel (a popped-out pane leaves its window and returns when that window closes). - Which panes a window shows is device-local (localStorage per project), never a column on the project. Two columns from xl; below that one pane at a time and the strip chooses; below md the phone's rows. - Each column's side rail (the session's Loki rail, the chat's history) is remembered for the workbench apart from its own page and starts closed in a column: TerminalSurface gets `rail`, LokiWorkspace gets `basePath`, `project` and `history`. - Full screen is the browser's own, on the workbench root. - Pure parts tested: scripts/test/workbench-layout.ts, workbench-windows.ts, workbench-placement.ts. Checked by hand at 390, 720, 1000, 1440 and 1920px and as a one-pane window at 900px, no horizontal scroll. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmswy1H6cYyL3hmLRy9 * refactor(workbench): one placement rule, a window's own layout, honest re-opens A second pass over the workbench after an independent review of the diff. - One placement module for both sides: src/lib/workbench/placement.ts is the pure rule the browser popup and Fleet Runner's real windows share (the desktop copy is gone). Tiling respects the caller's minimum width, so the 800px shell and the new window meet on a 1440px display instead of overlapping; only a display too small for both overlaps. - The layout is the window's: sessionStorage per project, kept across the window's reloads and never shared. Two full workbench windows of one project each keep their own arrangement; localStorage's cross-window storage event clobbered them. useLocalStorageState takes the area. - A popped-out pane announces itself closed on every way out — pagehide and a soft navigation away — and open again from the back-forward cache. - A window already open is brought forward, never navigated again: the site's address carries a pass minted per visit, and a second navigation left it unread in the address bar. Fleet Runner keys windows by the URL without its fragment, restores a minimized one and places it where the person now asks. - The screen-management prompt is raised when "On the other screen" is chosen, not on the open that follows: a click that waits for a prompt goes stale and the browser refuses the window. - Close in a solo window leads somewhere even when window.close() is a no-op (a typed address): it falls through to the whole workbench. - The dock click on macOS asks whether the SHELL window exists, not any window, so a site window open with the shell closed no longer hides it. - Which panes are on screen (columns, or one of them) is a pure, tested rule; window opening lives in one hook (use-workbench-windows) instead of two states; the phone's rows read each pane's surface from the registry; useBodyClass serves both the immersive chat and the solo window. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmswy1H6cYyL3hmLRy9 * feat(workbench): one box — Session and Watch, not Session and Loki The first cut put Loki's chat in the second column. Beside the session's box that was a second place to type on one screen, and a person had to work out which box did what ("I see two chats, and it just gets confusing"). The session's box already does the one thing the screen is for — it types into the live agent, or starts one — and the session already offers Loki about itself ("What's going on?"). - The second column is Watch: the project's run as a live thread (what you asked, Loki narrating, the agent's screen, and where the change is — pull request, tested and merged, live), mounted from ProjectWatch as it is. It has no box. Loki's chat stays its own page. - The pane registry carries where each pane's own page is (`pageHref`), so the phone's rows and the columns read one list. - A pane body can be a scrolling thread (Watch) or a surface that fills the pane (the session). - LokiWorkspace is back to what it was: the host-path, project and history props it only grew for the workbench are gone with their only caller. - The project row says what the screen is for: "Say what to change and watch it happen, with the site beside". Checked by hand at 390, 720, 1000, 1440 and 1920px and in both solo windows: no horizontal scroll, no console errors. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmswy1H6cYyL3hmLRy9 * feat(workbench): one screen, one box — the site as Loki sees it, the robot, one line of state "If a user sees tons of options, they can feel a paralysis" (owner, 2026-10-31). The screen showed about twenty controls: the Sessions page's builder picker, tab strip, agent and view switches, Watch's card with its own buttons, pane toggles, a window-placement menu. One thing to do, a few things to see — so: - The site, left, as Loki's own browser sees it (WorkbenchSiteView): the review worker already walks the site in a headless Chromium on the box and keeps one frame per action with the action named. While it walks, this shows the robot using the site, frame by frame — the one thing no window of yours can show; at rest, the last look. A tap opens the real site in its own window, where the person uses it and the widget does the watching. Fleet sites forbid framing and sever window.opener, so a picture of Loki's browser is what can honestly be shown inside Loki. - The robot, right: TerminalSurface in a new quiet shape (`quiet`) — no builder picker (which builder runs a project is a stored decision), no tab strip of other projects, no shell rows; the chat | terminal switch and the agent stay. Its box is the ONE box on the screen. - One line of state over the robot (WorkbenchStateLine): the sentence the Watch track composes, a dot for its tone, "Watch it work" for the whole story. Pure stateLine() in lib/workbench/state-line.ts, tested. The Watch column is gone from the screen. - One "⋯" for the rest: the robot in its own window / on the other screen, the site on the other screen, full screen. The pane toggles and the placement menu are gone; a placement named for one opening wins and becomes the remembered one. - The pane registry is the robot alone; the site is a region. Below xl the robot alone (the site is in its own window anyway). On a phone: the site, the robot, Watch it work, as rows. - TerminalSurface stayed under the function-size ceiling by lifting the builder-picker wrapper and the resume filter out of it. Checked by hand at 390, 720, 1440 and 1920px and in the solo window: no horizontal scroll, no console errors. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmswy1H6cYyL3hmLRy9 * feat(workbench): a focus screen — the app's chrome leaves while you build Three layers of navigation sat around two columns: the sidebar's twenty destinations, the project strip ("Profile · Chat · Home · Sessions"), then the workbench's own header and the robot's bar with the Sessions page's agent menu — "Frankenstein elements just thrown together" (owner, 2026-11-01). - While the workbench is open, the sidebar, top bar, bottom tabs, footer and project strip are gone (body.fc-workbench-focus, the former solo rule applied to the whole screen from md up). They are for moving between pages, and a person here is not moving. The one back link in the header is the way out. A phone keeps its own bars: the rows need them. - The robot's bar is the chat | terminal switch alone (TerminalSessionBar `agentSwitch`, off in the quiet shape): the session's own chip names the agent and its box changes it. What is on the screen now, left to right: back, Open the site, "⋯"; the site as Loki sees it; the robot with one line of state, the view switch and the one box. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmswy1H6cYyL3hmLRy9 * feat(workbench): two windows of one desk — one frame, a title bar each The site sat in a card and the robot stood bare beside it, with a line of state floating above and a caption floating below: two different things on one screen. Now both regions, and a solo window, are one frame (WorkbenchFrame): a title bar — a dot for its tone, one sentence, one link — over a body. - The site's bar is its address and what Loki is doing there ("Live", "Loki is using it: …", "Loki's last look: …"), like a browser's own tab; its body the page, top-aligned; before any look, the address alone and "Tap to open" — never a sentence apologising for an empty box. - The robot's bar is the build's state (hooks/use-run-state, the Watch track's sentence) with "Watch it work"; its body the session with the one box. WorkbenchStateLine is folded into it. - The floating Ask Loki button leaves in focus: its panel is the second chat this screen deliberately has not, and it sat on the send arrow. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmswy1H6cYyL3hmLRy9 * feat(nav): Loki first — the chat is the default screen, three words then folds The owner's philosophy, 2026-11-01, now in AGENTS.md ("Why Loki exists, and for whom"): a good Loki chat, reachable in one step, is the screen that opens; the rest of the app one tap away; a friend on your side, not a staff; never a screen that makes a person feel stupid; measure by effort, not features. - APP_HOME and RUNNER_HOME are /loki: signing in, and Fleet Runner starting with the computer, land on the chat. They landed on Today, a page to read before a person could say anything. - The sidebar is three bare words — Loki, Home, Projects — the same three as the phone's bottom bar (Loki first there too), then folded groups that each say the question they answer: Waiting for you (Approvals, Feedback), Your day (Today, Suggestions, Voice), Across your projects (Sessions, Missions, Activity, Prompts), Under the hood (Packages, System), and Private behind the PIN. Not a drawer called More: the navigation test records why a "More" section rots, and still forbids it; the phone's More is the folded groups as a sheet. - Every sidebar line says what it is for on hover (the item's own description), so nothing has to be guessed. - SidebarSection gains `bare` (no header, never folded) and `foldedByDefault`; the tests that pinned the old Build / Loki / To review / The fleet placement now pin the new homes. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmswy1H6cYyL3hmLRy9 * feat(voice): Loki speaks as someone on your side The owner's philosophy (AGENTS.md, "Why Loki exists"): a friend on your side, not a staff you direct; never a word that makes a person feel stupid. The public pages still said the opposite. - Hero: "Say what you want. Loki builds it with you." (was "Describe it. Agents build it."). The lede, APP_DESCRIPTION, the social-card tagline and the how-it-works steps follow. Every factual claim is one the product keeps: it builds with AI agents, puts it online, changes it on ask. - /why's principles open with two new ones from the owner's words: "On your side" and "Life is short". Commitments about how Loki is made, not claims about what it does. - The new-project card says "Say what you want. Loki sets it up and starts building." instead of repos and agents; the sidebar's Loki line drops "dispatch" for "Loki answers, or builds it with you". - The hero's two sentences are separate balanced blocks: on a phone each breaks as an even pair, never one word alone. The mission headline on /why ("Direct the creation of …") is left for the owner to decide. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmswy1H6cYyL3hmLRy9 * feat(voice): the mission reads "with someone on your side" /why's headline was "Direct the creation of everything you can imagine." — the staff-you-manage voice the owner set aside. It now reads "Make everything you can imagine, with someone on your side.", the owner's own call (2026-11-01). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmswy1H6cYyL3hmLRy9 --------- Co-authored-by: Claude <noreply@anthropic.com>
906 lines
42 KiB
JavaScript
906 lines
42 KiB
JavaScript
/**
|
|
* 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 <label> — the whole label is clickable
|
|
// • a 16x28 switch with an ::after overlay extending the hit area to 44px
|
|
// Measuring only the element's rect reported both as failures.
|
|
//
|
|
// The obvious fix — document.elementFromPoint on a 44px cross — is WRONG, and
|
|
// shipping it cost a full production run: elementFromPoint is viewport-only,
|
|
// so every control below the fold returned null and the report filled up with
|
|
// 44px, 55px and 65px "offenders". A measurement that depends on scroll
|
|
// position is not a measurement. So resolve the hit area from geometry, which
|
|
// is what the two real techniques above actually change.
|
|
const overlayBox = (el) => {
|
|
for (const pseudo of ["::after", "::before"]) {
|
|
const cs = getComputedStyle(el, pseudo);
|
|
if (!cs || cs.content === "none" || (cs.position !== "absolute" && cs.position !== "fixed"))
|
|
continue;
|
|
const h = Math.max(parseFloat(cs.height) || 0, parseFloat(cs.minHeight) || 0);
|
|
const w = Math.max(parseFloat(cs.width) || 0, parseFloat(cs.minWidth) || 0);
|
|
if (h > 0 || w > 0) return { height: h, width: w };
|
|
}
|
|
return null;
|
|
};
|
|
|
|
const hitBox = (el) => {
|
|
const own = el.getBoundingClientRect();
|
|
let best = { height: own.height, width: own.width };
|
|
// A wrapping <label> (or one pointing here with `for`) IS the hit area.
|
|
if (/^(input|select|textarea)$/i.test(el.tagName)) {
|
|
let lab = el.closest("label");
|
|
if (!lab && el.id) {
|
|
try {
|
|
lab = document.querySelector(`label[for="${CSS.escape(el.id)}"]`);
|
|
} catch {
|
|
lab = null;
|
|
}
|
|
}
|
|
if (lab) {
|
|
const lr = lab.getBoundingClientRect();
|
|
if (lr.height > best.height) best = { height: lr.height, width: lr.width };
|
|
}
|
|
}
|
|
const ov = overlayBox(el);
|
|
if (ov && ov.height > best.height) best = ov;
|
|
return best;
|
|
};
|
|
|
|
const small = [...document.querySelectorAll('button, a[href], [role="button"], input, select')]
|
|
.filter((el) => {
|
|
const r = el.getBoundingClientRect();
|
|
if (r.width === 0 || r.height === 0) return false;
|
|
const cs = getComputedStyle(el);
|
|
if (cs.visibility === "hidden" || cs.opacity === "0" || cs.pointerEvents === "none")
|
|
return false;
|
|
// WCAG 2.5.8's inline exception: a link INSIDE a sentence cannot be given
|
|
// a 44px box without wrecking the paragraph, and the surrounding text is
|
|
// what makes it findable. Only genuinely inline links in flowing text —
|
|
// a link that is a flex item has been blockified and is not this.
|
|
if (el.tagName === "A" && cs.display === "inline") {
|
|
const parentText = (el.parentElement?.textContent || "").trim().length;
|
|
const ownText = (el.textContent || "").trim().length;
|
|
if (parentText > ownText + 12) return false;
|
|
}
|
|
return hitBox(el).height < minTouch - 0.5;
|
|
})
|
|
.map((el) => ({
|
|
tag: el.tagName.toLowerCase(),
|
|
label: (el.getAttribute("aria-label") || el.textContent || "").trim().slice(0, 28),
|
|
// The class is what you actually fix. Without it every finding needs a
|
|
// reverse hunt from a truncated label back to a component.
|
|
cls:
|
|
((el.className || "").toString().match(/ui-[\w-]+/g) || []).join(".") ||
|
|
(el.className || "").toString().slice(0, 40),
|
|
h: Math.round(hitBox(el).height),
|
|
}))
|
|
.slice(0, 12);
|
|
|
|
// Text WIDER than its own box, where nothing on the page can scroll to the
|
|
// rest of it.
|
|
//
|
|
// This is the failure that shipped on the /fleet/[slug] profile: unbreakable
|
|
// GitHub URLs inside roadmap prose made the content 737px wide in a 390px
|
|
// column, and `.ui-public-surface` sets `overflow-x: hidden` — so the page
|
|
// reported no overflow (the clip absorbed it), no ellipsis appeared, no
|
|
// scrollbar appeared, and 47% of every line was simply gone. Every existing
|
|
// detector here was blind to it by construction: the overflow check reads
|
|
// `documentElement.scrollWidth`, which the clip holds at the viewport width;
|
|
// the clipped-text check below requires the element ITSELF to clip (here the
|
|
// clipper is an ancestor) and measures HEIGHT; clipped-prose requires a
|
|
// declared ellipsis.
|
|
//
|
|
// So the question asked here is the reader's: can I get to the rest of this
|
|
// sentence? An ellipsis, a line-clamp and a scrollable strip all answer yes,
|
|
// and are excluded; an ancestor with `overflow-x: hidden` answers no. Only
|
|
// evaluated when the PAGE itself does not scroll sideways — when it does,
|
|
// the overflow check owns the finding and states it better.
|
|
const SCROLLS_X = new Set(["auto", "scroll", "overlay"]);
|
|
const pageScrollsX = de.scrollWidth > vw + 1;
|
|
const unreachable = pageScrollsX
|
|
? []
|
|
: [...document.querySelectorAll("body *")]
|
|
.filter((el) => {
|
|
if (el.children.length > 0) return false;
|
|
if (/^(input|textarea|select|option|svg|path)$/i.test(el.tagName)) return false;
|
|
const t = (el.textContent || "").trim();
|
|
if (t.length < 12) return false;
|
|
const r = el.getBoundingClientRect();
|
|
// sr-only text lives in a 1px box with overflow hidden — visually
|
|
// hidden on purpose, and it would otherwise fill this report.
|
|
if (r.width <= 4 || r.height <= 4) return false;
|
|
const cs = getComputedStyle(el);
|
|
if (cs.visibility === "hidden" || cs.display === "none") return false;
|
|
if (cs.textOverflow === "ellipsis") return false;
|
|
if (cs.webkitLineClamp && cs.webkitLineClamp !== "none") return false;
|
|
if (el.scrollWidth <= el.clientWidth + 2) return false;
|
|
if (SCROLLS_X.has(cs.overflowX)) return false;
|
|
for (let a = el.parentElement; a; a = a.parentElement) {
|
|
if (SCROLLS_X.has(getComputedStyle(a).overflowX)) return false;
|
|
}
|
|
return true;
|
|
})
|
|
.map((el) => ({
|
|
tag: el.tagName.toLowerCase(),
|
|
text: (el.textContent || "").trim().slice(0, 40),
|
|
cls:
|
|
((el.className || "").toString().match(/ui-[\w-]+/g) || []).join(".") ||
|
|
(el.className || "").toString().slice(0, 40),
|
|
hidden: el.scrollWidth - el.clientWidth,
|
|
shownPct: Math.round((el.clientWidth / el.scrollWidth) * 100),
|
|
}))
|
|
.slice(0, 8);
|
|
|
|
// Text clipped by a fixed-height box: content the operator simply cannot
|
|
// read, and invisible to an overflow check because the container itself fits.
|
|
const clipped = [...document.querySelectorAll("body *")]
|
|
.filter((el) => {
|
|
if (el.children.length > 0) return false;
|
|
const t = (el.textContent || "").trim();
|
|
if (t.length < 12) return false;
|
|
const cs = getComputedStyle(el);
|
|
if (cs.overflow === "visible" || cs.visibility === "hidden") return false;
|
|
// Ellipsis is a deliberate design choice; genuine vertical clipping is not.
|
|
if (cs.textOverflow === "ellipsis" && el.scrollWidth > el.clientWidth) return false;
|
|
// line-clamp is the VERTICAL ellipsis and is just as deliberate. Without
|
|
// this the audit reported every summary card in the app as clipped —
|
|
// "(-1014px)" on a line-clamp-2 prompt preview, which is the feature
|
|
// working. That noise is what made the clipped-text section unreadable,
|
|
// and an unreadable section hides the real clipping underneath it.
|
|
if (cs.webkitLineClamp && cs.webkitLineClamp !== "none") return false;
|
|
return el.scrollHeight > el.clientHeight + 2;
|
|
})
|
|
.map((el) => ({
|
|
tag: el.tagName.toLowerCase(),
|
|
text: (el.textContent || "").trim().slice(0, 30),
|
|
cls:
|
|
((el.className || "").toString().match(/ui-[\w-]+/g) || []).join(".") ||
|
|
(el.className || "").toString().slice(0, 40),
|
|
hidden: el.scrollHeight - el.clientHeight,
|
|
}))
|
|
.slice(0, 5);
|
|
|
|
// A SENTENCE cut off by a single-line ellipsis.
|
|
//
|
|
// The vertical check above deliberately exempts `text-overflow: ellipsis`,
|
|
// and that exemption is right for what it was written for: a project name in
|
|
// a narrow rail, a filename, an id. Truncating an identifier is a normal
|
|
// affordance — you still recognise it, and 76 files in src/components use
|
|
// `truncate` for exactly that. A blanket rule would fire on all of them.
|
|
//
|
|
// It is not right for prose. /control's "Suggested next (profile): …" line
|
|
// showed 50 of its 644 pixels — the rest lived only in a `title` tooltip, and
|
|
// a phone has no hover. Clicking that line loads it into the composer, so the
|
|
// sentence was the decision and a tenth of a sentence is not one.
|
|
//
|
|
// Three conditions keep this narrow enough to stay silent on the legitimate
|
|
// cases: the text must READ as a sentence (long, many spaces — an id has
|
|
// neither), and more than half of it must be hidden (a chip losing its tail
|
|
// is fine; a line showing its first eight words is not).
|
|
const PROSE_MIN_CHARS = 60;
|
|
const PROSE_MIN_SPACES = 8;
|
|
const PROSE_MAX_VISIBLE_FRACTION = 0.5;
|
|
const clippedProse = [...document.querySelectorAll("body *")]
|
|
.filter((el) => {
|
|
const cs = getComputedStyle(el);
|
|
if (cs.textOverflow !== "ellipsis" || cs.whiteSpace !== "nowrap") return false;
|
|
if (cs.visibility === "hidden") return false;
|
|
const t = (el.textContent || "").trim();
|
|
if (t.length < PROSE_MIN_CHARS) return false;
|
|
if ((t.match(/\s/g) || []).length < PROSE_MIN_SPACES) return false;
|
|
const full = el.scrollWidth;
|
|
if (full <= el.clientWidth + 2 || full === 0) return false;
|
|
return el.clientWidth / full < PROSE_MAX_VISIBLE_FRACTION;
|
|
})
|
|
.map((el) => ({
|
|
tag: el.tagName.toLowerCase(),
|
|
text: (el.textContent || "").trim().slice(0, 44),
|
|
cls:
|
|
((el.className || "").toString().match(/ui-[\w-]+/g) || []).join(".") ||
|
|
(el.className || "").toString().slice(0, 40),
|
|
hidden: el.scrollWidth - el.clientWidth,
|
|
shownPct: Math.round((el.clientWidth / el.scrollWidth) * 100),
|
|
}))
|
|
.slice(0, 5);
|
|
|
|
// A line-clamp that is DECLARED but does nothing.
|
|
//
|
|
// `-webkit-line-clamp` is inert unless the box is `display: -webkit-box`,
|
|
// which the line-clamp utility sets — and Tailwind's `block` utility
|
|
// overrides. `block ... line-clamp-2` computes to `display: block;
|
|
// -webkit-line-clamp: 2` and clamps nothing. It shipped here once, on
|
|
// /control's "Suggested next" line, and looked fixed: with no clamp the text
|
|
// simply wraps, which reads fine until a long one arrives and shoves the
|
|
// composer off the viewport.
|
|
//
|
|
// The clipped-prose check above cannot see this — that measures a HORIZONTAL
|
|
// ellipsis, and this failure has none. Nor can `display === "-webkit-box"`:
|
|
// Chrome reported `flow-root` for a clamp that was working correctly, so the
|
|
// declared display is not a reliable signal either way.
|
|
//
|
|
// So test the BEHAVIOUR: an element declaring N lines that renders more than
|
|
// N is a clamp that is not being enforced. Requires no knowledge of how the
|
|
// browser normalises display.
|
|
const deadClamps = [...document.querySelectorAll("body *")]
|
|
.filter((el) => {
|
|
const cs = getComputedStyle(el);
|
|
const n = parseInt(cs.webkitLineClamp, 10);
|
|
if (!Number.isFinite(n) || n < 1) return false;
|
|
if (cs.visibility === "hidden") return false;
|
|
const r = el.getBoundingClientRect();
|
|
if (r.height === 0 || r.width === 0) return false;
|
|
const lh = parseFloat(cs.lineHeight);
|
|
if (!Number.isFinite(lh) || lh <= 0) return false;
|
|
// Half a line of slack absorbs padding and sub-pixel rounding.
|
|
return el.clientHeight / lh > n + 0.5;
|
|
})
|
|
.map((el) => {
|
|
const cs = getComputedStyle(el);
|
|
return {
|
|
tag: el.tagName.toLowerCase(),
|
|
text: (el.textContent || "").trim().slice(0, 40),
|
|
cls:
|
|
((el.className || "").toString().match(/(ui-[\w-]+|line-clamp-\d+|block)/g) || []).join(
|
|
".",
|
|
) || (el.className || "").toString().slice(0, 40),
|
|
declared: parseInt(cs.webkitLineClamp, 10),
|
|
rendered: Math.round(el.clientHeight / parseFloat(cs.lineHeight)),
|
|
display: cs.display,
|
|
};
|
|
})
|
|
.slice(0, 5);
|
|
|
|
// Content trapped under fixed chrome (mobile bottom nav). Reachable only if
|
|
// the page scrolls far enough; on a short page it is permanently covered.
|
|
const bars = [...document.querySelectorAll("body *")].filter((el) => {
|
|
const cs = getComputedStyle(el);
|
|
const r = el.getBoundingClientRect();
|
|
return (
|
|
cs.position === "fixed" &&
|
|
r.height > 24 &&
|
|
r.width > vw * 0.6 &&
|
|
r.bottom >= de.clientHeight - 2
|
|
);
|
|
});
|
|
const barTop = bars.length
|
|
? Math.min(...bars.map((b) => b.getBoundingClientRect().top))
|
|
: Infinity;
|
|
const buried =
|
|
bars.length === 0
|
|
? []
|
|
: [...document.querySelectorAll("button, a[href], input, select")]
|
|
.filter((el) => {
|
|
const r = el.getBoundingClientRect();
|
|
if (r.height === 0 || getComputedStyle(el).position === "fixed") return false;
|
|
// Intersects the bar AND the page cannot scroll further to free it.
|
|
return (
|
|
r.bottom > barTop && r.top < de.clientHeight && de.scrollHeight <= de.clientHeight + 2
|
|
);
|
|
})
|
|
.map((el) => ({
|
|
tag: el.tagName.toLowerCase(),
|
|
label: (el.getAttribute("aria-label") || el.textContent || "").trim().slice(0, 24),
|
|
}))
|
|
.slice(0, 4);
|
|
|
|
const brokenImages = [...document.querySelectorAll("img")]
|
|
.filter(
|
|
(img) => img.complete && img.naturalWidth === 0 && (img.getAttribute("src") || "").length > 0,
|
|
)
|
|
.map((img) => (img.getAttribute("src") || "").slice(0, 60))
|
|
.slice(0, 4);
|
|
|
|
return {
|
|
vw,
|
|
scrollWidth: de.scrollWidth,
|
|
overflow: de.scrollWidth > vw + 1,
|
|
offenders,
|
|
small,
|
|
clipped,
|
|
unreachable,
|
|
clippedProse,
|
|
deadClamps,
|
|
buried,
|
|
brokenImages,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Every word on the page drawn across two lines — chatkit's `findBrokenWords`,
|
|
* handed to the page as source (it is self-contained for exactly this). Words
|
|
* beside - / . @ : _ and anything over 24 characters are exempt there: a URL
|
|
* or an identifier has to break somewhere.
|
|
*/
|
|
const BROKEN_WORDS = `(${BROKEN_WORDS_SOURCE})(document.body)`;
|
|
|
|
/** Both measures of one page, in one place, so the retry below takes both. */
|
|
async function measure(page) {
|
|
const r = await page.evaluate(measurePage, MIN_TOUCH_PX);
|
|
const brokenWords = await page.evaluate(BROKEN_WORDS);
|
|
return { ...r, brokenWords };
|
|
}
|
|
|
|
async function main() {
|
|
const only = process.argv.slice(2).filter((a) => a.startsWith("/"));
|
|
const pages = only.length > 0 ? only : [...PUBLIC_PAGES, ...PAGES];
|
|
|
|
// A session is needed only for the authenticated half. Demanding one up front
|
|
// meant the public pages — which need none — could not be audited without
|
|
// credentials, which is a large part of why they never were.
|
|
const needsSession = pages.some((p) => !isPublicPage(p));
|
|
const token = needsSession ? await mintSessionToken(BASE) : null;
|
|
if (needsSession && !token) {
|
|
console.error(
|
|
"✗ no session. Set LOKI_SESSION_TOKEN, or AUDIT_DATABASE_URL + AUTH_SECRET.\n" +
|
|
" For a firewalled Postgres: bash scripts/db-tunnel.sh (prints the URL to use)\n" +
|
|
" Public routes need no session: pass them as arguments, e.g. `/ /fleet`.",
|
|
);
|
|
process.exit(2);
|
|
}
|
|
|
|
fs.mkdirSync(OUT, { recursive: true });
|
|
// CHROMIUM_PATH: run against a preinstalled Chromium (a sandbox whose
|
|
// Playwright pin has no matching browser download).
|
|
const browser = await chromium.launch(
|
|
process.env.CHROMIUM_PATH ? { executablePath: process.env.CHROMIUM_PATH } : {},
|
|
);
|
|
const failures = [];
|
|
const notes = [];
|
|
let checks = 0;
|
|
|
|
for (const vp of VIEWPORTS) {
|
|
const ctx = await browser.newContext({
|
|
viewport: { width: vp.width, height: vp.height },
|
|
hasTouch: vp.touch,
|
|
deviceScaleFactor: 1,
|
|
});
|
|
await ctx.addCookies(sessionCookies(BASE, token));
|
|
|
|
for (const route of pages) {
|
|
const page = await ctx.newPage();
|
|
// Console + network failures are free to collect while the page is open
|
|
// and are the cheapest signal that a surface is quietly broken — an audit
|
|
// that only measures boxes will pass a page whose data never loaded.
|
|
const consoleErrors = [];
|
|
page.on("console", (m) => {
|
|
if (m.type() === "error") consoleErrors.push(m.text().slice(0, 120));
|
|
});
|
|
page.on("pageerror", (e) =>
|
|
consoleErrors.push(`uncaught: ${String(e.message).slice(0, 120)}`),
|
|
);
|
|
const httpFailures = [];
|
|
// 4xx is tracked SEPARATELY and by URL. The first run of this audit
|
|
// reported "400 responses on /settings and /thoughts" and that was all it
|
|
// could say, because a 4xx only reached the log as the browser's generic
|
|
// "Failed to load resource" console line — truncated, with no path. A
|
|
// request your own app made and your own server rejected is a bug you
|
|
// cannot act on without knowing which one it was.
|
|
// Same-origin only: a 4xx from a third party is their problem, and 404s
|
|
// for things like favicons are noise, not findings.
|
|
const badRequests = [];
|
|
page.on("response", (r) => {
|
|
const s = r.status();
|
|
const url = r.url();
|
|
if (!url.startsWith(BASE)) return;
|
|
if (s >= 500) httpFailures.push(`${s} ${url.replace(BASE, "").slice(0, 70)}`);
|
|
else if (s >= 400 && s !== 404)
|
|
badRequests.push(`${s} ${url.replace(BASE, "").slice(0, 70)}`);
|
|
});
|
|
try {
|
|
const nav = await page.goto(`${BASE}${route}`, {
|
|
waitUntil: "networkidle",
|
|
timeout: 45_000,
|
|
});
|
|
// A listed route that 404s is a hole in the list, not a measurement.
|
|
// It matters most for the DYNAMIC samples — /fleet/heidi, /u/cato, one
|
|
// essay slug — which stand in for a whole template: rename the essay
|
|
// or unlist the project and this audit would go on measuring a
|
|
// not-found page and reporting it green, which is indistinguishable
|
|
// from coverage. Fails loudly instead, so the sample gets replaced.
|
|
const status = nav?.status() ?? 0;
|
|
if (status === 404) {
|
|
failures.push(`${route} @${vp.name}: 404 — the audit list names a page that is gone`);
|
|
console.log(` ✗ ${route} @${vp.name}px — 404, list is stale`);
|
|
continue;
|
|
}
|
|
// AUDIT_EXTRA_CSS: measure a stylesheet change against PRODUCTION
|
|
// markup, before shipping it. A design-system rule is only correct in
|
|
// contact with real pages in real states, and the alternatives are both
|
|
// bad: ship it and find out (this file exists because that cost a full
|
|
// production run), or stand up a local build — which measures a
|
|
// different database, and, on the day this was added, silently measured
|
|
// a DIFFERENT APP because another process already held the port.
|
|
// Injecting into the live page changes exactly one variable.
|
|
if (EXTRA_CSS) await page.addStyleTag({ content: EXTRA_CSS });
|
|
// Let late layout (fonts, async panes) settle before measuring — a
|
|
// measurement taken mid-hydration reports overflow that never reaches a
|
|
// human eye, and a flaky gate is a disabled gate.
|
|
await page.waitForTimeout(1200);
|
|
|
|
// A page that navigates AFTER networkidle — an auth refresh, an
|
|
// onboarding guard, a client-side redirect — destroys the execution
|
|
// context mid-measurement, and the run reports the route as a failure
|
|
// it is not. Seen on /history and then on /decisions: the route moved
|
|
// between runs, which is the signature of a race rather than a layout
|
|
// fault. Settle and measure once more; a gate that cries wolf is a gate
|
|
// someone learns to ignore.
|
|
let r;
|
|
try {
|
|
r = await measure(page);
|
|
} catch (err) {
|
|
if (!/Execution context was destroyed/.test(String(err?.message))) throw err;
|
|
await page.waitForLoadState("networkidle", { timeout: 20_000 }).catch(() => undefined);
|
|
await page.waitForTimeout(1200);
|
|
if (EXTRA_CSS) await page.addStyleTag({ content: EXTRA_CSS });
|
|
r = await measure(page);
|
|
}
|
|
checks++;
|
|
// A route that lands somewhere else is measuring a page it does not
|
|
// name. Not a failure — redirects are legitimate — but it must be SAID,
|
|
// or the list rots into aliases and the report credits coverage it
|
|
// never had.
|
|
const landed = new URL(page.url()).pathname;
|
|
if (landed !== route) notes.push(`${route} @${vp.name}: landed on ${landed}`);
|
|
const shot = path.join(
|
|
OUT,
|
|
`${route.split("?")[0].replace(/\//g, "") || "root"}-${vp.name}.png`,
|
|
);
|
|
await page.screenshot({ path: shot, fullPage: false });
|
|
|
|
// HARD failures: the page is broken, not merely imperfect.
|
|
if (r.overflow) {
|
|
failures.push(
|
|
`${route} @${vp.name}: horizontal overflow ${r.scrollWidth}px > ${r.vw}px\n` +
|
|
r.offenders
|
|
.map((o) => ` ${o.tag}.${o.cls} (right=${o.right}, w=${o.width})`)
|
|
.join("\n"),
|
|
);
|
|
console.log(` ✗ ${route} @${vp.name}px — overflow ${r.scrollWidth} > ${r.vw}`);
|
|
} else if (r.unreachable.length > 0) {
|
|
failures.push(
|
|
`${route} @${vp.name}: text clipped with no way to reach the rest — ` +
|
|
`the page does not scroll sideways and an ancestor hides the overflow\n` +
|
|
r.unreachable
|
|
.map(
|
|
(u) =>
|
|
` ${u.tag}.${u.cls} "${u.text}…" — ${u.shownPct}% shown, -${u.hidden}px`,
|
|
)
|
|
.join("\n"),
|
|
);
|
|
console.log(
|
|
` ✗ ${route} @${vp.name}px — ${r.unreachable.length} clipped, unreachable text run(s): ${r.unreachable[0].shownPct}% of "${r.unreachable[0].text}…" shown`,
|
|
);
|
|
} else if (r.brokenWords.length > 0) {
|
|
// A word cut in two is unreadable, not merely tight: "Di / re / ct /
|
|
// or / y" is five syllables nobody wrote. Every word is listed,
|
|
// because the list names the cause — one word is a narrow cell,
|
|
// all of them is a `break-all` on an ancestor.
|
|
const words = [...new Set(r.brokenWords)];
|
|
failures.push(
|
|
`${route} @${vp.name}: ${words.length} word(s) cut across two lines — ` +
|
|
words.map((w) => `"${w}"`).join(", "),
|
|
);
|
|
console.log(
|
|
` ✗ ${route} @${vp.name}px — ${words.length} word(s) cut across two lines: ${words
|
|
.slice(0, 6)
|
|
.map((w) => `"${w}"`)
|
|
.join(", ")}${words.length > 6 ? ", …" : ""}`,
|
|
);
|
|
} else if (httpFailures.length > 0) {
|
|
failures.push(
|
|
`${route} @${vp.name}: server error(s) — ${httpFailures.slice(0, 3).join("; ")}`,
|
|
);
|
|
console.log(` ✗ ${route} @${vp.name}px — ${httpFailures[0]}`);
|
|
} else if (r.buried.length > 0) {
|
|
failures.push(
|
|
`${route} @${vp.name}: control(s) trapped under fixed chrome on an unscrollable page — ${r.buried.map((b) => `${b.tag}"${b.label}"`).join(", ")}`,
|
|
);
|
|
console.log(
|
|
` ✗ ${route} @${vp.name}px — ${r.buried.length} control(s) buried under the bottom bar`,
|
|
);
|
|
} else if (vp.touch && r.small.length > 0) {
|
|
// Reported, not failed: the 44px rule has legitimate exceptions
|
|
// (inline text links), and failing on it would bury the overflow
|
|
// signal that actually breaks a page.
|
|
console.log(
|
|
` ⚠ ${route} @${vp.name}px — ${r.small.length} target(s) under ${MIN_TOUCH_PX}px: ${r.small.map((s) => `${s.tag}"${s.label}"[${s.cls}]=${s.h}px`).join(", ")}`,
|
|
);
|
|
} else {
|
|
console.log(` ✓ ${route} @${vp.name}px`);
|
|
}
|
|
// Soft signals, always reported alongside the verdict above.
|
|
if (r.clipped.length > 0)
|
|
console.log(
|
|
` ⚠ clipped text: ${r.clipped.map((c) => `"${c.text}"[${c.cls}] (-${c.hidden}px)`).join(", ")}`,
|
|
);
|
|
if (r.clippedProse.length > 0)
|
|
console.log(
|
|
` ⚠ sentence cut off by a single-line ellipsis (the rest is hover-only, so a phone cannot read it): ${r.clippedProse
|
|
.map((c) => `"${c.text}…"[${c.cls}] ${c.shownPct}% shown, -${c.hidden}px`)
|
|
.join(", ")}`,
|
|
);
|
|
if (r.deadClamps.length > 0)
|
|
console.log(
|
|
` ⚠ line-clamp declared but NOT enforced (a \`block\`/display utility beats it — the box grows instead): ${r.deadClamps
|
|
.map(
|
|
(c) =>
|
|
`"${c.text}…"[${c.cls}] declared ${c.declared} lines, renders ${c.rendered} (display:${c.display})`,
|
|
)
|
|
.join(", ")}`,
|
|
);
|
|
if (r.brokenImages.length > 0)
|
|
console.log(` ⚠ broken image(s): ${r.brokenImages.join(", ")}`);
|
|
if (badRequests.length > 0)
|
|
console.log(
|
|
` ⚠ rejected request(s): ${[...new Set(badRequests)].slice(0, 4).join(" | ")}`,
|
|
);
|
|
// Hydration errors get their own line rather than being one of two
|
|
// truncated console strings. They are never cosmetic: the server sent
|
|
// markup the browser disagreed with, so SOMETHING on the page rendered
|
|
// from state the server could not have — a clock, a locale, a random
|
|
// id, a width. The user sees the wrong content before React repairs it.
|
|
const hydration = [...new Set(consoleErrors)].filter((m) => HYDRATION_ERROR.test(m));
|
|
if (hydration.length > 0) console.log(` ⚠ HYDRATION MISMATCH: ${hydration[0]}`);
|
|
if (consoleErrors.length > 0)
|
|
console.log(` ⚠ console: ${[...new Set(consoleErrors)].slice(0, 2).join(" | ")}`);
|
|
} catch (e) {
|
|
failures.push(`${route} @${vp.name}: ${e instanceof Error ? e.message.slice(0, 120) : e}`);
|
|
console.log(
|
|
` ✗ ${route} @${vp.name}px — ${e instanceof Error ? e.message.slice(0, 80) : e}`,
|
|
);
|
|
} finally {
|
|
await page.close();
|
|
}
|
|
}
|
|
await ctx.close();
|
|
}
|
|
await browser.close();
|
|
|
|
console.log(`\n${checks} check(s) across ${VIEWPORTS.length} viewports · screenshots in ${OUT}/`);
|
|
if (notes.length > 0) {
|
|
console.log(`\nnote — ${notes.length} route(s) did not measure what they name:`);
|
|
for (const n of notes) console.log(` · ${n}`);
|
|
}
|
|
if (failures.length > 0) {
|
|
console.error(`\n✗ ${failures.length} responsive failure(s):\n`);
|
|
for (const f of failures) console.error(` - ${f}`);
|
|
process.exit(1);
|
|
}
|
|
console.log("✓ no horizontal overflow and no cut word at any tested width");
|
|
}
|
|
|
|
main().catch((e) => {
|
|
console.error(e);
|
|
process.exit(2);
|
|
});
|