b60ad6d98f
Keep the probe suite on the Material composition so browser fixtures and capture drivers no longer render or select Cupertino hosts. Record the final residual legacy arguments and implementation checks for the delivery gate.
773 lines
27 KiB
JavaScript
773 lines
27 KiB
JavaScript
import { spawn, execFile } from 'node:child_process';
|
|
import { promisify } from 'node:util';
|
|
import { mkdtemp, mkdir, rm, writeFile, readFile, realpath, stat } from 'node:fs/promises';
|
|
import { once } from 'node:events';
|
|
import { createServer } from 'node:http';
|
|
import { createHash } from 'node:crypto';
|
|
import { tmpdir } from 'node:os';
|
|
import { extname, join, resolve, sep } from 'node:path';
|
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
|
|
// Real-browser acceptance for the run-retry wiring.
|
|
//
|
|
// Usage (from app/):
|
|
// flutter build web --target=tool/retry_wiring_probe.dart -o build/retry_probe_web
|
|
// OPENCODE_ARTIFACT_DIR=<dir> node tool/retry_wiring_probe.mjs build/retry_probe_web
|
|
//
|
|
// Environment:
|
|
// OPENCODE_ARTIFACT_DIR required; receives the PNG captures
|
|
// PROBE_THEME `dark` (default) or `light`
|
|
// CHROME_PATH Chrome binary; defaults to the macOS install
|
|
// TESSERACT OCR binary; defaults to `tesseract` on PATH
|
|
//
|
|
// The fixture serves the real bundle over loopback and answers the same
|
|
// websocket protocol as the app server: one stopped failed run, `get_run`,
|
|
// and `retry_run`. It records the exact retry payload, replies with the new
|
|
// run's `run_started` detail and pushes the matching compact run event, so the
|
|
// real app must open only the id the server names. Chrome is required; OCR
|
|
// checks cover the canvas-rendered titles.
|
|
const output = process.env.OPENCODE_ARTIFACT_DIR;
|
|
if (!output) throw new Error('Set OPENCODE_ARTIFACT_DIR for the probe captures');
|
|
await mkdir(output, { recursive: true });
|
|
const theme = process.env.PROBE_THEME === 'light' ? 'light' : 'dark';
|
|
const chromePath =
|
|
process.env.CHROME_PATH ?? '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
|
|
const tesseract = process.env.TESSERACT ?? 'tesseract';
|
|
const root = await realpath(process.argv[2] ?? 'build/retry_probe_web');
|
|
|
|
const SOURCE_ID = 7;
|
|
const RUN = {
|
|
id: SOURCE_ID,
|
|
pipeline_id: 3,
|
|
title: 'Fixture failed run',
|
|
name: 'fixture-retry',
|
|
version: 2,
|
|
status: 'failed',
|
|
executing: false,
|
|
created_at: '2026-10-21T12:00:00Z',
|
|
finished_at: '2026-10-21T12:04:00Z',
|
|
};
|
|
const retries = [];
|
|
const counters = { listRuns: 0, getRun: 0 };
|
|
let nextRunId = SOURCE_ID + 1;
|
|
const runs = new Map([[SOURCE_ID, { ...RUN }]]);
|
|
|
|
function runRow(run) {
|
|
return {
|
|
id: run.id,
|
|
pipeline_id: run.pipeline_id,
|
|
title: run.title,
|
|
name: run.name,
|
|
version: run.version,
|
|
status: run.status,
|
|
executing: run.executing,
|
|
created_at: run.created_at,
|
|
finished_at: run.finished_at,
|
|
};
|
|
}
|
|
|
|
function runDetail(run) {
|
|
return {
|
|
...runRow(run),
|
|
retry_of: run.retry_of,
|
|
input: { prompt: ' fixture prompt with spaces ' },
|
|
steps: [
|
|
{ stage: 'build', sequence: 3, status: 'completed', outcome: 'success' },
|
|
],
|
|
};
|
|
}
|
|
|
|
function newRetry(mode) {
|
|
const id = nextRunId++;
|
|
const label = mode === 'restart' ? 'Restart' : 'Resume';
|
|
const run = {
|
|
id,
|
|
pipeline_id: RUN.pipeline_id,
|
|
title: `${label} of ${SOURCE_ID}`,
|
|
name: RUN.name,
|
|
version: RUN.version,
|
|
status: 'running',
|
|
executing: true,
|
|
retry_of: SOURCE_ID,
|
|
created_at: '2026-10-21T12:05:00Z',
|
|
finished_at: '',
|
|
};
|
|
runs.set(id, run);
|
|
return run;
|
|
}
|
|
|
|
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',
|
|
'.css': 'text/css; charset=utf-8',
|
|
'.png': 'image/png',
|
|
'.svg': 'image/svg+xml',
|
|
'.ico': 'image/x-icon',
|
|
'.ttf': 'font/ttf',
|
|
'.otf': 'font/otf',
|
|
'.woff': 'font/woff',
|
|
'.woff2': 'font/woff2',
|
|
};
|
|
|
|
function accept(key) {
|
|
return createHash('sha1')
|
|
.update(`${key}258EAFA5-E914-47DA-95CA-C5AB0DC85B11`)
|
|
.digest('base64');
|
|
}
|
|
|
|
function frame(opcode, payload) {
|
|
const length = payload.length;
|
|
let header;
|
|
if (length < 126) {
|
|
header = Buffer.from([0x80 | opcode, length]);
|
|
} else if (length < 65536) {
|
|
header = Buffer.alloc(4);
|
|
header[0] = 0x80 | opcode;
|
|
header[1] = 126;
|
|
header.writeUInt16BE(length, 2);
|
|
} else {
|
|
header = Buffer.alloc(10);
|
|
header[0] = 0x80 | opcode;
|
|
header[1] = 127;
|
|
header.writeBigUInt64BE(BigInt(length), 2);
|
|
}
|
|
return Buffer.concat([header, payload]);
|
|
}
|
|
|
|
class Connection {
|
|
constructor(socket) {
|
|
this.socket = socket;
|
|
this.buffer = Buffer.alloc(0);
|
|
}
|
|
|
|
push(chunk) {
|
|
if (chunk?.length) this.buffer = Buffer.concat([this.buffer, chunk]);
|
|
while (this.buffer.length >= 2) {
|
|
const first = this.buffer[0];
|
|
const second = this.buffer[1];
|
|
const opcode = first & 0x0f;
|
|
let length = second & 0x7f;
|
|
let offset = 2;
|
|
if (length === 126) {
|
|
if (this.buffer.length < 4) return;
|
|
length = this.buffer.readUInt16BE(2);
|
|
offset = 4;
|
|
} else if (length === 127) {
|
|
if (this.buffer.length < 10) return;
|
|
length = Number(this.buffer.readBigUInt64BE(2));
|
|
offset = 10;
|
|
}
|
|
const masked = (second & 0x80) !== 0;
|
|
const maskOffset = offset;
|
|
if (masked) {
|
|
if (this.buffer.length < offset + 4) return;
|
|
offset += 4;
|
|
}
|
|
if (this.buffer.length < offset + length) return;
|
|
let payload = Buffer.from(this.buffer.subarray(offset, offset + length));
|
|
if (masked) {
|
|
const mask = this.buffer.subarray(maskOffset, maskOffset + 4);
|
|
for (let index = 0; index < payload.length; index++) {
|
|
payload[index] ^= mask[index % 4];
|
|
}
|
|
}
|
|
this.buffer = this.buffer.subarray(offset + length);
|
|
if (opcode === 0x8) return this.close();
|
|
if (opcode === 0x9) {
|
|
this.socket.write(frame(0x0a, payload));
|
|
continue;
|
|
}
|
|
if (opcode !== 0x1) continue;
|
|
let request;
|
|
try {
|
|
request = JSON.parse(payload.toString('utf8'));
|
|
} catch {
|
|
continue;
|
|
}
|
|
this.message(request);
|
|
}
|
|
}
|
|
|
|
message(request) {
|
|
if (request.type === 'subscribe' || request.type === 'unsubscribe') return;
|
|
if (request.type === 'ping') {
|
|
this.send({ id: request.id, type: 'pong', build: { version: 'Retry fixture' } });
|
|
return;
|
|
}
|
|
if (request.type === 'list_runs') {
|
|
counters.listRuns++;
|
|
this.send({
|
|
id: request.id,
|
|
type: 'runs',
|
|
runs: [...runs.values()].map(runRow),
|
|
usage: null,
|
|
});
|
|
return;
|
|
}
|
|
if (request.type === 'get_run') {
|
|
counters.getRun++;
|
|
const run = runs.get(request.run_id);
|
|
if (!run) {
|
|
this.send({ id: request.id, type: 'error', error: `no run ${request.run_id}` });
|
|
return;
|
|
}
|
|
this.send({ id: request.id, type: 'run', run_detail: runDetail(run) });
|
|
return;
|
|
}
|
|
if (request.type === 'retry_run') {
|
|
const record = {
|
|
run_id: request.run_id,
|
|
request_key: request.request_key,
|
|
keys: Object.keys(request).filter((key) => !['type', 'id'].includes(key)).sort(),
|
|
};
|
|
if (request.retry_mode != null) record.retry_mode = request.retry_mode;
|
|
retries.push(record);
|
|
const source = runs.get(request.run_id);
|
|
if (!source || source.status !== 'failed' || source.executing) {
|
|
this.send({ id: request.id, type: 'error', error: 'only failed stopped runs can be retried' });
|
|
return;
|
|
}
|
|
if (!request.request_key) {
|
|
this.send({ id: request.id, type: 'error', error: 'retry requires an idempotency request key' });
|
|
return;
|
|
}
|
|
const created = newRetry(request.retry_mode === 'restart' ? 'restart' : 'resume');
|
|
this.send({ id: request.id, type: 'run_started', run_detail: runDetail(created) });
|
|
// The real server also pushes the new run to the compact watch; that row
|
|
// is what makes the retried run appear in the list after Back.
|
|
this.send({
|
|
type: 'run_event',
|
|
run_id: created.id,
|
|
pipeline_id: created.pipeline_id,
|
|
name: created.name,
|
|
title: created.title,
|
|
version: created.version,
|
|
status: created.status,
|
|
created_at: created.created_at,
|
|
finished_at: '',
|
|
});
|
|
return;
|
|
}
|
|
this.send({
|
|
id: request.id,
|
|
type: 'error',
|
|
error: `Fixture does not implement ${request.type}`,
|
|
});
|
|
}
|
|
|
|
send(value) {
|
|
if (!this.socket.destroyed) {
|
|
this.socket.write(frame(0x1, Buffer.from(JSON.stringify(value))));
|
|
}
|
|
}
|
|
|
|
close() {
|
|
if (!this.socket.destroyed) this.socket.end();
|
|
}
|
|
}
|
|
|
|
async function staticFile(base, pathname, res) {
|
|
let file = resolve(base, `.${pathname}`);
|
|
if (file !== base && !file.startsWith(base + sep)) {
|
|
res.writeHead(403).end();
|
|
return;
|
|
}
|
|
try {
|
|
if ((await stat(file)).isDirectory()) file = join(file, 'index.html');
|
|
} catch {
|
|
if (extname(pathname)) {
|
|
res.writeHead(404).end('not found');
|
|
return;
|
|
}
|
|
file = join(base, 'index.html');
|
|
}
|
|
try {
|
|
const body = await readFile(file);
|
|
res
|
|
.writeHead(200, {
|
|
'content-type': MIME[extname(file)] ?? 'application/octet-stream',
|
|
'cache-control': 'no-store',
|
|
})
|
|
.end(body);
|
|
} catch {
|
|
res.writeHead(404).end('not found');
|
|
}
|
|
}
|
|
|
|
const sockets = new Set();
|
|
const server = createServer(async (req, res) => {
|
|
const pathname = new URL(req.url, 'http://fixture').pathname;
|
|
if (pathname === '/fixture/state') {
|
|
res
|
|
.writeHead(200, { 'content-type': 'application/json' })
|
|
.end(JSON.stringify({ retries, runs: [...runs.values()], ...counters }));
|
|
return;
|
|
}
|
|
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
|
res.writeHead(405).end();
|
|
return;
|
|
}
|
|
await staticFile(root, pathname, res);
|
|
});
|
|
server.on('upgrade', (req, socket, head) => {
|
|
const url = new URL(req.url, 'http://fixture');
|
|
if (
|
|
url.pathname !== '/connect' ||
|
|
req.headers.upgrade?.toLowerCase() !== 'websocket' ||
|
|
!req.headers['sec-websocket-key']
|
|
) {
|
|
socket.end('HTTP/1.1 400 Bad Request\r\nConnection: close\r\n\r\n');
|
|
return;
|
|
}
|
|
socket.write(
|
|
'HTTP/1.1 101 Switching Protocols\r\n' +
|
|
'Upgrade: websocket\r\n' +
|
|
'Connection: Upgrade\r\n' +
|
|
`Sec-WebSocket-Accept: ${accept(req.headers['sec-websocket-key'])}\r\n\r\n`,
|
|
);
|
|
const connection = new Connection(socket);
|
|
socket.on('data', (chunk) => connection.push(chunk));
|
|
socket.on('error', () => socket.destroy());
|
|
sockets.add(socket);
|
|
socket.on('close', () => sockets.delete(socket));
|
|
connection.push(head);
|
|
});
|
|
server.listen(0, '127.0.0.1');
|
|
await once(server, 'listening');
|
|
const fixtureUrl = `http://127.0.0.1:${server.address().port}`;
|
|
|
|
const profile = await mkdtemp(join(tmpdir(), 'r2-title-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;
|
|
});
|
|
|
|
async function waitFor(check, label, attempts = 160) {
|
|
for (let attempt = 0; attempt < attempts; attempt++) {
|
|
const value = await check();
|
|
if (value) return value;
|
|
await delay(100);
|
|
}
|
|
throw new Error(`Timed out waiting for ${label}\n${stderr.slice(-1200)}`);
|
|
}
|
|
|
|
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.method === 'Runtime.exceptionThrown') {
|
|
console.error('PAGE EXCEPTION', JSON.stringify(message.params?.exceptionDetails));
|
|
}
|
|
if (message.method === 'Runtime.consoleAPICalled') {
|
|
const values = (message.params?.args ?? []).map((arg) => arg.value ?? arg.description);
|
|
if (values.some((value) => String(value).includes('ERROR'))) {
|
|
console.error('PAGE CONSOLE', values.join(' '));
|
|
}
|
|
}
|
|
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 target = (await send('Target.createTarget', { url: 'about:blank' })).result.targetId;
|
|
const session = (await send('Target.attachToTarget', { targetId: target, flatten: true })).result.sessionId;
|
|
await send('Page.enable', {}, session);
|
|
await send('Runtime.enable', {}, 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)}`);
|
|
if (response.result?.exceptionDetails) {
|
|
throw new Error(`Page exception: ${JSON.stringify(response.result.exceptionDetails)}`);
|
|
}
|
|
return response.result?.result?.value;
|
|
};
|
|
|
|
const enableSemantics = async () => {
|
|
await waitFor(
|
|
() => evaluate("Boolean(document.querySelector('flt-semantics-placeholder'))"),
|
|
'Flutter semantics placeholder',
|
|
);
|
|
await evaluate("document.querySelector('flt-semantics-placeholder')?.click()");
|
|
await delay(700);
|
|
};
|
|
|
|
const semanticText = () =>
|
|
evaluate(`(() => {
|
|
const chunks = [];
|
|
for (const el of document.querySelectorAll('flt-semantics')) {
|
|
const label = el.getAttribute('aria-label');
|
|
if (label) chunks.push(label);
|
|
const value = el.getAttribute('aria-valuetext');
|
|
if (value) chunks.push(value);
|
|
if (el.value) chunks.push(String(el.value));
|
|
if (!el.children.length && el.innerText) chunks.push(el.innerText);
|
|
}
|
|
for (const el of document.querySelectorAll('input, textarea')) {
|
|
const label = el.getAttribute('aria-label');
|
|
if (label) chunks.push(label);
|
|
if (el.value) chunks.push(String(el.value));
|
|
}
|
|
if (document.body?.innerText) chunks.push(document.body.innerText);
|
|
return [...new Set(chunks)].join('\\n');
|
|
})()`);
|
|
|
|
const assertBody = async (text) => {
|
|
try {
|
|
await waitFor(
|
|
async () => (await semanticText()).includes(text),
|
|
`body to contain ${JSON.stringify(text)}`,
|
|
);
|
|
} catch (error) {
|
|
throw new Error(`${error.message}\nBody now:\n${(await semanticText()).slice(0, 3000)}`);
|
|
}
|
|
};
|
|
|
|
// The action row once had no Wrap spacing, so the outlined Rename border met
|
|
// the filled Retry button at 320 px. Measure the real controls' bounds; a
|
|
// screenshot alone cannot prove the 8 dp convention was restored.
|
|
const actionGap = async (check) => {
|
|
const rects = await evaluate(`(() => {
|
|
const found = {};
|
|
for (const el of document.querySelectorAll('flt-semantics')) {
|
|
const label = (el.getAttribute('aria-label') || el.innerText || '').trim();
|
|
if (label !== 'Rename' && label !== 'Retry') continue;
|
|
const r = el.getBoundingClientRect();
|
|
const area = r.width * r.height;
|
|
if (!found[label] || area > found[label].area) {
|
|
found[label] = { left: r.left, right: r.right, top: r.top, bottom: r.bottom, area };
|
|
}
|
|
}
|
|
return found;
|
|
})()`);
|
|
if (!rects.Rename || !rects.Retry) {
|
|
throw new Error(`${check}: action bounds missing ${JSON.stringify(rects)}`);
|
|
}
|
|
const sameRow =
|
|
Math.min(rects.Rename.bottom, rects.Retry.bottom) >
|
|
Math.max(rects.Rename.top, rects.Retry.top);
|
|
const gap = sameRow
|
|
? rects.Retry.left - rects.Rename.right
|
|
: rects.Retry.top - rects.Rename.bottom;
|
|
const minimum = sameRow ? 8 : 4;
|
|
if (gap < minimum - 0.5) {
|
|
throw new Error(
|
|
`${check}: Rename/Retry are ${gap.toFixed(3)} px apart, expected at least ${minimum} dp`,
|
|
);
|
|
}
|
|
return {
|
|
check: `${check} actions stay ${minimum} dp apart`,
|
|
gap: Number(gap.toFixed(3)),
|
|
sameRow,
|
|
};
|
|
};
|
|
|
|
const clickText = async (text, { last = false } = {}) => {
|
|
const clicked = await evaluate(`(() => {
|
|
const wanted = ${JSON.stringify(text)};
|
|
const all = [...document.querySelectorAll('flt-semantics')].filter((el) => {
|
|
const label = (el.getAttribute('aria-label') || el.innerText || '').trim();
|
|
return label === wanted;
|
|
});
|
|
const candidates = all.filter((el) =>
|
|
['button', 'tab', 'link', 'checkbox', 'menuitem'].includes(el.getAttribute('role')),
|
|
);
|
|
const pool = candidates.length ? candidates : all;
|
|
// A modal route is appended after the page: choosing the last match
|
|
// targets the dialog confirm instead of the page action underneath.
|
|
const target = ${last ? 'pool.at(-1)' : 'pool[0]'};
|
|
if (!target) return false;
|
|
target.click();
|
|
return true;
|
|
})()`);
|
|
if (!clicked) {
|
|
const labels = await evaluate(`[...document.querySelectorAll('flt-semantics')]
|
|
.map((el) => (el.getAttribute('aria-label') || el.innerText || '').trim()).filter(Boolean)`);
|
|
throw new Error(`Could not click ${JSON.stringify(text)}. Labels: ${JSON.stringify(labels)}`);
|
|
}
|
|
await delay(400);
|
|
};
|
|
|
|
const clickContains = async (text) => {
|
|
const clicked = await evaluate(`(() => {
|
|
const wanted = ${JSON.stringify(text)};
|
|
const all = [...document.querySelectorAll('flt-semantics')].filter((el) => {
|
|
const label = (el.getAttribute('aria-label') || el.innerText || '').trim();
|
|
return label.includes(wanted);
|
|
});
|
|
const target = all.find((el) =>
|
|
['button', 'link', 'tab'].includes(el.getAttribute('role')),
|
|
) ?? all.at(-1);
|
|
if (!target) return false;
|
|
target.click();
|
|
return true;
|
|
})()`);
|
|
if (!clicked) throw new Error(`Could not click a row containing ${JSON.stringify(text)}`);
|
|
await delay(400);
|
|
};
|
|
|
|
const capture = async (name) => {
|
|
const data = (await send('Page.captureScreenshot', { format: 'png' }, session)).result.data;
|
|
const path = join(output, `${name}.png`);
|
|
await writeFile(path, Buffer.from(data, 'base64'));
|
|
return path;
|
|
};
|
|
|
|
const ocr = async (path) =>
|
|
(await promisify(execFile)(tesseract, [path, 'stdout'])).stdout;
|
|
|
|
const assertOcr = async (path, text) => {
|
|
const read = await ocr(path);
|
|
if (!read.toLowerCase().includes(text.toLowerCase())) {
|
|
throw new Error(`OCR of ${path} lacks ${JSON.stringify(text)}:\n${read.slice(0, 2000)}`);
|
|
}
|
|
};
|
|
|
|
const state = async () => (await (await fetch(`${fixtureUrl}/fixture/state`)).json());
|
|
|
|
const setView = async ({ width, height, deviceScaleFactor = 1 }) => {
|
|
await send(
|
|
'Emulation.setDeviceMetricsOverride',
|
|
{ width, height, deviceScaleFactor, mobile: width < 600 },
|
|
session,
|
|
);
|
|
await send(
|
|
'Emulation.setEmulatedMedia',
|
|
{ features: [{ name: 'prefers-color-scheme', value: theme }] },
|
|
session,
|
|
);
|
|
await delay(400);
|
|
};
|
|
|
|
const retryPromptOpen = async () =>
|
|
(await semanticText()).includes(`Retry run ${SOURCE_ID}?`);
|
|
const restartPromptOpen = async () =>
|
|
(await semanticText()).includes(`Restart run ${SOURCE_ID}?`);
|
|
|
|
const assertPayload = (record, { restart, check }) => {
|
|
if (!record) throw new Error(`${check}: the server recorded no retry`);
|
|
const keys = restart
|
|
? ['request_key', 'retry_mode', 'run_id']
|
|
: ['request_key', 'run_id'];
|
|
if (JSON.stringify(record.keys) !== JSON.stringify(keys)) {
|
|
throw new Error(`${check}: unexpected request fields ${JSON.stringify(record)}`);
|
|
}
|
|
if (record.run_id !== SOURCE_ID) {
|
|
throw new Error(`${check}: wrong run id ${JSON.stringify(record)}`);
|
|
}
|
|
if (!String(record.request_key).startsWith(`app-retry-${SOURCE_ID}-`)) {
|
|
throw new Error(`${check}: wrong request key ${JSON.stringify(record)}`);
|
|
}
|
|
if (String(record.request_key).length > 128) {
|
|
throw new Error(`${check}: request key too long ${JSON.stringify(record)}`);
|
|
}
|
|
if (restart && record.retry_mode !== 'restart') {
|
|
throw new Error(`${check}: restart mode missing ${JSON.stringify(record)}`);
|
|
}
|
|
if (!restart && record.retry_mode != null) {
|
|
throw new Error(`${check}: resume must omit retry_mode ${JSON.stringify(record)}`);
|
|
}
|
|
return record;
|
|
};
|
|
|
|
const captures = [];
|
|
const checks = [];
|
|
|
|
await setView({ width: 320, height: 480, deviceScaleFactor: 2 });
|
|
if (
|
|
!(await evaluate(`matchMedia('(prefers-color-scheme: ${theme})').matches`))
|
|
) {
|
|
throw new Error(`The fixture host is not in ${theme} mode`);
|
|
}
|
|
|
|
const open = async (id, expectedTitle) => {
|
|
const navigation = await send(
|
|
'Page.navigate',
|
|
{ url: `${fixtureUrl}/runs/${id}` },
|
|
session,
|
|
);
|
|
if (navigation.error || navigation.result?.errorText) throw new Error(JSON.stringify(navigation));
|
|
await enableSemantics();
|
|
await assertBody(expectedTitle);
|
|
if ((await evaluate('location.pathname')) !== `/runs/${id}`) {
|
|
throw new Error(`Deep link moved to ${await evaluate('location.pathname')}`);
|
|
}
|
|
};
|
|
|
|
const waitNewRun = async (id, title) => {
|
|
await waitFor(
|
|
async () => (await evaluate('location.pathname')) === `/runs/${id}`,
|
|
`the route to open run ${id}`,
|
|
);
|
|
await assertBody(title);
|
|
await assertBody('Original prompt');
|
|
};
|
|
|
|
// Material host (macOS browser), 320 CSS px at DPR 2 in dark mode.
|
|
await open(SOURCE_ID, 'Fixture failed run');
|
|
await assertBody('Rename');
|
|
await assertBody('Retry');
|
|
captures.push(await capture(`r2c-retry-material-${theme}-failed`));
|
|
await assertOcr(captures.at(-1), 'Fixture failed run');
|
|
checks.push(await actionGap('Material'));
|
|
checks.push({ check: `Material ${theme} 320px detail offers Retry`, path: await evaluate('location.pathname') });
|
|
|
|
await clickText('Retry');
|
|
await waitFor(retryPromptOpen, 'the retry prompt');
|
|
await assertBody('Only failed runs can be retried');
|
|
captures.push(await capture(`r2c-retry-material-${theme}-prompt`));
|
|
await assertOcr(captures.at(-1), 'Retry run 7?');
|
|
|
|
await clickText('Keep');
|
|
await waitFor(async () => !(await retryPromptOpen()), 'the closed retry prompt');
|
|
if ((await state()).retries.length !== 0) {
|
|
throw new Error('Keep sent retry_run');
|
|
}
|
|
checks.push({ check: 'Material Keep sent nothing', sent: 0 });
|
|
captures.push(await capture(`r2c-retry-material-${theme}-kept`));
|
|
|
|
// Restart: the browser-only second confirmation, then the server-named run.
|
|
await clickText('Retry');
|
|
await waitFor(retryPromptOpen, 'the retry prompt again');
|
|
await clickText('Restart from start');
|
|
await waitFor(restartPromptOpen, 'the restart prompt');
|
|
await assertBody('replays the whole pipeline');
|
|
captures.push(await capture(`r2c-retry-material-${theme}-restart-prompt`));
|
|
await clickText('Restart from start', { last: true });
|
|
try {
|
|
await waitFor(async () => (await state()).retries.length === 1, 'the first retry request');
|
|
} catch (error) {
|
|
console.error('STATE', JSON.stringify(await state()));
|
|
console.error('TEXT', (await semanticText()).slice(0, 2000));
|
|
await capture('r2c-retry-debug');
|
|
throw error;
|
|
}
|
|
const restart = assertPayload((await state()).retries[0], {
|
|
restart: true,
|
|
check: 'Material restart',
|
|
});
|
|
await waitNewRun(SOURCE_ID + 1, 'Restart of 7');
|
|
captures.push(await capture(`r2c-retry-material-${theme}-restart-run`));
|
|
await assertOcr(captures.at(-1), 'Restart of 7');
|
|
checks.push({ check: 'Material restart opened only the server-named run', restart, path: await evaluate('location.pathname') });
|
|
|
|
await clickText('Back');
|
|
await assertBody('Fixture failed run');
|
|
await assertBody('Restart of 7');
|
|
captures.push(await capture(`r2c-retry-material-${theme}-list`));
|
|
await assertOcr(captures.at(-1), 'Restart of 7');
|
|
|
|
// Resume after returning to the still-failed source run.
|
|
await clickContains('Fixture failed run');
|
|
await waitFor(
|
|
async () => (await evaluate('location.pathname')) === `/runs/${SOURCE_ID}`,
|
|
'the source run again',
|
|
);
|
|
await assertBody('Retry');
|
|
await clickText('Retry');
|
|
await waitFor(retryPromptOpen, 'the resume prompt');
|
|
await clickText('Retry', { last: true });
|
|
await waitFor(async () => (await state()).retries.length === 2, 'the resume request');
|
|
const resume = assertPayload((await state()).retries[1], {
|
|
restart: false,
|
|
check: 'Material resume',
|
|
});
|
|
await waitNewRun(SOURCE_ID + 2, 'Resume of 7');
|
|
captures.push(await capture(`r2c-retry-material-${theme}-resume-run`));
|
|
await assertOcr(captures.at(-1), 'Resume of 7');
|
|
checks.push({ check: 'Material resume omitted retry_mode and opened the reply run', resume, path: await evaluate('location.pathname') });
|
|
|
|
// Material host: the same deep link, shared gateway and normal app build.
|
|
await send(
|
|
'Emulation.setUserAgentOverride',
|
|
{
|
|
userAgent:
|
|
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 ' +
|
|
'(KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36',
|
|
platform: 'Linux x86_64',
|
|
},
|
|
session,
|
|
);
|
|
await open(SOURCE_ID, 'Fixture failed run');
|
|
await assertBody('Rename');
|
|
await assertBody('Retry');
|
|
captures.push(await capture(`r2c-retry-material-${theme}-failed`));
|
|
await assertOcr(captures.at(-1), 'Fixture failed run');
|
|
checks.push(await actionGap('Material'));
|
|
checks.push({ check: `Material ${theme} 320px detail offers Retry`, path: await evaluate('location.pathname') });
|
|
|
|
await clickText('Retry');
|
|
await waitFor(retryPromptOpen, 'the material retry prompt');
|
|
captures.push(await capture(`r2c-retry-material-${theme}-prompt`));
|
|
await clickText('Keep');
|
|
await waitFor(async () => !(await retryPromptOpen()), 'the closed material prompt');
|
|
if ((await state()).retries.length !== 2) {
|
|
throw new Error('Material Keep sent retry_run');
|
|
}
|
|
checks.push({ check: 'Material Keep sent nothing', sent: 0 });
|
|
|
|
await clickText('Retry');
|
|
await waitFor(retryPromptOpen, 'the material resume prompt');
|
|
await clickText('Retry', { last: true });
|
|
await waitFor(async () => (await state()).retries.length === 3, 'the material retry request');
|
|
const material = assertPayload((await state()).retries[2], {
|
|
restart: false,
|
|
check: 'Material resume',
|
|
});
|
|
await waitNewRun(SOURCE_ID + 3, 'Resume of 7');
|
|
captures.push(await capture(`r2c-retry-material-${theme}-run`));
|
|
await assertOcr(captures.at(-1), 'Resume of 7');
|
|
checks.push({ check: 'Material resume sent the exact payload and opened the reply run', material, path: await evaluate('location.pathname') });
|
|
|
|
const finalState = await state();
|
|
if (finalState.retries.length !== 3) {
|
|
throw new Error(`Expected three retry requests, saw ${JSON.stringify(finalState.retries)}`);
|
|
}
|
|
if (finalState.runs.filter((run) => run.id !== SOURCE_ID).length !== 3) {
|
|
throw new Error(`Expected three server-created runs, saw ${JSON.stringify(finalState.runs)}`);
|
|
}
|
|
console.log(JSON.stringify({ ok: true, fixture: fixtureUrl, checks, captures }, null, 2));
|
|
} finally {
|
|
ws?.close();
|
|
for (const socket of sockets) socket.destroy();
|
|
await new Promise((resolveClose) => server.close(resolveClose));
|
|
chrome.kill('SIGTERM');
|
|
await Promise.race([once(chrome, 'exit'), delay(3000)]);
|
|
await rm(profile, { recursive: true, force: true });
|
|
}
|