// Real-browser evidence for the run-detail Artifacts action and gallery page. // // Usage (from app/): // flutter build web --target tool/artifact_gallery_probe.dart --output build/probe-gallery // node tool/artifact_gallery_probe.mjs --root build/probe-gallery --out DIR // // Serves the built fixture on an OS-assigned loopback port, drives headless // Chrome, and records the actual recorded rows, the selection dialog, the safe // external Open, the empty/unavailable states, both native hosts, dark // Cupertino and the 320/2x states. No server or operator run is touched. import { createServer } from 'node:http'; import { mkdir, mkdtemp, readFile, rm, 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'; import zlib from 'node:zlib'; 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-gallery'); const out = resolve(args.get('out') ?? 'build/artifact-gallery-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 crcTable = Array.from({ length: 256 }, (_, n) => { let c = n; for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1; return c >>> 0; }); const crc32 = (buffer) => { let c = 0xffffffff; for (const byte of buffer) c = crcTable[(c ^ byte) & 0xff] ^ (c >>> 8); return (c ^ 0xffffffff) >>> 0; }; const pngChunk = (type, data) => { const length = Buffer.alloc(4); length.writeUInt32BE(data.length); const body = Buffer.concat([Buffer.from(type), data]); const crc = Buffer.alloc(4); crc.writeUInt32BE(crc32(body)); return Buffer.concat([length, body, crc]); }; // A real 160x100 gradient, so the preview evidence shows an actual image // rather than a one-pixel probe. const probePng = () => { const width = 160; const height = 100; const rows = Buffer.alloc(height * (width * 3 + 1)); for (let y = 0; y < height; y++) { const offset = y * (width * 3 + 1); rows[offset] = 0; for (let x = 0; x < width; x++) { rows[offset + 1 + x * 3] = 40 + Math.trunc((x * 120) / width); rows[offset + 2 + x * 3] = 90 + Math.trunc((y * 130) / height); rows[offset + 3 + x * 3] = 200 - Math.trunc((x * 80) / width); } } const header = Buffer.alloc(13); header.writeUInt32BE(width, 0); header.writeUInt32BE(height, 4); header[8] = 8; header[9] = 2; return Buffer.concat([ Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]), pngChunk('IHDR', header), pngChunk('IDAT', zlib.deflateSync(rows, { level: 9 })), pngChunk('IEND', Buffer.alloc(0)), ]); }; const png = probePng(); const probeCsv = Buffer.from('id,name\n1,alpha\n2,beta\n'); // A real one-second H.264 clip, so the in-app player is exercised against a // playable file (ffmpeg is required for this probe). async function probeMp4() { const dir = await mkdtemp(join(tmpdir(), 'gallery-mp4-')); const file = join(dir, 'clip.mp4'); const ffmpeg = spawn('ffmpeg', [ '-loglevel', 'error', '-f', 'lavfi', '-i', 'testsrc=size=320x180:rate=10', '-t', '1', '-pix_fmt', 'yuv420p', '-c:v', 'libx264', '-movflags', '+faststart', file, ]); const [code] = await once(ffmpeg, 'exit'); if (code !== 0) throw new Error('ffmpeg could not create the probe video'); const bytes = await readFile(file); await rm(dir, { recursive: true, force: true }); return bytes; } const mp4 = await probeMp4(); const server = createServer(async (req, res) => { const pathname = decodeURIComponent(new URL(req.url, 'http://localhost').pathname); if (pathname.startsWith('/fixture/')) { if (pathname.endsWith('/missing.png')) { res.writeHead(404, { 'content-type': 'text/plain; charset=utf-8' }); res.end('missing artifact\n'); return; } if (pathname.endsWith('/report.zip')) { res.writeHead(200, { 'content-type': 'application/zip', 'content-length': probeCsv.length, }); res.end(probeCsv); return; } if (pathname.endsWith('.png')) { res.writeHead(200, { 'content-type': 'image/png' }); res.end(png); return; } if (pathname.endsWith('.mp4')) { res.writeHead(200, { 'content-type': 'video/mp4', 'content-length': mp4.length }); res.end(mp4); return; } res.writeHead(200, { 'content-type': 'text/plain; charset=utf-8' }); res.end(`recorded artifact ${pathname}\n`); return; } try { let filePath = resolve(root, '.' + pathname); if (filePath !== root && !filePath.startsWith(root + sep)) { res.writeHead(403).end(); return; } if (pathname === '/' || pathname.endsWith('/')) filePath = join(filePath, 'index.html'); 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 origin = `http://127.0.0.1:${server.address().port}`; const profile = await mkdtemp(join(tmpdir(), 'a1w-chrome-')); const chrome = spawn( chromePath, ['--headless=new', '--no-first-run', '--no-default-browser-check', '--disable-gpu', '--disable-popup-blocking', '--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) => { for (let i = 0; i < 120; i++) { const value = await fn(); if (value) return value; await delay(100); } throw new Error(`Timed out waiting for ${what}: ${stderr.slice(-1500)}`); }; const evidence = { origin, captures: [], checks: [], contrast: [], pager: null }; let ws; try { const endpoint = await waitFor( () => stderr.match(/DevTools listening on (ws:\/\/[^\s]+)/)?.[1], 'Chrome DevTools', ); 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.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 session = (await send('Target.attachToTarget', { targetId: created.result.targetId, flatten: true, })).result.sessionId; await send('Page.enable', {}, session); await send('Runtime.enable', {}, session); // Record the real bytes the app hands to the OS. The download anchor's // click is swallowed so headless Chrome never writes into the profile; the // share function replaces the browser sheet with a recorder. await send('Page.addScriptToEvaluateOnNewDocument', { source: `(() => { const state = { objects: [], downloads: [], shares: [] }; window.__artifactTransfer = state; const realCreate = URL.createObjectURL.bind(URL); URL.createObjectURL = (blob) => { const url = realCreate(blob); const entry = { url, type: blob.type, size: blob.size, name: null, bytes: null }; state.objects.push(entry); blob.arrayBuffer().then((buffer) => { entry.bytes = Array.from(new Uint8Array(buffer)); }); return url; }; HTMLAnchorElement.prototype.click = function () { state.downloads.push({ name: this.download, href: this.href }); }; const navProto = Object.getPrototypeOf(navigator); Object.defineProperty(navProto, 'share', { configurable: true, value: async (data) => { state.shares.push((data?.files || []).map((file) => { const entry = { name: file.name, type: file.type, size: file.size, bytes: null }; file.arrayBuffer().then((buffer) => { entry.bytes = Array.from(new Uint8Array(buffer)); }); return entry; })); }, }); Object.defineProperty(navProto, 'canShare', { configurable: true, value: (data) => Array.isArray(data?.files) && data.files.length > 0, }); Object.defineProperty(navProto, 'userActivation', { configurable: true, get: () => ({ isActive: true, hasBeenActive: true }), }); })();`, }, session); await send('Browser.grantPermissions', { origin, permissions: ['clipboardReadWrite', 'clipboardSanitizedWrite'], }); await send('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 1, mobile: true, }, session); 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; }; const labels = () => evaluate( "[...document.querySelectorAll('flt-semantics')].map(x => x.getAttribute('aria-label') || (x.innerText || '').trim()).filter(Boolean)", ); const bodyText = () => evaluate('document.body.innerText'); const visibleText = async () => `${await bodyText()}\n${(await labels()).join('\n')}`; const hasLabel = async (label) => (await labels()).includes(label); const clickExact = async (label) => { const clicked = await evaluate(`(() => { const wanted = ${JSON.stringify(label)}; const text = (x) => x.getAttribute('aria-label') || (x.innerText || '').trim(); const nodes = [...document.querySelectorAll('flt-semantics')]; const tappable = nodes.filter(x => x.hasAttribute('flt-tappable')); // The tappable node is the one the engine listens to; a labelled wrapper // above it would swallow a synthetic click. const node = tappable.find(x => text(x) === wanted) || tappable.find(x => text(x).startsWith(wanted)) || nodes.find(x => text(x) === wanted); if (!node) return false; node.click(); return true; })()`); if (!clicked) throw new Error(`No exact semantics label ${JSON.stringify(label)}: ${JSON.stringify(await labels())}`); await delay(500); }; // The lowest matching row is the later visit's duplicate filename. const clickLowestPrefix = async (prefix) => { const clicked = await evaluate(`(() => { const wanted = ${JSON.stringify(prefix)}; const text = (x) => x.getAttribute('aria-label') || (x.innerText || '').trim(); const candidates = [...document.querySelectorAll('flt-semantics')] .filter(x => text(x).startsWith(wanted)) .filter(x => x.hasAttribute('flt-tappable')); if (!candidates.length) return false; candidates.sort((a, b) => b.getBoundingClientRect().y - a.getBoundingClientRect().y); candidates[0].click(); return true; })()`); if (!clicked) throw new Error(`No tappable label starting ${JSON.stringify(prefix)}: ${JSON.stringify(await labels())}`); await delay(600); }; const activate = async (expected = 'Artifacts gallery probe') => { await delay(3200); await evaluate("document.querySelector('flt-semantics-placeholder')?.click()"); await delay(900); const current = await labels(); if (expected !== null && !current.some((label) => label.includes(expected))) { throw new Error(`Flutter semantics unavailable: ${JSON.stringify(current)}`); } }; const navigate = async (url, expected = 'Artifacts gallery probe') => { const navigation = await send('Page.navigate', { url }, session); if (navigation.error || navigation.result?.errorText) throw new Error(JSON.stringify(navigation)); await activate(expected); }; const targetCount = async () => (await send('Target.getTargets')).result.targetInfos.filter( (target) => target.type === 'page', ).length; const transferState = () => evaluate(`(() => { const state = window.__artifactTransfer; return { downloads: state.downloads, objects: state.objects.map(({ url, type, size, name, bytes }) => ({ url, type, size, name, bytes })), shares: state.shares, }; })()`); const waitForBytes = async (read) => { for (let i = 0; i < 40; i++) { const value = await read(); if (value?.byteLength) return value; await delay(100); } throw new Error('Timed out waiting for transfer bytes'); }; const capture = async (name, width = 390, height = 844, scale = 1) => { await send('Emulation.setDeviceMetricsOverride', { width, height, deviceScaleFactor: scale, mobile: width < 600, }, session); await delay(350); const data = (await send('Page.captureScreenshot', { format: 'png' }, session)).result.data; const path = join(out, `${name}.png`); await writeFile(path, Buffer.from(data, 'base64')); evidence.captures.push(path); }; const rectOfPrefix = (prefix) => evaluate(`(() => { const wanted = ${JSON.stringify(prefix)}; const text = (x) => x.getAttribute('aria-label') || (x.innerText || '').trim(); const node = [...document.querySelectorAll('flt-semantics')].find(x => text(x).startsWith(wanted)); if (!node) return null; const r = node.getBoundingClientRect(); return { x: r.x, y: r.y, width: r.width, height: r.height }; })()`); const brightestPixel = async (rect) => { const shot = await send('Page.captureScreenshot', { format: 'png', clip: { ...rect, scale: 2 }, }, session); return evaluate(`(async () => { const img = new Image(); img.src = 'data:image/png;base64,${shot.result.data}'; await img.decode(); const canvas = document.createElement('canvas'); canvas.width = img.width; canvas.height = img.height; const ctx = canvas.getContext('2d'); ctx.drawImage(img, 0, 0); const data = ctx.getImageData(0, 0, img.width, img.height).data; let max = 0; for (let i = 0; i < data.length; i += 4) { const lum = (0.2126 * data[i] + 0.7152 * data[i + 1] + 0.0722 * data[i + 2]) / 255; if (lum > max) max = lum; } return { max, width: img.width, height: img.height }; })()`); }; // WCAG contrast of the explanatory (subtitle) line of a two-line row against // its own background. Only the row's lower half is sampled, so the darker // title glyphs cannot mask a dim absence line. The text luminance is the // text-coloured extreme (p2 in light mode, p98 in dark); the background is // the opposite extreme. const subtitleContrast = async (prefix, dark) => { const rect = await rectOfPrefix(prefix); if (!rect) throw new Error(`No row starting ${JSON.stringify(prefix)}`); const clip = { x: rect.x, y: rect.y + rect.height * 0.45, width: rect.width, height: rect.height * 0.55, scale: 1, }; const shot = await send('Page.captureScreenshot', { format: 'png', clip }, session); return evaluate(`(async () => { const img = new Image(); img.src = 'data:image/png;base64,${shot.result.data}'; await img.decode(); const canvas = document.createElement('canvas'); canvas.width = img.width; canvas.height = img.height; const ctx = canvas.getContext('2d'); ctx.drawImage(img, 0, 0); const data = ctx.getImageData(0, 0, img.width, img.height).data; const linear = (value) => { const c = value / 255; return c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4); }; const lums = []; for (let i = 0; i < data.length; i += 4) { lums.push(0.2126 * linear(data[i]) + 0.7152 * linear(data[i + 1]) + 0.0722 * linear(data[i + 2])); } lums.sort((a, b) => a - b); const at = (fraction) => lums[Math.min(lums.length - 1, Math.floor(lums.length * fraction))]; const text = ${dark} ? at(0.98) : at(0.02); const background = ${dark} ? at(0.02) : at(0.98); const high = Math.max(text, background); const low = Math.min(text, background); return { ratio: (high + 0.05) / (low + 0.05), textLuminance: text, backgroundLuminance: background, p01: at(0.01), p99: at(0.99), pixels: lums.length, width: img.width, height: img.height, }; })()`); }; const openGallery = async (query) => { await navigate(`${origin}/?${query}`); if (!(await hasLabel('Artifacts'))) { throw new Error(`Run detail has no Artifacts action: ${JSON.stringify(await labels())}`); } await clickExact('Artifacts'); await delay(600); }; // Material: recorded rows, duplicate filename, visit-2 capture facts and the // safe external Open. await navigate(`${origin}/?origin=${encodeURIComponent(origin)}`); if (!(await hasLabel('Artifacts'))) { throw new Error(`Material run detail has no Artifacts action: ${JSON.stringify(await labels())}`); } evidence.checks.push({ check: 'the run detail offers the native Artifacts action', value: true }); await capture('a1w-material-detail'); await clickExact('Artifacts'); const galleryBody = await bodyText(); for (const recorded of ['build.log', 'shot.png', 'application/zip', 'implementer · visit 1', 'reviewer · visit 2']) { if (!galleryBody.includes(recorded)) { throw new Error(`Gallery is missing recorded row ${recorded}: ${JSON.stringify(galleryBody)}`); } } if (!galleryBody.includes('Artifacts · 6 recorded')) { throw new Error(`Gallery summary missing: ${JSON.stringify(galleryBody)}`); } const resultRows = (await labels()).filter((label) => label.startsWith('result.zip')).length; if (resultRows < 2) { throw new Error(`Duplicate result.zip rows missing: ${JSON.stringify(await labels())}`); } evidence.checks.push({ check: 'the gallery lists the actual recorded rows, not nav labels', value: true }); await capture('a1w-material-gallery'); await clickLowestPrefix('result.zip'); const selectedBody = await bodyText(); for (const fact of ['reviewer · visit 2', 'application/zip · 4.0\u00a0KiB', 'Artifacts · 1 recorded · partial capture', '2 files excluded from artifact capture.']) { if (!selectedBody.includes(fact)) { throw new Error(`Selected visit-2 facts missing ${fact}: ${JSON.stringify(selectedBody)}`); } } if (!(await hasLabel('Open')) || !(await hasLabel('Copy link'))) { throw new Error(`Selection offers no Open/Copy link: ${JSON.stringify(await labels())}`); } evidence.checks.push({ check: 'the duplicate filename selected visit 2 with its own capture facts', value: true }); await capture('a1w-material-selected'); // The selection offers the safe external Open and a separate Copy link. // Headless Chrome cannot carry a user activation through a synthetic // semantics click, so the tab itself is proven by the widget test that // records the exact uri handed to the opener; the browser proves the actions // appear only for a url that resolves through the safe rules. if (!(await hasLabel('Open')) || !(await hasLabel('Copy link'))) { throw new Error(`Selection offers no Open/Copy link: ${JSON.stringify(await labels())}`); } evidence.checks.push({ check: 'the selection offers the native Open and separate Copy link for a safe recorded url', value: true, }); await capture('a1w-material-open'); await navigate(`${origin}/?origin=${encodeURIComponent(origin)}&state=unsafe`); await clickExact('Artifacts'); await clickLowestPrefix('result.zip'); const unsafeBody = await bodyText(); if (!unsafeBody.includes('The recorded artifact URL cannot be opened safely.')) { throw new Error(`Unsafe url wording missing: ${JSON.stringify(unsafeBody)}`); } if ((await hasLabel('Open')) || (await hasLabel('Copy link'))) { throw new Error(`Unsafe url still offered an action: ${JSON.stringify(await labels())}`); } evidence.checks.push({ check: 'a protocol-relative url offers no open or copy action', value: true }); await capture('a1w-material-unsafe'); await navigate(`${origin}/?origin=${encodeURIComponent(origin)}&state=nourl`); await clickExact('Artifacts'); await clickLowestPrefix('result.zip'); const nourlBody = await bodyText(); if (!nourlBody.includes('No artifact URL recorded.')) { throw new Error(`No-url wording missing: ${JSON.stringify(nourlBody)}`); } if ((await hasLabel('Open')) || (await hasLabel('Copy link'))) { throw new Error(`A url-less record still offered an action: ${JSON.stringify(await labels())}`); } evidence.checks.push({ check: 'a record with no url is explicit and offers no action', value: true }); await capture('a1w-material-nourl'); await navigate(`${origin}/?origin=${encodeURIComponent(origin)}&state=empty`); await clickExact('Artifacts'); const emptyBody = await bodyText(); if (!emptyBody.includes('No artifacts recorded for this run.')) { throw new Error(`Recorded empty capture wording missing: ${JSON.stringify(emptyBody)}`); } evidence.checks.push({ check: 'a recorded empty capture says nothing was recorded', value: true }); await capture('a1w-material-empty'); await navigate(`${origin}/?origin=${encodeURIComponent(origin)}&state=unavailable`); await clickExact('Artifacts'); const unavailableBody = await bodyText(); if (!unavailableBody.includes('Artifacts · capture unavailable')) { throw new Error(`Unavailable capture wording missing: ${JSON.stringify(unavailableBody)}`); } if (unavailableBody.includes('No artifacts recorded for this run.')) { throw new Error('Unavailable capture claimed nothing was recorded'); } evidence.checks.push({ check: 'an unavailable capture is never reported as empty', value: true }); await capture('a1w-material-unavailable'); // In-app artifact viewer: image, text, unsupported, paging, back and HTTP // failure. The fixture serves same-origin artifact urls on this loopback // origin, so the viewer is allowed to fetch them; no browser tab may open. const galleryView = (extra = '', platform = 'material') => `${origin}/?view=gallery&platform=${platform}&origin=${encodeURIComponent(origin)}${extra}`; const beforeViewerTargets = await targetCount(); await navigate(galleryView(), 'Artifacts'); await clickLowestPrefix('shot.png'); await delay(700); const imageBody = await bodyText(); for (const fact of [ 'shot.png', 'image/png · 78.7\u00a0KiB', '3 of 4 · image/png', 'reviewer · visit 1', ]) { if (!imageBody.includes(fact)) { throw new Error(`Image preview missing ${fact}: ${JSON.stringify(imageBody)}`); } } if (!(await hasLabel('Previous artifact')) || !(await hasLabel('Next artifact'))) { throw new Error(`Viewer has no paging controls: ${JSON.stringify(await labels())}`); } const afterViewerTargets = await targetCount(); if (afterViewerTargets !== beforeViewerTargets) { throw new Error(`Image preview opened a browser tab: ${beforeViewerTargets} -> ${afterViewerTargets}`); } evidence.checks.push({ check: 'an image is previewed in-app from the same-origin url without a new tab', value: true, targets: afterViewerTargets, }); await capture('a1w-viewer-image'); await clickExact('Next artifact'); const videoBody = await bodyText(); if (!videoBody.includes('4 of 4 · video/mp4')) { throw new Error(`Viewer did not page to the video: ${JSON.stringify(videoBody)}`); } // The video plays in-app: its player loads the real clip and offers Play. for (let i = 0; i < 20 && !(await hasLabel('Play video')); i++) await delay(250); if (!(await hasLabel('Play video'))) { throw new Error(`Video did not load in the player: ${JSON.stringify(await bodyText())}`); } if ((await bodyText()).includes('The video could not be played.')) { throw new Error('The playable probe clip was reported as unplayable'); } if (!(await hasLabel('Open')) || !(await hasLabel('Copy link'))) { throw new Error(`Video page lost its actions: ${JSON.stringify(await labels())}`); } await capture('a1w-viewer-video'); await clickExact('Next artifact'); if (!(await bodyText()).includes('4 of 4 · video/mp4')) { throw new Error('Next past the last artifact changed the page'); } evidence.checks.push({ check: 'a video plays in-app with Open/Copy and paging clamps', value: true }); await clickExact('Previous artifact'); await clickExact('Previous artifact'); await clickExact('Previous artifact'); await delay(500); const textBody = await visibleText(); if (!textBody.includes('1 of 4 · text/plain')) { throw new Error(`Text page missing: ${JSON.stringify(textBody)}`); } evidence.checks.push({ check: 'text/plain pages in the viewer with its recorded facts', value: true }); await capture('a1w-viewer-text'); await clickExact('Back'); await delay(500); const returnedBody = await bodyText(); if (!returnedBody.includes('shot.png') || !returnedBody.includes('reviewer · visit 2')) { throw new Error(`Back did not return to the gallery: ${JSON.stringify(returnedBody)}`); } evidence.checks.push({ check: 'native Back returns to the gallery row list', value: true }); await navigate(galleryView('&state=missing'), 'Artifacts'); await clickLowestPrefix('missing.png'); await delay(700); const missingBody = await visibleText(); if (!missingBody.includes('The server answered 404.')) { throw new Error(`Missing fetch status was not reported: ${JSON.stringify(missingBody)}`); } evidence.checks.push({ check: 'an HTTP failure reports its status instead of an empty preview', value: true }); await capture('a1w-viewer-http-error'); await navigate(galleryView('&state=external'), 'Artifacts'); await clickLowestPrefix('elsewhere.png'); await delay(500); const externalBody = await visibleText(); if (!externalBody.includes('This artifact is hosted on another origin and is not previewed here.')) { throw new Error(`External artifact was not marked: ${JSON.stringify(externalBody)}`); } if (!externalBody.includes('1 of 1 · image/png') || !(await hasLabel('Open'))) { throw new Error(`External artifact lost its facts/Open action: ${JSON.stringify(externalBody)}`); } evidence.checks.push({ check: 'an external artifact opens marked, unfetched, with facts and actions', value: true }); await capture('a1w-viewer-external'); // 320 px at 2x text on both hosts: the viewer keeps its facts, paging and // controls whole. const scaledViewer = async (platform, prefix) => { await navigate(galleryView('', platform), 'Artifacts'); await clickLowestPrefix('shot.png'); await delay(700); const scaledBody = await bodyText(); for (const fact of ['image/png · 78.7\u00a0KiB', '3 of 4 · image/png', 'reviewer · visit 1']) { if (!scaledBody.includes(fact)) { throw new Error(`2x viewer missing ${fact}: ${JSON.stringify(scaledBody)}`); } } if (!(await hasLabel('Previous artifact')) || !(await hasLabel('Next artifact'))) { throw new Error(`2x viewer lost paging: ${JSON.stringify(await labels())}`); } await capture(`${prefix}-viewer`, 320, 720, 1); }; await scaledViewer('material', 'a1w-material-2x-320'); evidence.checks.push({ check: 'Material 2x/320 viewer keeps facts and paging', value: true }); await scaledViewer('cupertino', 'a1w-cupertino-2x-320'); evidence.checks.push({ check: 'Cupertino 2x/320 viewer keeps facts and paging', value: true }); // Cupertino light: the tinted action, the native dialog and its actions. await openGallery(`platform=cupertino&theme=light&origin=${encodeURIComponent(origin)}`); const cupertinoBody = await bodyText(); if (!cupertinoBody.includes('shot.png') || !cupertinoBody.includes('reviewer · visit 2')) { throw new Error(`Cupertino gallery missing recorded rows: ${JSON.stringify(cupertinoBody)}`); } evidence.checks.push({ check: 'Cupertino lists the same recorded rows', value: true }); await capture('a1w-cupertino-gallery'); await clickLowestPrefix('result.zip'); if (!(await hasLabel('Open')) || !(await hasLabel('Copy link'))) { throw new Error(`Cupertino selection offers no actions: ${JSON.stringify(await labels())}`); } const cupertinoSelected = await bodyText(); if (!cupertinoSelected.includes('Artifacts · 1 recorded · partial capture')) { throw new Error(`Cupertino selection lost its capture facts: ${JSON.stringify(cupertinoSelected)}`); } evidence.checks.push({ check: 'Cupertino selection shows the recorded facts and native actions', value: true }); await capture('a1w-cupertino-selected'); // Cupertino dark: the gallery and its dialog on the dark host. await openGallery(`platform=cupertino&theme=dark&origin=${encodeURIComponent(origin)}`); await capture('a1w-cupertino-dark-gallery'); await clickLowestPrefix('result.zip'); const darkLabels = await labels(); const darkTitle = darkLabels.find((label) => label.startsWith('result.zip')); const titleRect = await rectOfPrefix('result.zip'); const darkText = [await bodyText(), ...darkLabels].join('\n'); if (!darkText.includes('Artifacts · 1 recorded · partial capture')) { throw new Error(`Dark Cupertino dialog did not render: ${JSON.stringify(darkText)}`); } if (!titleRect) throw new Error(`Dark Cupertino dialog title missing: ${JSON.stringify(darkLabels)}`); const luminance = await brightestPixel(titleRect); if (luminance.max < 0.5) { throw new Error(`Dark Cupertino dialog text is not light: ${JSON.stringify(luminance)}`); } evidence.checks.push({ check: 'dark Cupertino dialog text is light on the popup surface', value: true, luminance: luminance.max, title: darkTitle, }); await capture('a1w-cupertino-dark-selected'); // 320 px at 2x text on both hosts: the recorded rows and facts stay whole. const openScaled = async (platform, prefix) => { await openGallery(`platform=${platform}&theme=light&scale=2&origin=${encodeURIComponent(origin)}`); const scaled = await bodyText(); for (const recorded of ['build.log', 'shot.png', 'reviewer · visit 1']) { if (!scaled.includes(recorded)) { throw new Error(`2x gallery missing ${recorded}: ${JSON.stringify(scaled)}`); } } await capture(`${prefix}-gallery`, 320, 720, 1); await clickLowestPrefix('result.zip'); const facts = await bodyText(); if (!facts.includes('Artifacts · 3 recorded') && !facts.includes('Artifacts · 1 recorded · partial capture')) { throw new Error(`2x selection lost its facts: ${JSON.stringify(facts)}`); } if (!(await hasLabel('Open')) || !(await hasLabel('Copy link'))) { throw new Error(`2x selection lost its actions: ${JSON.stringify(await labels())}`); } await capture(`${prefix}-selected`, 320, 720, 1); }; await openScaled('material', 'a1w-material-2x-320'); evidence.checks.push({ check: 'Material 2x/320 keeps the recorded rows, facts and actions', value: true }); await openScaled('cupertino', 'a1w-cupertino-2x-320'); evidence.checks.push({ check: 'Cupertino 2x/320 keeps the recorded rows, facts and actions', value: true }); // Turn documents: recorded input/memory/output/session.html are their own // rows per visit, absent ones carry the exact wording, markdown opens in the // renderer and the session export stays external-only even when sniffed as // text/plain. for (const platform of ['material', 'cupertino']) { const prefix = `a4-${platform}`; await navigate(galleryView('&state=documents', platform), 'Artifacts'); const documentsBody = await bodyText(); for (const fact of [ 'Turn documents', 'input.md', 'output.md', 'session.html', 'memory.md', 'text/markdown · 120\u00a0B', 'text/plain · 512\u00a0B', 'No memory recorded for this visit.', 'No output recorded.', 'This visit has no harness session.', ]) { if (!documentsBody.includes(fact)) { throw new Error(`${platform} documents view is missing ${fact}: ${JSON.stringify(documentsBody)}`); } } if (documentsBody.includes('No input recorded.')) { throw new Error(`${platform} fabricated a missing input document: ${JSON.stringify(documentsBody)}`); } evidence.checks.push({ check: `${platform} presents recorded turn documents and exact absence wording`, value: true }); await capture(`${prefix}-documents`); await clickExact('session.html'); const sessionBody = await visibleText(); if (!sessionBody.includes('text/plain · 512\u00a0B') || !(await hasLabel('Open'))) { throw new Error(`${platform} session export lost its facts/Open: ${JSON.stringify(sessionBody)}`); } if (sessionBody.includes('Previous artifact') || sessionBody.includes('1 of ')) { throw new Error(`${platform} opened session.html in the in-app renderer`); } evidence.checks.push({ check: `${platform} keeps session.html external-only`, value: true }); await capture(`${prefix}-session`); await clickExact('Close'); await delay(300); await navigate(galleryView('&state=documents', platform), 'Artifacts'); await clickExact('input.md'); await delay(700); const inputBody = await visibleText(); if (!inputBody.includes('recorded artifact /fixture/input.md') || !inputBody.includes('1 of 4 · text/markdown')) { throw new Error(`${platform} markdown document did not render in the viewer: ${JSON.stringify(inputBody)}`); } evidence.checks.push({ check: `${platform} opens a recorded markdown document in the renderer`, value: true }); await capture(`${prefix}-document-viewer`); await clickExact('Back'); await delay(400); } // Absence rows are informational text, not disabled controls: the Material // subtitle keeps readable contrast in both themes. for (const theme of ['light', 'dark']) { // Rasterise at 3x so a 14px subtitle stroke reaches its nominal colour; // at 1x, antialiasing dilutes every text colour. await send('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 3, mobile: true, }, session); await navigate(galleryView(`&state=documents&theme=${theme}`), 'Artifacts'); const sample = await subtitleContrast('memory.md', theme === 'dark'); evidence.contrast.push({ sample: `material ${theme} absence subtitle (memory.md)`, ...sample, }); if (sample.ratio < 4.5) { throw new Error(`Material ${theme} absence subtitle contrast is ${sample.ratio.toFixed(2)}:1`); } evidence.checks.push({ check: `material ${theme} absence subtitle meets 4.5:1`, value: true, ratio: Number(sample.ratio.toFixed(2)), }); await capture(`a4-material-${theme}-absence-row`); } // The Material pager must keep both labelled controls whole at 320 px with 2x // text, not clip the second button at the viewport edge. await send('Emulation.setDeviceMetricsOverride', { width: 320, height: 720, deviceScaleFactor: 1, mobile: true, }, session); await navigate(galleryView('&state=documents&scale=2'), 'Artifacts'); await clickExact('input.md'); await delay(700); if (!(await visibleText()).includes('1 of 4 · text/markdown')) { throw new Error(`2x document viewer did not open: ${JSON.stringify(await visibleText())}`); } const pagerControls = {}; for (const label of ['Previous artifact', 'Next artifact']) { const rect = await rectOfPrefix(label); if (!rect) throw new Error(`2x pager lost ${label}: ${JSON.stringify(await labels())}`); if (rect.x < -0.5 || rect.x + rect.width > 320.5) { throw new Error(`${label} leaves the 320px viewport: ${JSON.stringify(rect)}`); } pagerControls[label] = rect; } evidence.pager = { viewport: 320, textScale: 2, controls: pagerControls }; evidence.checks.push({ check: 'Material paging controls stay inside a 320px viewport at 2x text', value: true, controls: pagerControls, }); await capture('a4-material-320-2x-document-viewer', 320, 720, 1); // File actions: a real same-origin artifact is fetched, then handed to the // host as a named file. Blob/anchor and navigator.share are intercepted above // so the evidence is the exact bytes, MIME type and download name, not a // screenshot of a promise. const sameBytes = (actual, expected) => Array.isArray(actual) && actual.length === expected.length && actual.every((value, index) => value === expected[index]); const fileProbe = async (platform, prefix, extra = '') => { await send('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 1, mobile: true, }, session); const before = await targetCount(); await navigate(galleryView(`&state=files${extra}`, platform), 'Artifacts'); await clickExact('report.zip'); await delay(500); if (!(await hasLabel('Download')) || !(await hasLabel('Share'))) { throw new Error(`${platform} selection lost its file actions: ${JSON.stringify(await labels())}`); } await capture(`${prefix}-files-selected`); await clickExact('Download'); let downloaded; try { downloaded = await waitFor(async () => { const state = await transferState(); return state.objects[0]?.bytes ? state : null; }, `${platform} download bytes`); } catch (error) { throw new Error( `${error.message}\nstate=${JSON.stringify(await transferState())}\nbody=${JSON.stringify(await bodyText())}`, ); } const download = downloaded.downloads[0]; const object = downloaded.objects[0]; if (downloaded.downloads.length !== 1) { throw new Error(`${platform} did not request exactly one download: ${JSON.stringify(downloaded)}`); } if (download.name !== 'report.zip') { throw new Error(`${platform} download name was ${JSON.stringify(download.name)}`); } if (!download.href.startsWith('blob:')) { throw new Error(`${platform} download used a non-blob href: ${JSON.stringify(download.href)}`); } if (object.type !== 'application/zip' || object.size !== probeCsv.length) { throw new Error(`${platform} blob was ${object.type}/${object.size}, expected application/zip/${probeCsv.length}`); } if (!sameBytes(object.bytes, Array.from(probeCsv))) { throw new Error(`${platform} download bytes differed from the served artifact`); } if (!(await bodyText()).includes('Downloaded report.zip.')) { throw new Error(`${platform} download did not report its file: ${JSON.stringify(await bodyText())}`); } evidence.checks.push({ check: `${platform} Download hands the host report.zip, application/zip, ${probeCsv.length} exact bytes`, value: true, name: download.name, mime: object.type, size: object.size, blob: download.href.startsWith('blob:'), }); await capture(`${prefix}-files-downloaded`); await clickExact('Share'); let shared; try { shared = await waitFor(async () => { const state = await transferState(); return state.shares[0]?.[0]?.bytes ? state : null; }, `${platform} share file`); } catch (error) { throw new Error( `${error.message}\nstate=${JSON.stringify(await transferState())}\nbody=${JSON.stringify(await bodyText())}`, ); } const file = shared.shares[0]?.[0]; if (shared.shares.length !== 1 || shared.shares[0].length !== 1) { throw new Error(`${platform} share received ${JSON.stringify(shared.shares)}`); } if (file.name !== 'report.zip' || file.type !== 'application/zip' || file.size !== probeCsv.length) { throw new Error(`${platform} shared file was ${JSON.stringify(file)}`); } if (!sameBytes(file.bytes, Array.from(probeCsv))) { throw new Error(`${platform} shared bytes differed from the served artifact`); } if (!(await bodyText()).includes('File shared.')) { throw new Error(`${platform} share did not report success: ${JSON.stringify(await bodyText())}`); } if ((await targetCount()) !== before) { throw new Error(`${platform} file actions opened a browser tab`); } evidence.checks.push({ check: `${platform} Share hands the host a report.zip, application/zip, ${probeCsv.length} byte file`, value: true, name: file.name, mime: file.type, size: file.size, }); await capture(`${prefix}-files-shared`); }; await fileProbe('material', 'a3-material'); await fileProbe('cupertino', 'a3-cupertino'); await fileProbe('cupertino', 'a3-cupertino-dark', '&theme=dark'); console.log(JSON.stringify(evidence, null, 2)); } finally { ws?.close(); chrome.kill('SIGTERM'); await Promise.race([once(chrome, 'exit'), delay(3000)]); server.close(); await rm(profile, { recursive: true, force: true }); }