// Real-Chrome fixture probe for the Pipelines P1 screen. // // It serves a prebuilt Flutter web bundle, drives it through Chrome DevTools // (accessibility tree + real mouse events), and writes PNGs and a JSON log. // No live server, socket or operator data is involved. // // Usage: node tool/pipelines_probe_cdp.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, clickAt, dragSelect, 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-captures"); const { server, url } = await startServer(buildDir); await mkdir(captureDir, { recursive: true }); const profile = join(tmpdir(), `pipelines-p1-chrome-${process.pid}`); const chrome = launchChrome(CHROME, profile, url); let connection; const log = { url, captures: [], checks: [], axSamples: [] }; 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 connection.send("Emulation.setDeviceMetricsOverride", { width: 1200, height: 900, deviceScaleFactor: 1, mobile: false, }); await waitFor( () => connection.evaluate("document.querySelector('flutter-view') !== null"), 20000, ); await sleep(1200); await enableSemantics(connection); const nodes = await axNodes(connection); log.axSamples = nodes .filter((node) => node.name?.value) .slice(0, 40) .map((node) => `${node.role?.value}: ${node.name.value}`); await assertName(connection, "Release verification", "list row", log); await capture(connection, captureDir, log, "01-list-desktop"); await click(connection, "Release verification"); await assertName(connection, "Content hash", "summary detail", log); await capture(connection, captureDir, log, "02-detail-summary"); await click(connection, "Source"); await capture(connection, captureDir, log, "03-source-latest"); // Select the first source line with a real drag. The capture shows the // browser's text selection, proving the source is selectable. await dragSelect(connection, 500, 194, 880, 194); await capture(connection, captureDir, log, "04-source-selection"); log.checks.push("source drag selection"); await click(connection, "Summary"); // The detail body is drawn on the canvas and Flutter's semantics tree omits // its list rows in this build, so the v1 row is clicked at the fixture layout // position for the fixed 1200x900 viewport. await clickAt(connection, 620, 489); await sleep(800); await capture(connection, captureDir, log, "05-version-v1"); await click(connection, "Source"); await capture(connection, captureDir, log, "06-source-v1"); await connection.send("Emulation.setDeviceMetricsOverride", { width: 390, height: 844, deviceScaleFactor: 1, mobile: true, }); await sleep(500); await click(connection, "Back to pipelines"); await assertName(connection, "Release verification", "mobile list", log); await capture(connection, captureDir, log, "07-list-390"); await click(connection, "Hotfix triage"); await assertName(connection, "Content hash", "mobile detail", log); await capture(connection, captureDir, log, "08-detail-390"); await click(connection, "Back to pipelines"); await assertName(connection, "Release verification", "mobile list again", log); await click(connection, "Filter"); await assertName(connection, "Filter pipelines", "mobile filter", log); await capture(connection, captureDir, log, "09-filter-390"); } 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, 120); } 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(); }