Files
heidi/scripts/audit/responsive.mjs
CatoandClaude ffc2596393 Heidi: plans page, sign-up CTA, privacy choice to Settings (#440)
- /[locale]/plans: Free, Heidi Pass (highlighted), Organisations; 30 days | 1 year
  toggle with a saving badge computed from the env prices; questions a day read
  from lib/config/caps.ts; no price while sales are off, "Coming soon, get
  notified" keeps an address in the new pass_interest table (migration 0032).
- /pass redirects to /plans; the code field is under "Have a code?".
- Four first-party counts in usage_counts: plans views, sign-ups started,
  checkouts started, passes paid.
- Signed-out home: one primary "See plans".
- "Keep on this device only" moves from My space to Settings > Privacy.
- Header, phone menu and footer link "Plans".

Co-authored-by: Claude <noreply@anthropic.com>
2026-12-02 22:40:05 +01:00

580 lines
29 KiB
JavaScript

/**
* Every page, at every phone width, in every language — does anything run off
* the side of the screen?
*
* WHY THIS EXISTS AS A SCRIPT RATHER THAN A TEST. Horizontal overflow is a
* LAYOUT fact: it depends on the real width of real glyphs in a real font at a
* real viewport, and no amount of reading the source finds it. It was reported
* three times from a phone before anything caught it, and each time the fix
* was applied to the one page in the screenshot while three others stayed
* broken — because nobody could see them.
*
* WHAT IT CHECKS, and the second one is the one that matters:
*
* OVER an element's box extends past the viewport. Before `overflow-x: clip`
* went on the body this made the whole DOCUMENT scroll sideways; now it
* is clipped, so `document.scrollWidth` no longer reveals it and this
* has to measure the elements themselves.
* CLIP an element's content is wider than the element and the element does
* not scroll — text cut off and unreachable. The same defect, one level
* down, and invisible without measuring.
* WORD a word drawn across two lines — "Te / rm", "Di / re / ct / or / y".
* Nothing overflows and nothing is clipped; the text simply cannot be
* read. `wrap-anywhere` on the wrong element does this, and so does a
* table cell at phone width. chatkit's `findBrokenWords` measures each
* word's line boxes (a word beside - / . @ : and anything over 24
* characters is exempt, since a link has to break somewhere).
*
* AND IT OPENS THINGS, because measuring a page at rest missed a real one. The
* account dropdown hangs `absolute right-0` off its button; the day the avatar
* stopped being the last control in the bar, the panel's left third went off
* the screen with its labels cut in half. Every check here passed, because
* every dropdown on the page was shut. So the header's disclosures are opened
* one at a time and measured open — on a couple of representative pages rather
* than all of them, since the header is the same header everywhere.
*
* It seeds real browser state first: a dozen kept words, in several scripts,
* with the contexts they were kept from — one of them a link, because a
* learner keeping a word from a pasted URL is the exact case that broke
* `/portal`, and an empty localStorage would have shown a clean page.
*
* pnpm run dev # in another terminal
* pnpm run audit:responsive
* LOCALES=de,fr WIDTHS=320 pnpm run audit:responsive # narrow it down
*
* NOT part of `pnpm run verify`: it needs a running server and a browser
* binary, which `verify` deliberately does not. Run it when you touch layout.
*/
import { BROKEN_WORDS_SOURCE } from "@bitbaum/chatkit/audit";
import { chromium } from "playwright";
const BASE = process.env.BASE ?? "http://localhost:3000";
const LOCALES = (process.env.LOCALES ?? "de,fr,ru").split(",");
const WIDTHS = (process.env.WIDTHS ?? "320,360,390").split(",").map(Number);
const THEMES = (process.env.THEMES ?? "light,dark").split(",");
/**
* Where the header's dropdowns are opened and measured.
*
* Two pages rather than all of them: the header is the same header everywhere,
* and opening three disclosures on five hundred renders would turn a two
* minute check into a twenty minute one nobody runs.
*/
const PROBE = ["", "/portal"];
/** Every page below a locale. A route missing here is a route nobody measures. */
const PATHS = [
"", "/chat", "/portal", "/about", "/contribute", "/dialect", "/dialect/zueriduetsch",
// Basel is the one area on the far side of the first isogloss, and the one
// whose branch panel shows two identical forms; Bündnerdütsch is the one
// that belongs to no branch. Both render a path the taught area does not.
"/dialect/baseldytsch", "/dialect/buendnerdueuetsch",
"/essays", "/essays/warum-die-schweiz-ihre-mundarten-behalten-hat",
"/grammar", "/impressum", "/investors", "/listen", "/method", "/organisations",
// The pass page: one card per pass, a price and a button per way of paying
// (francs and Bitcoin both, where both are on), the code field below.
"/pass",
"/plans",
// Which models answer: a table of names and numbers, the widest thing on it a model id.
"/models",
"/practice", "/privacy", "/settings", "/speaking", "/technology", "/vocabulary",
// The situations index, plus the two scenes most likely to break a phone:
// `handover` holds the longest line in the pack («S Zimmer, wo mir gschtern
// gruumt händ, isch parat.») beside a German gloss that is longer still, and
// `evening-unrest` is the scene whose rows carry a grammar link under both
// halves — the three-deep stack that has nothing to shrink if the grid track
// is left at `auto`.
"/situations", "/situations/handover", "/situations/evening-unrest", "/languages",
// Two of the scenes added on 2026-11-26, one per domain: the longest
// German line of the new care scenes (`at-the-door`) and the longest
// everyday title in Russian (`asking-the-way`).
"/situations/at-the-door", "/situations/asking-the-way",
// The language pages the map opens: Romansh carries the idioms, French the
// longest region sentence, and all three the interest form beside the map.
"/languages/fr", "/languages/it", "/languages/rm", "/dialect/wallisertitsch",
// A grammar topic page, and the two worst cases among them: `no-preterite`
// has the longest example pair in the pack and now also lists the scene
// lines that use it, and `unified-plural` renders «Mir händ, ihr händ, si
// händ.» beside a German gloss half again as long.
"/grammar/no-preterite", "/grammar/unified-plural",
// The practice page in a SCOPED state, which is a different layout: it adds
// the scope banner above the session, and its pill wraps in three languages.
"/practice?topic=no-preterite",
// The session screens: no header and no footer, a body exactly the screen
// high, and the answer bar pinned under a scrolling question. The test
// carries its clock in the top bar, the one place a long label can collide.
"/practice/session", "/practice/session?flow=test", "/warmup", "/warmup/session", "/profile",
// The same screen AFTER an answer the learner typed or revealed: `ANSWERED`
// below. Reported cut off on a phone on 2026-11-25, in a state no sweep had
// ever rendered — every page above is measured as it loads.
"/practice/session?scene=apero",
// A situation: its opener is `/situations/handover` above; this is the
// reference list behind it, and the guided run itself — measured at every
// kind of step and at its ending, not only as it loads (`RUN` below).
"/situations/handover/lines", "/situations/handover/run",
// Reading: the shelf, and two OPEN texts — the longest sourced passage
// (place names nobody here chose the length of, each word a button) and an
// exchange from a care scene, whose lines are the longest the course has.
"/reading", "/reading/pfaeffikersee", "/reading/handover",
];
/**
* The guided run that is walked: a care scene, whose lines are the longest.
* Each kind of step is measured the first time it comes up — a line to
* follow, the same line answered, a sentence to build and built, a line to
* say, the replay with every line shown — and then the ending. If the ending
* is not reached the run FAILS as unreachable.
*/
const RUN = { path: "/situations/handover/run", kinds: ["follow", "build", "speak", "replay"] };
/**
* A sitting left half way on `ANSWERED.path`, so the audit opens on a typed
* question and then a revealed one instead of on whatever the plan deals.
* The session screen resumes it (`resume.ts`). If these ids leave the packs
* the sitting is not resumed, no field appears, and the run FAILS as
* unreachable rather than quietly measuring something else.
*/
const ANSWERED = {
path: "/practice/session?scene=apero",
key: "mixed|scene:apero",
ids: ["translate:scene:apero:3", "cloze:apero:0:cho"],
// A word missing and a word respelled: every line of the comparison shows.
typed: "Für mich lieber öpis Alkohol, aber ohni Donaudampfschifffahrtsgesellschaftskapitän",
};
/**
* A browser that has been used.
*
* The long link and the 49-letter compound are not decoration: they are the
* two shapes with no break opportunity in them, and they are what a learner
* pastes. The Cyrillic and French contexts are here because a kept word
* carries the sentence it came from, in whatever language that was.
*/
const LINK =
"https://www.zuerich.ch/de/portal/verwaltung/mitteilungen/2026/wohnungsvergabe-mitteilung-an-alle-mieterinnen.html";
const SAVED = {
version: 1,
words: [
{ target: "chrank", bridge: "krank", context: "Je suis malade", savedAt: "2026-09-19T08:00:00.000Z" },
{ target: "hesch", bridge: "hast", context: "Hesch mir mal de Schlüssel, bitte?", savedAt: "2026-09-17T08:00:00.000Z" },
{ target: "Morn", bridge: "morgen", context: "tomorrow you have your MRI Mr meijer", savedAt: "2026-09-17T08:00:00.000Z" },
{ target: "wotsch", bridge: "willst", context: "Wanna go to this party", savedAt: "2026-09-17T08:00:00.000Z" },
{ target: "ha", bridge: "habe", context: "Sagen Sie das bestimmter — ich habe schon zweimal gefragt.", savedAt: "2026-09-16T08:00:00.000Z" },
{ target: "wett", bridge: "möchte", context: "я хочу пойти на концерт в пятницу вечером", savedAt: "2026-09-16T08:00:00.000Z" },
{ target: "Donaudampfschifffahrtsgesellschaftskapitaenswitwe", bridge: "Donaudampfschifffahrtsgesellschaftskapitänswitwe", context: LINK, savedAt: "2026-09-15T08:00:00.000Z" },
{ target: "znacht", bridge: "Abendessen", context: "Mir gaht's guet, danke. Und dir?", savedAt: "2026-09-15T08:00:00.000Z" },
{ target: "öppis", bridge: "etwas", context: "Wotsch öppis z trinke?", savedAt: "2026-09-13T08:00:00.000Z" },
],
};
/** An answer carrying every field that has ever run off the edge. */
const ANSWER = {
mode: "produce",
text: `Sie antworten, dass es Ihnen gut geht. Nachschlagen: ${LINK}`,
dialect: "Mir gaht's guet, danke. Und dir?",
dialectClean: false,
dialectFlags: ["nicht-zuerichdeutsche-form-xyz", "unbekannte-schreibung-abcdefgh"],
tone: "warm",
toneNote: "Warm und freundlich, passt für Kolleginnen und Kollegen in einem informellen Gespräch.",
glosses: [
{ form: "gaht's", standard: "geht es", english: "geht es", rule: "nd → nn" },
{ form: "Donaudampfschifffahrtsgesellschaftskapitaenswitwe", standard: "Donaudampfschifffahrtsgesellschaftskapitänswitwe", english: "Witwe eines Donaudampfschiffskapitäns", rule: "nd → nn" },
],
suggestions: [
{ label: "WÄRMER UND VIEL LÄNGER ALS ÜBLICH", text: LINK, english: "Ein sehr langer Link", variety: "bridge", clean: false, flags: ["flag-eins-sehr-lang", "flag-zwei"] },
{ label: "KÜRZER", text: "Guet, danke!", english: "Gut, danke!", clean: true, flags: [] },
],
next: [{ id: "reply" }, { id: "rephrase", axis: "warmer" }, { id: "grammar", topic: "no-preterite" }],
// The ONE row under the latest answer (`answerRow`): replies first, then
// the moves and learn chips, capped — so a full row, with the longest reply
// chatkit keeps (48 characters) and the grammar link that must survive it.
replies: ["Ja, gern", "Wie säg ich das förmlicher für d Verwaltig?", "Wie antworte ich darauf?", "Nein danke"],
model: "openai/gpt-oss-120b-instruct-turbo-preview-2026",
};
const DRAFT = {
version: 1,
locale: "de",
messages: [
{ id: "m1", authorId: "me", body: `Wie antworte ich darauf? ${LINK}`, createdAt: "2026-09-19T08:00:00.000Z" },
{ id: "m2", authorId: "heidi", body: ANSWER.text, createdAt: "2026-09-19T08:00:05.000Z", answer: ANSWER },
],
};
/** Runs in the page: every element whose box or whose content is too wide. */
function findOverflow(viewport) {
const over = [];
const clipped = [];
for (const el of document.querySelectorAll("body *")) {
const box = el.getBoundingClientRect();
const visible = box.width > 0 || box.height > 0;
if (visible && (box.right > viewport + 1 || box.left < -1) && !insideScroller(el)) {
// Only the outermost offender: a child sticking out of a parent that is
// itself sticking out is one defect reported twice.
const parent = el.parentElement?.getBoundingClientRect();
if (!parent || (parent.right <= viewport + 1 && parent.left >= -1)) {
over.push(describe(el, box));
}
}
if (el.scrollWidth > el.clientWidth + 1) {
const overflowX = getComputedStyle(el).overflowX;
// A real scroller is a deliberate choice; `visible` and `clip` are not.
if (overflowX === "visible" || overflowX === "clip") clipped.push(describe(el, box));
}
}
return { over, clipped, doc: document.documentElement.scrollWidth };
/**
* Is this element simply further along inside something that scrolls?
*
* THE SAME EXEMPTION THE `clipped` CHECK ALREADY MAKES, which this one was
* missing. Two lines below, content wider than its box is reported only
* when `overflow-x` is `visible` or `clip`, because "a real scroller is a
* deliberate choice" — but the horizontal check above had no such rule, so
* the third item of any sideways-scrolling row was reported as overflow for
* being where a scrolled item is supposed to be.
*
* It matters because the two checks disagreeing is worse than either being
* wrong: the on-this-page rail became a one-row scroller on phones, the
* document did NOT overflow (375px in a 375px viewport, measured), and the
* audit still printed four findings. A check that cries wolf on a correct
* page is a check people start passing `|| true` to.
*
* The scrolling ancestor must itself be inside the viewport. If the
* scroller is the thing hanging off the screen, that is a real defect and
* it is still reported — on the scroller, where it belongs.
*/
function insideScroller(el) {
for (let p = el.parentElement; p && p !== document.body; p = p.parentElement) {
const ox = getComputedStyle(p).overflowX;
if (ox === "auto" || ox === "scroll") {
const r = p.getBoundingClientRect();
if (r.right <= viewport + 1 && r.left >= -1) return true;
}
}
return false;
}
function describe(el, box) {
return {
tag: el.tagName.toLowerCase(),
cls: (el.getAttribute("class") ?? "").slice(0, 110),
left: Math.round(box.left),
right: Math.round(box.right),
sw: el.scrollWidth,
cw: el.clientWidth,
text: (el.textContent ?? "").replace(/\s+/g, " ").trim().slice(0, 44),
};
}
}
/**
* Does the header's CONTENT still fit the height the token promises?
*
* `--header-height` (globals.css) is what the on-this-page rail pins below
* and what every anchored heading scrolls clear of. The header is now given
* that height outright, so asking "is the header the token height" answers
* itself — it is, by construction, even when the token is wrong. A check
* that cannot fail is worse than no check, because a clean run then means
* nothing.
*
* The falsifiable question is the other one: does what the header CONTAINS
* still fit inside it? Add a taller control — a second line of nav, a bigger
* avatar — and the content outgrows the fixed box and is quietly clipped,
* while every consumer of the token keeps clearing the old height. That is
* the failure this catches, and nothing in the type checker or the unit
* tests can see it: it is real glyphs in a real font at a real width.
*/
function measureHeader() {
const header = document.querySelector("header");
if (!header) return null;
const box = header.getBoundingClientRect().height;
// The tallest thing actually laid out inside the bar.
let content = 0;
for (const el of header.querySelectorAll("*")) {
const cs = getComputedStyle(el);
if (cs.position === "absolute" || cs.position === "fixed" || cs.display === "none") continue;
const r = el.getBoundingClientRect();
if (r.height > 0) content = Math.max(content, r.bottom - header.getBoundingClientRect().top);
}
return { box, content, declared: getComputedStyle(document.documentElement).getPropertyValue("--header-height").trim() };
}
/**
* `pnpm exec playwright install chromium` provides one; an environment that
* already ships a browser (a CI image, a sandbox) points at it instead rather
* than downloading a second copy.
*/
const browser = await chromium.launch(
process.env.CHROMIUM ? { executablePath: process.env.CHROMIUM } : {},
);
let renders = 0;
let headerDrift = 0;
/**
* Counted apart, because conflating them misled me once already.
*
* A long run against a dev server can hit a page that will not compile for
* unrelated reasons, and the summary said "40 with overflow" for forty HTTP
* 500s. A check that reports the wrong KIND of failure sends you looking in
* the wrong place, which is most of the cost of a failing check.
*/
let overflowing = 0;
let unreachable = 0;
let brokenWords = 0;
for (const theme of THEMES) {
for (const width of WIDTHS) {
const context = await browser.newContext({
viewport: { width, height: 780 },
isMobile: true,
hasTouch: true,
colorScheme: theme,
});
// Before the first paint, so the page renders WITH the data rather than
// filling in afterwards and being measured empty.
await context.addInitScript(
([saved, draft, answered]) => {
try {
localStorage.setItem("heidi.saved.v1", JSON.stringify(saved));
localStorage.setItem("heidi.chat.draft.v1", JSON.stringify({ ...draft, updatedAt: new Date().toISOString() }));
localStorage.setItem(
"heidi.practice.session.v2",
JSON.stringify({ v: 2, courses: { "gsw-zh": { key: answered.key, ids: answered.ids, at: 0, outcomes: [], savedAt: new Date().toISOString() } } }),
);
// A learner who said what interests them: `/listen` then opens with
// «Für dich» (a caption, a row and a note per suggestion, the widest
// thing on that page), and `/profile` resumes on the interests
// question, the one with nine tiles.
localStorage.setItem(
"heidi.profile.v2",
JSON.stringify({ v: 2, courses: { "gsw-zh": { interests: ["politics", "sport", "science"], step: "interests", at: new Date().toISOString() } } }),
);
} catch {
// A browser with storage denied still has to render; so does this.
}
},
[SAVED, DRAFT, ANSWERED],
);
const page = await context.newPage();
// No model is called: the answer above is the fixture, so the audit is
// deterministic and costs nobody a token.
await page.route("**/api/chat", (route) =>
route.fulfill({
status: 200,
headers: { "content-type": "text/event-stream" },
body: `event: message\ndata: ${JSON.stringify({ type: "answer", answer: ANSWER })}\n\n`,
}),
);
for (const locale of LOCALES) {
for (const path of PATHS) {
const url = `${BASE}/${locale}${path}`;
let response;
try {
response = await page.goto(url, { waitUntil: "domcontentloaded", timeout: 30_000 });
} catch (error) {
console.log(`ERR ${locale}${path} @${width} ${theme}: ${String(error).slice(0, 90)}`);
unreachable += 1;
continue;
}
if (!response || response.status() >= 400) {
console.log(`HTTP ${response?.status()} ${locale}${path} @${width} ${theme}`);
unreachable += 1;
continue;
}
await page.waitForTimeout(350);
renders += 1;
// Every word on one line, as well. chatkit's function is handed over
// as source text: it runs inside the page, where the glyphs are.
const measure = async () => ({
found: await page.evaluate(findOverflow, width),
broken: await page.evaluate(`(${BROKEN_WORDS_SOURCE})(document.body)`),
});
const states = [{ name: "", ...(await measure()) }];
const head = await page.evaluate(measureHeader);
if (head && head.content > head.box + 1) {
headerDrift += 1;
console.log(
`\nHEAD ${locale}${path} @${width} ${theme}: the header contains ${Math.round(head.content)}px ` +
`of content in a ${Math.round(head.box)}px bar (--header-height: ${head.declared}).\n` +
` It is being clipped, and the rail and every anchored heading still clear the old height.`,
);
}
// Then again with each header disclosure open, one at a time.
if (PROBE.includes(path)) {
const toggles = page.locator("header button[aria-expanded]:visible");
for (let i = 0; i < (await toggles.count()); i += 1) {
const toggle = toggles.nth(i);
const name = (await toggle.getAttribute("aria-label")) ?? (await toggle.innerText()).trim().slice(0, 16);
await toggle.click({ timeout: 5_000 }).catch(() => {});
await page.waitForTimeout(150);
states.push({ name: ` [open: ${name}]`, ...(await measure()) });
await toggle.click({ timeout: 5_000 }).catch(() => {});
await page.waitForTimeout(100);
}
}
// And a guided run, step by step to its ending (`RUN`).
if (path === RUN.path) {
const bar = page.locator("[data-chrome=session] > div:last-child");
const seen = new Set();
let ended = false;
for (let i = 0; i < 60 && !ended; i++) {
await page.waitForTimeout(120);
if ((await page.locator("[data-ending]").count()) > 0) {
ended = true;
break;
}
const kind = await page.locator("[data-run-step]").first().getAttribute("data-run-step").catch(() => null);
const first = kind !== null && !seen.has(kind);
if (first) {
seen.add(kind);
states.push({ name: ` [run: ${kind}]`, ...(await measure()) });
}
if (kind === "follow") {
await page.locator("[data-run-step] button:not([disabled])").first().click({ timeout: 5_000 }).catch(() => {});
if (first) states.push({ name: " [run: follow, answered]", ...(await measure()) });
await bar.locator("button").first().click({ timeout: 5_000 }).catch(() => {});
} else if (kind === "build") {
const tiles = page.locator("[data-run-step] ul button:not([disabled])");
const count = await tiles.count();
for (let k = 0; k < count - 1; k++) await tiles.first().click({ timeout: 5_000 }).catch(() => {});
await bar.locator("button").last().click({ timeout: 5_000 }).catch(() => {});
await page.waitForTimeout(250);
if (first) states.push({ name: " [run: build, checked]", ...(await measure()) });
await bar.locator("button").last().click({ timeout: 5_000 }).catch(() => {});
} else if (kind === "replay") {
await bar.locator("button").last().click({ timeout: 5_000 }).catch(() => {});
await page.waitForTimeout(250);
states.push({ name: " [run: replay, every line]", ...(await measure()) });
await bar.locator("button").first().click({ timeout: 5_000 }).catch(() => {});
} else {
// A line to say: not spoken here (`audit:speaking` has the microphone).
await bar.locator("button").first().click({ timeout: 5_000 }).catch(() => {});
}
}
if (!ended || RUN.kinds.some((kind) => !seen.has(kind))) {
console.log(`ERR ${locale}${path} @${width} ${theme}: the run did not reach its ending through every kind of step`);
unreachable += 1;
} else {
await page.waitForTimeout(300);
states.push({ name: " [run: ending]", ...(await measure()) });
}
}
// And the answered states of a sitting: a typed answer compared with
// the line it should be, then a gap revealed.
if (path === ANSWERED.path) {
const field = page.locator("textarea");
if ((await field.count()) === 0) {
console.log(`ERR ${locale}${path} @${width} ${theme}: the typed question did not open (see ANSWERED)`);
unreachable += 1;
} else {
await field.fill(ANSWERED.typed);
await field.press("Enter");
await page.waitForTimeout(250);
states.push({ name: " [typed answer compared]", ...(await measure()) });
await page.locator("details > summary").first().click({ timeout: 5_000 }).catch(() => {});
await page.waitForTimeout(150);
states.push({ name: " [typed answer, more open]", ...(await measure()) });
// «I had it», then the gap: reveal it.
await page.keyboard.press("1");
await page.waitForTimeout(250);
await page.keyboard.press("Enter");
await page.waitForTimeout(250);
states.push({ name: " [gap revealed]", ...(await measure()) });
}
}
for (const { name, broken } of states) {
if (broken.length === 0) continue;
brokenWords += 1;
console.log(
`\nWORD ${locale}${path} @${width} ${theme}${name}: cut across two lines: ${[...new Set(broken)].join(", ")}`,
);
}
for (const { name, found } of states) {
if (found.over.length === 0 && found.clipped.length === 0) continue;
overflowing += 1;
console.log(`\n### ${locale}${path} @${width} ${theme}${name} (document ${found.doc}px)`);
for (const o of found.over.slice(0, 6)) {
console.log(` OVER <${o.tag}> L${o.left} R${o.right} "${o.text}"\n ${o.cls}`);
}
for (const o of found.clipped.slice(0, 6)) {
console.log(` CLIP <${o.tag}> content ${o.sw}px in ${o.cw}px "${o.text}"\n ${o.cls}`);
}
}
}
}
await context.close();
}
}
/*
* THE NAVIGATION CONTRACT, AT THE WIDTHS THIS FILE NEVER RENDERED.
*
* `fleet/SHARED.md` holds eight rules for nav chrome, and names where they
* break: "one width was never a sample of the layout, only of one branch of
* it." This audit sweeps phone widths only. Measured on 2026-09-25, Heidi's
* desktop nav — Start, Chat, Lernen, Üben, Über Heidi — was 16 to 20px tall
* at 1440px, against the contract's 44px, and had been since it shipped.
* Every phone-width run was clean.
*
* So the header alone gets checked at a tablet and a desktop width, per
* locale: every control at least 44x44 (rule 3) and none crossing the
* viewport edge (rule 7). One page each, because the header is the same on
* every page — six renders rather than doubling the whole sweep.
*/
let navBreaches = 0;
for (const width of [834, 1440]) {
const context = await browser.newContext({ viewport: { width, height: 900 } });
const page = await context.newPage();
for (const locale of LOCALES) {
try {
await page.goto(`${BASE}/${locale}`, { waitUntil: "domcontentloaded", timeout: 30_000 });
} catch {
continue;
}
await page.waitForTimeout(350);
const found = await page.evaluate((w) => {
const out = [];
for (const el of document.querySelectorAll("header a, header button")) {
const r = el.getBoundingClientRect();
if (r.width === 0 || r.height === 0 || getComputedStyle(el).visibility === "hidden") continue;
const name = (el.innerText || el.getAttribute("aria-label") || el.tagName).trim().slice(0, 24);
if (r.width < 43.5 || r.height < 43.5) out.push(`SMALL ${name} ${Math.round(r.width)}x${Math.round(r.height)}`);
if (r.right > w + 0.5 || r.left < -0.5) out.push(`EDGE ${name} L${Math.round(r.left)} R${Math.round(r.right)}`);
}
return out;
}, width);
for (const line of found) {
navBreaches += 1;
console.log(`NAV ${locale} @${width}: ${line}`);
}
}
await context.close();
}
await browser.close();
console.log(
`\n${renders} page renders measured — ${overflowing} with overflow` +
(brokenWords > 0 ? `, ${brokenWords} with a word cut across two lines` : "") +
(headerDrift > 0 ? `, ${headerDrift} where the header is not its token height` : "") +
(navBreaches > 0 ? `, ${navBreaches} navigation-contract breaches at 834/1440` : "") +
(unreachable > 0 ? `, and ${unreachable} that did not load at all` : ""),
);
if (unreachable > 0) {
console.log("A page that does not load is not a layout finding. Check the server before reading the rest.");
}
process.exit(
overflowing === 0 && unreachable === 0 && headerDrift === 0 && navBreaches === 0 && brokenWords === 0 ? 0 : 1,
);