// Real web navigation against the isolated fixture; no deployed service/data. // node tool/detail_navigation_probe.mjs build/navigation_web build/navigation-evidence import assert from 'node:assert/strict'; import { mkdtemp, mkdir, writeFile } from 'node:fs/promises'; import { once } from 'node:events'; import { tmpdir } from 'node:os'; import { join, resolve } from 'node:path'; import { startFixture } from './runs_probe_server.mjs'; import { startWiringFixture } from './pipelines_wiring_probe_server.mjs'; import { launchChrome, waitForPort, waitForPage, connect, sleep, } from './pipelines_probe_cdp_lib.mjs'; import { enableSemantics, click, clickAt, assertName, capture, waitFor, axNodes, } from './pipelines_probe_cdp_input.mjs'; const build = resolve(process.argv[2] ?? 'build/navigation_web'); const output = resolve(process.argv[3] ?? 'build/navigation-evidence'); await mkdir(output, { recursive: true }); const fixture = await startFixture({ root: build }); const pipelineFixture = await startWiringFixture({ root: build }); const profile = await mkdtemp(join(tmpdir(), 'detail-navigation-')); const chrome = launchChrome( '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', profile, 'about:blank', ); const log = { checks: [], captures: [] }; let connection; try { const port = await waitForPort(join(profile, 'DevToolsActivePort')); connection = await connect((await waitForPage(port)).webSocketDebuggerUrl); await connection.send('Page.enable'); await connection.send('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 1, mobile: true, }); const path = () => connection.evaluate('location.pathname'); const expectPath = async (expected) => { assert.ok(await waitFor(async () => await path() === expected, 12000), `Expected ${expected}, got ${await path()}`); }; const clickRow = async (label) => { const group = (await axNodes(connection)).find(node => node.role?.value === 'group' && node.name?.value?.startsWith(label)); if (!group) return click(connection, label); const { model } = await connection.send('DOM.getBoxModel', { backendNodeId: group.backendDOMNodeId, }); const [x1, y1, , , x3, y3] = model.content; await clickAt(connection, (x1 + x3) / 2, (y1 + y3) / 2); }; for (const [root, row, detail, server] of [ ['/pipelines', 'Release verification', '/pipelines/3', pipelineFixture], ['/runs', 'Fixture live run', '/runs/1', fixture], ['/chat', 'Probe conversation', '/chat/ses_probechat', fixture], ]) { if (process.env.PROBE_DESTINATION && root !== process.env.PROBE_DESTINATION) continue; await connection.send('Page.navigate', { url: server.url + root }); assert.ok(await waitFor(() => connection.evaluate( "Boolean(document.querySelector('flt-semantics-placeholder'))", ), 12000), 'Flutter semantics ready'); await enableSemantics(connection); await assertName(connection, row, `${root} list loaded`, log); await capture(connection, output, log, `${root.slice(1)}-list`); await writeFile(join(output, `${root.slice(1)}-ax.json`), JSON.stringify(await axNodes(connection), null, 2)); await clickRow(row); await expectPath(detail); await sleep(800); await capture(connection, output, log, `${root.slice(1)}-detail`); // Browser history uses the Router; this must remove the pushed detail, // not leave a hidden page which reappears on the next selection. await connection.evaluate('history.back()'); await expectPath(root); await assertName(connection, row, `${root} browser Back restores list`, log); await capture(connection, output, log, `${root.slice(1)}-back`); await connection.evaluate('history.forward()'); await expectPath(detail); await sleep(800); await click(connection, 'Back'); await expectPath(root); await assertName(connection, row, `${root} toolbar Back restores list`, log); await clickRow(row); await expectPath(detail); await sleep(800); await click(connection, 'Back'); await expectPath(root); await assertName(connection, row, `${root} repeated open/pop restores list`, log); } console.log(JSON.stringify(log, null, 2)); } finally { await writeFile(join(output, 'result.json'), JSON.stringify(log, null, 2)); connection?.close(); const exited = once(chrome, 'exit'); chrome.kill(); await exited; await fixture.close(); await pipelineFixture.close(); }