// Real-browser evidence for Search result-target selection. // // Usage (from app/): // flutter build web --target tool/search_selection_probe_entry.dart \ // --output build/probe-search-selection // node tool/search_selection_probe.mjs --root build/probe-search-selection \ // --out build/search-selection-probe // // Serves the fixture build over loopback (extension-less paths fall back to // index.html so the app's real `/runs/7` and `/search` locations load), drives // headless Chrome through the Chrome DevTools Protocol, enables Flutter // semantics, types a query into the real search field, clicks result rows by // their exact row title and asserts the run detail state the hit selects: // // field hit -> run Summary with the matched Output section expanded // artifact hit -> the recorded visit pane (`build · visit 2`) // retired field -> the plain Summary, no section expanded // unknown visit -> the plain Summary, no visit pane // // Every reply comes from the in-app fixture channel in // tool/search_selection_probe_entry.dart; no server is contacted. import { createServer } from 'node:http'; import { mkdir, mkdtemp, readFile, rm, stat, writeFile } from 'node:fs/promises'; import { spawn } from 'node:child_process'; import { once } from 'node:events'; import { setTimeout as delay } from 'node:timers/promises'; import { extname, join, resolve, sep } from 'node:path'; import { tmpdir } from 'node:os'; const args = new Map(); for (let i = 2; i < process.argv.length; i++) { const value = process.argv[i]; if (value.startsWith('--')) args.set(value.slice(2), process.argv[++i]); } const root = resolve(args.get('root') ?? 'build/probe-search-selection'); const out = resolve(args.get('out') ?? 'build/search-selection-probe'); const chromePath = process.env.CHROME_PATH ?? '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'; await mkdir(out, { recursive: true }); const mime = { '.html': 'text/html; charset=utf-8', '.js': 'text/javascript; charset=utf-8', '.mjs': 'text/javascript; charset=utf-8', '.json': 'application/json; charset=utf-8', '.wasm': 'application/wasm', '.png': 'image/png', '.svg': 'image/svg+xml', '.ico': 'image/x-icon', '.ttf': 'font/ttf', '.otf': 'font/otf', '.woff': 'font/woff', '.woff2': 'font/woff2', '.bin': 'application/octet-stream', '.frag': 'application/octet-stream', }; const server = createServer(async (req, res) => { try { const pathname = decodeURIComponent(new URL(req.url, 'http://localhost').pathname); let filePath = resolve(root, '.' + pathname); if (filePath !== root && !filePath.startsWith(root + sep)) { res.writeHead(403).end(); return; } // The app uses path URLs (`/runs/7`, `/search`); any route path without a // file extension is the single page, as the Pipelines proxy serves it. try { if ((await stat(filePath)).isDirectory()) filePath = join(filePath, 'index.html'); } catch { if (!extname(pathname)) filePath = join(root, 'index.html'); } const file = await readFile(filePath); const type = mime[extname(filePath)] ?? 'application/octet-stream'; res.writeHead(200, { 'content-type': type, 'cache-control': 'no-store' }).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 origin = `http://127.0.0.1:${port}`; const profile = await mkdtemp(join(tmpdir(), 'x1-search-selection-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, what, attempts = 120) => { for (let i = 0; i < attempts; i++) { const value = await fn(); if (value) return value; await delay(100); } throw new Error(`Timed out waiting for ${what}: ${stderr.slice(-1500)}`); }; // The exact row titles the fixture's six `release` hits render, one per kind, // and the row meta each one announces (tool/search_selection_probe_entry.dart). const RELEASE_ROWS = [ { title: 'Release train', meta: 'Pipeline' }, { title: 'pipeline 22 · v6', meta: 'Pipeline version' }, { title: 'run #7 · Release train', meta: 'Run' }, { title: 'run #7 · plan visit 2', meta: 'Step' }, { title: 'run #7 · step 5 · output', meta: 'Field' }, { title: 'release-report.txt', meta: 'Artifact' }, ]; const RELEASE_BOUNDS = '6 results · cap 50 · scanned 3 steps · 2.0 KiB scanned · scan limit 1.0 MiB'; const BUILD_VISIT = 'build · visit 2'; // Flutter web renders a read-only SelectableText as a