merge(app): land the recorded visit pane after a retained deadline

This commit is contained in:
2026-10-22 02:05:36 +01:00
28 changed files with 2419 additions and 52 deletions
+14 -8
View File
@@ -236,21 +236,27 @@ try {
}
await clickPrefix('plan');
await waitForText('plan · visit 1', 'timeline after stage click');
await waitForText('plan · visit 1', 'timeline visit pane after stage click');
await waitForText('Status: completed', 'recorded visit facts');
await waitForText('Timeline', 'timeline tab');
const timeline = await semantics();
const rowCandidates = timeline
const titleCandidates = timeline
.filter((entry) => entry.visible && entry.label.startsWith('plan · visit 1'))
.sort((a, b) => a.width * a.height - b.width * b.height);
const row = rowCandidates[0];
if (!row) throw new Error(`Selected timeline row missing: ${JSON.stringify(timeline.map((entry) => entry.label))}`);
if (row.selected !== 'true') {
throw new Error(`Timeline row is not selected: ${JSON.stringify(rowCandidates)}`);
if (!titleCandidates.length) {
throw new Error(`Opened visit pane missing: ${JSON.stringify(timeline.map((entry) => entry.label))}`);
}
const paneLabels = timeline.map((entry) => entry.label);
for (const section of ['Input', 'Output', 'Artifacts', 'Session', 'Definition']) {
if (!paneLabels.includes(section)) {
throw new Error(`Visit section ${section} is missing: ${JSON.stringify(paneLabels)}`);
}
}
if ((await bodyText()).includes('audit · visit')) {
throw new Error('A visit was invented for the unvisited stage');
}
check('a stage click selects the recorded visit in Timeline', row.selected);
check('a stage click opens the recorded visit pane', true);
check('the visit pane offers its recorded sections', true);
// The programmatic switch must reveal its own tab, not leave an offscreen
// selection behind a strip still showing Summary/Graph.
const timelineTab = await findVisible((entry) => entry.label === 'Timeline' && entry.tappable);
@@ -259,7 +265,7 @@ try {
throw new Error(`Selected Timeline tab is clipped: ${JSON.stringify({ timelineTab, width })}`);
}
check('the selected Timeline tab is revealed in the strip', `${Math.round(timelineTab.x)}..${Math.round(timelineTab.x + timelineTab.width)}`);
evidence.selectedRow = row;
evidence.openedPane = titleCandidates[0];
evidence.captures.push(await capture('selected-visit'));
await navigate(
+189
View File
@@ -0,0 +1,189 @@
// Standalone fixture entry for real-browser recorded-visit pane evidence.
//
// Build and probe (from app/):
// flutter build web --target tool/run_detail_visit_probe.dart \
// --output build/probe-run-detail-visit
// PROBE_VARIANT=material OPENCODE_ARTIFACT_DIR=DIR \
// node tool/run_detail_visit_probe.mjs
//
// Server-shaped fixtures only: a fake gateway answers the same get_run envelope
// the app consumes. 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/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});
}
}
/// plan -> build, with a rich first visit and a sparse second visit.
JsonMap _graph() => <String, dynamic>{
'name': 'Release verification',
'stages': <dynamic>[
<String, dynamic>{
'key': 'plan',
'type': 'model',
'prompt': 'Draft the plan.',
'output': 'A plan.',
'edges': <String, String?>{'success': 'build', 'error': '#'},
},
<String, dynamic>{
'key': 'build',
'type': 'model',
'prompt': 'Build the candidate.',
'edges': <String, String?>{'success': '#success', 'error': '#'},
},
],
};
JsonMap _run() => <String, dynamic>{
'id': 512,
'title': 'Release verification',
'name': 'release',
'pipeline_id': 7,
'version': 3,
'status': 'succeeded',
'executing': false,
'input': <String, dynamic>{'prompt': 'Verify the candidate release.'},
'output': <String, dynamic>{'result': 'verified'},
'graph': _graph(),
'steps': <dynamic>[
<String, dynamic>{
'stage': 'plan',
'sequence': 1,
'status': 'completed',
'outcome': 'success',
'target': 'build',
'provider': 'anthropic',
'model': 'claude-x',
'started_at': '2026-10-22T00:00:00Z',
'finished_at': '2026-10-22T00:02:05Z',
'diagnostic': 'Plan checked.',
'verdict': <String, dynamic>{
'option': 'approve',
'reason': 'Looks good.',
},
'input': <String, dynamic>{'markdown': 'Draft the plan.\n'},
'output': <String, dynamic>{'result': 'ok'},
'session_id': 'sess-1',
'session_export': <String, dynamic>{
'html': 'session.html',
'status': 'complete',
'messages': 3,
'html_bytes': 1234,
},
'artifacts': <dynamic>[
<String, dynamic>{
'name': 'plan.csv',
'url': 'https://example.test/artifacts/plan.csv',
'content_type': 'text/csv',
'size_bytes': 42,
},
<String, dynamic>{
'name': 'session.html',
'url': 'https://example.test/artifacts/session.html',
'content_type': 'text/html',
'size_bytes': 100,
},
],
},
<String, dynamic>{
'stage': 'build',
'sequence': 2,
'status': 'completed',
'outcome': 'success',
'target': '#success',
'diagnostic': 'Built.',
},
],
};
void main() {
final params = Uri.base.queryParameters;
final cupertino = params['platform'] == 'cupertino';
final dark = params['theme'] == 'dark';
final scale = double.tryParse(params['scale'] ?? '') ?? 1;
runApp(
_ProbeBody(cupertino: cupertino, dark: dark, scale: scale, run: _run()),
);
}
class _ProbeBody extends StatefulWidget {
const _ProbeBody({
required this.cupertino,
required this.dark,
required this.scale,
required this.run,
});
final bool cupertino;
final bool dark;
final double scale;
final JsonMap run;
@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(512);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final detail = RunDetailView(
controller: _controller,
gateway: _gateway,
onBack: () {},
);
final theme = widget.dark ? Brightness.dark : Brightness.light;
Widget scaled(BuildContext context, Widget? app) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: TextScaler.linear(widget.scale)),
child: app!,
);
if (widget.cupertino) {
return CupertinoApp(
title: 'Visit pane fixture',
theme: CupertinoThemeData(brightness: theme),
builder: scaled,
home: CupertinoPageScaffold(child: SafeArea(child: detail)),
);
}
return MaterialApp(
title: 'Visit pane fixture',
theme: ThemeData(brightness: theme, platform: TargetPlatform.android),
builder: scaled,
home: Scaffold(body: SafeArea(child: detail)),
);
}
}
+290
View File
@@ -0,0 +1,290 @@
// Real-browser acceptance for the run detail's recorded-visit pane.
//
// Serves the probe build (`flutter build web -t tool/run_detail_visit_probe.dart`)
// on an OS-assigned loopback port and drives the actual RunDetailView over a
// server-shaped fixture. It checks that a Graph stage click opens the recorded
// visit in Timeline with its facts and native tabs, that the tabs show the
// recorded Input, Artifacts, Session and Definition, that the visit's artifact
// row opens a gallery listing exactly that visit's attributed files, that Back
// returns to the rows, that a sparse visit does not invent Duration or
// provider/model, and that a visit with no artifact field says the capture is
// unavailable rather than empty.
//
// 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/run_detail_visit_probe.mjs
import { createServer } from 'node:http';
import { spawn } from 'node:child_process';
import { once } from 'node:events';
import { setTimeout as delay } from 'node:timers/promises';
import { join, extname, resolve, sep } from 'node:path';
import { tmpdir } from 'node:os';
import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
const root = resolve(
process.env.PROBE_WEB_ROOT ??
join(process.cwd(), 'build/probe-run-detail-visit'),
);
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 = `run-detail-visit-${variant}-${scheme}-${scale}x-${width}x${height}`;
const mime = {
'.html': 'text/html',
'.js': 'text/javascript',
'.json': 'application/json',
'.wasm': 'application/wasm',
'.png': 'image/png',
'.ico': 'image/x-icon',
'.otf': 'font/otf',
'.ttf': 'font/ttf',
};
const server = createServer(async (req, res) => {
try {
const path = resolve(root, '.' + decodeURIComponent(new URL(req.url, 'http://localhost').pathname));
if (path !== root && !path.startsWith(root + sep)) return res.writeHead(403).end();
const filePath = path === root || path.endsWith('/') ? join(path, 'index.html') : path;
const file = await readFile(filePath);
res.writeHead(200, { 'content-type': mime[extname(filePath)] ?? 'application/octet-stream' }).end(file);
} catch {
res.writeHead(404).end('not found');
}
});
server.listen(0, '127.0.0.1');
await once(server, 'listening');
const port = server.address().port;
const profile = await mkdtemp(join(tmpdir(), 'run-detail-visit-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: width < 600,
}, 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 semantics = () => evaluate(`[...document.querySelectorAll('flt-semantics')].map(x => {
const r = x.getBoundingClientRect();
return {
label: (x.getAttribute('aria-label') || (x.innerText || '')).trim(),
selected: x.getAttribute('aria-selected') || x.getAttribute('aria-current'),
tappable: x.hasAttribute('flt-tappable'),
x: r.x, y: r.y, width: r.width, height: r.height,
visible: r.width > 0 && r.height > 0 && r.bottom > 0 && r.top < innerHeight,
};
})`);
const labels = async () => (await semantics()).map((item) => item.label).filter(Boolean);
const bodyText = async () => [await evaluate('document.body.innerText'), ...(await labels())].join('\n');
const waitForText = async (needle, context) => {
for (let attempt = 0; attempt < 60; attempt++) {
if ((await bodyText()).includes(needle)) return;
await delay(250);
}
throw new Error(`${context}: missing ${JSON.stringify(needle)}\n${await bodyText()}`);
};
const clickItem = async (item) => {
const x = item.x + item.width / 2;
const y = item.y + item.height / 2;
await send('Input.dispatchMouseEvent', {
type: 'mousePressed', x, y, button: 'left', clickCount: 1,
}, session);
await send('Input.dispatchMouseEvent', {
type: 'mouseReleased', x, y, button: 'left', clickCount: 1,
}, session);
await delay(1000);
};
const findVisible = async (predicate) => {
const items = (await semantics()).filter((item) => item.visible && predicate(item));
items.sort((a, b) => a.width * a.height - b.width * b.height);
return items[0] ?? null;
};
const clickSemantics = async (wanted, { lowest = false, prefix: asPrefix = false } = {}) => {
const clicked = await evaluate(`(() => {
const wanted = ${JSON.stringify(wanted)};
const lowest = ${lowest ? 'true' : 'false'};
const asPrefix = ${asPrefix ? 'true' : 'false'};
const text = (x) => (x.getAttribute('aria-label') || x.innerText || '').trim();
const matches = [...document.querySelectorAll('flt-semantics')]
.filter((x) => x.hasAttribute('flt-tappable'))
.filter((x) => asPrefix ? text(x).startsWith(wanted) : text(x) === wanted);
if (!matches.length) return false;
matches.sort((a, b) => {
const ra = a.getBoundingClientRect();
const rb = b.getBoundingClientRect();
if (lowest) return rb.bottom - ra.bottom;
return ra.width * ra.height - rb.width * rb.height;
});
matches[0].click();
return true;
})()`);
if (!clicked) throw new Error(`Missing tappable ${JSON.stringify(wanted)}: ${JSON.stringify(await labels())}`);
await delay(1000);
};
const clickLabel = (label, options) => clickSemantics(label, options);
const clickPrefix = (prefixText) => clickSemantics(prefixText, { prefix: true });
const capture = async (name) => {
const data = (await send('Page.captureScreenshot', {
format: 'png', captureBeyondViewport: false,
}, session)).result.data;
const file = `${prefix}-${name}.png`;
await writeFile(join(artifactDir, file), Buffer.from(data, 'base64'));
return file;
};
const evidence = { variant, scheme, scale, width, height, checks: [], captures: [] };
const check = (text, value) => evidence.checks.push({ check: text, value });
const navigation = await send('Page.navigate', {
url: `http://127.0.0.1:${port}/?platform=${variant}&theme=${scheme === 'dark' ? 1 : 0}&scale=${scale}`,
}, session);
if (navigation.error || navigation.result?.errorText) throw new Error(JSON.stringify(navigation));
await delay(3200);
await evaluate("document.querySelector('flt-semantics-placeholder')?.click()");
await delay(900);
await waitForText('Release verification', 'fixture load');
check('the real run detail opened over the recorded fixture', true);
await clickLabel('Graph');
await waitForText('Executed', 'graph legend');
await clickPrefix('plan');
await waitForText('plan · visit 1', 'visit pane after graph click');
await waitForText('Provider/model', 'visit facts');
await waitForText('anthropic / claude-x', 'visit facts');
await waitForText('2m 5s', 'recorded duration');
await waitForText('Plan checked.', 'recorded diagnostic');
await waitForText('approve', 'recorded verdict');
const paneLabels = await labels();
for (const section of ['Input', 'Output', 'Artifacts', 'Session', 'Definition']) {
if (!paneLabels.includes(section)) {
throw new Error(`Visit section ${section} is missing: ${JSON.stringify(paneLabels)}`);
}
}
check('Graph stage click opens the recorded visit pane with its tabs', true);
evidence.captures.push(await capture('visit-pane'));
await clickLabel('Definition', { lowest: true });
await waitForText('Type model', 'authored definition');
await waitForText('Prompt', 'authored definition prompt');
await waitForText('Draft the plan.', 'pinned prompt');
check('Definition shows the pinned authored source', true);
evidence.captures.push(await capture('definition'));
await clickLabel('Session', { lowest: true });
await waitForText('sess-1', 'recorded session pointer');
await waitForText('Open session.html', 'session export link');
check('Session shows the recorded pointer and export open', true);
evidence.captures.push(await capture('session'));
await clickLabel('Artifacts', { lowest: true });
await waitForText('plan.csv', 'visit artifact');
check('Artifacts lists the visit recorded files', true);
evidence.captures.push(await capture('artifacts'));
await clickLabel('Back to timeline');
await waitForText('build · visit 2', 'timeline rows after back');
if ((await bodyText()).includes('Plan checked.')) {
throw new Error('Back left the visit pane open');
}
check('Back returns to the recorded rows', true);
evidence.captures.push(await capture('timeline-rows'));
await clickPrefix('build · visit 2');
await waitForText('build · visit 2', 'sparse visit pane');
const sparse = await bodyText();
for (const absent of ['Provider/model', 'Duration', '2m 5s', 'anthropic / claude-x']) {
if (sparse.includes(absent)) {
throw new Error(`A sparse visit invented ${JSON.stringify(absent)}\n${sparse}`);
}
}
check('a sparse visit does not invent duration or provider/model', true);
evidence.captures.push(await capture('sparse-visit'));
await clickLabel('Artifacts', { lowest: true });
await waitForText('Artifacts · capture unavailable', 'sparse capture state');
check('a visit without an artifact field says capture unavailable', true);
evidence.captures.push(await capture('sparse-artifacts'));
await clickLabel('Back to timeline');
await waitForText('plan · visit 1', 'rows before the gallery check');
await clickPrefix('plan · visit 1');
await waitForText('Provider/model', 'plan visit for the gallery check');
await clickLabel('Artifacts', { lowest: true });
await waitForText('plan.csv', 'plan visit artifacts');
await clickPrefix('plan.csv');
await waitForText('Artifacts · 1 recorded', 'visit gallery summary');
await waitForText('plan · visit 1', 'visit gallery group');
const galleryText = await bodyText();
if (galleryText.includes('session.html')) {
throw new Error(`The visit gallery listed the session evidence file\n${galleryText}`);
}
check('the artifact row opens exactly the visit attributed group', true);
evidence.captures.push(await capture('visit-gallery'));
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 });
}