feat(app): add the Graph tab and recorded-stage selection to run detail
This commit is contained in:
@@ -0,0 +1,157 @@
|
||||
// Standalone fixture entry for real-browser run-detail Graph evidence.
|
||||
//
|
||||
// Build and probe (from app/):
|
||||
// flutter build web --target tool/run_detail_graph_probe.dart \
|
||||
// --output build/probe-run-detail-graph
|
||||
// PROBE_VARIANT=material OPENCODE_ARTIFACT_DIR=DIR \
|
||||
// node tool/run_detail_graph_probe.mjs
|
||||
//
|
||||
// Server-shaped fixtures only: a fake gateway answers the same get_run envelope
|
||||
// the app consumes. The run's own pinned graph and recorded steps drive the
|
||||
// Graph tab; 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 -> audit, with plan and build recorded and audit unvisited.
|
||||
JsonMap _graph() => <String, dynamic>{
|
||||
'name': 'Release verification',
|
||||
'stages': <dynamic>[
|
||||
<String, dynamic>{
|
||||
'key': 'plan',
|
||||
'type': 'model',
|
||||
'edges': <String, String?>{'success': 'build', 'error': '#'},
|
||||
'fallback_error': true,
|
||||
},
|
||||
<String, dynamic>{
|
||||
'key': 'build',
|
||||
'type': 'model',
|
||||
'edges': <String, String?>{'success': 'audit', 'error': '#'},
|
||||
},
|
||||
<String, dynamic>{
|
||||
'key': 'audit',
|
||||
'type': 'model',
|
||||
'edges': <String, String?>{'success': '#success', 'error': '#failure'},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
JsonMap _run({required bool graph}) => <String, dynamic>{
|
||||
'id': 488,
|
||||
'title': 'Release verification',
|
||||
'name': 'release',
|
||||
'status': 'succeeded',
|
||||
'executing': false,
|
||||
'input': <String, dynamic>{'prompt': 'Verify the candidate release.'},
|
||||
'output': <String, dynamic>{'result': 'verified'},
|
||||
'steps': <dynamic>[
|
||||
<String, dynamic>{
|
||||
'stage': 'plan',
|
||||
'sequence': 1,
|
||||
'status': 'completed',
|
||||
'outcome': 'success',
|
||||
'target': 'build',
|
||||
},
|
||||
<String, dynamic>{
|
||||
'stage': 'build',
|
||||
'sequence': 2,
|
||||
'status': 'completed',
|
||||
'outcome': 'success',
|
||||
'target': 'audit',
|
||||
},
|
||||
],
|
||||
if (graph) 'graph': _graph(),
|
||||
};
|
||||
|
||||
void main() {
|
||||
final params = Uri.base.queryParameters;
|
||||
final cupertino = params['platform'] == 'cupertino';
|
||||
final dark = params['theme'] == 'dark';
|
||||
final scale = double.tryParse(params['scale'] ?? '') ?? 1;
|
||||
final run = _run(graph: params['case'] != 'missing');
|
||||
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(488);
|
||||
}
|
||||
|
||||
@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: 'Run graph fixture',
|
||||
theme: CupertinoThemeData(brightness: theme),
|
||||
builder: scaled,
|
||||
home: CupertinoPageScaffold(child: SafeArea(child: detail)),
|
||||
);
|
||||
}
|
||||
return MaterialApp(
|
||||
title: 'Run graph fixture',
|
||||
theme: ThemeData(brightness: theme, platform: TargetPlatform.android),
|
||||
builder: scaled,
|
||||
home: Scaffold(body: SafeArea(child: detail)),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,292 @@
|
||||
// Real-browser acceptance for the run detail's Graph tab.
|
||||
//
|
||||
// Serves the probe build (`flutter build web -t tool/run_detail_graph_probe.dart`)
|
||||
// on an OS-assigned loopback port and drives the actual RunDetailView over a
|
||||
// server-shaped fixture. It checks the Graph tab's recorded evidence and legend,
|
||||
// that an unvisited node does nothing, that a visited stage click selects the
|
||||
// recorded visit in Timeline, and the exact missing-graph wording. Captures are
|
||||
// written for both hosts.
|
||||
//
|
||||
// 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_graph_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-graph'),
|
||||
);
|
||||
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-graph-${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-graph-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;
|
||||
};
|
||||
// A native control's semantics node is the one the engine listens to; a
|
||||
// synthetic DOM click avoids coordinate ambiguity in a horizontally scrolled
|
||||
// tab strip and in a panned graph canvas.
|
||||
const clickSemantics = async (wanted, prefix = false) => {
|
||||
const clicked = await evaluate(`(() => {
|
||||
const wanted = ${JSON.stringify(wanted)};
|
||||
const prefix = ${prefix ? '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) => prefix ? text(x).startsWith(wanted) : text(x) === wanted);
|
||||
if (!matches.length) return false;
|
||||
matches.sort((a, b) => {
|
||||
const ra = a.getBoundingClientRect();
|
||||
const rb = b.getBoundingClientRect();
|
||||
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) => clickSemantics(label);
|
||||
const clickPrefix = (prefix) => clickSemantics(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 activate = async () => {
|
||||
await delay(3200);
|
||||
await evaluate("document.querySelector('flt-semantics-placeholder')?.click()");
|
||||
await delay(900);
|
||||
};
|
||||
const navigate = async (query, needle) => {
|
||||
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));
|
||||
await activate();
|
||||
await waitForText(needle, 'fixture load');
|
||||
};
|
||||
|
||||
await navigate(
|
||||
`?platform=${variant}&theme=${scheme === 'dark' ? 1 : 0}&scale=${scale}&case=default`,
|
||||
'Release verification',
|
||||
);
|
||||
check('the real run detail opened over the recorded fixture', true);
|
||||
|
||||
await clickLabel('Graph');
|
||||
await waitForText('Executed', 'graph legend');
|
||||
await waitForText('Not executed', 'graph legend');
|
||||
const graphLabels = await labels();
|
||||
const plan = await findVisible((entry) => entry.label.startsWith('plan') && entry.tappable);
|
||||
const build = await findVisible((entry) => entry.label.startsWith('build') && entry.tappable);
|
||||
const audit = await findVisible((entry) => entry.label === 'audit');
|
||||
if (!plan) throw new Error(`Visited stage node is missing: ${JSON.stringify(graphLabels)}`);
|
||||
if (audit?.tappable) throw new Error('An unvisited node is a tap target');
|
||||
if (plan.y + plan.height > height) {
|
||||
throw new Error(`Graph node falls outside the bounded viewport: ${JSON.stringify({ plan, height })}`);
|
||||
}
|
||||
check(
|
||||
'Graph draws the recorded stages inside the viewport',
|
||||
`${Math.round(plan.width)}x${Math.round(plan.height)} plan${build ? ', build visible' : ''}`,
|
||||
);
|
||||
check('Graph legend shows Executed and Not executed', true);
|
||||
evidence.captures.push(await capture('graph'));
|
||||
|
||||
// An unvisited node is not a control: clicking its label leaves the Graph tab
|
||||
// exactly as it was and creates no visit. At 320/2x the canvas is panned, so
|
||||
// the later node may sit outside the visible viewport; the widget test covers
|
||||
// that case there.
|
||||
if (audit) {
|
||||
await clickItem(audit);
|
||||
await waitForText('Executed', 'graph after unvisited click');
|
||||
if ((await bodyText()).includes('plan · visit 1')) {
|
||||
throw new Error('An unvisited node invented a timeline visit');
|
||||
}
|
||||
check('an unvisited node does nothing and invents no visit', true);
|
||||
} else {
|
||||
check('unvisited node is outside this bounded viewport; widget test covers it', 'skipped');
|
||||
}
|
||||
|
||||
await clickPrefix('plan');
|
||||
await waitForText('plan · visit 1', 'timeline after stage click');
|
||||
await waitForText('Timeline', 'timeline tab');
|
||||
const timeline = await semantics();
|
||||
const rowCandidates = 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 ((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);
|
||||
// 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);
|
||||
if (!timelineTab) throw new Error(`Timeline tab is not visible: ${JSON.stringify(await labels())}`);
|
||||
if (timelineTab.x < 0 || timelineTab.x + timelineTab.width > width) {
|
||||
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.captures.push(await capture('selected-visit'));
|
||||
|
||||
await navigate(
|
||||
`?platform=${variant}&theme=${scheme === 'dark' ? 1 : 0}&scale=${scale}&case=missing`,
|
||||
'Release verification',
|
||||
);
|
||||
await clickLabel('Graph');
|
||||
await waitForText('This server did not include the run graph.', 'missing graph');
|
||||
if ((await semantics()).some((entry) => entry.label === 'audit')) {
|
||||
throw new Error('A run without a graph still drew stage nodes');
|
||||
}
|
||||
check('a run without a graph states the exact missing wording', true);
|
||||
evidence.captures.push(await capture('missing-graph'));
|
||||
|
||||
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 });
|
||||
}
|
||||
Reference in New Issue
Block a user