Files
heidi/scripts/audit/responsive.mjs
CatoandClaude 37edcd8b99 Round two: situations, reading, dialects map, photographs, R2-ready media (#364)
* feat(dialects): one sourced register of dialect forms, and the language map's data

The same twelve everyday items in seven Swiss German dialects, each form
with the atlas map or article section it was read in (accessed 2026-11-26),
Zurich's column read from the pack, and a cell nobody could read safely
left «nicht belegt». The register lives with the pack (`family.register`),
so the leak gate holds; `lib/dialects/` only resolves, compares and narrows.

Re-reading the Kleiner Sprachatlas maps at full resolution corrected five
cells: Basel and Chur say «eppis», Lucerne «mier», St. Gallen «hend» and
«Chend»; Chur's butter shows Schmaalz beside Butter.

The language map: swissBOUNDARIES3D (©swisstopo) coloured by the BFS
typology «Sprachgebiete 2020»; the language figures moved to
`lib/config/languages.ts`, with the Italian region counted correctly
(121 municipalities, not 114).

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T

* feat(dialects): an interactive language map opens the area, with profiles, comparison and a helper

/dialect opens with one map of Switzerland: every Swiss German dialect area
links to its page, the Romandie, Italian Switzerland and the Romansh region
to a new language page each (/languages/fr, /it, /rm, one template: where,
in BFS figures, what Heidi offers today, what is planned without a date, and
the interest form). Under the map: the seven dialects a learner meets (where,
three forms to recognise by ear against Zurich, what that means for
following), the same words side by side, «which dialect am I hearing?», the
message reader and every area by branch.

Each area page opens with the same map, its area in red, and for the seven
compared dialects the profile and the comparison with Zurich. The home page
shows the map instead of the town dots and links it from its ways in; the
languages page opens the language pages; both new kinds of page are in the
sitemap and the responsive audit.

Dictionary text was checked against the sources: claims without one
(«Lucerne sounds between Bern and Zurich», «asking again is normal») are gone,
the superlative about Valais German is softened to what Wikipedia says.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T

* fix(practice): the stretch in a sitting stays a stretch

A new question may be one band above the learner's level, and which kinds
take the first seats is luck. With more kinds that have nothing on level 1
than kinds that do, luck alone could deal a beginner a sitting that was
mostly one band too high: seventeen new situations moved the scene items
around and one seed of the "fit" setting came out 3 of 8 on the level.

While a kind still has a question on the nearest level, at most half of
what one deal seats is above it. Seats are never left empty for it: once
the nearest level runs out, the next band is the nearest.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T

* feat(situations): a purity gate over every line, and seventeen new situations

THE GATE. `lib/variety/purity.ts` holds what we publish in the taught
variety to three things the chat gate does not check, all read out of the
pack: no Standard German word where the pack gives the Zurich form (leaks,
correspondences, every one-word pair of the word list); no marked form of
another dialect (the regional rules, each with a source); one spelling per
word, the pack's. A test runs it over every scene line, the template
validator over every hand-written sentence, and a third test holds the pack
to its own spelling.

What it finds in the 412 lines of 2026-11-25: 37 lines — 29 spellings
(«gschlaafe», «sii», «staa», «umstiege», «laufed», «nüüt» …), 5 Standard
German words («Hauswart» twice, «Nachbar», «redet», «weg»), 4 Weinland «üs»
— four words spelled two ways across scenes, and the pack itself writing
seven words two ways (nüt/nüüt, gä/gää, lüted/lüüted, Aabig/Abig,
blibe/bliibe, blibed/bliibed, gärn/gern) plus «do» for «hier» where every
line says «da». Fixed at the cause: the pack's examples and leak
suggestions, then the lines, then 29 hand-written question sentences.
«gäng» was a Zurich word in the list; German Wikipedia names it a Bernese
speciality and it is now a regional rule. «schwierig» is «schwirig» in the
line and wherever the copy quotes it.

THE SCENES, all `reviewed: false` with the pack: relative on the phone, pain
in more detail, medication round, a new resident's first day, washing and
dressing, the night round, the doctor's round and — new in this commit — a
resident at the front door who wants to go home (care); pharmacy, post
office, a repair with the Abwart, bank, Coiffeur, bakery, asking the way,
Badi, a first evening at a Verein (everyday). The municipality scene gains a
second beat, the permit renewal. Every beat now falls between two exchanges,
not inside one. Words outside the pack were looked up in the Idiotikon
register; the at-the-door scene records the columns.

THE ORDER. The care list runs the way a day runs (handover, morning care,
washing, meals, medication, pain, the doctor, visitors, the phone, the new
resident, the evening, the door, the night); everyday runs the way settling
in does, so a learner who says "I have just moved" is handed the way to the
station, the municipality and the bank first.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T

* feat(reading): texts to read in Zurich German, held to one purity gate

- /reading: a shelf of texts, easiest first. The course's own situation
  lines composed into short exchanges, and passages from the Alemannic
  Wikipedia's Zurich German pages, verbatim, each with page, revision,
  history link and licence (CC BY-SA 4.0). No text claims a review.
- One gate for reading texts, purityProblems(text, pack): standard forms
  derived from the pack (paradigm rows, cognate headwords,
  correspondences, the article mapping, small leaks with a dialect
  ending, st where the course writes scht); other dialects' marked forms,
  each sourced; one spelling (house rules, shapes of other conventions,
  letters the course never writes, and words that fold onto the course's
  own written another way). A shelf-wide check keeps every word to one
  spelling across texts.
- scripts/reading-harvest.ts lists and fetches all 375 pages of
  «Artikel uf Züritüütsch», gates every sentence and prints the counts
  the page shows; --verify checks each shipped passage verbatim against
  the revision it names.
- A text is read in large type with pressable words (meanings only from
  the vocabulary, none guessed), then three to five questions, then the
  shared ending. Reachable from the menu, home, Mein Bereich and the end
  of a situation with a text of its own.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T

* fix(dialects): area pages lead with where the dialect is spoken; a thinner, legible map

The map draws thin muted borders instead of white gaps, so its areas read in
the dark theme too; a hovered area gets a red edge, a focused one a thick
one; on the dialects page it is no wider than 56rem. An area page states
where the dialect is spoken under its name rather than repeating the name in
a profile below. «Not attested» is a quiet status rather than a form, and
the Russian label is «нет данных»: the long one ran out of its column at
320 and 390px on the Basel and Graubünden pages (responsive audit).

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T

* feat(glosses): every new scene line in English, French, Italian and Russian

HEIDI.md says these four exist for every word, scene line and hand-written
question text. The new situations arrived without theirs: 381 lines, 54%
coverage of the phrases. All four are now at 792 of 792, drafted from the
Zurich line and its German together, unreviewed like the rest of the set —
and a test now fails the day a line is added without them, so the sentence
in HEIDI.md is a gate rather than a hope.

«Und wie chume ich dänn an See?» was answered «Nei, nur über d Brugg» —
a no to a how. It is «Eifach über d Brugg».

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T

* fix(reading): the opener names the texts, and a number keeps its unit

The /reading opener said «Alle Situationen», borrowed from the situations
page; it now says «Alle Texte». In a text, «8 km» no longer breaks between
the number and its unit; the words themselves are untouched.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T

* feat(design): legible in both themes, sharper openers, and a list of 37 situations that reads

THE LIST. The short list of a learner's own situations (practice, Mein
Bereich) printed every one a reason gives — fourteen for somebody in care —
above the rest of the page. It shows five, from where the learner is
(`previewOf`): finished ones drop off the front, the order never reshuffles,
the one recommended next is always there. The full list opens with one line
of links to its two domains, so the ward is not twenty-three rows down.

