// Browser acceptance for the pipeline detail's landed Graph tab. // // Serves the probe build (`flutter build web -t tool/pipeline_graph_tab_probe.dart`) // on an OS-assigned loopback port and drives the actual PipelinesScreen: open a // pipeline, switch to Graph, select a stage node, verify the definition pane's // pinned identity, close it with Back and confirm the Graph tab is still there. // Captures are written for both hosts, dark at 2x; the file prefix carries the // viewport so short-window and large-text runs cannot overwrite each other. // // PROBE_VARIANT=material|cupertino PROBE_SCHEME=dark|light PROBE_SCALE=1|2 \ // PROBE_WIDTH=1280 PROBE_HEIGHT=900 PROBE_WEB_ROOT= \ // OPENCODE_ARTIFACT_DIR= node tool/pipeline_graph_tab_probe.mjs import { createServer } from 'node:http'; import { spawn } from 'node:child_process'; import { once } from 'node:events'; import { setTimeout as delay } from 'node:timers/promises'; import { join, extname, resolve, sep } from 'node:path'; import { tmpdir } from 'node:os'; import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'; const root = resolve( process.env.PROBE_WEB_ROOT ?? join(process.cwd(), 'build/pipeline_graph_tab_probe_web'), ); const variant = process.env.PROBE_VARIANT ?? 'material'; const scheme = process.env.PROBE_SCHEME ?? 'dark'; const scale = process.env.PROBE_SCALE ?? '2'; const width = Number(process.env.PROBE_WIDTH ?? 1280); const height = Number(process.env.PROBE_HEIGHT ?? 900); const chromePath = process.env.CHROME_PATH ?? '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'; const artifactDir = process.env.OPENCODE_ARTIFACT_DIR; if (!artifactDir) throw new Error('Set OPENCODE_ARTIFACT_DIR for the probe captures'); await mkdir(artifactDir, { recursive: true }); const prefix = `pipeline-graph-${variant}-${scheme}-${scale}x-${width}x${height}`; const mime = { '.html': 'text/html', '.js': 'text/javascript', '.json': 'application/json', '.wasm': 'application/wasm', '.png': 'image/png', '.ico': 'image/x-icon', '.otf': 'font/otf', '.ttf': 'font/ttf', }; const server = createServer(async (req, res) => { try { const path = resolve(root, '.' + decodeURIComponent(new URL(req.url, 'http://localhost').pathname)); if (path !== root && !path.startsWith(root + sep)) return res.writeHead(403).end(); const filePath = path === root || path.endsWith('/') ? join(path, 'index.html') : path; const file = await readFile(filePath); res.writeHead(200, { 'content-type': mime[extname(filePath)] ?? 'application/octet-stream' }).end(file); } catch { res.writeHead(404).end('not found'); } }); server.listen(0, '127.0.0.1'); await once(server, 'listening'); const port = server.address().port; const profile = await mkdtemp(join(tmpdir(), 'pipeline-graph-chrome-')); const chrome = spawn(chromePath, [ '--headless=new', '--no-first-run', '--no-default-browser-check', '--disable-gpu', '--remote-debugging-port=0', `--user-data-dir=${profile}`, 'about:blank', ], { stdio: ['ignore', 'ignore', 'pipe'] }); let stderr = ''; chrome.stderr.on('data', (data) => { stderr += data; }); const waitFor = async (fn) => { for (let i = 0; i < 140; i++) { const value = await fn(); if (value) return value; await delay(100); } throw new Error('Timed out waiting for Chrome DevTools'); }; let ws; try { const endpoint = await waitFor(() => stderr.match(/DevTools listening on (ws:\/\/[^\s]+)/)?.[1]); ws = new WebSocket(endpoint); await once(ws, 'open'); let id = 0; const pending = new Map(); ws.addEventListener('message', (event) => { const message = JSON.parse(event.data); if (message.method === 'Runtime.exceptionThrown') { console.error('PAGE EXCEPTION', JSON.stringify(message.params?.exceptionDetails?.exception?.description)); } if (message.id && pending.has(message.id)) { pending.get(message.id)(message); pending.delete(message.id); } }); const send = (method, params = {}, sessionId) => new Promise((resolveCall) => { const callId = ++id; pending.set(callId, resolveCall); ws.send(JSON.stringify({ id: callId, method, params, ...(sessionId ? { sessionId } : {}) })); }); const created = await send('Target.createTarget', { url: 'about:blank' }); const target = created.result.targetId; const session = (await send('Target.attachToTarget', { targetId: target, flatten: true })).result.sessionId; await send('Page.enable', {}, session); await send('Runtime.enable', {}, session); await send('Emulation.setEmulatedMedia', { features: [{ name: 'prefers-color-scheme', value: scheme }], }, session); await send('Emulation.setDeviceMetricsOverride', { width, height, deviceScaleFactor: 1, mobile: false, }, session); const query = `?style=${variant}&dark=${scheme === 'dark' ? 1 : 0}&scale=${scale}`; const navigation = await send('Page.navigate', { url: `http://127.0.0.1:${port}/${query}` }, session); if (navigation.error || navigation.result?.errorText) throw new Error(JSON.stringify(navigation)); const evaluate = async (expression) => { const response = await send('Runtime.evaluate', { expression, returnByValue: true, awaitPromise: true, }, session); if (response.error) throw new Error(`Runtime.evaluate failed: ${JSON.stringify(response)}`); return response.result?.result?.value; }; await delay(3500); const loaded = await evaluate('({url:location.href, ready:document.readyState})'); if (!loaded?.url.includes(`127.0.0.1:${port}/${query}`)) { throw new Error(`Fixture did not load: ${JSON.stringify(loaded)}`); } await evaluate("document.querySelector('flt-semantics-placeholder')?.click()"); await delay(2200); const semantics = () => evaluate(`[...document.querySelectorAll('flt-semantics')].map(x => { const r = x.getBoundingClientRect(); return { label: (x.getAttribute('aria-label') || (x.innerText || '')).trim(), x: r.x, y: r.y, width: r.width, height: r.height, visible: r.width > 0 && r.height > 0 && r.bottom > 0 && r.top < innerHeight, }; })`); const labels = async () => (await semantics()).map((item) => item.label).filter(Boolean); const bodyText = async () => [await evaluate('document.body.innerText'), ...(await labels())].join('\n'); const waitForText = async (needle, context) => { for (let attempt = 0; attempt < 60; attempt++) { if ((await bodyText()).includes(needle)) return; await delay(250); } throw new Error(`${context}: missing ${JSON.stringify(needle)}\n${await bodyText()}`); }; const exact = async (label) => { const items = await semantics(); return items.filter((item) => item.label === label && item.visible) .sort((a, b) => a.width * a.height - b.width * b.height)[0] ?? null; }; const clickItem = async (item) => { const x = item.x + item.width / 2; const y = item.y + item.height / 2; await send('Input.dispatchMouseEvent', { type: 'mousePressed', x, y, button: 'left', clickCount: 1, }, session); await send('Input.dispatchMouseEvent', { type: 'mouseReleased', x, y, button: 'left', clickCount: 1, }, session); await delay(1200); }; const clickExact = async (label) => { const item = await exact(label); if (!item) throw new Error(`Missing control ${JSON.stringify(label)}: ${JSON.stringify(await labels())}`); await clickItem(item); }; // A list row's merged semantics label starts with the pipeline name and also // carries its id/version/run text, so match that prefix and use the row box. const clickNamed = async (name) => { const items = await semantics(); const item = items.filter((entry) => entry.label.startsWith(name) && entry.visible) .sort((a, b) => a.width * a.height - b.width * b.height)[0]; if (!item) throw new Error(`Missing row ${JSON.stringify(name)}: ${JSON.stringify(await labels())}`); await clickItem(item); }; const capture = async (name) => { const data = (await send('Page.captureScreenshot', { format: 'png', captureBeyondViewport: false, }, session)).result.data; const file = `${prefix}-${name}.png`; await writeFile(join(artifactDir, file), Buffer.from(data, 'base64')); return file; }; const evidence = { variant, scheme, scale, width, height, checks: [], captures: [] }; const check = (text, value) => evidence.checks.push({ check: text, value }); await waitForText('Release verification', 'pipeline list'); await clickNamed('Release verification'); await waitForText('Content hash', 'pipeline detail'); check('actual pipeline detail opened from the list', true); await clickExact('Graph'); await waitForText('select a stage for details', 'graph tab guidance'); await waitForText('inspect', 'definition stage node'); const graphSemantics = await semantics(); const note = graphSemantics.find((item) => item.label.startsWith('Scroll or pinch to zoom')); if (!note?.visible) throw new Error(`Graph note is not visible: ${JSON.stringify(note)}`); const tab = graphSemantics.find((item) => item.label === 'Graph'); const node = graphSemantics.find((item) => item.label === 'inspect'); if (!node?.visible || node.width <= 0 || node.height <= 0) { throw new Error(`Measured stage node is not visible: ${JSON.stringify(node)}`); } // The graph is bounded: the tabs and note stay on screen above the canvas // instead of the canvas growing with the routed layout. if (!tab?.visible) throw new Error(`Graph tab scrolled away: ${JSON.stringify(tab)}`); if (note.y + note.height > node.y) { throw new Error(`Canvas overlaps the note: ${JSON.stringify({ note, node })}`); } if (note.height < 16) throw new Error(`Guidance note collapsed: ${JSON.stringify(note)}`); evidence.nodeRect = node; evidence.noteRect = note; // A capped note must be a real scroll region with its remainder present, not // a label clipped at the viewport edge. Flutter's semantics expose that region // as an overflow-scrolling group with a scroll-overflow marker, so the page // proves the hidden guidance exists and is reachable. const noteScroll = await evaluate(`(() => { const matches = [...document.querySelectorAll('flt-semantics')] .filter(x => ((x.getAttribute('aria-label') || x.innerText || '').trim() .startsWith('Scroll or pinch to zoom'))); matches.sort((a, b) => a.getBoundingClientRect().height - b.getBoundingClientRect().height); let element = matches[0]; while (element && element.tagName === 'FLT-SEMANTICS') { if (getComputedStyle(element).overflowY === 'scroll') { const marker = element.querySelector('flt-semantics-scroll-overflow'); return { scrollable: true, viewport: element.getBoundingClientRect().height, overflowHeight: marker ? marker.getBoundingClientRect().height : 0, }; } element = element.parentElement; } return { scrollable: false, viewport: 0, overflowHeight: 0 }; })()`); evidence.noteScroll = noteScroll; if (noteScroll.scrollable) { if (!(noteScroll.overflowHeight > 0)) { throw new Error(`Capped note has no scrollable remainder: ${JSON.stringify(noteScroll)}`); } check( 'capped guidance note is an explicit scroll region, not a clipped label', `${Math.round(noteScroll.viewport)}px viewport`, ); } else { check('the guidance note fits its slot without scrolling', true); } check('graph tab draws a measured native stage node inside a bounded viewport', true); check('guidance note keeps a readable slot above the canvas', `${note.width}x${note.height}`); evidence.captures.push(await capture('graph')); await clickExact('inspect'); await waitForText('inspect definition', 'stage definition pane'); await waitForText('Release verification · v3', 'pinned identity'); await waitForText('Inspect the candidate release.', 'stage definition field'); const paneLabels = await labels(); if (paneLabels.includes('Release verification') && !paneLabels.includes('Graph')) { throw new Error(`Definition pane did not replace the detail: ${JSON.stringify(paneLabels)}`); } evidence.checks.push({ check: 'selecting a stage opens the definition pane for the exact pinned identity', value: 'Release verification · v3', }); evidence.captures.push(await capture('stage-definition')); await clickExact('Back'); await waitForText('Scroll or pinch to zoom, drag to pan', 'graph tab after Back'); const afterClose = await bodyText(); if (afterClose.includes('inspect definition')) { throw new Error(`Definition pane stayed open after Back: ${afterClose}`); } check('Back closes the definition pane and returns to the same graph tab', true); evidence.captures.push(await capture('closed')); // A capped note is a real scroll region; prove its hidden tail moves under a // wheel rather than being unreachable clipped text. if (noteScroll.scrollable) { const noteScrollTop = () => evaluate(`(() => { const matches = [...document.querySelectorAll('flt-semantics')] .filter(x => ((x.getAttribute('aria-label') || x.innerText || '').trim() .startsWith('Scroll or pinch to zoom'))); matches.sort((a, b) => a.getBoundingClientRect().height - b.getBoundingClientRect().height); let element = matches[0]; while (element && element.tagName === 'FLT-SEMANTICS') { if (getComputedStyle(element).overflowY === 'scroll') return element.scrollTop; element = element.parentElement; } return -1; })()`); await send('Input.dispatchMouseEvent', { type: 'mouseWheel', x: Math.round(note.x + note.width / 2), y: Math.round(note.y + note.height / 2), deltaX: 0, deltaY: 120, button: 'none', }, session); await delay(600); const scrolled = await noteScrollTop(); if (!(scrolled > 0)) { throw new Error(`Wheel did not scroll the capped note: ${JSON.stringify({ scrolled, note })}`); } evidence.noteScrolledPixels = scrolled; check('wheel reaches the guidance note tail inside its scroll region', `${scrolled}px`); evidence.captures.push(await capture('note-scrolled')); } // The two definition states the widget tests cover also render in the real // page. They need the list on screen, so they run where list and detail sit // side by side instead of behind one another. if (width >= 1200 && height >= 900) { // At a larger text scale the last rows start below the window; wheel the // list itself until the row is fully on screen, then click its own box. const clickListRow = async (name) => { for (let attempt = 0; attempt < 8; attempt++) { const item = (await semantics()) .filter((entry) => entry.label.startsWith(name) && entry.visible) .sort((a, b) => a.width * a.height - b.width * b.height)[0]; if (item && item.y >= 0 && item.y + item.height <= height) { await clickItem(item); return; } await send('Input.dispatchMouseEvent', { type: 'mouseWheel', x: Math.round(width * 0.15), y: Math.round(height * 0.5), deltaX: 0, deltaY: 240, button: 'none', }, session); await delay(600); } throw new Error(`Missing list row ${JSON.stringify(name)}: ${JSON.stringify(await labels())}`); }; const openGraph = async (name) => { await clickListRow(name); await clickExact('Graph'); }; const hasStageNode = async () => (await semantics()).some((item) => item.label === 'inspect' && item.visible); await openGraph('Unparsed definition'); await waitForText('did not include the pipeline definition graph', 'missing graph state'); if (await hasStageNode()) { throw new Error('A reply without a graph still drew a stage node'); } check('a reply without a definition graph states it and draws nothing', true); evidence.captures.push(await capture('missing-graph')); await openGraph('Empty definition'); await waitForText('This pipeline has no stages.', 'empty definition state'); if (await hasStageNode()) { throw new Error('An empty definition still drew a stage node'); } check('an empty definition keeps its native empty message', true); evidence.captures.push(await capture('empty-definition')); } console.log(JSON.stringify(evidence, null, 2)); } finally { if (ws?.readyState === WebSocket.OPEN) { ws.send(JSON.stringify({ id: 2147483647, method: 'Browser.close' })); } await Promise.race([once(chrome, 'exit'), delay(3000)]); ws?.close(); if (chrome.exitCode === null) chrome.kill('SIGTERM'); chrome.stderr.destroy(); chrome.unref(); await new Promise((resolveClose) => { server.close(resolveClose); server.closeAllConnections(); }); await rm(profile, { recursive: true, force: true }); }