feat(app): finish measured native graph canvas and clear labels from wires
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
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/definition_graph_view.dart';
|
||||
|
||||
const String _longKey = 'implementer-with-an-unusually-long-stage-label';
|
||||
|
||||
/// A definition with forward, fallback, self-loop and terminal edges so one
|
||||
/// canvas shows measured wrapping nodes, native outcome labels and arrows.
|
||||
JsonMap _definition() => <String, dynamic>{
|
||||
'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': _longKey, 'retry': 'build'},
|
||||
},
|
||||
<String, dynamic>{
|
||||
'key': _longKey,
|
||||
'type': 'model',
|
||||
'edges': <String, String?>{'success': 'audit', 'blocked': '#failure'},
|
||||
},
|
||||
<String, dynamic>{
|
||||
'key': 'audit',
|
||||
'type': 'model',
|
||||
'edges': <String, String?>{'success': '#success', 'error': '#failure'},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
/// Isolated browser fixture for `DefinitionGraphView` only.
|
||||
///
|
||||
/// Not wired into the app or shell. `style=cupertino` selects the native
|
||||
/// Cupertino host, `scale=2` applies a real 2x text scale to the graph viewport,
|
||||
/// and a click reports the exact stage key in the status line.
|
||||
void main() {
|
||||
final parameters = Uri.base.queryParameters;
|
||||
final cupertino = parameters['style'] == 'cupertino';
|
||||
final scale = double.tryParse(parameters['scale'] ?? '') ?? 1;
|
||||
runApp(_ProbeApp(cupertino: cupertino, scale: scale));
|
||||
}
|
||||
|
||||
class _ProbeApp extends StatelessWidget {
|
||||
const _ProbeApp({required this.cupertino, required this.scale});
|
||||
|
||||
final bool cupertino;
|
||||
final double scale;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final page = _ProbePage(scale: scale);
|
||||
if (cupertino) {
|
||||
return CupertinoApp(
|
||||
home: CupertinoPageScaffold(
|
||||
navigationBar: const CupertinoNavigationBar(
|
||||
middle: Text('Definition graph'),
|
||||
),
|
||||
child: SafeArea(child: page),
|
||||
),
|
||||
);
|
||||
}
|
||||
return MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
darkTheme: ThemeData(
|
||||
platform: TargetPlatform.android,
|
||||
brightness: Brightness.dark,
|
||||
),
|
||||
themeMode: ThemeMode.system,
|
||||
home: Scaffold(
|
||||
appBar: AppBar(title: const Text('Definition graph')),
|
||||
body: SafeArea(child: page),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ProbePage extends StatefulWidget {
|
||||
const _ProbePage({required this.scale});
|
||||
|
||||
final double scale;
|
||||
|
||||
@override
|
||||
State<_ProbePage> createState() => _ProbePageState();
|
||||
}
|
||||
|
||||
class _ProbePageState extends State<_ProbePage> {
|
||||
String? _selected = 'build';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Selected: ${_selected ?? 'none'}'),
|
||||
const SizedBox(height: 8),
|
||||
Expanded(
|
||||
child: MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: TextScaler.linear(widget.scale)),
|
||||
child: DefinitionGraphView(
|
||||
graph: _definition(),
|
||||
selectedStage: _selected,
|
||||
onSelected: (key) => setState(() => _selected = key),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
// Browser acceptance for the isolated DefinitionGraphView fixture.
|
||||
//
|
||||
// Serves the probe build (`flutter build web -t tool/graph_canvas_probe.dart`)
|
||||
// on an OS-assigned loopback port, drives a real headless Chrome, asserts the
|
||||
// native node/label semantics, selection identity, measured node rectangles and
|
||||
// that a real drag pans the stock InteractiveViewer, then writes captures.
|
||||
//
|
||||
// PROBE_VARIANT=material|cupertino PROBE_SCHEME=dark|light PROBE_SCALE=1|2 \
|
||||
// PROBE_WEB_ROOT=<probe build> OPENCODE_ARTIFACT_DIR=<dir> \
|
||||
// node tool/graph_canvas_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/graph_canvas_probe'));
|
||||
const variant = process.env.PROBE_VARIANT ?? 'material';
|
||||
const scheme = process.env.PROBE_SCHEME ?? 'dark';
|
||||
const scale = process.env.PROBE_SCALE ?? '1';
|
||||
const artifactDir = process.env.OPENCODE_ARTIFACT_DIR ?? join(tmpdir(), 'graph-canvas-capture');
|
||||
const prefix = scheme === 'light' ? 'light-' : '';
|
||||
const longKey = 'implementer-with-an-unusually-long-stage-label';
|
||||
const nodes = ['plan', 'build', longKey, 'audit', 'Success', 'Failure'];
|
||||
const edgeLabels = ['success', 'error*', 'retry', 'blocked'];
|
||||
await mkdir(artifactDir, { recursive: true });
|
||||
const mime = { '.html': 'text/html', '.js': 'text/javascript', '.json': 'application/json', '.wasm': 'application/wasm', '.png': 'image/png', '.ico': 'image/x-icon' };
|
||||
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(), 'graph-canvas-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; });
|
||||
const waitFor = async fn => {
|
||||
for (let i = 0; i < 100; 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 msg = JSON.parse(event.data);
|
||||
if (msg.id && pending.has(msg.id)) { pending.get(msg.id)(msg); pending.delete(msg.id); }
|
||||
});
|
||||
const send = (method, params = {}, sessionId) => new Promise(resolve => {
|
||||
const callId = ++id; pending.set(callId, resolve);
|
||||
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);
|
||||
const url = `http://127.0.0.1:${port}/?style=${variant}&scale=${scale}`;
|
||||
const navigation = await send('Page.navigate', { url }, session);
|
||||
if (navigation.error || navigation.result?.errorText) throw new Error(JSON.stringify(navigation));
|
||||
await send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 800, deviceScaleFactor: 1, mobile: false }, 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;
|
||||
};
|
||||
await delay(3500);
|
||||
const loaded = await evaluate('({url:location.href, ready:document.readyState})');
|
||||
if (!loaded?.url.includes(`127.0.0.1:${port}/?style=${variant}&scale=${scale}`)) throw new Error(`Fixture did not load: ${JSON.stringify(loaded)}`);
|
||||
await evaluate("document.querySelector('flt-semantics-placeholder')?.click()");
|
||||
await delay(2500);
|
||||
const semantics = () => evaluate("[...document.querySelectorAll('flt-semantics')].map(x=>({label:(x.getAttribute('aria-label')||x.innerText||'').trim(), selected:x.getAttribute('aria-current')}))");
|
||||
const nodeAt = label => `[...document.querySelectorAll('flt-semantics')].find(x => (x.getAttribute('aria-label')||x.innerText||'').trim() === ${JSON.stringify(label)})`;
|
||||
const body = await evaluate('document.body.innerText');
|
||||
if (!body.includes('Selected: build')) throw new Error(`Initial selection missing: ${body}`);
|
||||
const initial = await semantics();
|
||||
// Flutter web maps Semantics(selected:) to aria-current, not aria-selected.
|
||||
const current = initial.find(x => x.selected === 'true');
|
||||
if (!current?.label.startsWith('build')) throw new Error(`Selected node is not announced: ${JSON.stringify(initial)}`);
|
||||
const nodeRect = async label => evaluate(`(() => { const e=${nodeAt(label)}; if (!e) return null; const r=e.getBoundingClientRect(); return {x:r.x,y:r.y,width:r.width,height:r.height}; })()`);
|
||||
const rects = {};
|
||||
for (const label of nodes) {
|
||||
const rect = await nodeRect(label);
|
||||
if (rect?.width > 0 && rect?.height > 0) rects[label] = rect;
|
||||
}
|
||||
// Measured native nodes occupy separate rectangles: no fixed-size overlap.
|
||||
const visibleNodes = Object.keys(rects);
|
||||
for (let a = 0; a < visibleNodes.length; a++) {
|
||||
for (let b = a + 1; b < visibleNodes.length; b++) {
|
||||
const one = rects[visibleNodes[a]], two = rects[visibleNodes[b]];
|
||||
const overlap = one.x < two.x + two.width && two.x < one.x + one.width &&
|
||||
one.y < two.y + two.height && two.y < one.y + one.height;
|
||||
if (overlap) throw new Error(`Nodes overlap: ${visibleNodes[a]} ${JSON.stringify(one)} vs ${visibleNodes[b]} ${JSON.stringify(two)}`);
|
||||
}
|
||||
}
|
||||
if (!(rects[longKey].height > rects.plan.height || rects[longKey].width > rects.plan.width)) {
|
||||
throw new Error(`Long key did not determine its own native extent: ${JSON.stringify(rects)}`);
|
||||
}
|
||||
const clickLabel = async label => {
|
||||
const point = await evaluate(`(() => { const e=${nodeAt(label)}; if (!e) return null; const r=e.getBoundingClientRect(); return {x:r.x+r.width/2,y:r.y+r.height/2}; })()`);
|
||||
if (!point) return false;
|
||||
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);
|
||||
return true;
|
||||
};
|
||||
const capture = async (name, width, height) => {
|
||||
await send('Emulation.setDeviceMetricsOverride', { width, height, deviceScaleFactor: 1, mobile: width < 600 }, session);
|
||||
await delay(2500);
|
||||
const data = (await send('Page.captureScreenshot', { format: 'png', captureBeyondViewport: false }, session)).result.data;
|
||||
const file = `${prefix}${variant}-graph-${scale}x-${name}.png`;
|
||||
await writeFile(`${artifactDir}/${file}`, Buffer.from(data, 'base64'));
|
||||
return file;
|
||||
};
|
||||
const captures = [];
|
||||
captures.push(await capture('desktop', 1280, 800));
|
||||
captures.push(await capture('phone', 390, 844));
|
||||
if (!await clickLabel('plan')) throw new Error('Could not click plan node');
|
||||
await delay(800);
|
||||
const afterPlan = await evaluate('document.body.innerText');
|
||||
if (!afterPlan.includes('Selected: plan')) throw new Error(`plan callback did not carry its key: ${afterPlan}`);
|
||||
const planCurrent = (await semantics()).find(x => x.selected === 'true');
|
||||
if (planCurrent?.label !== 'plan') throw new Error(`plan is not announced selected: ${JSON.stringify(planCurrent)}`);
|
||||
captures.push(await capture('selected-plan', 1280, 800));
|
||||
const seen = new Set();
|
||||
const drag = async (start, dx, dy = 0) => {
|
||||
await send('Input.dispatchMouseEvent', {type:'mousePressed', ...start, button:'left', buttons:1, clickCount:1}, session);
|
||||
for (let step=1; step<=5; step++) {
|
||||
await send('Input.dispatchMouseEvent', {type:'mouseMoved', x:start.x+dx*step/5, y:start.y+dy*step/5, button:'left', buttons:1}, session);
|
||||
await delay(40);
|
||||
}
|
||||
await send('Input.dispatchMouseEvent', {type:'mouseReleased', x:start.x+dx, y:start.y+dy, button:'left', clickCount:1}, session);
|
||||
await delay(800);
|
||||
};
|
||||
// Native content-sized graphs need not fit on one screen. Verify offscreen
|
||||
// nodes through actual pan gestures rather than assuming fixed node boxes.
|
||||
for (let pass=0; pass<10; pass++) {
|
||||
const labels = (await semantics()).map(item => item.label);
|
||||
for (const needle of [...nodes, ...edgeLabels]) {
|
||||
if (labels.some(label => label.includes(needle))) seen.add(needle);
|
||||
}
|
||||
if ([...nodes, ...edgeLabels].every(label => seen.has(label)) &&
|
||||
(await nodeRect('Success'))?.width > 0) break;
|
||||
await drag({x:900,y:300}, -500);
|
||||
}
|
||||
for (const label of [...nodes, ...edgeLabels]) {
|
||||
if (!seen.has(label)) throw new Error(`Graph pan never revealed ${label}`);
|
||||
}
|
||||
if (!await clickLabel('Success')) throw new Error('Could not click Success terminal');
|
||||
await delay(800);
|
||||
const afterTerminal = await evaluate('document.body.innerText');
|
||||
if (!afterTerminal.includes('Selected: #success')) throw new Error(`terminal callback did not carry its key: ${afterTerminal}`);
|
||||
captures.push(await capture('selected-terminal',1280,800));
|
||||
await send('Page.reload', {}, session);
|
||||
await delay(2500);
|
||||
await evaluate("document.querySelector('flt-semantics-placeholder')?.click()");
|
||||
await delay(1500);
|
||||
// A real drag on a phone viewport, where the measured graph is wider than
|
||||
// the viewport, must pan the stock InteractiveViewer: the node moves.
|
||||
await send('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 1, mobile: true }, session);
|
||||
await delay(1500);
|
||||
const before = await nodeRect('plan');
|
||||
const start = { x: before.x + before.width / 2, y: before.y + before.height / 2 };
|
||||
await drag(start, -40, -10);
|
||||
const after = await nodeRect('plan');
|
||||
if (!after || (Math.abs(after.x - before.x) < 20 && Math.abs(after.y - before.y) < 20)) {
|
||||
throw new Error(`Drag did not pan the graph: ${JSON.stringify({ before, after })}`);
|
||||
}
|
||||
captures.push(await capture('panned-phone', 390, 844));
|
||||
console.log(JSON.stringify({ variant, scheme, scale, rects, captures }, 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(resolve => {
|
||||
server.close(resolve);
|
||||
server.closeAllConnections();
|
||||
});
|
||||
await rm(profile, { recursive: true, force: true });
|
||||
}
|
||||
Reference in New Issue
Block a user