THE OPENERS. A 16:9 photograph covering a phone screen is drawn about 1500
pixels wide; `sizes` said 150vw, so a DPR-2 phone was served 1200 pixels at
quality 75 and it looked soft. It says 200vw and the quality is 85, one step
each (`images.qualities` allows it). Bytes at 390px, DPR 2 / DPR 3:
home 130 KB / 225 KB → 272 KB / 272 KB, practice 127 / 215 → 257 / 257,
listen 99 / 194 → 240 / 240 — the whole 1600-pixel file at DPR 2 now.

LIGHT AND DARK, measured at 390px over sixteen pages (solid text against its
real background, focus on the first tab stops): every token pair passes. What
did not: controls that cannot be used yet were drawn at 40–60% opacity —
«Leichter» 2.7:1, a disabled «Prüfen» 2.7:1 in dark — and an answer that is
out of the running was muted ink at 60%, grey on grey. They are muted ink at
full strength now (4.5:1 or more on every surface). A wrong answer's words
were flag red on its own tint, 4.4:1; they take the deep red ink
(`--color-incorrect-ink`, 7.1:1; dark keeps its lifted red, 5.8:1).

ALSO. The listening opener's button said «Zwanzig Minuten»; it says what it
leads to, «Drei für heute», in seven languages. The six sectors on
/organisations were a ragged stack of chips on a phone; they are a list
there, chips from `sm`, in their own component. The Badi opens on the
Strandbad picture already in the register. The responsive audit measures two
of the new scenes.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T

