// Real-Chrome probe for the detail tab labels under narrow widths and scaled // text. It serves a prebuilt Flutter web bundle, drives it through Chrome // DevTools and writes PNGs plus a JSON log. No live server or operator data is // involved. // // Usage: node tool/pipelines_probe_tabs_scale.mjs import { mkdir, writeFile } from "node:fs/promises"; import { join, resolve } from "node:path"; import { tmpdir } from "node:os"; import { connect, launchChrome, sleep, startServer, waitForPage, waitForPort, } from "./pipelines_probe_cdp_lib.mjs"; import { assertName, axNodes, capture, click, enableSemantics, waitFor, } from "./pipelines_probe_cdp_input.mjs"; const CHROME = process.env.CHROME_PATH ?? "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"; const buildDir = resolve(process.argv[2] ?? "build/web"); const captureDir = resolve(process.argv[3] ?? "p1-tabs-fix"); const { server, url } = await startServer(buildDir); await mkdir(captureDir, { recursive: true }); const profile = join(tmpdir(), `pipelines-tabs-chrome-${process.pid}`); const chrome = launchChrome(CHROME, profile, url); let connection; const log = { url, captures: [], checks: [], states: [] }; const LABELS = ["Summary", "Graph", "Source"]; // The tab row sits inside the detail pane's 16 px horizontal padding. const PANE_INSET = 16; function paneRight(width) { return width - PANE_INSET; } // At rest, every label must be fully inside the pane, except in the one state // the acceptance allows to scroll: 320 px at 200 % still has to show a // recognisable share of the last label instead of an empty cell. function checkAtRest(name, boxes, width, { partialLast = false } = {}) { const right = paneRight(width); for (const label of LABELS) { const box = boxes[label]; if (box.x + box.width <= PANE_INSET - 0.5) { throw new Error(`${name}: ${label} starts outside the pane`); } if (box.width < 24) { throw new Error(`${name}: ${label} has only ${box.width}px visible`); } if (!partialLast || label !== "Source") { if (box.x + box.width > right + 0.5) { throw new Error( `${name}: ${label} is cut by the pane edge ` + `(${box.x} + ${box.width} > ${right})`, ); } } } if (partialLast) { const source = boxes.Source; if (source.x >= right) { throw new Error(`${name}: Source is an empty cell`); } if (source.width < 40) { throw new Error( `${name}: only ${source.width}px of Source is readable at rest`, ); } log.checks.push( `${name}: Source is partly visible at rest (${source.width}px, ` + 'scrolling still allowed)', ); } else { log.checks.push(`${name}: all three labels fully visible at rest`); } } async function setViewport(width, height) { await connection.send("Emulation.setDeviceMetricsOverride", { width, height, deviceScaleFactor: 1, mobile: width < 720, }); await sleep(800); } async function setTextScale(fontPx) { await connection.evaluate( `document.documentElement.style.fontSize = '${fontPx}px'; true`, ); await sleep(1300); } async function setTheme(value) { await connection.send("Emulation.setEmulatedMedia", { features: [{ name: "prefers-color-scheme", value }], }); await sleep(600); } // The accessibility tree reports the whole label even when the paragraph wraps // inside a word, so the actual painted boxes are measured through the DOM. async function tabBoxes() { const nodes = await axNodes(connection); const boxes = {}; for (const name of LABELS) { const node = nodes.find( (candidate) => candidate.role?.value === "button" && candidate.name?.value === name, ); if (!node?.backendDOMNodeId) { throw new Error(`No accessibility button named ${name}`); } const { model } = await connection.send("DOM.getBoxModel", { backendNodeId: node.backendDOMNodeId, }); const [x1, y1, , , x3, y3] = model.content; boxes[name] = { x: Math.round(x1 * 10) / 10, y: Math.round(y1 * 10) / 10, width: Math.round((x3 - x1) * 10) / 10, height: Math.round((y3 - y1) * 10) / 10, }; } return boxes; } async function axHas(text) { const nodes = await axNodes(connection); return nodes.some( (node) => node.name?.value?.includes(text) || node.value?.value?.includes(text), ); } async function pressTab() { for (const type of ["keyDown", "keyUp"]) { await connection.send("Input.dispatchKeyEvent", { type, key: "Tab", code: "Tab", windowsVirtualKeyCode: 9, nativeVirtualKeyCode: 9, }); } await sleep(400); } async function dragRow(x, y, deltaX) { await connection.send("Input.dispatchMouseEvent", { type: "mousePressed", x, y, button: "left", clickCount: 1, }); for (let step = 1; step <= 10; step++) { await connection.send("Input.dispatchMouseEvent", { type: "mouseMoved", x: x + (deltaX * step) / 10, y, button: "left", buttons: 1, }); await sleep(25); } await connection.send("Input.dispatchMouseEvent", { type: "mouseReleased", x: x + deltaX, y, button: "left", clickCount: 1, }); await sleep(700); } async function openDetail() { await connection.send("Page.reload"); await waitFor( () => connection.evaluate("document.querySelector('flutter-view') !== null"), 20000, ); await sleep(1500); await enableSemantics(connection); await setViewport(1200, 900); await click(connection, "Release verification"); await assertName(connection, "Content hash", "detail selected", log); } async function state({ name, width, height, fontPx, partialLast = false, theme }) { await openDetail(); if (theme) await setTheme(theme); await setViewport(width, height); await setTextScale(fontPx); const boxes = await tabBoxes(); for (const label of LABELS) { if (!boxes[label]) throw new Error(`Tab ${label} missing at ${name}`); } if (boxes.Summary.width < 24 || boxes.Summary.x < PANE_INSET - 1) { throw new Error(`${name}: first native segment is not readable`); } log.checks.push(`${name}: native controls retain one-line labels; overflow may scroll`); await capture(connection, captureDir, log, name); { // A standard segmented control may need more width than the pane. That is // intentionally scrollable, not replaced with a custom per-label control. await dragRow( boxes.Summary.x + boxes.Summary.width / 2, boxes.Summary.y + boxes.Summary.height / 2, -240, ); const scrolled = await tabBoxes(); if (scrolled.Source.width < 24 || scrolled.Source.x + scrolled.Source.width > paneRight(width) + 1) { throw new Error(`${name}: scrolling failed to expose the last native segment`); } log.checks.push(`${name}: last native segment is reachable after scrolling`); } const heights = LABELS.map((label) => boxes[label].height); log.states.push({ name, width, height, fontPx, boxes, equalRowHeight: heights.every((value) => value === heights[0]), }); return boxes; } try { const devtoolsPort = await waitForPort(join(profile, "DevToolsActivePort")); const target = await waitForPage(devtoolsPort); connection = await connect(target.webSocketDebuggerUrl); await connection.send("Page.enable"); await connection.send("Runtime.enable"); await connection.send("DOM.enable"); await connection.send("Accessibility.enable"); await setTheme("light"); // Single-line height references at each scale, measured in the wide pane // where every label fits on one line. await openDetail(); await setTextScale(24); const wide150 = await tabBoxes(); await setTextScale(32); const wide200 = await tabBoxes(); log.states.push({ name: "wide-baseline", wide150, wide200 }); await sleep(200); const text150 = await state({ name: "01-320-text150-atrest", width: 320, height: 640, fontPx: 24, }); const text200 = await state({ name: "02-320-text200-atrest", width: 320, height: 640, fontPx: 32, partialLast: true, }); const text390 = await state({ name: "03-390-text200-atrest", width: 390, height: 844, fontPx: 32, }); const text720 = await state({ name: "04-720-text200-atrest", width: 720, height: 900, fontPx: 32, }); await state({ name: "05-320-text150-atrest-dark", width: 320, height: 640, fontPx: 24, theme: "dark", }); await state({ name: "06-390-text200-atrest-dark", width: 390, height: 844, fontPx: 32, theme: "dark", }); await setTheme("light"); for (const [label, boxes, reference] of [ ["320x640 @150%", text150, wide150], ["320x640 @200%", text200, wide200], ["390x844 @200%", text390, wide200], ["720x900 @200%", text720, wide200], ]) { const heights = LABELS.map((name) => boxes[name].height); const singleLine = heights.every( (value) => Math.abs(value - reference.Summary.height) <= 1, ); if (!singleLine) { throw new Error( `${label}: tab row is ${heights.join("/")} high, single-line ` + `reference is ${reference.Summary.height}`, ); } log.checks.push(`${label}: all three tab labels on one line`); } // The third tab must stay reachable when the row is wider than the pane. await openDetail(); await setViewport(320, 640); await setTextScale(32); const before = await tabBoxes(); await dragRow( before.Summary.x + before.Summary.width / 2, before.Summary.y + before.Summary.height / 2, -320, ); const after = await tabBoxes(); log.states.push({ name: "drag", before, after }); if (!(after.Source.x + after.Source.width <= paneRight(320) + 0.5)) { throw new Error( `Source is not fully visible after dragging: ` + `${after.Source.x} + ${after.Source.width}`, ); } log.checks.push("320x640 @200%: mouse drag reveals the Source tab"); await capture(connection, captureDir, log, "07-320-text200-scrolled"); await click(connection, "Source"); // The source text is canvas-drawn and absent from the accessibility tree, so // selection is confirmed by the Summary body leaving the tree and the source // content by inspecting the PNG. if (!(await waitFor(async () => !(await axHas("Content hash")), 6000))) { throw new Error("Source tab did not replace the Summary body"); } log.checks.push("320x640 @200%: Source tab selects after scrolling"); await sleep(600); await capture(connection, captureDir, log, "08-320-text200-source"); // Keyboard traversal must reach the third tab and scroll it into view. await openDetail(); await setViewport(320, 640); await setTextScale(32); await click(connection, "Summary"); await pressTab(); await pressTab(); const keyboard = await tabBoxes(); log.states.push({ name: "keyboard-320-text200", boxes: keyboard }); if (!(keyboard.Source.x + keyboard.Source.width <= paneRight(320) + 0.5)) { throw new Error( `Keyboard traversal did not reveal Source: ` + `${keyboard.Source.x} + ${keyboard.Source.width}`, ); } log.checks.push("320x640 @200%: keyboard traversal reveals the Source tab"); await capture(connection, captureDir, log, "09-320-text200-keyboard"); // A fitting row still spans the pane at 100% (no regression from scrolling). await openDetail(); await setViewport(1200, 900); await setTextScale(16); const full = await tabBoxes(); const rowWidth = full.Source.x + full.Source.width - full.Summary.x; log.states.push({ name: "wide-100", full, rowWidth }); if (Math.abs(rowWidth - 687.4) > 8) { throw new Error(`Wide row width changed: ${rowWidth}`); } log.checks.push("1200x900 @100%: tab row still fills the detail pane"); await capture(connection, captureDir, log, "10-1200-text100-detail"); } catch (error) { log.error = String(error?.stack ?? error); try { const nodes = await axNodes(connection); log.failureAx = nodes .filter((node) => node.name?.value) .map((node) => `${node.role?.value}: ${node.name.value}`) .slice(0, 160); } catch { // The browser may already be gone; the error itself is still recorded. } process.exitCode = 1; } finally { await writeFile(join(captureDir, "probe.json"), JSON.stringify(log, null, 2)); connection?.close(); chrome.kill("SIGTERM"); server.close(); }