#!/usr/bin/env node /** * Self-test for ui-defect-audit.mjs. * Run: node scripts/ci/test-ui-defect-audit.mjs * * A detector is only worth its output if BOTH sides are pinned. The first draft * of this audit flagged 88 "defects" across 14 sites, and most of the alignment * ones were a heading followed by consistently indented items — correct markup * reported as broken. A rule that fires on everything is as useless as one that * fires on nothing, and it is more expensive, because someone has to read it. * * So every fixture below asserts a VERDICT, not just a run: * - the real loki bug is still caught (positive) * - correct markup stays silent (negative) * * Fixtures are inline data: URLs — no network, no fleet, no auth. */ import { DISCLOSE, MEASURE, loadPlaywright, parseViewports } from "./ui-defect-audit.mjs"; const FIXTURES = { // ── navigation fixtures ─────────────────────────────────────────────────── // The orangecat sidebar as it shipped: the section title is an

in a //
, and the ONLY thing carrying the click is the chevron beside it. // Visitors aimed at the word "Fund" and nothing happened. navDeadLabel: `
`, // The same row done correctly: the label lives INSIDE the control, so the // whole row is the target. This must stay silent. navLabelInsideControl: `
`, // A nav containing a link to the page we are on, with nothing announcing it. navUnmarkedCurrent: `
`, // The same nav, announcing correctly. navMarkedCurrent: `
`, // A nav of outbound links only — it legitimately contains no link to the // current page, so "no aria-current" is CORRECT here and must stay silent. navNoSelfLink: `
`, // Targets below the fleet's 44px floor. navSmallTargets: `
`, // The original loki fleet card: an icon INLINE at the head of two of // the four rows, shoving only those lines sideways by its own width, and a // wrapped hint whose second line falls back to the container edge. raggedStack: `

Fleet autopilot

Idle — nothing queued

0 working21 idle

Autopilot on — agents work through each project's queue, then pick the next-best task automatically and keep going until the queue is empty.

`, // The SAME visual family done correctly: icons hang in a fixed gutter, every // row shares one text column, the wrapped line has a hanging indent. fixedStack: `

Fleet autopilot

Idle — nothing queued

0 working21 idle

Autopilot on — agents work through each project's queue, then pick the next-best task automatically and keep going until the queue is empty.

`, // Correct markup that the first draft wrongly flagged: a label, then items // deliberately indented under it. The column goes out once and STAYS — no // return to a previous edge, so it is structure, not raggedness. intentionalIndent: `

GUT · BRAIN AXIS

Vollständige Mikrobiomanalyse

Darmpermeabilitätsmarker

Neurotransmitter-Vorläuferstatus

`, // An action below the AA floor, and one comfortably above it. contrast: `
Full inbox — screenshots, history, widget setup
New feedback
`, // Chips on a 4%-white overlay over near-black. A naive single canvas paint // resolves that overlay to SOLID WHITE and reports these as failures. translucentChips: `
`, // A nested GROUP between peer lines. datacat renders exactly this: a card // title, a description, an icon checklist, then a CTA back at the card edge. // The checklist is indented because it is a group, not because anything is // broken — and the CTA returning to the base indent is what made the first // draft call it ragged. nestedGroup: `

Formular-Erfassung

Erstellen Sie benutzerdefinierte Formulare für Umfragen.

KI-gestützte Sentiment-Analyse
Automatische Kategorisierung
Trend-Erkennung
Formular erstellen →
`, // Centered copy. Every line starts at a different x BY DESIGN. centeredCopy: `

Every feature — health tracking, digital twin, vet network, marketplace, and adoption listings — is included free with no pet limits.