* docs(situations): the short list and the domain links in HEIDI.md, and where each new word was looked up

HEIDI.md §4 says how the list of situations reads with thirty-seven of them.
The new scenes now name, beside the lines, the Idiotikon register entries
their words outside the pack were checked against (volume, column), the way
the at-the-door scene already did.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T

* merge: dictionaries keep the dialects and the reading namespaces; one entry per source

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T

* refactor(purity): one gate for every line the course prints

The reading gate and the situations' gate become one module,
lib/variety/purity.ts, with one API used by the situations, the reading
shelf and the authored questions. It keeps the stronger checks of each:
paradigm, cognate and inflection-derived standard forms, the scht rule,
letters and diacritics the course never writes, the shelf-wide
one-spelling check, the leaks, correspondences and word pairs, and the
sourced regional rules.

- The other-dialect list is one list in the pack's rules: the Bern and
  Basel forms the reading pack carried move there, deduplicated; the
  shapes of the standard language and of another spelling convention are
  the pack's houseMarks; the distinct spellings are one list.
- The pack gave «Aache» as Wallis/Fribourg butter citing SDS 5/179.
  Kleiner Sprachatlas map 28 (SDS 5/179), opened today, prints no such
  form: Wallis «Aichu», «Aihu», «Öi(c)hu»; Sense «Ou(c)he»; «Aahe» in the
  south-west Bernese Oberland. The rule now says so.
- The pack wrote «gsee» and «gseh» for one word; it now writes «gseh».
- Reading: one situation text per scene from the current lines (36; the
  post-office scene has no word to ask about and waits); the harvest was
  run again against the one gate; «Villa Liebegg» lost one sentence
  («nachhär»), and --verify found all eight passages verbatim.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T

* fix(dialects): a readable map in dark, the map on the first screen, a row of sections that says it scrolls

- The language map has its own colour roles (land, edge, hatch, water,
  hover) in globals.css; in dark the land is lifted off the page and the
  edges and hatches are light enough to count twenty areas.
- From lg the dialect area's map sits beside its title (PageHeader
  `aside`), so 1280×900 opens on it; the area rows follow (MapAreaList).
- The section rail fades the end that has more behind it and keeps the
  current chip in view, so a cut-off chip no longer looks like the last.
- «Welche Mundart?»: on a phone the verdict rides along the bottom of the
  clues once one is ticked, with a way down to the reasoning (reduced
  motion respected).
- Mein Bereich offers reading from the start, not only after a text.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T

* feat(photos): stronger openers, places for everyday scenes, and photographs ready for object storage

Every photograph was rendered where it is used, at 390 and 1280, light and
dark. Replaced:
- station (practice, asking the way): the front was crossed by tram wires
  and parked cars; now the main hall (Dining Car from Wien, CC BY-SA 2.0).
- the lake (reading, Mein Bereich, care): a strip of hills and grey water on
  a phone; now the Glarus Alps over Lake Zurich (Roland zh, CC BY-SA 3.0).
- the dawn lake (dark of the same pages): an empty orange gradient on a
  phone; those pages now use the city at night already on the site.
- the night sky on Über Heidi: haze over a dark strip; now the Blüemlisalp
  glacier under stars (Deralpinbergsteiger, CC BY-SA 4.0).
New places: the Seebad Utoquai for the Badi, Butterzöpfe for the bakery,
the Fraumünsterpost for the post office, the Erismannhof courtyard for
neighbours, the laundry room and the Bünzli. Author and licence from each
file's record at Wikimedia Commons; alt text in all seven languages.

Served bytes: next/image now prefers AVIF; every opener at 390px DPR 2 is
58-162 KB (WebP at the same quality was up to 272 KB). A test holds each
registered width and height to the file's own header.

Object storage: NEXT_PUBLIC_MEDIA_BASE (lib/config/media.ts) makes every
photo resolve to <base>/photos/<file> and gives next/image the host;
unset, nothing changes. scripts/media/upload-photos.mjs uploads
public/photos to an S3-compatible bucket with PHOTOS_S3_* settings named
like Solon's: dry run by default, skips objects already there, SigV4 signed
with node:crypto (checked against AWS's published example).

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmvb6xi489TfZMg7n9T

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-26 10:39:16 +01:00

579 lines
28 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",
// 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,
);