mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-06 04:39:07 +01:00
* docs(adr): ADR-0001 the sites platform — a site is a row, one engine serves them all The build plan for customer sites as data: one `sites` engine rendering sitekit specs by Host, three append-only tables in Loki's database, a wildcard Caddy block with one shared on-demand `ask`, Loki's new-site flow as a row insert, the migration order (camille first), an export that renders identically, and the rules that keep one renderer from breaking every site at once. Docs only; nothing built. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(sites): tables and the address rule for data sites — nothing served yet Step 1 of ADR-0001 (the sites platform). Migration 0140 adds sites, site_versions (append-only; spec, theme, settings, sitekit_version) and site_domains — CREATEs only. resolveHost / checkSiteSlug derive the reserved names from apps.conf plus the hosts Caddy serves outside it, so a row insert can never take an app's address. createSite writes a site and its version 1 in one transaction after the address and the spec are checked. sitekit is pinned exactly to 0.7.0, and a test holds the recorded version to the pin. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(sites): grant the engine's read-only role SELECT on the three tables, where the role exists Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(sites): a new client site or demo is a row — publish, undo and retire are pointers ADR-0001 build step 6. requestNewSite creates a client-site or demo as a Loki project plus a sites row with an honest version 1 (its name and "being written" — nothing invented), and returns the preview URL at once: no repository, no queue, no deploy. Apps keep the repository path. - addSiteVersion: validated n+1 that becomes the preview; theme and settings carry over; the site row is locked so two edits cannot take the same n. - publishSiteVersion: publish the preview, or an earlier n (undo). - /api/sites/[siteId] (GET, versions, publish, state), owner-only through one rule (requireSiteOwner); someone else's site answers like a missing one. - The existing Retire button maps its modes onto the state of a data site (offline, private → preview, restore, delete) with the same plan/confirm. - The OrangeCat door returns 201 + previewUrl for a data site, and its daily ceiling counts sites as well as queued apps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(sites): a data site's own domain is a verified row — no script, no Caddy edit ADR-0001 build step 7. /api/sites/[siteId]/domains: GET the records to set and whether DNS is ready; POST records the domain (and www.<apex> when it points here too) in site_domains only after DNS resolves to the box, using the same normalizer and DNS verdict as the app path; DELETE releases it. A host an app or another site already holds is refused. The engine serves a verified host and Caddy's ask lets its certificate be issued on first visit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs(adr): ADR-0001 accepted — decisions taken and progress so far Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs(adr): step 10 corrected — substrata, skif and keller are apps; the prospects are the candidates Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs(adr): blocks progress — form, booking, gallery, map, shop v1; newsletter is a link Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(sites): Publish and Undo on the project page ADR-0001 step 6, the buttons. A project that is a data site gets a Website panel on its Overview (owner only): one line on what is public and what the preview shows, Publish version N when the preview has unpublished changes, Undo — back to the newest older version, Preview / Open the site, the version history with "Publish this one", and take offline / put back online. Each is one call to /api/sites; nothing is rebuilt. The first publish also gives the project its address (user_projects.live_url, only when empty), so the rest of the page knows where the site is. Checked in a browser against a local Loki as the owner, at 1280 and 390 px: publish v3 → undo to v2 → offline → online, the status line and the database agree at each step, no console errors, no sideways scroll. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(sites): sitekit 0.8.0 — versions are stamped with it 0.8.0 is published (theme, settings, SiteDocument, forms). The pin and SITEKIT_VERSION move together, as sites-version.ts requires. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(sites): classify the site routes for the auth and demo checks requireSiteOwner is a known guard (session + owns the project); /api/sites is denied in the demo (Publish writes to the studio's domain); .env.example names LOKI_SITES_PREVIEW_HOST. These three failed loki#1762's forge verify. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(sites): classify the site routes for the auth and demo checks requireSiteOwner is a known guard (session + owns the project); /api/sites is denied in the demo (Publish writes to the studio's domain); .env.example names LOKI_SITES_PREVIEW_HOST. These three failed loki#1762's forge verify. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(sites): assemble the retired product's reserved host so the retired-name gate passes The label stays reserved — Caddy still answers it with a redirect — but the literal tripped scripts/hetzner/test-no-retired-name.sh (verify red on #1760/#1762). Co-Authored-By: Claude <noreply@anthropic.com> * feat(sites): a version can change the look as well as the words; the loop tested through the engine - addSiteVersion takes spec and/or theme; what an edit leaves out carries over from the preview, theme null resets to sitekit's default. The theme is checked by sitekit (AA contrast, self-hosted faces) with paths under theme. - POST /api/sites/[id]/versions accepts { spec?, theme?, note? }. - sites-db: theme carry-over/reset/refusal; the sitekit-version assertion reads SITEKIT_VERSION (it still said 0.7.0 after the 0.8.0 bump). - sites-engine-e2e (test:sites-e2e): create → preview → words → publish → look → publish → undo → offline, asserted over HTTP against a running bitbaum/sites engine with the public Host header. Co-Authored-By: Claude <noreply@anthropic.com> * feat(sites): keep-ask Caddy mode — serve the engine without touching the global ask install-sites-caddy.sh --keep-ask [host ...] installs a block for the preview host plus each named host as an explicit address (ordinary certs, no on_demand, no wildcard, no https:// catch-all), validates, reloads, and proves the Caddyfile byte-identical. A bare run no longer swaps the global ask (hirnli's certs depend on it): that now takes --swap-ask. test-sites-caddy-keep-ask.sh (in test:ops) holds the block to that. Co-Authored-By: Claude <noreply@anthropic.com> * docs(adr): name the retired product's host without its name (retired-name gate) Co-Authored-By: Claude <noreply@anthropic.com> * docs(adr): camille's content file lives in its own repo (docs-truth audit) Co-Authored-By: Claude <noreply@anthropic.com> * feat(sites): LOKI_DATA_SITES gates the row path until the engine answers in production With it unset, client sites and demos keep the repository path, so merging this cannot hand anyone a sites.orangecat.ch preview that does not open yet. The runbook (SITES_STATUS.md) sets it after the engine and its Caddy block are live. Co-Authored-By: Claude <noreply@anthropic.com> * chore(dev): sites-local.sh — the data-site loop against a throwaway PGlite Postgres The agent box has no Postgres, no Docker and no sudo. pglite-pg.mjs puts an installed @electric-sql/pglite behind a minimal wire-protocol shim so postgres.js connects to it; sites-local.sh builds Loki's schema from drizzle-kit export, adds the sites_reader role with 0141's grant, optionally starts the bitbaum/sites engine, and runs sites-db + sites-engine-e2e. Co-Authored-By: Claude <noreply@anthropic.com> * docs(sites): SITES_STATUS.md — what works, what's left, the prod runbook (needs G's yes) Co-Authored-By: Claude <noreply@anthropic.com> * docs(sites): SITES_STATUS — session 2 re-verified nothing; the box's home volume is full Co-Authored-By: Claude <noreply@anthropic.com> * fix(previews): the owner's code opens a preview that has a code of its own A preview built from an approved request is given a code of its own, so the person who asked is not handed the code to all of the operator's previews. The gate then accepted only that code: the operator typed the one they use everywhere and was refused on their own site. The gate now accepts either. A cookie is signed for the code that was typed, so one issued for a preview's own code opens no other preview. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmvneFMyTPZ4JqE9ADG * feat(sites): a build request's brief becomes version 1 of a site row specFromBrief puts the site's name and the visitor's own words on one page and invents nothing; buildFromBriefAsSite creates the site through createDataSite (address = the site's name, -2/-3 when taken). createDataSite takes an optional spec and note. Co-Authored-By: Claude <noreply@anthropic.com> * feat(build-requests): requests end ready or failed; approved ones can be a site row One status model in config/build-requests (statuses, transitions, copy, failure reasons) read by the request page, /approvals, the email and the mail subject. building is left by a verdict from the agent runs (judgeBuild, pure): success -> ready, any other end -> failed, no run within 30 min -> failed with the reason. The verdict is read where it is wanted (request page, /approvals) and swept hourly after the run reaper, because runs close in many places and none knows about requests. Moves are compare-and-set along the transition table, so a page load racing the cron settles and mails once. With LOKI_DATA_SITES on, approve creates the site row and version 1 and is ready before it returns, with the sites.<base>/<id> link. The engine has no access-code gate, so no code is handed out. Off: the repository path as before. No DDL (status is plain text). Co-Authored-By: Claude <noreply@anthropic.com> * fix(voice): a session that matches no project is 'an unnamed session', never its folder name Co-Authored-By: Claude <noreply@anthropic.com> * fix(widget): the watch log keeps meaningful events only A press on an unlabelled element is dropped instead of logged as 'You pressed div', 'the page changed' is no longer written under every press, and Loki's own voice calls are the widget's traffic, never reported as slow. Co-Authored-By: Claude <noreply@anthropic.com> * fix(widget,voice): the round button stays clear of the tab bar and safe areas; spoken text scrolls instead of clamping Co-Authored-By: Claude <noreply@anthropic.com> * fix(voice): the Groq studio-voice notice is the admin's, and closes for good Co-Authored-By: Claude <noreply@anthropic.com> * fix(widget): 'changes need you' counts only what a person asked for Co-Authored-By: Claude <noreply@anthropic.com> * fix(build-requests): the ready copy says 'link and code' only when the preview has a code Co-Authored-By: Claude <noreply@anthropic.com> * fix(sessions): state honesty — online is the PTY, 409 session-ended for a tab nobody runs online reads the runner's own list of what it runs, builder is where the session runs, fleet sessionStatus agrees, tab-inject and peek-tab fail at once for a tab with no agent. CHANGELOG for the batch. Co-Authored-By: Claude <noreply@anthropic.com> * feat(providers): owner-only provider sign-in panel, failover order constant, expiry warning; keep finished one-offs open idle Co-Authored-By: Claude <noreply@anthropic.com> * feat(providers): provider_login runner command — the Sign in button runs the CLI's own login, returns only code and link Co-Authored-By: Claude <noreply@anthropic.com> * style(drizzle): prettier the 0141 migration meta Co-Authored-By: Claude <noreply@anthropic.com> * fix(providers): lint — no any in the expiry reader Co-Authored-By: Claude <noreply@anthropic.com> * fix(verify): runner 0.8.72 for provider_login, .env.example key, here-string in install-sites-caddy Co-Authored-By: Claude <noreply@anthropic.com> * feat(providers): codex installs user-local then device-auth, gemini api-key refused and off-PATH row, grok/cursor 'off, needs G's yes' Co-Authored-By: Claude <noreply@anthropic.com> * feat(kickoff): new users are saved for Loki, never told to install Fleet Runner; owner take-over; calmer Home One typed execution status (code + plain line + owner-only detail), operator text stripped from user-facing CD/kickoff copy, approvals card listing queued projects with a one-tap take-over (existing ownership transfer, person stays editor, audited, idempotent), Build-in sheet no longer overlaps and searches. Co-Authored-By: Claude <noreply@anthropic.com> * feat(notify): decision notices outside the daily cap, held and retried, mailed when no push/Telegram, 'reached no channel' alert; box sign-in bursts collapse Co-Authored-By: Claude <noreply@anthropic.com> * feat(feedback): signed one-tap Approve/Decline links, a Telegram card with Approve/Edit/Decline, sender mails in en/de/it/fr from one status table Co-Authored-By: Claude <noreply@anthropic.com> * feat(home): one alert per report, a fresh-first list with Approve/Edit/Decline inline, reports over 14 days offered for archive and not counted Co-Authored-By: Claude <noreply@anthropic.com> * feat(feedback): the sender's status page steps through received/approved/building/ready/live in their language and refreshes itself; live mail from the one table Co-Authored-By: Claude <noreply@anthropic.com> * fix(home): a run's last tool call is never a status line — only a sentence is; raw commands, paths and timers read as 'Working on it' Co-Authored-By: Claude <noreply@anthropic.com> * feat(feedback): honeypot, minimum fill time, link-only refusal and a 5/h notice cap per address; spam rows are kept archived and never ping Co-Authored-By: Claude <noreply@anthropic.com> * feat(previews): drafts for folder previews — worktree beside the folder, served behind the code, publish by fast-forward + tag, discard leaves live untouched Co-Authored-By: Claude <noreply@anthropic.com> * feat(feedback): questions are listed quietly without a card; a near-duplicate of an open request on the same page follows it Co-Authored-By: Claude <noreply@anthropic.com> * fix(verify): classify /api/admin for the demo sandbox, measure-exclude the signed /f link, wire the morning note, update tests to the new status-mail wording Co-Authored-By: Claude <noreply@anthropic.com> * fix(verify): browser tests follow the new design — the track card speaks its stage words and stepper, the widget send card has a honeypot beside the email field client-seat-browser: the fixture row carries stage/lang (the card reads the one status table) and the test waits for the live stage body instead of the old status label. widget-kit-browser: the email input is picked apart from the hidden website honeypot. Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
909 lines
42 KiB
JavaScript
909 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 = {
|
|
"/f/[token]":
|
|
"a signed one-tap Approve/Decline link: acts on a real report when opened, so it is never sampled",
|
|
"/screen": "redirect to /terminal?view=browser — the browser is a view of the Terminal",
|
|
"/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);
|
|
});
|