`, // A bare wrapper anchor around a styled button. The anchor's own ink is // never painted — the button paints the label — so measuring the anchor read // 1:1 on surf-your-life's "Konto erstellen". The button itself passes. wrapperAnchor: `
`, // A disabled control is dim BECAUSE it is disabled — WCAG exempts it. Its // enabled twin with the same colors is a real finding. disabledControl: `
`, // A row of padded buttons in a text column: the BUTTON BOX is flush with the // column and only the labels sit padding deeper — aoz-wohnen's hero read as // ragged for exactly this. buttonRow: `

Gemeinsam wohnen

Die Wohnung, auf die ihr euch einigen könnt.

AusprobierenAnmelden

Kein Konto nötig.

`, // The same hero with the button row genuinely off the column: the BOX edge // returns 16px out and back, and the box edge is what must be measured. buttonRowRagged: `

Gemeinsam wohnen

Die Wohnung, auf die ihr euch einigen könnt.

AusprobierenAnmelden

Kein Konto nötig.

`, // substrata's mobile menu as it shipped. The
sits in the middle of // the header, so `right: 0` on an absolutely positioned panel measures from // THERE — and a 320px panel lands mostly off the left of a 390px screen. // Every existing rule passes on this markup; the links simply are not on it. navPanelOffLeft: `
Substrata
Menu
`, // The same menu anchored to the header instead of to the button — the fix. // It must stay silent, or the rule cannot tell a bug from its own remedy. navPanelAnchored: `
Substrata
Menu
`, // A closed slide-in drawer, parked entirely off the left. This is CORRECT — // it is how every drawer in this fleet waits — and reporting it would make // the rule fire on reparaturbonus-zh and anything else with one. navClosedDrawer: `
`, }; function assert(cond, msg) { if (!cond) throw new Error(msg); } async function main() { const { chromium } = loadPlaywright(); const browser = await chromium.launch(); const ctx = await browser.newContext({ viewport: { width: 1440, height: 900 } }); const page = await ctx.newPage(); const measure = async (html) => { await page.setContent(`${html}`, { waitUntil: "load" }); await page.waitForTimeout(120); return page.evaluate(MEASURE); }; // The nav detectors compare each link's pathname against location.pathname, // which setContent alone cannot exercise: an about:blank page has no path to // match. Serve the fixture from a routed URL so "the link to the page you are // on" is a real condition rather than one the test can never reach. const measureAt = async (html, path) => { const url = `https://fixture.test${path}`; await page.route("https://fixture.test/**", (route) => route.fulfill({ status: 200, contentType: "text/html", body: `${html}`, }), ); await page.goto(url, { waitUntil: "load" }); await page.waitForTimeout(120); const r = await page.evaluate(MEASURE); await page.unroute("https://fixture.test/**"); return r; }; // The off-viewport rule only exists at a narrow width with the panel OPEN, // so it needs its own page: a 1440px context cannot reach the defect, and // measuring a closed
cannot either. const phone = await browser.newContext({ viewport: { width: 390, height: 844 } }); const phonePage = await phone.newPage(); const measurePhone = async (html) => { await phonePage.setContent(`${html}`, { waitUntil: "load" }); await phonePage.waitForTimeout(120); await phonePage.evaluate(DISCLOSE); await phonePage.waitForTimeout(80); return phonePage.evaluate(MEASURE); }; let passed = 0; const check = async (label, fn) => { await fn(); passed += 1; console.log(` ✓ ${label}`); }; await check("catches the ragged stack it was written for", async () => { const r = await measure(FIXTURES.raggedStack); assert(r.ragged.length >= 1, "the zigzag stack must be reported"); assert( r.ragged.some((g) => g.spread >= 4 && g.spread <= 24), `spread must land in the accidental-indent band, got ${JSON.stringify(r.ragged.map((g) => g.spread))}`, ); }); await check("catches the wrapped line with no hanging indent", async () => { const r = await measure(FIXTURES.raggedStack); assert(r.wrapped.length >= 1, "line 2 starting left of line 1 must be reported"); }); await check("stays silent once the gutter fix is applied", async () => { const r = await measure(FIXTURES.fixedStack); assert(r.ragged.length === 0, `fixed stack must be clean, got ${JSON.stringify(r.ragged)}`); assert(r.wrapped.length === 0, `hanging indent must be clean, got ${JSON.stringify(r.wrapped)}`); }); await check("does NOT flag a label with deliberately indented items", async () => { const r = await measure(FIXTURES.intentionalIndent); assert( r.ragged.length === 0, `structure must not read as raggedness, got ${JSON.stringify(r.ragged)}`, ); }); await check("reports a sub-AA action and spares a passing one", async () => { const r = await measure(FIXTURES.contrast); const dim = r.contrast.find((c) => c.href === "#dim"); const ok = r.contrast.find((c) => c.href === "#ok"); assert(dim && dim.value < dim.floor, `dim link must fail, got ${dim && dim.value}`); assert(ok && ok.value >= ok.floor, `readable link must pass, got ${ok && ok.value}`); }); await check("composites translucent chips instead of calling them white", async () => { const r = await measure(FIXTURES.translucentChips); const chips = r.contrast.filter((c) => /working|idle/.test(c.text)); assert(chips.length === 2, `expected 2 chips, got ${chips.length}`); for (const c of chips) { assert( c.value >= c.floor, `light text on a 4%-white overlay over near-black is readable; got ${c.value}:1 ` + `(a single canvas paint reports ~3.2 here)`, ); } }); await check("does NOT flag a nested group between peer lines", async () => { const r = await measure(FIXTURES.nestedGroup); assert( r.ragged.length === 0, `an indented list between a description and a CTA is structure, got ${JSON.stringify(r.ragged)}`, ); }); await check("ignores a wrapper anchor whose label a nested button paints", async () => { const r = await measure(FIXTURES.wrapperAnchor); assert(!r.contrast.some((c) => c.tag === "a"), `the wrapper must be skipped, got ${JSON.stringify(r.contrast)}`); const btn = r.contrast.find((c) => c.tag === "button"); assert(btn && btn.value >= btn.floor, `the painted button passes on its own fill, got ${btn && btn.value}`); }); await check("exempts a disabled control but reports its enabled twin", async () => { const r = await measure(FIXTURES.disabledControl); assert(!r.contrast.some((c) => c.text === "Send"), "the disabled button is exempt (WCAG inactive)"); const twin = r.contrast.find((c) => c.text === "Send twin"); assert(twin && twin.value < twin.floor, `the enabled twin is a real finding, got ${twin && twin.value}`); }); await check("measures a padded button row by its box edge, not its label", async () => { const r = await measure(FIXTURES.buttonRow); assert(r.ragged.length === 0, `a flush button row is aligned, got ${JSON.stringify(r.ragged)}`); }); await check("still catches a button row whose box is off the column", async () => { const r = await measure(FIXTURES.buttonRowRagged); assert(r.ragged.length >= 1, "a 16px box offset that returns must be reported"); }); await check("does NOT flag centered copy as a missing hanging indent", async () => { const r = await measure(FIXTURES.centeredCopy); assert( r.wrapped.length === 0, `centered lines start at different x by design, got ${JSON.stringify(r.wrapped)}`, ); }); await check("catches a nav label that is not the control (the orangecat sidebar bug)", async () => { const r = await measure(FIXTURES.navDeadLabel); // innerText is the RENDERED text, so `text-transform: uppercase` reports // "FUND" and not the "Fund" in the source. Compare case-insensitively — // the detector is right and a case-sensitive assertion would be the bug. assert( r.navDeadLabels.length === 1 && r.navDeadLabels[0].label.toLowerCase() === "fund", `the stranded "Fund" heading must be reported, got ${JSON.stringify(r.navDeadLabels)}`, ); }); await check("stays silent when the label lives inside the control", async () => { const r = await measure(FIXTURES.navLabelInsideControl); assert( r.navDeadLabels.length === 0, `a full-row button is correct markup, got ${JSON.stringify(r.navDeadLabels)}`, ); }); await check("catches a current page that no link announces", async () => { const r = await measureAt(FIXTURES.navUnmarkedCurrent, "/here"); assert( r.navMissingCurrent.length === 1 && r.navMissingCurrent[0].href === "/here", `the unmarked self-link must be reported, got ${JSON.stringify(r.navMissingCurrent)}`, ); }); await check("stays silent when the current page IS announced", async () => { const r = await measureAt(FIXTURES.navMarkedCurrent, "/here"); assert( r.navMissingCurrent.length === 0, `aria-current is present, got ${JSON.stringify(r.navMissingCurrent)}`, ); }); await check("does NOT demand aria-current from a nav with no link to this page", async () => { // A footer of outbound links has no current page to mark. Flagging it would // make the detector fire on every site that has one. const r = await measureAt(FIXTURES.navNoSelfLink, "/somewhere-else"); assert( r.navMissingCurrent.length === 0, `no self-link means nothing to announce, got ${JSON.stringify(r.navMissingCurrent)}`, ); }); await check("catches nav targets below the 44px floor", async () => { const r = await measureAt(FIXTURES.navSmallTargets, "/x"); assert( r.navSmallTargets.length === 2, `both 32px targets must be reported, got ${JSON.stringify(r.navSmallTargets)}`, ); }); await check("stays silent on nav targets that meet the floor", async () => { const r = await measureAt(FIXTURES.navMarkedCurrent, "/here"); assert( r.navSmallTargets.length === 0, `44px targets are fine, got ${JSON.stringify(r.navSmallTargets)}`, ); }); await check("opens a closed
before measuring it", async () => { // Without this the panel rule can never fire on a real site, because a menu // is closed on arrival. Pinned separately so a regression here is not // mistaken for the fleet suddenly being clean. await phonePage.setContent( `
MenuA
`, { waitUntil: "load" }, ); const opened = await phonePage.evaluate(DISCLOSE); assert(opened === 1, `DISCLOSE must open the one closed panel, got ${opened}`); }); await check("catches a menu panel painted off the side of the screen", async () => { const r = await measurePhone(FIXTURES.navPanelOffLeft); assert( r.navOffViewport.length >= 1, `substrata's off-left panel must be reported, got ${JSON.stringify(r.navOffViewport)}`, ); assert( r.navOffViewport.every((f) => f.side === "left"), `the overflow is off the LEFT edge, got ${JSON.stringify(r.navOffViewport)}`, ); }); await check("stays silent once the panel is anchored to the header", async () => { const r = await measurePhone(FIXTURES.navPanelAnchored); assert( r.navOffViewport.length === 0, `the fixed panel is on screen, got ${JSON.stringify(r.navOffViewport)}`, ); }); await check("does NOT flag a closed drawer parked off-screen", async () => { // A drawer entirely outside the viewport is how a drawer waits. Only a // control CROSSING the edge — part on, part off — is the defect. const r = await measurePhone(FIXTURES.navClosedDrawer); assert( r.navOffViewport.length === 0, `a closed drawer is correct, got ${JSON.stringify(r.navOffViewport)}`, ); }); await check("parses viewports, and refuses a malformed one", async () => { assert(parseViewports("390x844").length === 1, "one pair parses"); const three = parseViewports("390x844,834x1112,1440x1000"); assert(three.length === 3 && three[0].label === "390", `got ${JSON.stringify(three)}`); assert(parseViewports("").length === 3, "empty falls back to the default three"); let threw = false; try { parseViewports("wide"); } catch { threw = true; } assert(threw, "a viewport with no WIDTHxHEIGHT must throw rather than silently skip"); }); await browser.close(); console.log(`\n${passed}/${passed} ui-defect-audit self-tests passed`); } main().catch((e) => { console.error(`\n✗ ${e.message}`); process.exit(1); });