Merge branch 'main' into flutter/chat-markdown
This commit is contained in:
@@ -0,0 +1,309 @@
|
||||
// Standalone fixture entry for real-browser run-detail Artifacts evidence.
|
||||
//
|
||||
// Build and probe (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
|
||||
//
|
||||
// Server-shaped fixtures only: a fake gateway answers the same get_run envelope
|
||||
// the app consumes. The recorded urls point at the probe's own loopback origin,
|
||||
// so the external Open action has a real target. No server or operator run is
|
||||
// touched.
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_gallery_page.dart';
|
||||
import 'package:pipelines_app/features/runs/data/runs_repository.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_view.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/runs_controller.dart';
|
||||
|
||||
class _FakeGateway implements ApiGateway {
|
||||
_FakeGateway(this.detail);
|
||||
|
||||
final JsonMap detail;
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => const Stream<JsonMap>.empty();
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
||||
if (type != 'get_run') throw UnsupportedError(type);
|
||||
return Future.value({'run_detail': detail});
|
||||
}
|
||||
}
|
||||
|
||||
JsonMap _file(
|
||||
String name, {
|
||||
required String url,
|
||||
required String contentType,
|
||||
required int sizeBytes,
|
||||
}) => <String, dynamic>{
|
||||
'name': name,
|
||||
'url': url,
|
||||
'content_type': contentType,
|
||||
'size_bytes': sizeBytes,
|
||||
};
|
||||
|
||||
/// The recorded steps for one probe state. `default` carries two visits that
|
||||
/// both record `result.csv` plus a partial capture on the second visit.
|
||||
List<JsonMap> _steps(String origin, String state) {
|
||||
if (state == 'unavailable') {
|
||||
return <JsonMap>[
|
||||
<String, dynamic>{
|
||||
'stage': 'implementer',
|
||||
'sequence': 1,
|
||||
'status': 'completed',
|
||||
'control': <String, dynamic>{'visit': 1},
|
||||
},
|
||||
];
|
||||
}
|
||||
if (state == 'empty') {
|
||||
return <JsonMap>[
|
||||
<String, dynamic>{
|
||||
'stage': 'implementer',
|
||||
'sequence': 1,
|
||||
'status': 'completed',
|
||||
'control': <String, dynamic>{'visit': 1},
|
||||
'artifacts': const <JsonMap>[],
|
||||
},
|
||||
];
|
||||
}
|
||||
if (state == 'unsafe' || state == 'nourl') {
|
||||
return <JsonMap>[
|
||||
<String, dynamic>{
|
||||
'stage': 'reviewer',
|
||||
'sequence': 1,
|
||||
'status': 'completed',
|
||||
'control': <String, dynamic>{'visit': 1},
|
||||
'artifacts': [
|
||||
_file(
|
||||
'result.csv',
|
||||
url: state == 'unsafe' ? '//evil.test/result.csv' : '',
|
||||
contentType: 'text/csv',
|
||||
sizeBytes: 2048,
|
||||
),
|
||||
],
|
||||
},
|
||||
];
|
||||
}
|
||||
if (state == 'missing') {
|
||||
return <JsonMap>[
|
||||
<String, dynamic>{
|
||||
'stage': 'reviewer',
|
||||
'sequence': 1,
|
||||
'status': 'completed',
|
||||
'control': <String, dynamic>{'visit': 1},
|
||||
'artifacts': [
|
||||
_file(
|
||||
'missing.png',
|
||||
url: '$origin/fixture/missing.png',
|
||||
contentType: 'image/png',
|
||||
sizeBytes: 128,
|
||||
),
|
||||
],
|
||||
},
|
||||
];
|
||||
}
|
||||
if (state == 'external') {
|
||||
return <JsonMap>[
|
||||
<String, dynamic>{
|
||||
'stage': 'reviewer',
|
||||
'sequence': 1,
|
||||
'status': 'completed',
|
||||
'control': <String, dynamic>{'visit': 1},
|
||||
'artifacts': [
|
||||
_file(
|
||||
'elsewhere.png',
|
||||
url: 'https://elsewhere.test/elsewhere.png',
|
||||
contentType: 'image/png',
|
||||
sizeBytes: 4096,
|
||||
),
|
||||
],
|
||||
},
|
||||
];
|
||||
}
|
||||
return <JsonMap>[
|
||||
<String, dynamic>{
|
||||
'stage': 'implementer',
|
||||
'sequence': 1,
|
||||
'status': 'completed',
|
||||
'control': <String, dynamic>{'visit': 1},
|
||||
'artifacts': [
|
||||
_file(
|
||||
'build.log',
|
||||
url: '$origin/fixture/build.log',
|
||||
contentType: 'text/plain; charset=utf-8',
|
||||
sizeBytes: 2337,
|
||||
),
|
||||
_file(
|
||||
'notes.txt',
|
||||
url: '$origin/fixture/notes.txt',
|
||||
contentType: 'text/plain',
|
||||
sizeBytes: 2337,
|
||||
),
|
||||
],
|
||||
},
|
||||
<String, dynamic>{
|
||||
'stage': 'reviewer',
|
||||
'sequence': 2,
|
||||
'status': 'completed',
|
||||
'control': <String, dynamic>{'visit': 1},
|
||||
'artifacts': [
|
||||
_file(
|
||||
'result.csv',
|
||||
url: '$origin/fixture/result.csv',
|
||||
contentType: 'text/csv',
|
||||
sizeBytes: 2048,
|
||||
),
|
||||
_file(
|
||||
'shot.png',
|
||||
url: '$origin/fixture/shot.png',
|
||||
contentType: 'image/png',
|
||||
sizeBytes: 80544,
|
||||
),
|
||||
_file(
|
||||
'clip.mp4',
|
||||
url: '$origin/fixture/clip.mp4',
|
||||
contentType: 'video/mp4',
|
||||
sizeBytes: 40544,
|
||||
),
|
||||
],
|
||||
},
|
||||
<String, dynamic>{
|
||||
'stage': 'reviewer',
|
||||
'sequence': 3,
|
||||
'status': 'completed',
|
||||
'control': <String, dynamic>{'visit': 2},
|
||||
'artifacts': [
|
||||
_file(
|
||||
'result.csv',
|
||||
url: '$origin/fixture/result-2.csv',
|
||||
contentType: 'text/csv',
|
||||
sizeBytes: 4096,
|
||||
),
|
||||
],
|
||||
'artifacts_skipped': 2,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
JsonMap _run(String origin, String state) => <String, dynamic>{
|
||||
'id': 31,
|
||||
'title': 'Artifacts gallery probe',
|
||||
'name': 'gallery',
|
||||
'status': 'succeeded',
|
||||
'steps': _steps(origin, state),
|
||||
};
|
||||
|
||||
void main() {
|
||||
final params = Uri.base.queryParameters;
|
||||
final cupertino = params['platform'] == 'cupertino';
|
||||
final theme = params['theme'] == 'dark' ? Brightness.dark : Brightness.light;
|
||||
final origin = params['origin'] ?? 'https://artifacts.invalid';
|
||||
final state = params['state'] ?? 'default';
|
||||
final gallery = params['view'] == 'gallery';
|
||||
final originUrl = Uri.tryParse(origin);
|
||||
final endpoint = originUrl == null
|
||||
? ''
|
||||
: originUrl
|
||||
.replace(
|
||||
scheme: originUrl.scheme == 'https' ? 'wss' : 'ws',
|
||||
path: '/connect',
|
||||
query: null,
|
||||
)
|
||||
.toString();
|
||||
// Browser text scaling is a fixture input like platform and theme.
|
||||
final textScale = double.tryParse(params['scale'] ?? '') ?? 1;
|
||||
final body = _ProbeBody(
|
||||
run: _run(origin, state),
|
||||
gallery: gallery,
|
||||
endpoint: endpoint,
|
||||
);
|
||||
Widget scaled(BuildContext context, Widget? app) => MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: TextScaler.linear(textScale)),
|
||||
child: app!,
|
||||
);
|
||||
if (cupertino) {
|
||||
runApp(
|
||||
CupertinoApp(
|
||||
title: 'Artifacts probe',
|
||||
theme: CupertinoThemeData(brightness: theme),
|
||||
builder: (context, app) => Theme(
|
||||
data: ThemeData(platform: TargetPlatform.iOS),
|
||||
child: scaled(context, app),
|
||||
),
|
||||
home: body,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
runApp(
|
||||
MaterialApp(
|
||||
title: 'Artifacts probe',
|
||||
theme: ThemeData(brightness: theme, platform: TargetPlatform.android),
|
||||
builder: scaled,
|
||||
home: body,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ProbeBody extends StatefulWidget {
|
||||
const _ProbeBody({
|
||||
required this.run,
|
||||
required this.gallery,
|
||||
required this.endpoint,
|
||||
});
|
||||
|
||||
final JsonMap run;
|
||||
final bool gallery;
|
||||
final String endpoint;
|
||||
|
||||
@override
|
||||
State<_ProbeBody> createState() => _ProbeBodyState();
|
||||
}
|
||||
|
||||
class _ProbeBodyState extends State<_ProbeBody> {
|
||||
late final _FakeGateway _gateway = _FakeGateway(widget.run);
|
||||
late final RunsController _controller = RunsController(
|
||||
RunsRepository(_gateway),
|
||||
);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller.select(31);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (widget.gallery) {
|
||||
final steps = (widget.run['steps'] as List).cast<JsonMap>();
|
||||
return ArtifactGalleryPage(
|
||||
steps: steps,
|
||||
configuredEndpoint: widget.endpoint,
|
||||
);
|
||||
}
|
||||
final detail = RunDetailView(
|
||||
controller: _controller,
|
||||
gateway: _gateway,
|
||||
onBack: () {},
|
||||
);
|
||||
if (Theme.of(context).platform == TargetPlatform.iOS) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: const CupertinoNavigationBar(middle: Text('Runs')),
|
||||
child: SafeArea(child: detail),
|
||||
);
|
||||
}
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Runs')),
|
||||
body: detail,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,601 @@
|
||||
// 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 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('.png')) {
|
||||
res.writeHead(200, { 'content-type': 'image/png' });
|
||||
res.end(png);
|
||||
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: [] };
|
||||
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);
|
||||
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 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 };
|
||||
})()`);
|
||||
};
|
||||
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', 'text/csv', '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.csv')).length;
|
||||
if (resultRows < 2) {
|
||||
throw new Error(`Duplicate result.csv 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.csv');
|
||||
const selectedBody = await bodyText();
|
||||
for (const fact of ['reviewer · visit 2', 'text/csv · 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.csv');
|
||||
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.csv');
|
||||
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)}`);
|
||||
}
|
||||
if (!videoBody.includes('This file type cannot be previewed here.')) {
|
||||
throw new Error(`Video was not marked unpresentable: ${JSON.stringify(videoBody)}`);
|
||||
}
|
||||
if (!(await hasLabel('Open')) || !(await hasLabel('Copy link'))) {
|
||||
throw new Error(`Unsupported page lost its actions: ${JSON.stringify(await labels())}`);
|
||||
}
|
||||
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: 'unsupported types are explicit with Open/Copy and paging clamps', value: true });
|
||||
await capture('a1w-viewer-unsupported');
|
||||
|
||||
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.csv');
|
||||
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.csv');
|
||||
const darkLabels = await labels();
|
||||
const darkTitle = darkLabels.find((label) => label.startsWith('result.csv'));
|
||||
const titleRect = await rectOfPrefix('result.csv');
|
||||
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.csv');
|
||||
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 });
|
||||
|
||||
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 });
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/screen.dart';
|
||||
|
||||
/// Browser fixture for the Chat destination wiring: the real session list opens
|
||||
/// the real controller/view against a scripted gateway. Server data only; no
|
||||
/// composer, routes, sockets or production store are involved.
|
||||
///
|
||||
/// Sessions page with different server answers so the driver can reproduce the
|
||||
/// disclosure-state variants: alternating turns with the older page keeping or
|
||||
/// ending history, and pages of consecutive assistant messages that fold into
|
||||
/// one turn at the page boundary.
|
||||
class _FixtureGateway implements ApiGateway {
|
||||
final _frames = StreamController<JsonMap>.broadcast();
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => _frames.stream;
|
||||
|
||||
void _pushLiveDelta() {
|
||||
Timer(const Duration(milliseconds: 500), () {
|
||||
_frames.add({
|
||||
'type': 'chat_event',
|
||||
'chat_event': {
|
||||
'session_id': 'probe-session',
|
||||
'message_id': 'a-NEWEST',
|
||||
'kind': 'text',
|
||||
'part': {'id': 'p-live', 'type': 'text'},
|
||||
'delta': 'A live delta updated this thread.',
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
||||
switch (type) {
|
||||
case 'chat_sessions':
|
||||
return {
|
||||
'chat_sessions': [
|
||||
{
|
||||
'id': 'probe-session',
|
||||
'title': 'Probe conversation',
|
||||
'directory': '/workspace/demo',
|
||||
'starred': true,
|
||||
},
|
||||
{
|
||||
'id': 'probe-more',
|
||||
'title': 'Probe paging session',
|
||||
'directory': '/workspace/demo',
|
||||
},
|
||||
{
|
||||
'id': 'probe-other',
|
||||
'title': 'Another stored chat',
|
||||
'directory': '/workspace/demo',
|
||||
},
|
||||
{
|
||||
'id': 'probe-fold',
|
||||
'title': 'Probe assistant fold session',
|
||||
'directory': '/workspace/demo',
|
||||
},
|
||||
{
|
||||
'id': 'probe-fold-end',
|
||||
'title': 'Probe assistant fold last page',
|
||||
'directory': '/workspace/demo',
|
||||
},
|
||||
],
|
||||
};
|
||||
case 'chat_subscribe':
|
||||
return {};
|
||||
case 'chat_messages':
|
||||
final query = fields['chat_query'] as Map? ?? const {};
|
||||
final cursor = '${query['cursor'] ?? ''}';
|
||||
if (query['session_id'] == 'probe-fold' ||
|
||||
query['session_id'] == 'probe-fold-end') {
|
||||
final keepsPaging = query['session_id'] == 'probe-fold';
|
||||
if (cursor.isEmpty) {
|
||||
return _foldPage(
|
||||
prefix: 'FOLD_NEWEST',
|
||||
ids: const ['fold-newest', 'fold-fourth'],
|
||||
reasoning: const [
|
||||
'FOLD NEWEST reasoning body.',
|
||||
'FOLD FOURTH reasoning body.',
|
||||
],
|
||||
cursor: 'probe/opaque?fold=2',
|
||||
hasMore: true,
|
||||
);
|
||||
}
|
||||
return _foldPage(
|
||||
prefix: 'FOLD_OLDER',
|
||||
ids: const ['fold-second', 'fold-oldest'],
|
||||
reasoning: const [
|
||||
'FOLD SECOND reasoning body.',
|
||||
'FOLD OLDEST reasoning body.',
|
||||
],
|
||||
cursor: keepsPaging ? 'probe/opaque?fold=3' : '',
|
||||
hasMore: keepsPaging,
|
||||
);
|
||||
}
|
||||
if (query['session_id'] == 'probe-more') {
|
||||
return cursor.isEmpty
|
||||
? _page(
|
||||
prefix: 'MORE_NEWEST',
|
||||
user: 'A second read-only question from the server.',
|
||||
reasoning: 'MORE NEWEST reasoning body.',
|
||||
reply: 'The second stored assistant reply.',
|
||||
cursor: 'probe/opaque?more=2',
|
||||
hasMore: true,
|
||||
)
|
||||
: _page(
|
||||
prefix: 'MORE_OLDER',
|
||||
user: 'An even older message for the second chat.',
|
||||
reasoning:
|
||||
'MORE OLDER reasoning body that must stay collapsed.',
|
||||
reply: 'Second older reply.',
|
||||
cursor: 'probe/opaque?more=3',
|
||||
hasMore: true,
|
||||
);
|
||||
}
|
||||
if (cursor.isEmpty) {
|
||||
// Deliver the live delta only after the initial history page, so the
|
||||
// merge cannot be mistaken for the delta being lost.
|
||||
_pushLiveDelta();
|
||||
return _page(
|
||||
prefix: 'NEWEST',
|
||||
user: 'Please keep this exact read-only message from the server.',
|
||||
reasoning:
|
||||
'NEWEST reasoning body that belongs to the newest answer.',
|
||||
reply:
|
||||
'The stored assistant reply is rendered by the existing '
|
||||
'native message view.',
|
||||
cursor: 'probe/opaque?page=2',
|
||||
hasMore: true,
|
||||
);
|
||||
}
|
||||
return _page(
|
||||
prefix: 'OLDER',
|
||||
user: 'This older stored message came from the opaque cursor page.',
|
||||
reasoning:
|
||||
'OLDER reasoning body that must not steal the newest '
|
||||
'disclosure.',
|
||||
reply: 'Older reply kept in order.',
|
||||
cursor: '',
|
||||
hasMore: false,
|
||||
);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
JsonMap _page({
|
||||
required String prefix,
|
||||
required String user,
|
||||
required String reasoning,
|
||||
required String reply,
|
||||
required String cursor,
|
||||
required bool hasMore,
|
||||
}) => {
|
||||
'chat_history': {
|
||||
'messages': [
|
||||
{
|
||||
'id': 'u-$prefix',
|
||||
'role': 'user',
|
||||
'client': 'Probe host',
|
||||
'parts': [
|
||||
{'type': 'text', 'text': user},
|
||||
],
|
||||
},
|
||||
{
|
||||
'id': 'a-$prefix',
|
||||
'role': 'assistant',
|
||||
'parts': [
|
||||
{'type': 'reasoning', 'text': reasoning},
|
||||
{'type': 'text', 'text': reply},
|
||||
{'type': 'tool', 'name': 'shell'},
|
||||
],
|
||||
},
|
||||
],
|
||||
'next_cursor': cursor,
|
||||
'has_more': hasMore,
|
||||
},
|
||||
};
|
||||
|
||||
/// The paged-history fixture shape: a page of consecutive assistant messages
|
||||
/// with no user message at the page boundary, so paging folds into one turn.
|
||||
JsonMap _foldPage({
|
||||
required String prefix,
|
||||
required List<String> ids,
|
||||
required List<String> reasoning,
|
||||
required String cursor,
|
||||
required bool hasMore,
|
||||
}) => {
|
||||
'chat_history': {
|
||||
'messages': [
|
||||
for (var index = 0; index < ids.length; index++)
|
||||
{
|
||||
'id': ids[index],
|
||||
'role': 'assistant',
|
||||
'parts': [
|
||||
{
|
||||
'type': 'reasoning',
|
||||
'id': 'r-${ids[index]}',
|
||||
'text': reasoning[index],
|
||||
},
|
||||
{
|
||||
'type': 'text',
|
||||
'id': 't-${ids[index]}',
|
||||
'text': 'Answer $prefix stored as ${ids[index]}.',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
'next_cursor': cursor,
|
||||
'has_more': hasMore,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const _style = String.fromEnvironment(
|
||||
'CHAT_WIRE_PROBE_STYLE',
|
||||
defaultValue: 'material',
|
||||
);
|
||||
|
||||
void main() {
|
||||
final screen = ChatScreen(
|
||||
gateway: _FixtureGateway(),
|
||||
onSessionSelected: null,
|
||||
);
|
||||
if (_style == 'cupertino') {
|
||||
runApp(
|
||||
CupertinoApp(
|
||||
theme: const CupertinoThemeData(brightness: Brightness.dark),
|
||||
home: CupertinoPageScaffold(
|
||||
navigationBar: const CupertinoNavigationBar(middle: Text('Chat')),
|
||||
child: SafeArea(child: screen),
|
||||
),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
runApp(
|
||||
MaterialApp(
|
||||
theme: ThemeData(
|
||||
brightness: Brightness.dark,
|
||||
platform: TargetPlatform.android,
|
||||
),
|
||||
home: Scaffold(
|
||||
appBar: AppBar(title: const Text('Chat')),
|
||||
body: screen,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,530 @@
|
||||
// Real-browser evidence for the Chat destination wiring fixture.
|
||||
//
|
||||
// Build one host, then run from app/:
|
||||
// flutter build web -t tool/chat_wire_probe.dart \
|
||||
// --dart-define=CHAT_WIRE_PROBE_STYLE=material \
|
||||
// --output build/probe-chat-wire-material
|
||||
// node tool/chat_wire_probe.mjs --root build/probe-chat-wire-material \
|
||||
// --out DIR --style material
|
||||
//
|
||||
// The Cupertino host is the same fixture built with CHAT_WIRE_PROBE_STYLE=cupertino.
|
||||
// Requires Google Chrome and Tesseract: Flutter web paints selectable text on
|
||||
// the canvas, so OCR confirms the actual message body, not just nav labels.
|
||||
import { createServer } from 'node:http';
|
||||
import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
|
||||
import { spawn, execFile } from 'node:child_process';
|
||||
import { once } from 'node:events';
|
||||
import { promisify } from 'node:util';
|
||||
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-chat-wire-material');
|
||||
const out = resolve(args.get('out') ?? 'build/chat-wire-probe');
|
||||
const style = args.get('style') ?? 'material';
|
||||
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',
|
||||
'.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',
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
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',
|
||||
});
|
||||
res.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(), 'c2-wire-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) => {
|
||||
for (let i = 0; i < 180; i++) {
|
||||
const value = await fn();
|
||||
if (value) return value;
|
||||
await delay(100);
|
||||
}
|
||||
throw new Error(`Timed out waiting for ${what}: ${stderr.slice(-1500)}`);
|
||||
};
|
||||
|
||||
let ws;
|
||||
const evidence = { origin, style, captures: [], checks: [] };
|
||||
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' });
|
||||
if (!created.result) throw new Error('Target creation failed');
|
||||
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.setDeviceMetricsOverride',
|
||||
{ width: 390, height: 844, deviceScaleFactor: 2, mobile: true },
|
||||
session,
|
||||
);
|
||||
await send(
|
||||
'Emulation.setEmulatedMedia',
|
||||
{ features: [{ name: 'prefers-color-scheme', value: 'dark' }] },
|
||||
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 nodes = () =>
|
||||
evaluate(`[...document.querySelectorAll('flt-semantics')].map(x => {
|
||||
const r = x.getBoundingClientRect();
|
||||
return {
|
||||
label: x.getAttribute('aria-label'),
|
||||
text: (x.innerText || '').trim(),
|
||||
x: r.x, y: r.y, w: r.width, h: r.height,
|
||||
};
|
||||
})`);
|
||||
const findNode = async (name) => {
|
||||
const all = await nodes();
|
||||
return all.find((node) => node.label === name || node.text === name);
|
||||
};
|
||||
const requireNode = async (name) => {
|
||||
const node = await findNode(name);
|
||||
if (!node) {
|
||||
const shown = (await nodes())
|
||||
.map((entry) => entry.label ?? entry.text)
|
||||
.filter(Boolean);
|
||||
throw new Error(
|
||||
`Missing semantics ${JSON.stringify(name)}: ${JSON.stringify(shown)}`,
|
||||
);
|
||||
}
|
||||
return node;
|
||||
};
|
||||
const click = async (name, { large = false } = {}) => {
|
||||
const point = await evaluate(`(() => {
|
||||
const wanted = ${JSON.stringify(name)};
|
||||
const large = ${large};
|
||||
const matches = [...document.querySelectorAll('flt-semantics')]
|
||||
.map(x => {
|
||||
const label = x.getAttribute('aria-label') || '';
|
||||
const text = (x.innerText || '').trim();
|
||||
const r = x.getBoundingClientRect();
|
||||
const labelHit = label.includes(wanted) ? 0 : 1;
|
||||
return { x, label, text, labelHit, area: r.width * r.height };
|
||||
})
|
||||
.filter(x => large ? x.labelHit === 0 : (x.labelHit === 0 || x.text.includes(wanted)))
|
||||
.sort(large
|
||||
? (a, b) => b.area - a.area
|
||||
: (a, b) => a.labelHit - b.labelHit || a.area - b.area);
|
||||
const node = matches[0]?.x;
|
||||
if (!node) return null;
|
||||
const r = node.getBoundingClientRect();
|
||||
return {
|
||||
x: large ? r.x + Math.min(r.width / 2, 100) : r.x + r.width / 2,
|
||||
y: r.y + r.height / 2,
|
||||
};
|
||||
})()`);
|
||||
if (!point) {
|
||||
const shown = (await nodes())
|
||||
.map((entry) => entry.label ?? entry.text)
|
||||
.filter(Boolean);
|
||||
throw new Error(
|
||||
`Could not find ${JSON.stringify(name)}: ${JSON.stringify(shown)}`,
|
||||
);
|
||||
}
|
||||
await send(
|
||||
'Input.dispatchMouseEvent',
|
||||
{ type: 'mousePressed', x: point.x, y: point.y, button: 'left', clickCount: 1 },
|
||||
session,
|
||||
);
|
||||
await send(
|
||||
'Input.dispatchMouseEvent',
|
||||
{ type: 'mouseReleased', x: point.x, y: point.y, button: 'left', clickCount: 1 },
|
||||
session,
|
||||
);
|
||||
await delay(700);
|
||||
};
|
||||
// The first matching control in document order. A folded assistant turn can
|
||||
// hold several `Reasoning` labels; the newest message renders first.
|
||||
const clickFirst = async (name) => {
|
||||
const node = (await nodes()).find(
|
||||
(entry) => entry.label === name || entry.text === name,
|
||||
);
|
||||
if (!node) {
|
||||
const shown = (await nodes())
|
||||
.map((entry) => entry.label ?? entry.text)
|
||||
.filter(Boolean);
|
||||
throw new Error(
|
||||
`Could not find ${JSON.stringify(name)}: ${JSON.stringify(shown)}`,
|
||||
);
|
||||
}
|
||||
const x = node.x + node.w / 2;
|
||||
const y = node.y + node.h / 2;
|
||||
for (const type of ['mousePressed', 'mouseReleased']) {
|
||||
await send(
|
||||
'Input.dispatchMouseEvent',
|
||||
{ type, x, y, button: 'left', clickCount: 1 },
|
||||
session,
|
||||
);
|
||||
}
|
||||
await delay(700);
|
||||
};
|
||||
const capture = async (name) => {
|
||||
const data = (
|
||||
await send('Page.captureScreenshot', { format: 'png' }, session)
|
||||
).result.data;
|
||||
const file = join(out, `${style}-${name}.png`);
|
||||
await writeFile(file, Buffer.from(data, 'base64'));
|
||||
evidence.captures.push(file);
|
||||
return file;
|
||||
};
|
||||
const ocr = async (path) => {
|
||||
const { stdout } = await promisify(execFile)('tesseract', [path, 'stdout']);
|
||||
return stdout.replace(/\s+/g, ' ');
|
||||
};
|
||||
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, 1600)}`,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const hasText = async (fragment) => {
|
||||
const all = await nodes();
|
||||
return all.some((node) =>
|
||||
`${node.label ?? ''} ${node.text ?? ''}`
|
||||
.toLowerCase()
|
||||
.includes(fragment.toLowerCase()),
|
||||
);
|
||||
};
|
||||
|
||||
await send('Page.navigate', { url: `${origin}/` }, session);
|
||||
await delay(3500);
|
||||
await evaluate("document.querySelector('flt-semantics-placeholder')?.click()");
|
||||
await delay(1200);
|
||||
await waitFor(
|
||||
async () => hasText('Probe conversation'),
|
||||
'session list semantics',
|
||||
);
|
||||
|
||||
const list = await capture('list');
|
||||
await assertOcr(list, 'Probe conversation');
|
||||
await assertOcr(list, 'Another stored chat');
|
||||
if (!(await hasText('New chat'))) {
|
||||
throw new Error('Embedded list lost its New chat action');
|
||||
}
|
||||
if (!(await hasText('Refresh'))) {
|
||||
throw new Error('Embedded list lost its Refresh action');
|
||||
}
|
||||
evidence.checks.push({
|
||||
check: 'embedded list renders server rows and actions',
|
||||
labels: (await nodes())
|
||||
.map((node) => node.label)
|
||||
.filter(Boolean)
|
||||
.slice(0, 20),
|
||||
});
|
||||
|
||||
await click('Probe conversation', { large: true });
|
||||
await waitFor(
|
||||
async () => Boolean(await findNode('Assistant message')),
|
||||
'thread semantics',
|
||||
);
|
||||
for (const name of [
|
||||
'User message',
|
||||
'Assistant message',
|
||||
'Reasoning',
|
||||
'shell',
|
||||
]) {
|
||||
await requireNode(name);
|
||||
}
|
||||
const thread = await capture('thread');
|
||||
for (const text of [
|
||||
'read-only message from the server',
|
||||
'stored assistant reply',
|
||||
'existing native message view',
|
||||
'Probe conversation',
|
||||
]) {
|
||||
await assertOcr(thread, text);
|
||||
}
|
||||
const closed = await ocr(thread);
|
||||
for (const hidden of [
|
||||
'Reasoning stays behind',
|
||||
'NEWEST reasoning body',
|
||||
]) {
|
||||
if (closed.toLowerCase().includes(hidden.toLowerCase())) {
|
||||
throw new Error(`Collapsed disclosure leaked ${JSON.stringify(hidden)}`);
|
||||
}
|
||||
}
|
||||
evidence.checks.push({
|
||||
check: 'actual stored message body renders in the thread',
|
||||
style,
|
||||
});
|
||||
|
||||
await delay(1500);
|
||||
const live = await capture('live');
|
||||
await assertOcr(live, 'A live delta updated this thread');
|
||||
evidence.checks.push({
|
||||
check: 'a pushed chat_event delta updates the open thread',
|
||||
style,
|
||||
});
|
||||
|
||||
// Repro B: expand the newest reasoning, then load the one older page whose
|
||||
// `has_more` is false, so the `Load older` child disappears.
|
||||
await click('Reasoning');
|
||||
const expanded = await capture('expanded');
|
||||
await assertOcr(expanded, 'NEWEST reasoning body');
|
||||
|
||||
await click('Load older');
|
||||
await delay(1200);
|
||||
const afterOlder = await capture('older');
|
||||
const afterOlderText = await ocr(afterOlder);
|
||||
const newestKept = afterOlderText.includes('NEWEST reasoning body');
|
||||
const olderLeaked = afterOlderText.includes('OLDER reasoning body');
|
||||
const loadOlderGone = !(await findNode('Load older'));
|
||||
evidence.observations = {
|
||||
...evidence.observations,
|
||||
afterOlderRemovesControl: { newestKept, olderLeaked, loadOlderGone },
|
||||
};
|
||||
if (!newestKept) {
|
||||
throw new Error(
|
||||
`The newest open reasoning was lost after Load older:\n${afterOlderText.slice(0, 1600)}`,
|
||||
);
|
||||
}
|
||||
if (olderLeaked) {
|
||||
throw new Error(
|
||||
`The older reasoning stole the newest disclosure:\n${afterOlderText.slice(0, 1600)}`,
|
||||
);
|
||||
}
|
||||
if (!loadOlderGone) {
|
||||
throw new Error('Load older stayed visible after has_more became false');
|
||||
}
|
||||
await assertOcr(afterOlder, 'older stored message came from the opaque cursor page');
|
||||
await assertOcr(afterOlder, 'Older reply kept in order');
|
||||
evidence.checks.push({
|
||||
check: 'Load older keeps the open disclosure and renders the opaque page',
|
||||
style,
|
||||
});
|
||||
|
||||
// Repro A: the same action while the server still reports `has_more`, so the
|
||||
// paging control remains in the indexed list.
|
||||
await click(style === 'cupertino' ? 'Back' : 'Back to chats');
|
||||
await waitFor(
|
||||
async () => hasText('Probe paging session'),
|
||||
'list after Back',
|
||||
);
|
||||
await click('Probe paging session', { large: true });
|
||||
await waitFor(
|
||||
async () => Boolean(await findNode('Assistant message')),
|
||||
'second thread semantics',
|
||||
);
|
||||
await click('Reasoning');
|
||||
const moreExpanded = await capture('more-expanded');
|
||||
await assertOcr(moreExpanded, 'MORE NEWEST reasoning body');
|
||||
|
||||
await click('Load older');
|
||||
await delay(1200);
|
||||
const moreAfterOlder = await capture('more-older');
|
||||
const moreAfterOlderText = await ocr(moreAfterOlder);
|
||||
const moreNewestKept = moreAfterOlderText.includes('MORE NEWEST reasoning body');
|
||||
const moreOlderLeaked = moreAfterOlderText.includes('MORE OLDER reasoning body');
|
||||
const moreControlStays = Boolean(await findNode('Load older'));
|
||||
evidence.observations.afterOlderKeepsControl = {
|
||||
newestKept: moreNewestKept,
|
||||
olderLeaked: moreOlderLeaked,
|
||||
loadOlderPresent: moreControlStays,
|
||||
};
|
||||
if (!moreNewestKept) {
|
||||
throw new Error(
|
||||
`The newest open reasoning was lost while has_more stayed true:\n${moreAfterOlderText.slice(0, 1600)}`,
|
||||
);
|
||||
}
|
||||
if (moreOlderLeaked) {
|
||||
throw new Error(
|
||||
`The older reasoning stole the newest disclosure while has_more stayed true:\n${moreAfterOlderText.slice(0, 1600)}`,
|
||||
);
|
||||
}
|
||||
if (!moreControlStays) {
|
||||
throw new Error('Load older disappeared although has_more stayed true');
|
||||
}
|
||||
evidence.checks.push({
|
||||
check: 'an open disclosure follows its part while paging keeps has_more',
|
||||
style,
|
||||
});
|
||||
|
||||
// New repro: the paged-history fixture's shape. Both pages hold only
|
||||
// consecutive assistant messages, so an older page prepends into the single
|
||||
// folded turn and changes its first message id. The row element must survive
|
||||
// that identity change and keep the operator's open block.
|
||||
for (const fold of [
|
||||
{
|
||||
title: 'Probe assistant fold session',
|
||||
tag: 'fold',
|
||||
keepsControl: true,
|
||||
},
|
||||
{
|
||||
title: 'Probe assistant fold last page',
|
||||
tag: 'fold-end',
|
||||
keepsControl: false,
|
||||
},
|
||||
]) {
|
||||
await click(style === 'cupertino' ? 'Back' : 'Back to chats');
|
||||
await waitFor(
|
||||
async () => hasText(fold.title),
|
||||
`list before ${fold.tag}`,
|
||||
);
|
||||
await click(fold.title, { large: true });
|
||||
await waitFor(
|
||||
async () => Boolean(await findNode('Assistant message')),
|
||||
`${fold.tag} thread semantics`,
|
||||
);
|
||||
await clickFirst('Reasoning');
|
||||
await delay(400);
|
||||
const foldExpanded = await capture(`${fold.tag}-expanded`);
|
||||
await assertOcr(foldExpanded, 'FOLD NEWEST reasoning body');
|
||||
|
||||
await click('Load older');
|
||||
await delay(1200);
|
||||
const foldAfter = await capture(`${fold.tag}-older`);
|
||||
const foldText = await ocr(foldAfter);
|
||||
const foldNewestKept = foldText.includes('FOLD NEWEST reasoning body');
|
||||
const foldOlderLeaked = [
|
||||
'FOLD SECOND reasoning body',
|
||||
'FOLD OLDEST reasoning body',
|
||||
].some((body) => foldText.includes(body));
|
||||
const foldControlStays = Boolean(await findNode('Load older'));
|
||||
evidence.observations = {
|
||||
...evidence.observations,
|
||||
[`${fold.tag}AfterOlder`]: {
|
||||
newestKept: foldNewestKept,
|
||||
olderLeaked: foldOlderLeaked,
|
||||
loadOlderPresent: foldControlStays,
|
||||
},
|
||||
};
|
||||
if (!foldNewestKept) {
|
||||
throw new Error(
|
||||
`The folded turn lost the open reasoning after Load older:\n${foldText.slice(0, 1600)}`,
|
||||
);
|
||||
}
|
||||
if (foldOlderLeaked) {
|
||||
throw new Error(
|
||||
`An older block in the folded turn opened itself:\n${foldText.slice(0, 1600)}`,
|
||||
);
|
||||
}
|
||||
if (foldControlStays !== fold.keepsControl) {
|
||||
throw new Error(
|
||||
`Load older presence ${foldControlStays} did not match has_more ${fold.keepsControl}`,
|
||||
);
|
||||
}
|
||||
evidence.checks.push({
|
||||
check:
|
||||
'an open disclosure survives paging inside a folded assistant turn',
|
||||
style,
|
||||
case: fold.tag,
|
||||
});
|
||||
}
|
||||
|
||||
const report = JSON.stringify(evidence, null, 2);
|
||||
await writeFile(join(out, `${style}-evidence.json`), report);
|
||||
console.log(report);
|
||||
} finally {
|
||||
ws?.close();
|
||||
chrome.kill();
|
||||
server.close();
|
||||
for (let attempt = 0; attempt < 10; attempt++) {
|
||||
try {
|
||||
await rm(profile, { recursive: true, force: true });
|
||||
break;
|
||||
} catch {
|
||||
await delay(200);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:pipelines_app/application/bootstrap.dart';
|
||||
|
||||
/// Browser acceptance entrypoint for the run-retry wiring probe.
|
||||
///
|
||||
/// This is the normal app composition; the deterministic failed run, retry
|
||||
/// replies and new-run details come from the isolated loopback fixture in
|
||||
/// `tool/retry_wiring_probe.mjs`, never from app-side fake data. The zone and
|
||||
/// `FlutterError` hooks only report probe failures to the driver; they do not
|
||||
/// alter composition or behavior.
|
||||
void main() {
|
||||
FlutterError.onError = (details) {
|
||||
debugPrint('FLUTTER ERROR: ${details.exceptionAsString()}');
|
||||
FlutterError.presentError(details);
|
||||
};
|
||||
runZonedGuarded(
|
||||
runPipelinesApp,
|
||||
(error, stack) => debugPrint('ZONE ERROR: $error\n$stack'),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,772 @@
|
||||
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');
|
||||
};
|
||||
|
||||
// Cupertino 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-cupertino-${theme}-failed`));
|
||||
await assertOcr(captures.at(-1), 'Fixture failed run');
|
||||
checks.push(await actionGap('Cupertino'));
|
||||
checks.push({ check: `Cupertino ${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-cupertino-${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: 'Cupertino Keep sent nothing', sent: 0 });
|
||||
captures.push(await capture(`r2c-retry-cupertino-${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-cupertino-${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: 'Cupertino restart',
|
||||
});
|
||||
await waitNewRun(SOURCE_ID + 1, 'Restart of 7');
|
||||
captures.push(await capture(`r2c-retry-cupertino-${theme}-restart-run`));
|
||||
await assertOcr(captures.at(-1), 'Restart of 7');
|
||||
checks.push({ check: 'Cupertino 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-cupertino-${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: 'Cupertino resume',
|
||||
});
|
||||
await waitNewRun(SOURCE_ID + 2, 'Resume of 7');
|
||||
captures.push(await capture(`r2c-retry-cupertino-${theme}-resume-run`));
|
||||
await assertOcr(captures.at(-1), 'Resume of 7');
|
||||
checks.push({ check: 'Cupertino 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 });
|
||||
}
|
||||
+82
-17
@@ -260,35 +260,75 @@ try {
|
||||
await assertBody('Original prompt');
|
||||
await assertBody('Timeline');
|
||||
await assertBody('build · visit 3');
|
||||
captures.push(await capture('i1-runs-phone-detail'));
|
||||
await assertOcr(captures[5], 'fixture prompt with spaces');
|
||||
const detailCapture = await capture('i1-runs-phone-detail');
|
||||
captures.push(detailCapture);
|
||||
await assertOcr(detailCapture, 'fixture prompt with spaces');
|
||||
|
||||
// The recorded Changes action opens the landed viewer for this run's steps:
|
||||
// the recorded file, its rendered diff, and back to the same detail.
|
||||
await clickText('Changes');
|
||||
await assertBody('1 file changed');
|
||||
await assertBody('lib/features/fixture.dart');
|
||||
captures.push(await capture('changes-phone-list'));
|
||||
await clickText('lib/features/fixture.dart', { contains: true });
|
||||
await assertBody('Rendered');
|
||||
await assertBody('added fixture line');
|
||||
await assertBody('removed fixture line');
|
||||
captures.push(await capture('changes-phone-diff'));
|
||||
await clickText('Close diff');
|
||||
await assertBody('lib/features/fixture.dart');
|
||||
await delay(600);
|
||||
await clickText('Back', { contains: true });
|
||||
await assertBody('Original prompt');
|
||||
|
||||
// The recorded artifacts action lists each visit's own files, keeps a
|
||||
// repeated filename distinct, and shows the selected record's facts.
|
||||
await clickText('Artifacts');
|
||||
await assertBody('build · visit 1');
|
||||
await assertBody('test · visit 1');
|
||||
await assertBody('build-report.html');
|
||||
await assertBody('result.csv');
|
||||
captures.push(await capture('artifacts-phone-list'));
|
||||
await delay(500);
|
||||
await clickText('result.csv', { contains: true });
|
||||
await assertBody('text/csv');
|
||||
await assertBody('4.0');
|
||||
captures.push(await capture('artifacts-phone-selected'));
|
||||
await clickText('Close');
|
||||
await delay(400);
|
||||
await clickText('Back', { contains: true });
|
||||
await assertBody('Original prompt');
|
||||
|
||||
await setSize(1280, 800);
|
||||
await assertBody('Original prompt');
|
||||
captures.push(await capture('i1-runs-desktop-detail'));
|
||||
await assertOcr(captures[6], 'fixture prompt with spaces');
|
||||
const desktopDetail = await capture('i1-runs-desktop-detail');
|
||||
captures.push(desktopDetail);
|
||||
await assertOcr(desktopDetail, 'fixture prompt with spaces');
|
||||
await setSize(390, 844);
|
||||
|
||||
await clickText('Input');
|
||||
await wheel(250);
|
||||
await delay(300);
|
||||
captures.push(await capture('i1-runs-phone-detail-input'));
|
||||
await assertOcr(captures[7], 'input payload');
|
||||
const inputCapture = await capture('i1-runs-phone-detail-input');
|
||||
captures.push(inputCapture);
|
||||
await assertOcr(inputCapture, 'input payload');
|
||||
|
||||
await scrollUntil('Output');
|
||||
await clickText('Output');
|
||||
await wheel(250);
|
||||
await delay(300);
|
||||
captures.push(await capture('i1-runs-phone-detail-output'));
|
||||
await assertOcr(captures[8], 'answer');
|
||||
const outputCapture = await capture('i1-runs-phone-detail-output');
|
||||
captures.push(outputCapture);
|
||||
await assertOcr(outputCapture, 'answer');
|
||||
|
||||
await scrollUntil('Metrics');
|
||||
await clickText('Metrics');
|
||||
await wheel(300);
|
||||
await delay(300);
|
||||
captures.push(await capture('i1-runs-phone-detail-metrics'));
|
||||
await assertOcr(captures[9], 'Total tokens');
|
||||
await assertOcr(captures[9], 'Reported cost');
|
||||
const metricsCapture = await capture('i1-runs-phone-detail-metrics');
|
||||
captures.push(metricsCapture);
|
||||
await assertOcr(metricsCapture, 'Total tokens');
|
||||
await assertOcr(metricsCapture, 'Reported cost');
|
||||
|
||||
// Browser Back/Forward move between the in-app routes, not out of the app.
|
||||
const path = () => evaluate('location.pathname');
|
||||
@@ -305,8 +345,9 @@ try {
|
||||
async () => (await semanticText()).includes('Fixture live run'),
|
||||
'browser Back to the runs list',
|
||||
);
|
||||
captures.push(await capture('i1-runs-phone-browser-back-list'));
|
||||
await assertOcr(captures[10], 'Fixture live run');
|
||||
const backListCapture = await capture('i1-runs-phone-browser-back-list');
|
||||
captures.push(backListCapture);
|
||||
await assertOcr(backListCapture, 'Fixture live run');
|
||||
|
||||
await evaluate('history.forward()');
|
||||
await waitFor(
|
||||
@@ -333,8 +374,9 @@ try {
|
||||
if (duringDrop.includes(raw)) throw new Error(`Raw transport text shown: ${raw}`);
|
||||
}
|
||||
if ((await path()) !== '/runs/1') throw new Error(`Drop moved the URL to ${await path()}`);
|
||||
captures.push(await capture('i1-reconnect-detail-retained-phone'));
|
||||
await assertOcr(captures[13], 'Original prompt');
|
||||
const retainedCapture = await capture('i1-reconnect-detail-retained-phone');
|
||||
captures.push(retainedCapture);
|
||||
await assertOcr(retainedCapture, 'Original prompt');
|
||||
|
||||
// Accepting again plus Retry restores the same detail without a remount.
|
||||
const accepted = await fetch(`${fixture.url}/fixture/accept`, { method: 'POST' });
|
||||
@@ -359,12 +401,13 @@ try {
|
||||
for (const raw of ['WebSocketException', 'WebSocketChannelException', 'Failed to connect']) {
|
||||
if (gate.includes(raw)) throw new Error(`Gate printed raw transport text: ${raw}`);
|
||||
}
|
||||
captures.push(await capture('i1-gate-unavailable-friendly-phone'));
|
||||
const gateCapture = await capture('i1-gate-unavailable-friendly-phone');
|
||||
captures.push(gateCapture);
|
||||
await delay(1500);
|
||||
if (!(await semanticText()).includes('Pipelines server unavailable')) {
|
||||
throw new Error('Gate left the unavailable state while retrying');
|
||||
}
|
||||
await assertOcr(captures[15], 'Pipelines server unavailable');
|
||||
await assertOcr(gateCapture, 'Pipelines server unavailable');
|
||||
|
||||
await fetch(`${fixture.url}/fixture/accept`, { method: 'POST' });
|
||||
await clickText('Retry');
|
||||
@@ -427,6 +470,28 @@ try {
|
||||
}
|
||||
captures.push(await capture('settings-material-registered-phone'));
|
||||
|
||||
// The registered Chat destination opens a real conversation over the shared
|
||||
// socket: list row -> session route -> stored turn, then Back to the list.
|
||||
await clickText('Chat');
|
||||
await assertBody('Probe conversation');
|
||||
captures.push(await capture('chat-material-list'));
|
||||
await clickText('Probe conversation', { contains: true });
|
||||
await assertBody('User message');
|
||||
await assertBody('Assistant message');
|
||||
if ((await path()) !== '/chat/ses_probechat') {
|
||||
throw new Error(`Chat selection did not update the route: ${await path()}`);
|
||||
}
|
||||
await delay(900);
|
||||
const threadCapture = await capture('chat-material-thread');
|
||||
captures.push(threadCapture);
|
||||
await assertOcr(threadCapture, 'Read-only probe question.');
|
||||
await assertOcr(threadCapture, 'Stored probe answer.');
|
||||
await clickText('Back', { contains: true });
|
||||
await assertBody('Probe conversation');
|
||||
if ((await path()) !== '/chat') {
|
||||
throw new Error(`Chat Back left the route at ${await path()}`);
|
||||
}
|
||||
|
||||
await clickText('Runs');
|
||||
await clickText('Fixture cancel run', { contains: true });
|
||||
await assertBody('Original prompt');
|
||||
|
||||
@@ -110,6 +110,34 @@ function detail(id, live, canceled = false) {
|
||||
status: 'completed',
|
||||
outcome: 'success',
|
||||
target: '#success',
|
||||
file_changes: {
|
||||
status: 'complete',
|
||||
scope: 'Git tracked and nonignored files in the run directory',
|
||||
files: [
|
||||
{
|
||||
path: 'lib/features/fixture.dart',
|
||||
kind: 'modified',
|
||||
patch:
|
||||
'--- a/lib/features/fixture.dart\n' +
|
||||
'+++ b/lib/features/fixture.dart\n' +
|
||||
'@@ -1,2 +1,2 @@\n' +
|
||||
' context line\n' +
|
||||
'-removed fixture line\n' +
|
||||
'+added fixture line\n',
|
||||
},
|
||||
],
|
||||
skipped: 0,
|
||||
omitted: 0,
|
||||
diagnostic: '',
|
||||
},
|
||||
artifacts: [
|
||||
{
|
||||
name: 'build-report.html',
|
||||
size_bytes: 2048,
|
||||
content_type: 'text/html; charset=utf-8',
|
||||
url: '/artifacts/1/3/build-report.html',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
stage: 'test',
|
||||
@@ -117,6 +145,14 @@ function detail(id, live, canceled = false) {
|
||||
status: status === 'failed' ? 'failed' : 'completed',
|
||||
outcome: status === 'failed' ? 'failure' : 'success',
|
||||
target: status === 'failed' ? '#failure' : '#success',
|
||||
artifacts: [
|
||||
{
|
||||
name: 'result.csv',
|
||||
size_bytes: 4096,
|
||||
content_type: 'text/csv',
|
||||
url: '/artifacts/1/4/result.csv',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -288,6 +324,15 @@ export async function startFixture({ root }) {
|
||||
const cancelRequests = [];
|
||||
let decisionAccepted = false;
|
||||
const decisionRequests = [];
|
||||
let chatSubscribed = 0;
|
||||
let chatHistory = 0;
|
||||
const CHAT_SESSION = {
|
||||
id: 'ses_probechat',
|
||||
title: 'Probe conversation',
|
||||
kind: 'operator',
|
||||
directory: '/srv/probe',
|
||||
updated_at: '2026-10-21T12:00:00Z',
|
||||
};
|
||||
|
||||
const dropConnections = () => {
|
||||
for (const connection of connections) connection.close();
|
||||
@@ -336,6 +381,8 @@ export async function startFixture({ root }) {
|
||||
getRun,
|
||||
cancelRequests,
|
||||
decisionRequests,
|
||||
chatSubscribed,
|
||||
chatHistory,
|
||||
}));
|
||||
return;
|
||||
}
|
||||
@@ -427,6 +474,32 @@ export async function startFixture({ root }) {
|
||||
client.send({ id: request.id, type: 'run', run_detail: humanDetail(true) });
|
||||
return;
|
||||
}
|
||||
if (request.type === 'chat_sessions') {
|
||||
client.send({ id: request.id, type: 'chat_sessions',
|
||||
chat_sessions: [CHAT_SESSION] });
|
||||
return;
|
||||
}
|
||||
if (request.type === 'chat_subscribe') {
|
||||
chatSubscribed++;
|
||||
client.send({ id: request.id, type: 'chat_subscribe' });
|
||||
return;
|
||||
}
|
||||
if (request.type === 'chat_messages') {
|
||||
chatHistory++;
|
||||
client.send({
|
||||
id: request.id, type: 'chat_history',
|
||||
chat_history: {
|
||||
messages: [
|
||||
{ id: 'm1', session_id: CHAT_SESSION.id, role: 'user',
|
||||
parts: [{ type: 'text', text: 'Read-only probe question.' }] },
|
||||
{ id: 'm2', session_id: CHAT_SESSION.id, role: 'assistant',
|
||||
parts: [{ type: 'text', text: 'Stored probe answer.' }] },
|
||||
],
|
||||
next_cursor: '', has_more: false,
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
client.send({
|
||||
id: request.id,
|
||||
type: 'error',
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/graph/widgets/stage_definition_view.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/host.dart';
|
||||
|
||||
/// A definition with an authored stage (including an unknown future field), a
|
||||
/// declared route to a terminal, and no declaration for `ghost`.
|
||||
JsonMap _graph() => <String, dynamic>{
|
||||
'stages': <dynamic>[
|
||||
<String, dynamic>{
|
||||
'key': 'plan',
|
||||
'type': 'model',
|
||||
'prompt': 'Plan the change.',
|
||||
'output': 'A short plan.',
|
||||
'edges': <String, String?>{'success': 'build', 'error': '#'},
|
||||
'fallback_error': true,
|
||||
'configs': <String, dynamic>{
|
||||
'provider': 'openai',
|
||||
'model': 'gpt-5',
|
||||
'budget_usd': 12.5,
|
||||
},
|
||||
'blocks': <String, dynamic>{'tools': 'shell\nread_file'},
|
||||
'limits': <String, dynamic>{
|
||||
'max_visits': 2,
|
||||
'on': <String>['error'],
|
||||
},
|
||||
'memory': <String, dynamic>{'context': 'latest'},
|
||||
'notify': <String, dynamic>{
|
||||
'on': <String>['failure'],
|
||||
'destination': 'ops@example.test',
|
||||
'artifacts': <String>['run.log'],
|
||||
},
|
||||
'future_field': <String, dynamic>{'kept': true},
|
||||
},
|
||||
<String, dynamic>{
|
||||
'key': 'build',
|
||||
'type': 'shell',
|
||||
'edges': <String, String?>{'success': '#success', 'error': '#failure'},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
/// Isolated browser fixture for the read-only stage definition pane.
|
||||
///
|
||||
/// `style=cupertino` selects the Cupertino host, `dark=1` its dark theme,
|
||||
/// `scale=2` a real 2x text scale. Every button opens the exact helper the
|
||||
/// pipeline graph hook will call; nothing contacts a server or reads a run.
|
||||
void main() {
|
||||
final parameters = Uri.base.queryParameters;
|
||||
runApp(
|
||||
_ProbeApp(
|
||||
cupertino: parameters['style'] == 'cupertino',
|
||||
dark: parameters['dark'] == '1',
|
||||
scale: double.tryParse(parameters['scale'] ?? '') ?? 1,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _ProbeApp extends StatelessWidget {
|
||||
const _ProbeApp({
|
||||
required this.cupertino,
|
||||
required this.dark,
|
||||
required this.scale,
|
||||
});
|
||||
|
||||
final bool cupertino;
|
||||
final bool dark;
|
||||
final double scale;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget scaled(BuildContext context, Widget? child) => MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: TextScaler.linear(scale)),
|
||||
child: child ?? const SizedBox.shrink(),
|
||||
);
|
||||
if (cupertino) {
|
||||
return CupertinoApp(
|
||||
theme: CupertinoThemeData(
|
||||
brightness: dark ? Brightness.dark : Brightness.light,
|
||||
),
|
||||
builder: scaled,
|
||||
home: const CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
middle: Text('Stage definition fixture'),
|
||||
),
|
||||
child: SafeArea(child: _Launcher()),
|
||||
),
|
||||
);
|
||||
}
|
||||
return MaterialApp(
|
||||
theme: ThemeData(
|
||||
platform: TargetPlatform.android,
|
||||
brightness: Brightness.light,
|
||||
),
|
||||
darkTheme: ThemeData(
|
||||
platform: TargetPlatform.android,
|
||||
brightness: Brightness.dark,
|
||||
),
|
||||
themeMode: dark ? ThemeMode.dark : ThemeMode.light,
|
||||
builder: scaled,
|
||||
home: Scaffold(
|
||||
appBar: AppBar(title: const Text('Stage definition fixture')),
|
||||
body: const SafeArea(child: _Launcher()),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Launcher extends StatelessWidget {
|
||||
const _Launcher();
|
||||
|
||||
void _open(BuildContext context, String key) => openStageDefinition(
|
||||
context,
|
||||
graph: _graph(),
|
||||
stageKey: key,
|
||||
pipelineId: 41,
|
||||
pipelineName: 'Demo pipeline',
|
||||
version: 7,
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino = usesCupertinoHost(context);
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
const Text('Fixture home'),
|
||||
for (final key in <String>['plan', '#failure', 'ghost'])
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: cupertino
|
||||
? CupertinoButton.filled(
|
||||
onPressed: () => _open(context, key),
|
||||
child: Text('$key definition'),
|
||||
)
|
||||
: FilledButton(
|
||||
onPressed: () => _open(context, key),
|
||||
child: Text('$key definition'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,380 @@
|
||||
// Browser acceptance for the isolated read-only stage definition pane.
|
||||
//
|
||||
// Serves the probe build (`flutter build web -t tool/stage_definition_probe.dart`)
|
||||
// on an OS-assigned loopback port, drives real headless Chrome, opens the pane
|
||||
// through the same native helper the manager graph hook uses, asserts the
|
||||
// pinned identity, actual field values, outcomes, raw unknown fields, terminal
|
||||
// and unknown-stage states, closes it with Back on both hosts, and writes
|
||||
// captures.
|
||||
//
|
||||
// PROBE_VARIANT=material|cupertino PROBE_SCHEME=dark|light PROBE_SCALE=1|2 \
|
||||
// PROBE_WIDTH=1280 PROBE_HEIGHT=900 PROBE_WEB_ROOT=<probe build> \
|
||||
// OPENCODE_ARTIFACT_DIR=<dir> node tool/stage_definition_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 { createHash } from 'node:crypto';
|
||||
import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
|
||||
|
||||
const root = resolve(
|
||||
process.env.PROBE_WEB_ROOT ?? join(process.cwd(), 'build/stage_definition_probe_web'),
|
||||
);
|
||||
const variant = process.env.PROBE_VARIANT ?? 'material';
|
||||
const scheme = process.env.PROBE_SCHEME ?? 'dark';
|
||||
const scale = process.env.PROBE_SCALE ?? '1';
|
||||
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 = `stage-definition-${variant}-${scheme}-${scale}x` +
|
||||
(width === 1280 && height === 900 ? '' : `-${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(), 'stage-definition-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 labels = () => evaluate(
|
||||
"[...document.querySelectorAll('flt-semantics')].map(x=>x.getAttribute('aria-label')||(x.innerText||'').trim()).filter(Boolean)",
|
||||
);
|
||||
const bodyText = async () => [await evaluate('document.body.innerText'), ...(await labels())].join('\n');
|
||||
const clickExact = async (label) => {
|
||||
const point = await evaluate(`(() => {
|
||||
const e = [...document.querySelectorAll('flt-semantics')].find(x =>
|
||||
(x.getAttribute('aria-label')||(x.innerText||'').trim()).trim() === ${JSON.stringify(label)});
|
||||
if (!e) return null;
|
||||
const r = e.getBoundingClientRect();
|
||||
return { x: r.x + r.width / 2, y: r.y + r.height / 2 };
|
||||
})()`);
|
||||
if (!point) throw new Error(`Missing control ${label}: ${JSON.stringify(await labels())}`);
|
||||
await send('Input.dispatchMouseEvent', {
|
||||
type: 'mousePressed', x: point.x, y: point.y, button: 'left', clickCount: 1,
|
||||
}, session);
|
||||
await send('Input.dispatchMouseEvent', {
|
||||
type: 'mouseReleased', x: point.x, y: point.y, button: 'left', clickCount: 1,
|
||||
}, session);
|
||||
await delay(1000);
|
||||
};
|
||||
const capture = async (name) => {
|
||||
const data = (await send('Page.captureScreenshot', {
|
||||
format: 'png', captureBeyondViewport: false,
|
||||
}, session)).result.data;
|
||||
const buffer = Buffer.from(data, 'base64');
|
||||
const file = `${prefix}-${name}.png`;
|
||||
await writeFile(join(artifactDir, file), buffer);
|
||||
return { file, sha1: createHash('sha1').update(buffer).digest('hex') };
|
||||
};
|
||||
const visible = async (needle, exact = false) => evaluate(`(() => {
|
||||
const found = [...document.querySelectorAll('flt-semantics')].filter(x => {
|
||||
const label = (x.getAttribute('aria-label')||(x.innerText||'')).trim();
|
||||
return ${exact ? `label === ${JSON.stringify(needle)}` : `label.includes(${JSON.stringify(needle)})`};
|
||||
});
|
||||
if (!found.length) return null;
|
||||
found.sort((a, b) => {
|
||||
const ra = a.getBoundingClientRect(), rb = b.getBoundingClientRect();
|
||||
return ra.width * ra.height - rb.width * rb.height;
|
||||
});
|
||||
const r = found[0].getBoundingClientRect();
|
||||
return { 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 };
|
||||
})()`);
|
||||
// Scroll by the measured delta instead of fixed steps: a fixed gesture can
|
||||
// stop with a target half-entered (and its neighbours not built), which is
|
||||
// exactly what made the raw-section check fail on shorter content.
|
||||
const scrollTo = async (needle, { exact = false, maxTop = null } = {}) => {
|
||||
for (let attempt = 0; attempt < 24; attempt++) {
|
||||
const r = await visible(needle, exact);
|
||||
const fullyVisible = r && r.width > 0 && r.height > 0 &&
|
||||
r.y >= 32 && r.y + r.height <= height - 32;
|
||||
if (fullyVisible && (maxTop == null || r.y <= maxTop)) return r;
|
||||
// Scroll down until the target is fully in view; for a target that must
|
||||
// sit high (the raw title above its JSON), keep scrolling until it does.
|
||||
const wanted = r
|
||||
? Math.round(r.y - (maxTop ?? height / 2))
|
||||
: Math.round(height / 3);
|
||||
const distance = Math.sign(wanted || 1) *
|
||||
Math.max(60, Math.min(400, Math.abs(wanted)));
|
||||
await send('Input.synthesizeScrollGesture', {
|
||||
x: Math.round(width / 2), y: Math.round(height / 2),
|
||||
yDistance: -distance, gestureSourceType: 'mouse', speed: 900,
|
||||
preventFling: true,
|
||||
}, session);
|
||||
await delay(300);
|
||||
}
|
||||
throw new Error(
|
||||
`${needle} never scrolled into view: ${JSON.stringify(await bodyText())}`,
|
||||
);
|
||||
};
|
||||
// The raw section is one selectable block whose whole value must be
|
||||
// inspected. Scroll to the pane's end so the JSON tail (the unknown fields
|
||||
// the raw section exists for) is really on screen, not just built.
|
||||
const scrollToRaw = async () => {
|
||||
let previous = null;
|
||||
for (let attempt = 0; attempt < 16; attempt++) {
|
||||
const r = await visible('future_field');
|
||||
if (r && previous != null && Math.abs(r.y - previous) < 1) {
|
||||
if (!r.visible || r.y + r.height > height + 1) {
|
||||
throw new Error(`The raw JSON did not settle in view: ${JSON.stringify(r)}`);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
previous = r?.y ?? null;
|
||||
await send('Input.synthesizeScrollGesture', {
|
||||
x: Math.round(width / 2), y: Math.round(height / 2),
|
||||
yDistance: -600, gestureSourceType: 'mouse', speed: 900,
|
||||
preventFling: true,
|
||||
}, session);
|
||||
await delay(300);
|
||||
}
|
||||
throw new Error(
|
||||
`The raw JSON never settled: ${JSON.stringify(await bodyText())}`,
|
||||
);
|
||||
};
|
||||
const evidence = { variant, scheme, scale, checks: [], captures: [] };
|
||||
const expectText = async (needle, context) => {
|
||||
const text = await bodyText();
|
||||
if (!text.includes(needle)) throw new Error(`${context}: missing ${JSON.stringify(needle)}\n${text}`);
|
||||
};
|
||||
|
||||
await expectText('Fixture home', 'fixture home');
|
||||
await clickExact('plan definition');
|
||||
for (const needle of [
|
||||
'Demo pipeline · v7',
|
||||
'Plan the change.',
|
||||
'A short plan.',
|
||||
'success → build',
|
||||
'error → FAILURE (terminal)',
|
||||
]) {
|
||||
await expectText(needle, 'declared stage');
|
||||
}
|
||||
// Two two-line blocks must share the host line rhythm. A fallback font for
|
||||
// the outcomes arrow must not stretch only that block, so compare the whole
|
||||
// label+value block: equal line counts mean equal heights.
|
||||
if (width >= 1000) {
|
||||
const blockHeight = async (prefixText) => evaluate(`(() => {
|
||||
const found = [...document.querySelectorAll('flt-semantics')].filter(x =>
|
||||
(x.getAttribute('aria-label')||(x.innerText||'')).trim().startsWith(${JSON.stringify(prefixText)}));
|
||||
if (!found.length) return null;
|
||||
found.sort((a, b) => {
|
||||
const ra = a.getBoundingClientRect(), rb = b.getBoundingClientRect();
|
||||
return ra.width * ra.height - rb.width * rb.height;
|
||||
});
|
||||
const r = found[0].getBoundingClientRect();
|
||||
return { height: r.height, width: r.width };
|
||||
})()`);
|
||||
const outcomes = await blockHeight('Outcomes');
|
||||
const tools = await blockHeight('Tools');
|
||||
const ratio = outcomes && tools ? outcomes.height / tools.height : 0;
|
||||
if (!(ratio >= 0.8 && ratio <= 1.25)) {
|
||||
throw new Error(
|
||||
`Outcomes line rhythm differs from Tools: ${JSON.stringify({ outcomes, tools, ratio })}`,
|
||||
);
|
||||
}
|
||||
evidence.rhythm = {
|
||||
outcomesHeight: outcomes.height,
|
||||
toolsHeight: tools.height,
|
||||
ratio,
|
||||
};
|
||||
evidence.checks.push({
|
||||
check: 'the outcomes block keeps the host line rhythm of other two-line blocks',
|
||||
value: ratio,
|
||||
});
|
||||
}
|
||||
evidence.checks.push({
|
||||
check: 'declared stage shows pinned identity and the web field values',
|
||||
value: true,
|
||||
});
|
||||
const declaredCapture = await capture('declared');
|
||||
evidence.captures.push(declaredCapture);
|
||||
|
||||
// Remaining declared fields, reached by scrolling so the probe also covers
|
||||
// viewports shorter than the full pane.
|
||||
for (const needle of [
|
||||
'Provider', 'openai', 'Model', 'gpt-5', 'Budget (USD)', '12.5',
|
||||
'Tools', 'shell', 'read_file', 'Max visits', 'Limit on', 'Memory',
|
||||
'context: latest',
|
||||
]) {
|
||||
await scrollTo(needle);
|
||||
await expectText(needle, 'declared stage');
|
||||
}
|
||||
evidence.checks.push({
|
||||
check: 'every declared field value is present in the rendered pane',
|
||||
value: true,
|
||||
});
|
||||
|
||||
await scrollTo('Notify destination');
|
||||
for (const needle of ['Notify on', 'failure', 'Notify destination', 'ops@example.test', 'Notify artifacts', 'run.log']) {
|
||||
await expectText(needle, 'notify definition');
|
||||
}
|
||||
|
||||
const rawJson = await scrollToRaw();
|
||||
evidence.rawJsonRect = rawJson;
|
||||
evidence.rawSectionSeen = (await bodyText()).includes('Raw stage definition');
|
||||
for (const needle of ['future_field', 'kept', 'fallback_error']) {
|
||||
await expectText(needle, 'raw unknown fields');
|
||||
}
|
||||
evidence.checks.push({
|
||||
check: 'unknown stage fields remain in the selectable raw JSON',
|
||||
value: true,
|
||||
});
|
||||
const rawCapture = await capture('raw');
|
||||
if (rawCapture.sha1 === declaredCapture.sha1) {
|
||||
throw new Error('The raw capture is identical to the unscrolled pane');
|
||||
}
|
||||
evidence.captures.push(rawCapture);
|
||||
|
||||
await clickExact('Back');
|
||||
await expectText('Fixture home', 'Back');
|
||||
evidence.checks.push({ check: 'Back returned to the graph host', value: true });
|
||||
|
||||
await clickExact('#failure definition');
|
||||
const terminalText = await bodyText();
|
||||
if (terminalText.includes('#failure')) {
|
||||
throw new Error(`The terminal title still exposes the raw key: ${terminalText}`);
|
||||
}
|
||||
await expectText('Failure definition', 'terminal title');
|
||||
for (const needle of [
|
||||
'Success and Failure are definition targets, not recorded visits.',
|
||||
'Incoming routes',
|
||||
'plan · error* → FAILURE',
|
||||
'build · error → FAILURE',
|
||||
]) {
|
||||
await expectText(needle, 'terminal definition');
|
||||
}
|
||||
evidence.checks.push({
|
||||
check: 'the terminal page is titled with its display label, not the protocol key',
|
||||
value: true,
|
||||
});
|
||||
evidence.checks.push({
|
||||
check: 'terminal explains definition routes without claiming a visit',
|
||||
value: true,
|
||||
});
|
||||
evidence.captures.push(await capture('terminal'));
|
||||
await clickExact('Back');
|
||||
await expectText('Fixture home', 'terminal Back');
|
||||
|
||||
await clickExact('ghost definition');
|
||||
await expectText(
|
||||
'This stage is not declared in this pipeline version.',
|
||||
'unknown stage',
|
||||
);
|
||||
const unknown = await bodyText();
|
||||
if (unknown.includes('Raw stage definition') || unknown.includes('Incoming routes')) {
|
||||
throw new Error(`Unknown stage invented definition content: ${unknown}`);
|
||||
}
|
||||
evidence.checks.push({
|
||||
check: 'unknown stage has an explicit missing state with no defaults',
|
||||
value: true,
|
||||
});
|
||||
evidence.captures.push(await capture('unknown'));
|
||||
await clickExact('Back');
|
||||
await expectText('Fixture home', 'unknown Back');
|
||||
evidence.checks.push({ check: 'every open used one native bar and Back', value: true });
|
||||
evidence.captures.push(await capture('closed'));
|
||||
|
||||
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 });
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
import 'dart:async';
|
||||
import 'dart:js_interop';
|
||||
import 'dart:js_interop_unsafe';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/core/transport/connection_state.dart';
|
||||
import 'package:pipelines_app/features/templates/screen.dart';
|
||||
|
||||
/// Browser capture entrypoint for the reusable Templates gallery.
|
||||
///
|
||||
/// The fixture gateway is in-process and records every request; nothing here
|
||||
/// opens a socket or contacts a real server. Query parameters:
|
||||
/// `host=material|cupertino`, `scale=<text scale>` and
|
||||
/// `scenario=default|empty|refresh-refusal`. The state published at
|
||||
/// `globalThis.templatesGalleryProbe` is read by the driver.
|
||||
const _source = ' name: "release"\n\tstages:\n - key: "añadir" 😀 \n';
|
||||
|
||||
const _galleryRows = [
|
||||
{
|
||||
'key': 'release',
|
||||
'name': 'Release workflow',
|
||||
'description': 'Ship a version',
|
||||
'source': _source,
|
||||
'scheduled': true,
|
||||
},
|
||||
{
|
||||
'key': 'blank',
|
||||
'name': '',
|
||||
'description': 'No display name',
|
||||
'source': 'name: "unnamed"\n',
|
||||
'scheduled': false,
|
||||
},
|
||||
];
|
||||
|
||||
class _ProbeGateway implements ApiGateway {
|
||||
_ProbeGateway(
|
||||
this.publish, {
|
||||
required this.empty,
|
||||
required this.failingRefresh,
|
||||
});
|
||||
|
||||
final VoidCallback publish;
|
||||
final bool empty;
|
||||
final bool failingRefresh;
|
||||
int listCalls = 0;
|
||||
int validates = 0;
|
||||
int submits = 0;
|
||||
final List<JsonMap> created = [];
|
||||
String? lastSource;
|
||||
JsonMap? lastSubmit;
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => const Stream.empty();
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
||||
if (type == 'list_templates') {
|
||||
listCalls++;
|
||||
publish();
|
||||
if (failingRefresh) {
|
||||
// The catalogue loads, then a Refresh from the open template refuses so
|
||||
// the driver can prove the failure is visible above that detail.
|
||||
if (listCalls == 2) {
|
||||
await Future<void>.delayed(const Duration(milliseconds: 250));
|
||||
throw const ProtocolError('fixture refresh unavailable');
|
||||
}
|
||||
return {'templates': _galleryRows};
|
||||
}
|
||||
if (listCalls == 1 && !empty) {
|
||||
// The first read refuses, so the driver can exercise the honest error
|
||||
// state and Retry on a real host.
|
||||
await Future<void>.delayed(const Duration(milliseconds: 250));
|
||||
throw const ProtocolError('fixture catalogue unavailable');
|
||||
}
|
||||
if (listCalls == 2) {
|
||||
// Enough time to capture the loading state after Retry.
|
||||
await Future<void>.delayed(const Duration(milliseconds: 1200));
|
||||
}
|
||||
if (empty) return {'templates': const []};
|
||||
return {
|
||||
'templates': [
|
||||
..._galleryRows,
|
||||
if (listCalls >= 3)
|
||||
{
|
||||
'key': 'added',
|
||||
'name': 'Added after refresh',
|
||||
'description': 'Proves the catalogue was re-read',
|
||||
'source': 'name: "added"\n',
|
||||
'scheduled': false,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
if (type == 'validate') {
|
||||
validates++;
|
||||
lastSource = fields['source'] as String?;
|
||||
publish();
|
||||
await Future<void>.delayed(const Duration(milliseconds: 200));
|
||||
return {
|
||||
'graph': {'stages': const []},
|
||||
};
|
||||
}
|
||||
if (type == 'submit') {
|
||||
submits++;
|
||||
lastSubmit = Map<String, dynamic>.from(fields);
|
||||
publish();
|
||||
return {
|
||||
'detail': {'id': 41, 'name': 'Probe created'},
|
||||
};
|
||||
}
|
||||
throw StateError('The templates probe does not implement $type');
|
||||
}
|
||||
}
|
||||
|
||||
void main() => runApp(const _ProbeApp());
|
||||
|
||||
class _ProbeApp extends StatefulWidget {
|
||||
const _ProbeApp();
|
||||
|
||||
@override
|
||||
State<_ProbeApp> createState() => _ProbeAppState();
|
||||
}
|
||||
|
||||
class _ProbeAppState extends State<_ProbeApp> {
|
||||
late final _params = Uri.base.queryParameters;
|
||||
late final _cupertino = _params['host'] == 'cupertino';
|
||||
late final _scale = double.tryParse(_params['scale'] ?? '') ?? 1;
|
||||
late final _gateway = _ProbeGateway(
|
||||
_publish,
|
||||
empty: _params['scenario'] == 'empty',
|
||||
failingRefresh: _params['scenario'] == 'refresh-refusal',
|
||||
);
|
||||
|
||||
void _publish() {
|
||||
globalContext.setProperty(
|
||||
'templatesGalleryProbe'.toJS,
|
||||
<String, Object?>{
|
||||
'listCalls': _gateway.listCalls,
|
||||
'validates': _gateway.validates,
|
||||
'submits': _gateway.submits,
|
||||
'created': _gateway.created,
|
||||
'lastSource': _gateway.lastSource,
|
||||
'lastSubmit': _gateway.lastSubmit,
|
||||
}.jsify(),
|
||||
);
|
||||
}
|
||||
|
||||
void _created(JsonMap detail) {
|
||||
_gateway.created.add(detail);
|
||||
_publish();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget scaled(BuildContext context, Widget? app) => MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: TextScaler.linear(_scale)),
|
||||
child: app!,
|
||||
);
|
||||
final screen = TemplatesScreen(gateway: _gateway, onCreated: _created);
|
||||
if (_cupertino) {
|
||||
return CupertinoApp(
|
||||
theme: CupertinoThemeData(brightness: Brightness.dark),
|
||||
builder: scaled,
|
||||
home: screen,
|
||||
);
|
||||
}
|
||||
return MaterialApp(
|
||||
theme: ThemeData(brightness: Brightness.dark),
|
||||
builder: scaled,
|
||||
home: screen,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,386 @@
|
||||
import { createServer } from 'node:http';
|
||||
import { readFile, mkdir, mkdtemp, 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 { join, extname, resolve, sep } from 'node:path';
|
||||
import { tmpdir } from 'node:os';
|
||||
|
||||
// Real-browser acceptance for the reusable Templates gallery.
|
||||
//
|
||||
// Usage (from app/):
|
||||
// flutter build web --target=tool/templates_gallery_probe.dart \
|
||||
// -o build/templates_gallery_probe_web
|
||||
// OPENCODE_ARTIFACT_DIR=<dir> node tool/templates_gallery_probe.mjs
|
||||
//
|
||||
// PROBE_HOST (material|cupertino), PROBE_SCALE, PROBE_WIDTH/PROBE_HEIGHT,
|
||||
// PROBE_SCENARIO (default|empty|refresh-refusal) and PROBE_CAPTURE_PREFIX
|
||||
// select the host and evidence. The fixture gateway is in-process: no socket
|
||||
// is opened and no real Pipelines server is contacted.
|
||||
|
||||
const root = resolve(process.env.PROBE_WEB_ROOT ?? 'build/templates_gallery_probe_web');
|
||||
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 width = Number(process.env.PROBE_WIDTH ?? 390);
|
||||
const height = Number(process.env.PROBE_HEIGHT ?? 844);
|
||||
const textScale = process.env.PROBE_SCALE ?? '1';
|
||||
const host = process.env.PROBE_HOST ?? 'material';
|
||||
const scenario = process.env.PROBE_SCENARIO ?? 'default';
|
||||
const capturePrefix = process.env.PROBE_CAPTURE_PREFIX ?? 't1-gallery';
|
||||
const deviceScaleFactor = Number(process.env.PROBE_DPR ?? 1);
|
||||
|
||||
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 pathname = decodeURIComponent(new URL(req.url, 'http://localhost').pathname);
|
||||
const path = resolve(root, `.${pathname}`);
|
||||
if (path !== root && !path.startsWith(root + sep)) {
|
||||
res.writeHead(403).end();
|
||||
return;
|
||||
}
|
||||
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 origin = `http://127.0.0.1:${server.address().port}`;
|
||||
|
||||
const profile = await mkdtemp(join(tmpdir(), 'templates-gallery-chrome-'));
|
||||
const chrome = spawn('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', [
|
||||
'--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?.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 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);
|
||||
await send(
|
||||
'Emulation.setDeviceMetricsOverride',
|
||||
{ width, height, deviceScaleFactor, mobile: true },
|
||||
session,
|
||||
);
|
||||
await send(
|
||||
'Emulation.setEmulatedMedia',
|
||||
{ features: [{ name: 'prefers-color-scheme', value: 'dark' }] },
|
||||
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 semanticText = () =>
|
||||
evaluate(`(() => {
|
||||
const chunks = [];
|
||||
for (const el of document.querySelectorAll('flt-semantics')) {
|
||||
const label = el.getAttribute('aria-label');
|
||||
if (label) chunks.push(label);
|
||||
if (!el.children.length && el.innerText) chunks.push(el.innerText);
|
||||
}
|
||||
for (const el of document.querySelectorAll('input, textarea')) {
|
||||
if (el.getAttribute('aria-label')) chunks.push(el.getAttribute('aria-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 labels = () =>
|
||||
evaluate(
|
||||
"[...document.querySelectorAll('flt-semantics')].map((el) => (el.getAttribute('aria-label') || el.innerText || '').trim()).filter(Boolean)",
|
||||
);
|
||||
|
||||
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)}`);
|
||||
}
|
||||
};
|
||||
|
||||
const clickLabel = async (label, { contains = false } = {}) => {
|
||||
const point = await evaluate(`(() => {
|
||||
const needle = ${JSON.stringify(label)};
|
||||
const candidates = [...document.querySelectorAll('flt-semantics')].filter((el) => {
|
||||
const text = (el.getAttribute('aria-label') || el.innerText || '').trim();
|
||||
return ${contains ? 'text.includes(needle)' : 'text === needle'};
|
||||
});
|
||||
const target = candidates.find((el) =>
|
||||
['button', 'tab', 'link', 'checkbox', 'menuitem'].includes(el.getAttribute('role')),
|
||||
) ?? candidates[0];
|
||||
if (!target) return null;
|
||||
const r = target.getBoundingClientRect();
|
||||
if (r.width === 0 || r.height === 0) return null;
|
||||
return { x: r.x + r.width / 2, y: r.y + r.height / 2 };
|
||||
})()`);
|
||||
if (!point) {
|
||||
throw new Error(`Could not click ${JSON.stringify(label)}. Labels: ${JSON.stringify(await labels())}`);
|
||||
}
|
||||
await send('Input.dispatchMouseEvent', { type: 'mousePressed', x: point.x, y: point.y, button: 'left', clickCount: 1 }, session);
|
||||
await send('Input.dispatchMouseEvent', { type: 'mouseReleased', x: point.x, y: point.y, button: 'left', clickCount: 1 }, session);
|
||||
await delay(400);
|
||||
};
|
||||
|
||||
const typeName = async (value) => {
|
||||
const focused = await evaluate(`(() => {
|
||||
const input = document.querySelector('input');
|
||||
if (!input) return false;
|
||||
input.focus();
|
||||
input.select?.();
|
||||
input.setSelectionRange?.(0, (input.value || '').length);
|
||||
return true;
|
||||
})()`);
|
||||
if (!focused) throw new Error('The name field was not exposed as a semantics input');
|
||||
await delay(300);
|
||||
await send('Input.insertText', { text: value }, session);
|
||||
await delay(400);
|
||||
};
|
||||
|
||||
const state = () => evaluate('globalThis.templatesGalleryProbe ?? null');
|
||||
const capture = async (name) => {
|
||||
const data = (await send('Page.captureScreenshot', { format: 'png' }, session)).result.data;
|
||||
const path = join(artifactDir, `${name}.png`);
|
||||
await writeFile(path, Buffer.from(data, 'base64'));
|
||||
return path;
|
||||
};
|
||||
|
||||
const checks = [];
|
||||
const captures = [];
|
||||
await send(
|
||||
'Page.navigate',
|
||||
{ url: `${origin}/?scale=${textScale}&host=${host}&scenario=${scenario}` },
|
||||
session,
|
||||
);
|
||||
await waitFor(
|
||||
() => evaluate("Boolean(document.querySelector('flt-semantics-placeholder'))"),
|
||||
'semantics placeholder',
|
||||
);
|
||||
await evaluate("document.querySelector('flt-semantics-placeholder')?.click()");
|
||||
await delay(900);
|
||||
|
||||
if (scenario === 'empty') {
|
||||
await assertBody('No templates are available on this server.');
|
||||
const emptyState = await state();
|
||||
if (emptyState?.listCalls !== 1) {
|
||||
throw new Error(`The empty catalogue made unexpected requests: ${JSON.stringify(emptyState)}`);
|
||||
}
|
||||
captures.push(await capture(`${capturePrefix}-empty`));
|
||||
checks.push({ check: 'empty catalogue stated honestly', state: emptyState });
|
||||
} else if (scenario === 'refresh-refusal') {
|
||||
// The catalogue loads, a template is open, and Refresh genuinely refuses:
|
||||
// the refusal must stay visible above that detail, with Retry.
|
||||
await assertBody('Release workflow');
|
||||
await clickLabel('Release workflow', { contains: true });
|
||||
await assertBody('Definition source');
|
||||
const before = await state();
|
||||
if (before?.listCalls !== 1 || before?.validates !== 0 || before?.submits !== 0) {
|
||||
throw new Error(`Opening the template made unexpected requests: ${JSON.stringify(before)}`);
|
||||
}
|
||||
|
||||
await clickLabel('Refresh');
|
||||
await assertBody('fixture refresh unavailable');
|
||||
await assertBody('Retry');
|
||||
await assertBody('Definition source');
|
||||
await assertBody('Create pipeline from this template');
|
||||
const refused = await state();
|
||||
if (refused?.listCalls !== 2 || refused?.validates !== 0 || refused?.submits !== 0) {
|
||||
throw new Error(`The failed refresh did not stay read-only: ${JSON.stringify(refused)}`);
|
||||
}
|
||||
captures.push(await capture(`${capturePrefix}-detail-refresh-error`));
|
||||
checks.push({ check: 'failed refresh visible above the open template', state: refused });
|
||||
|
||||
await clickLabel('Retry');
|
||||
await waitFor(
|
||||
async () => !(await semanticText()).includes('fixture refresh unavailable'),
|
||||
'the refusal banner to clear after Retry',
|
||||
);
|
||||
await assertBody('Definition source');
|
||||
const retried = await state();
|
||||
if (retried?.listCalls !== 3) {
|
||||
throw new Error(`Retry did not re-read exactly once: ${JSON.stringify(retried)}`);
|
||||
}
|
||||
captures.push(await capture(`${capturePrefix}-detail-refresh-retried`));
|
||||
checks.push({ check: 'Retry re-read while keeping the template open', state: retried });
|
||||
} else {
|
||||
// The first read genuinely refuses; the screen must say so and retry.
|
||||
await assertBody('fixture catalogue unavailable');
|
||||
await assertBody('Retry');
|
||||
const failed = await state();
|
||||
if (failed?.listCalls !== 1) {
|
||||
throw new Error(`The refusal state made unexpected requests: ${JSON.stringify(failed)}`);
|
||||
}
|
||||
captures.push(await capture(`${capturePrefix}-error`));
|
||||
checks.push({ check: 'catalogue refusal shown with Retry', state: failed });
|
||||
|
||||
await clickLabel('Retry');
|
||||
await assertBody('Loading templates…');
|
||||
captures.push(await capture(`${capturePrefix}-loading`));
|
||||
await assertBody('Release workflow');
|
||||
await assertBody('(unnamed template)');
|
||||
await assertBody('Ship a version');
|
||||
const gallery = await state();
|
||||
if (gallery?.listCalls !== 2) {
|
||||
throw new Error(`Retry did not re-read exactly once: ${JSON.stringify(gallery)}`);
|
||||
}
|
||||
captures.push(await capture(`${capturePrefix}-gallery`));
|
||||
checks.push({ check: 'retry loaded the actual catalogue rows', state: gallery });
|
||||
|
||||
await clickLabel('Release workflow', { contains: true });
|
||||
await assertBody('Definition source');
|
||||
await assertBody('Key');
|
||||
await assertBody('Includes a schedule');
|
||||
await assertBody('Create pipeline from this template');
|
||||
const detail = await state();
|
||||
if (detail?.validates !== 0 || detail?.submits !== 0) {
|
||||
throw new Error(`Opening a template sent a write: ${JSON.stringify(detail)}`);
|
||||
}
|
||||
captures.push(await capture(`${capturePrefix}-detail`));
|
||||
checks.push({ check: 'selected template shows metadata and verbatim source', state: detail });
|
||||
|
||||
await clickLabel('Back');
|
||||
await assertBody('Release workflow');
|
||||
await clickLabel('Refresh');
|
||||
await assertBody('Added after refresh');
|
||||
const refreshed = await state();
|
||||
if (refreshed?.listCalls !== 3) {
|
||||
throw new Error(`Refresh made unexpected requests: ${JSON.stringify(refreshed)}`);
|
||||
}
|
||||
captures.push(await capture(`${capturePrefix}-refreshed`));
|
||||
checks.push({ check: 'native back returned and refresh re-read the catalogue', state: refreshed });
|
||||
|
||||
await clickLabel('Release workflow', { contains: true });
|
||||
await assertBody('Create pipeline from this template');
|
||||
await clickLabel('Create pipeline from this template');
|
||||
await assertBody('Create from Release workflow');
|
||||
await assertBody('New pipeline name (required)');
|
||||
captures.push(await capture(`${capturePrefix}-create-blank`));
|
||||
await typeName('Probe release');
|
||||
await clickLabel('Cancel');
|
||||
await waitFor(async () => !(await semanticText()).includes('Create from Release workflow'), 'the prompt to close');
|
||||
const cancelled = await state();
|
||||
if (cancelled?.validates !== 0 || cancelled?.submits !== 0 || cancelled?.created?.length !== 0) {
|
||||
throw new Error(`Cancel sent a request: ${JSON.stringify(cancelled)}`);
|
||||
}
|
||||
checks.push({ check: 'Cancel sent nothing', state: cancelled });
|
||||
|
||||
await waitFor(
|
||||
async () => (await semanticText()).includes('Create pipeline from this template'),
|
||||
'the detail after the prompt closed',
|
||||
);
|
||||
await clickLabel('Create pipeline from this template');
|
||||
await assertBody('Create from Release workflow');
|
||||
await typeName('Probe release');
|
||||
await clickLabel('Create');
|
||||
await assertBody('Created "Probe created". It is in the Pipelines list.');
|
||||
const created = await state();
|
||||
if (created?.validates !== 1 || created?.submits !== 1 || created?.created?.length !== 1) {
|
||||
throw new Error(`The accepted create was not reported exactly once: ${JSON.stringify(created)}`);
|
||||
}
|
||||
if (created.lastSubmit?.name !== 'Probe release' || created.lastSubmit?.create_only !== true) {
|
||||
throw new Error(`Submit payload drifted: ${JSON.stringify(created.lastSubmit)}`);
|
||||
}
|
||||
const verbatim = ' name: "release"\n\tstages:\n - key: "añadir" 😀 \n';
|
||||
if (created.lastSubmit?.source !== created.lastSource || created.lastSource !== verbatim) {
|
||||
throw new Error(`Source was not sent verbatim: ${JSON.stringify(created)}`);
|
||||
}
|
||||
captures.push(await capture(`${capturePrefix}-created`));
|
||||
checks.push({
|
||||
check: 'accepted create forwarded the detail once with the verbatim source',
|
||||
state: created,
|
||||
});
|
||||
|
||||
await clickLabel('Close');
|
||||
await waitFor(async () => !(await semanticText()).includes('Create from Release workflow'), 'the prompt to close');
|
||||
const closed = await state();
|
||||
if (closed?.created?.length !== 1 || closed?.submits !== 1) {
|
||||
throw new Error(`Close changed the request counts: ${JSON.stringify(closed)}`);
|
||||
}
|
||||
checks.push({ check: 'Close dismissed without another request', state: closed });
|
||||
}
|
||||
|
||||
console.log(JSON.stringify({
|
||||
ok: true,
|
||||
origin,
|
||||
viewport: { width, height },
|
||||
deviceScaleFactor,
|
||||
textScale,
|
||||
host,
|
||||
scenario,
|
||||
checks,
|
||||
captures,
|
||||
}, 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 });
|
||||
}
|
||||
Reference in New Issue
Block a user