feat(app): add native authored stage definition pane
This commit is contained in:
@@ -0,0 +1,212 @@
|
||||
import 'graph_definition.dart';
|
||||
import 'graph_protocol.dart';
|
||||
|
||||
/// The read-only definition of one declared stage, as field rows.
|
||||
///
|
||||
/// Mirrors `stageDefinitionFields`/`terminalFields` from `web/src/graph.js`:
|
||||
/// the same labels, the same order, and the same rule that blank fields are
|
||||
/// omitted rather than shown as an empty row. Pure data only: nothing here
|
||||
/// reads run visits, so a definition can be inspected without claiming that a
|
||||
/// stage executed.
|
||||
class StageDefinitionField {
|
||||
const StageDefinitionField(this.label, this.value, {this.block = false});
|
||||
|
||||
final String label;
|
||||
final String value;
|
||||
|
||||
/// Multi-line content (prompt, output, outcomes, tools, memory, routes).
|
||||
final bool block;
|
||||
}
|
||||
|
||||
/// The one stage declaration [key] names, or null when this version does not
|
||||
/// declare it.
|
||||
///
|
||||
/// The last declaration wins, matching the web pane's `new Map(stages)`.
|
||||
Map<String, dynamic>? stageDefinitionFor(dynamic graph, String key) {
|
||||
final stages = graph is Map ? graph['stages'] : null;
|
||||
if (stages is! List) return null;
|
||||
Map<String, dynamic>? found;
|
||||
for (final stage in stages) {
|
||||
if (stage is Map && _text(stage['key']) == key) {
|
||||
found = Map<String, dynamic>.from(stage);
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
/// A stage's effective type: a blank/absent type reads `model`, exactly as
|
||||
/// `effectiveStageType` in `web/src/templates.js`.
|
||||
String effectiveStageType(dynamic type) {
|
||||
final text = _text(type);
|
||||
return text.trim().isEmpty ? 'model' : text;
|
||||
}
|
||||
|
||||
/// A config key's display label (`configLabel` in `web/src/graph.js`).
|
||||
String stageConfigLabel(String key) {
|
||||
switch (key) {
|
||||
case 'provider':
|
||||
return 'Provider';
|
||||
case 'model':
|
||||
return 'Model';
|
||||
case 'retries':
|
||||
return 'Retries';
|
||||
case 'timeout':
|
||||
return 'Timeout';
|
||||
case 'budget_usd':
|
||||
return 'Budget (USD)';
|
||||
case 'budget_tokens':
|
||||
return 'Budget (tokens)';
|
||||
case 'harness':
|
||||
return 'Harness';
|
||||
default:
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
/// The definition fields of one stage declaration, in the web pane's order.
|
||||
///
|
||||
/// Only non-blank fields are emitted. Unknown keys are deliberately not
|
||||
/// interpreted here; the pane keeps the stage's raw JSON so they stay visible.
|
||||
List<StageDefinitionField> stageDefinitionFields(dynamic stage) {
|
||||
if (stage is! Map) return const <StageDefinitionField>[];
|
||||
final fields = <StageDefinitionField>[
|
||||
StageDefinitionField('Type', effectiveStageType(stage['type'])),
|
||||
];
|
||||
|
||||
final prompt = _text(stage['prompt']);
|
||||
if (prompt.trim().isNotEmpty) {
|
||||
fields.add(StageDefinitionField('Prompt', prompt, block: true));
|
||||
}
|
||||
final output = _text(stage['output']);
|
||||
if (output.trim().isNotEmpty) {
|
||||
fields.add(StageDefinitionField('Output', output, block: true));
|
||||
}
|
||||
|
||||
final edges = stage['edges'];
|
||||
final outcomes = <String>[];
|
||||
for (final outcome in stageOutcomes(stage)) {
|
||||
final raw = edges is Map ? edges[outcome] : null;
|
||||
final target = resolveTarget(outcome, raw == null ? '' : _text(raw)) ?? '';
|
||||
final suffix = isTerminalTarget(target) ? ' (terminal)' : '';
|
||||
outcomes.add('$outcome \u2192 ${nodeLabel(target)}$suffix');
|
||||
}
|
||||
if (outcomes.isNotEmpty) {
|
||||
fields.add(
|
||||
StageDefinitionField('Outcomes', outcomes.join('\n'), block: true),
|
||||
);
|
||||
}
|
||||
|
||||
final configs = stage['configs'];
|
||||
if (configs is Map) {
|
||||
final entries = configs.entries.toList()
|
||||
..sort((a, b) => _text(a.key).compareTo(_text(b.key)));
|
||||
for (final entry in entries) {
|
||||
final value = _text(entry.value);
|
||||
if (entry.value == null || value.trim().isEmpty) continue;
|
||||
fields.add(
|
||||
StageDefinitionField(stageConfigLabel(_text(entry.key)), value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final blocks = stage['blocks'];
|
||||
if (blocks is Map) {
|
||||
final tools = blocks['tools'];
|
||||
final text = _text(tools);
|
||||
if (tools != null && text.trim().isNotEmpty) {
|
||||
fields.add(StageDefinitionField('Tools', text, block: true));
|
||||
}
|
||||
}
|
||||
|
||||
final limits = stage['limits'];
|
||||
if (limits is Map) {
|
||||
final maxVisits = limits['max_visits'];
|
||||
final visits = maxVisits is num
|
||||
? maxVisits
|
||||
: num.tryParse(_text(maxVisits));
|
||||
if (visits != null && visits > 0) {
|
||||
fields.add(StageDefinitionField('Max visits', _text(maxVisits)));
|
||||
}
|
||||
final on = _items(limits['on']);
|
||||
if (on.isNotEmpty) {
|
||||
fields.add(StageDefinitionField('Limit on', on.join(', ')));
|
||||
}
|
||||
}
|
||||
|
||||
final memory = stage['memory'];
|
||||
if (memory is Map && memory.isNotEmpty) {
|
||||
fields.add(
|
||||
StageDefinitionField(
|
||||
'Memory',
|
||||
[
|
||||
for (final entry in memory.entries)
|
||||
'${_text(entry.key)}: ${_text(entry.value)}',
|
||||
].join('\n'),
|
||||
block: true,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final notify = stage['notify'];
|
||||
if (notify is Map) {
|
||||
final on = _items(notify['on']);
|
||||
if (on.isNotEmpty) {
|
||||
fields.add(StageDefinitionField('Notify on', on.join(', ')));
|
||||
}
|
||||
final destination = _text(notify['destination']);
|
||||
if (destination.trim().isNotEmpty) {
|
||||
fields.add(StageDefinitionField('Notify destination', destination));
|
||||
}
|
||||
final artifacts = _items(notify['artifacts']);
|
||||
if (artifacts.isNotEmpty) {
|
||||
fields.add(
|
||||
StageDefinitionField('Notify artifacts', artifacts.join(', ')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
||||
/// A terminal pane's fields: the declared routes into that target.
|
||||
///
|
||||
/// A terminal is part of the definition, not evidence that a run reached it.
|
||||
List<StageDefinitionField> terminalDefinitionFields(dynamic graph, String key) {
|
||||
final lines = <String>[
|
||||
for (final edge in graphEdges(graph))
|
||||
if (edge.target == key)
|
||||
'${edge.source} \u00b7 ${edge.label} \u2192 ${nodeLabel(key)}',
|
||||
];
|
||||
return lines.isEmpty
|
||||
? const <StageDefinitionField>[]
|
||||
: <StageDefinitionField>[
|
||||
StageDefinitionField(
|
||||
'Incoming routes',
|
||||
lines.join('\n'),
|
||||
block: true,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
List<String> _items(dynamic value) {
|
||||
if (value is! List) return const <String>[];
|
||||
return <String>[for (final item in value) _text(item)];
|
||||
}
|
||||
|
||||
/// Web `String(value)` for the values the definition fields carry. Numbers
|
||||
/// that are integral render without a trailing `.0`, as JavaScript does; a
|
||||
/// complex value stays visible but its exact shape is preserved by the raw
|
||||
/// JSON section instead.
|
||||
String _text(dynamic value) {
|
||||
if (value == null) return '';
|
||||
if (value is String) return value;
|
||||
if (value is num) {
|
||||
if (value.isFinite &&
|
||||
value == value.roundToDouble() &&
|
||||
value.abs() < 1e21) {
|
||||
return value.toInt().toString();
|
||||
}
|
||||
return value.toString();
|
||||
}
|
||||
return value.toString();
|
||||
}
|
||||
@@ -0,0 +1,241 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../ui/adaptive/host.dart';
|
||||
import '../domain/graph_protocol.dart';
|
||||
import '../domain/stage_definition.dart';
|
||||
|
||||
/// Wording for a stage that this pinned definition does not declare.
|
||||
const String unknownStageDefinition =
|
||||
'This stage is not declared in this pipeline version. '
|
||||
'No definition has been reconstructed.';
|
||||
|
||||
/// The web pane's message when a node has no recorded stage or incoming routes.
|
||||
const String noStageDefinitionDetails = 'No details recorded for this node.';
|
||||
|
||||
/// Terminals are definition targets; this pane never presents one as evidence.
|
||||
const String terminalDefinitionNote =
|
||||
'Success and Failure are definition targets, not recorded visits. '
|
||||
'This pane shows where the definition routes.';
|
||||
|
||||
/// The raw section's heading: unknown stage fields stay visible and selectable.
|
||||
const String rawStageDefinitionTitle = 'Raw stage definition';
|
||||
|
||||
/// A read-only native view of one stage's declared definition.
|
||||
///
|
||||
/// [graph] is the graph pinned for exactly [pipelineId]/[version] and
|
||||
/// [stageKey] is a node key (a stage or `#success`/`#failure`). Nothing is
|
||||
/// fetched and no run visit is read, so the pane cannot imply that the stage
|
||||
/// executed. Unknown stage declarations get an explicit missing state; every
|
||||
/// declared stage also keeps its exact JSON below the structured fields.
|
||||
class StageDefinitionView extends StatelessWidget {
|
||||
const StageDefinitionView({
|
||||
super.key,
|
||||
required this.graph,
|
||||
required this.stageKey,
|
||||
required this.pipelineId,
|
||||
required this.pipelineName,
|
||||
required this.version,
|
||||
});
|
||||
|
||||
final JsonMap graph;
|
||||
final String stageKey;
|
||||
final int pipelineId;
|
||||
final String pipelineName;
|
||||
final int version;
|
||||
|
||||
String get _identity =>
|
||||
'${pipelineName.isEmpty ? 'Pipeline' : pipelineName} \u00b7 v$version';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final style = _StageDefinitionStyle.of(context);
|
||||
final stage = stageDefinitionFor(graph, stageKey);
|
||||
final terminal = isTerminalTarget(stageKey);
|
||||
final fields = stage != null
|
||||
? stageDefinitionFields(stage)
|
||||
: terminal
|
||||
? terminalDefinitionFields(graph, stageKey)
|
||||
: const <StageDefinitionField>[];
|
||||
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
Text(_identity, style: style.muted),
|
||||
const SizedBox(height: 16),
|
||||
if (stage == null && !terminal)
|
||||
Text(unknownStageDefinition, style: style.value)
|
||||
else ...[
|
||||
if (terminal) ...[
|
||||
Text(terminalDefinitionNote, style: style.muted),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
for (final field in fields)
|
||||
_StageDefinitionFieldView(field: field, style: style),
|
||||
if (terminal && fields.isEmpty)
|
||||
Text(noStageDefinitionDetails, style: style.muted),
|
||||
if (stage != null) ...[
|
||||
const SizedBox(height: 8),
|
||||
Text(rawStageDefinitionTitle, style: style.heading),
|
||||
const SizedBox(height: 8),
|
||||
_SelectableDefinitionText(
|
||||
value: const JsonEncoder.withIndent(' ').convert(stage),
|
||||
style: style.value,
|
||||
),
|
||||
],
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens the platform's native full-screen stage-definition page.
|
||||
///
|
||||
/// The page owns the single navigation bar and its standard back control; the
|
||||
/// caller only supplies the pinned graph and identity. This is the hook the
|
||||
/// pipeline graph uses when a node is selected.
|
||||
Future<void> openStageDefinition(
|
||||
BuildContext context, {
|
||||
required JsonMap graph,
|
||||
required String stageKey,
|
||||
required int pipelineId,
|
||||
required String pipelineName,
|
||||
required int version,
|
||||
}) {
|
||||
final view = StageDefinitionView(
|
||||
graph: graph,
|
||||
stageKey: stageKey,
|
||||
pipelineId: pipelineId,
|
||||
pipelineName: pipelineName,
|
||||
version: version,
|
||||
);
|
||||
final settings = RouteSettings(
|
||||
name: 'stage-definition/$pipelineId/$version/$stageKey',
|
||||
);
|
||||
// A terminal is a definition target, not its protocol key: the web pane
|
||||
// titles it with `nodeDisplayLabel` (`Failure`/`Success`).
|
||||
final title = '${nodeDisplayLabel(stageKey)} definition';
|
||||
final route = usesCupertinoHost(context)
|
||||
? CupertinoPageRoute<void>(
|
||||
settings: settings,
|
||||
builder: (_) => CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(middle: Text(title)),
|
||||
child: SafeArea(child: view),
|
||||
),
|
||||
)
|
||||
: MaterialPageRoute<void>(
|
||||
settings: settings,
|
||||
builder: (_) => Scaffold(
|
||||
appBar: AppBar(title: Text(title)),
|
||||
body: SafeArea(child: view),
|
||||
),
|
||||
);
|
||||
return Navigator.of(context).push(route);
|
||||
}
|
||||
|
||||
/// One labelled field: a compact row for scalars, a selectable block when the
|
||||
/// value is multi-line authored text.
|
||||
class _StageDefinitionFieldView extends StatelessWidget {
|
||||
const _StageDefinitionFieldView({required this.field, required this.style});
|
||||
|
||||
final StageDefinitionField field;
|
||||
final _StageDefinitionStyle style;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(field.label, style: style.label),
|
||||
const SizedBox(height: 4),
|
||||
if (field.block)
|
||||
_SelectableDefinitionText(value: field.value, style: style.value)
|
||||
else
|
||||
Text(field.value, style: style.value),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Authored definition text in the host's selectable body.
|
||||
///
|
||||
/// The semantic leaf carries the exact value: Flutter web maps a
|
||||
/// [SelectableText] to an empty read-only field, so without this a screen
|
||||
/// reader (and a browser check) sees only its label. The child keeps native
|
||||
/// pointer selection and the host's system typography.
|
||||
///
|
||||
/// The strut is derived from that same host style and forced, so a glyph the
|
||||
/// host font lacks (the outcomes arrow `→` is one example) cannot pull in a
|
||||
/// fallback font with taller metrics and double-space only that block. It is
|
||||
/// the host's own line metrics, not a font override or a fixed height.
|
||||
class _SelectableDefinitionText extends StatelessWidget {
|
||||
const _SelectableDefinitionText({required this.value, required this.style});
|
||||
|
||||
final String value;
|
||||
final TextStyle style;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Semantics(
|
||||
label: value,
|
||||
child: ExcludeSemantics(
|
||||
child: SelectableText(
|
||||
value,
|
||||
style: style,
|
||||
strutStyle: StrutStyle.fromTextStyle(style, forceStrutHeight: true),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Host text roles only: no palette, font family or explicit size.
|
||||
class _StageDefinitionStyle {
|
||||
const _StageDefinitionStyle({
|
||||
required this.label,
|
||||
required this.value,
|
||||
required this.muted,
|
||||
required this.heading,
|
||||
});
|
||||
|
||||
factory _StageDefinitionStyle.of(BuildContext context) {
|
||||
if (usesCupertinoHost(context)) {
|
||||
final theme = CupertinoTheme.of(context);
|
||||
final secondary = CupertinoColors.secondaryLabel.resolveFrom(context);
|
||||
return _StageDefinitionStyle(
|
||||
label: theme.textTheme.tabLabelTextStyle.copyWith(color: secondary),
|
||||
// SelectableText needs a style it can merge into the default text
|
||||
// style; Cupertino's textStyle is a complete style with `inherit: false`
|
||||
// and no baseline.
|
||||
value: theme.textTheme.textStyle.copyWith(inherit: true),
|
||||
muted: theme.textTheme.textStyle.copyWith(
|
||||
inherit: true,
|
||||
color: secondary,
|
||||
),
|
||||
heading: theme.textTheme.navTitleTextStyle,
|
||||
);
|
||||
}
|
||||
final theme = Theme.of(context);
|
||||
return _StageDefinitionStyle(
|
||||
label: (theme.textTheme.labelMedium ?? const TextStyle()).copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
value: theme.textTheme.bodyMedium ?? const TextStyle(),
|
||||
muted: (theme.textTheme.bodySmall ?? const TextStyle()).copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
heading: theme.textTheme.titleSmall ?? const TextStyle(),
|
||||
);
|
||||
}
|
||||
|
||||
final TextStyle label;
|
||||
final TextStyle value;
|
||||
final TextStyle muted;
|
||||
final TextStyle heading;
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
# P2 stage: read-only definition pane
|
||||
|
||||
The definition graph can now open one stage's authored definition without
|
||||
reading a run. `StageDefinitionView` receives the graph JsonMap pinned for a
|
||||
pipeline/version, a stage key and that identity; it performs no request and
|
||||
shows no visit, status or session data. `openStageDefinition` pushes the
|
||||
platform's normal page with one navigation bar and its standard back control,
|
||||
for the manager's graph hook.
|
||||
|
||||
## Behaviour
|
||||
|
||||
- Fields match `stageDefinitionFields`/`terminalFields` in `web/src/graph.js`:
|
||||
Type, Prompt, Output, Outcomes (ordered, targets resolved, terminals marked),
|
||||
configs in sorted order with the web labels, Tools, Max visits, Limit on,
|
||||
Memory, Notify on/destination/artifacts. Only non-blank fields are emitted.
|
||||
- `effectiveStageType` keeps the web rule that a blank/absent type reads
|
||||
`model`; no other default is invented.
|
||||
- A terminal (`#success`/`#failure`) lists its incoming definition routes and
|
||||
says explicitly that these are definition targets, not recorded visits. Its
|
||||
page is titled with the web's display label (`Failure definition` /
|
||||
`Success definition`, via `nodeDisplayLabel`), never the raw `#failure` key.
|
||||
- A stage key this version does not declare gets an explicit missing state. No
|
||||
fields, terminal note or raw JSON are fabricated.
|
||||
- Every declared stage also shows its exact pretty-printed stage JSON in a
|
||||
selectable raw section, so unknown/future fields stay available. The raw
|
||||
value is the only source for those keys; the structured rows only interpret
|
||||
documented ones.
|
||||
- Host text roles only: Material `Theme`/`ColorScheme`, Cupertino
|
||||
`CupertinoTheme`/`CupertinoColors`, system fonts, light/dark and text scale
|
||||
follow the host. No palette, font family, fixed component size or custom
|
||||
control clone.
|
||||
- Selectable body blocks force a strut derived from that same host style.
|
||||
Without it, a glyph the host font lacks (the outcomes arrow `→`) pulls in a
|
||||
fallback font with taller metrics and doubles only that block's leading. The
|
||||
strut is the host's own family/size, not a font override or fixed height, and
|
||||
selection stays native.
|
||||
|
||||
## UI review fixes
|
||||
|
||||
- Cupertino `Outcomes` leading: the block's rendered line pitch matched a
|
||||
fallback font (34 px between outcome lines against 19 px for `Tools` at 1×,
|
||||
68 px against 30 px at 2×). With the forced host strut the line pitch is
|
||||
19 px for both blocks at 1× and 37/39 px at 2×, and the semantics block
|
||||
heights are equal (72/72 at 1×, 123/123 at 2×). The 390×844 / 2× wrap of
|
||||
`(terminal)` now sits on the same rhythm as the line above it.
|
||||
- Terminal titles: `#failure definition`/`#success definition` became
|
||||
`Failure definition`/`Success definition`. The Cupertino widget test now
|
||||
asserts `Success definition` and the absence of the raw key; a Material
|
||||
test covers `Failure definition`; the browser probe fails if `#failure`
|
||||
reappears in the terminal page or if the outcomes/Tools block heights
|
||||
diverge.
|
||||
|
||||
## Integration dependency
|
||||
|
||||
`PipelineDetail` still has no `graph` field, so the manager's graph hook must
|
||||
supply the pinned JsonMap it already draws. This item deliberately does not
|
||||
change the pipeline repository/model. There is no run-mode latest-visit pane
|
||||
here; recorded visits remain the separate run-graph/audit work.
|
||||
|
||||
## Checks run
|
||||
|
||||
- `flutter test test/features/graph` - 140 tests passed (138 before; two new
|
||||
regression tests for the terminal title and the forced host strut).
|
||||
- `flutter analyze` - no issues.
|
||||
- `dart format --set-exit-if-changed` on the five Dart files - 0 changed.
|
||||
- `flutter build web` (normal app) - succeeded.
|
||||
- `flutter build web -t tool/stage_definition_probe.dart` - succeeded.
|
||||
- `node --check tool/stage_definition_probe.mjs`.
|
||||
- Real Chrome probe, 1280x900: material dark/light 1x, Cupertino dark/light 1x
|
||||
and Cupertino dark/light 2x. Each case passed 9 checks and produced 5
|
||||
captures. The probe now compares the `Outcomes` and `Tools` semantics block
|
||||
heights (equal in every case), fails on any raw `#failure` in the terminal
|
||||
page, asserts `Failure definition`, and scrolls to the pane bottom so the
|
||||
raw capture really shows `future_field.kept` and `fallback_error`.
|
||||
- Real Chrome probe, 390x844: Cupertino dark 2x and Material light 1x. Each
|
||||
passed 8 checks and produced 5 captures, including the `(terminal)` wrap and
|
||||
the raw JSON at the narrow width. The accent-free rhythm check is skipped at
|
||||
this width because the outcomes value wraps to three lines.
|
||||
- Pixel measurement of the final captures: Cupertino 1x outcomes 19 px vs
|
||||
Tools 19 px (was 34 vs 19); Cupertino 2x outcomes 37 px vs Tools 39 px (was
|
||||
68 vs 30); Material 1x outcomes 19 px vs Tools 20 px.
|
||||
|
||||
Captures (under the run's shared artifact folder
|
||||
`public/stage-definition/`): `<host>-<scheme>-<scale>x-{declared,raw,terminal,unknown,closed}.png`
|
||||
for the six 1280x900 cases, and the same names prefixed with `stage-definition-`
|
||||
under `narrow-390x844/` for the two 390x844 cases. The raw capture is the real
|
||||
bottom-scrolled state and its sha1 differs from the declared capture in every
|
||||
case.
|
||||
|
||||
Mobile (Android/iOS) remains unverified; only web was run.
|
||||
|
||||
## Manager completion after result-validation failure
|
||||
|
||||
Run 77's final Review visit returned no parseable outcome, so the runner retained
|
||||
its edits and failed the stage without undoing them. No retry was started. The
|
||||
manager verified the dirty files were the reviewed slice only, ran the focused
|
||||
domain/view tests (10 pass), and drove the real-browser probe on both hosts:
|
||||
Material light 1x desktop and Cupertino dark 2x 390x844. Each run passed and
|
||||
produced five captures (declared, raw, terminal, unknown, closed) under approved
|
||||
temp/stage-def-browser. The Cupertino dark 2x declared pane was inspected: pinned
|
||||
identity, wrapping outcome line, native type roles, readable secondary labels.
|
||||
This remains a definition pane only; run visits and the pipeline graph hook are
|
||||
separate work.
|
||||
@@ -0,0 +1,159 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/graph/domain/stage_definition.dart';
|
||||
|
||||
import 'graph_fixtures.dart';
|
||||
|
||||
JsonMap _stage() => <String, dynamic>{
|
||||
'key': 'build',
|
||||
'prompt': 'Implement the planned change.',
|
||||
'output': 'A committed change.',
|
||||
'edges': <String, String?>{
|
||||
'success': 'audit',
|
||||
'approved': '#',
|
||||
'error': '#failure',
|
||||
},
|
||||
'fallback_error': true,
|
||||
'configs': <String, dynamic>{
|
||||
'provider': 'openai',
|
||||
'model': 'gpt-5',
|
||||
'budget_usd': 12.5,
|
||||
'retries': 2,
|
||||
'harness': 'codex',
|
||||
'timeout': '15m',
|
||||
'skipped_blank': ' ',
|
||||
'skipped_null': null,
|
||||
},
|
||||
'blocks': <String, dynamic>{'tools': 'shell\nread_file'},
|
||||
'limits': <String, dynamic>{
|
||||
'max_visits': 3,
|
||||
'on': <String>['success', 'error'],
|
||||
},
|
||||
'memory': <String, dynamic>{'context': 'latest', 'notes': 'keep'},
|
||||
'notify': <String, dynamic>{
|
||||
'on': <String>['failure'],
|
||||
'destination': 'ops@example.test',
|
||||
'artifacts': <String>['run.log'],
|
||||
},
|
||||
'custom_flag': true,
|
||||
};
|
||||
|
||||
void main() {
|
||||
group('stage fields', () {
|
||||
test('follow the web pane order, labels and blank-field rules', () {
|
||||
final fields = stageDefinitionFields(_stage());
|
||||
|
||||
expect(fields.map((field) => field.label), <String>[
|
||||
'Type',
|
||||
'Prompt',
|
||||
'Output',
|
||||
'Outcomes',
|
||||
'Budget (USD)',
|
||||
'Harness',
|
||||
'Model',
|
||||
'Provider',
|
||||
'Retries',
|
||||
'Timeout',
|
||||
'Tools',
|
||||
'Max visits',
|
||||
'Limit on',
|
||||
'Memory',
|
||||
'Notify on',
|
||||
'Notify destination',
|
||||
'Notify artifacts',
|
||||
]);
|
||||
expect(fields.first.value, 'model');
|
||||
expect(fields[1].block, isTrue);
|
||||
expect(fields[2].value, 'A committed change.');
|
||||
expect(
|
||||
fields[3].value,
|
||||
'success → audit\n'
|
||||
'approved → SUCCESS (terminal)\n'
|
||||
'error → FAILURE (terminal)',
|
||||
);
|
||||
expect(fields[4].value, '12.5');
|
||||
expect(fields[5].value, 'codex');
|
||||
expect(fields[10].value, 'shell\nread_file');
|
||||
expect(fields[11].value, '3');
|
||||
expect(fields[12].value, 'success, error');
|
||||
expect(fields[13].value, 'context: latest\nnotes: keep');
|
||||
expect(fields[14].value, 'failure');
|
||||
expect(fields[15].value, 'ops@example.test');
|
||||
expect(fields[16].value, 'run.log');
|
||||
});
|
||||
|
||||
test('a blank or absent type reads model; an authored type is kept', () {
|
||||
expect(effectiveStageType(null), 'model');
|
||||
expect(effectiveStageType(' '), 'model');
|
||||
expect(effectiveStageType('shell'), 'shell');
|
||||
expect(
|
||||
stageDefinitionFields(<String, dynamic>{'key': 'a'}).single.value,
|
||||
'model',
|
||||
);
|
||||
});
|
||||
|
||||
test('config keys outside the known labels are shown verbatim', () {
|
||||
final fields = stageDefinitionFields(<String, dynamic>{
|
||||
'key': 'a',
|
||||
'configs': <String, dynamic>{'temperature': 0},
|
||||
});
|
||||
|
||||
expect(fields.map((field) => field.label), contains('temperature'));
|
||||
expect(
|
||||
fields.firstWhere((field) => field.label == 'temperature').value,
|
||||
'0',
|
||||
);
|
||||
});
|
||||
|
||||
test('zero visits and missing limits emit no invented rows', () {
|
||||
final fields = stageDefinitionFields(<String, dynamic>{
|
||||
'key': 'a',
|
||||
'limits': <String, dynamic>{'max_visits': 0, 'on': <String>[]},
|
||||
});
|
||||
|
||||
expect(fields.map((field) => field.label), <String>['Type']);
|
||||
});
|
||||
|
||||
test(
|
||||
'the stage lookup preserves unknown keys and the last declaration',
|
||||
() {
|
||||
final graph = <String, dynamic>{
|
||||
'stages': <dynamic>[
|
||||
<String, dynamic>{'key': 'build', 'type': 'old'},
|
||||
_stage(),
|
||||
],
|
||||
};
|
||||
final stage = stageDefinitionFor(graph, 'build');
|
||||
|
||||
expect(stage?['type'], isNull);
|
||||
expect(effectiveStageType(stage?['type']), 'model');
|
||||
expect(stage?['custom_flag'], isTrue);
|
||||
expect(stageDefinitionFor(graph, 'ghost'), isNull);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('terminal fields', () {
|
||||
test('list incoming definition routes, including the fallback marker', () {
|
||||
expect(terminalDefinitionFields(linearGraph(), '#failure'), hasLength(1));
|
||||
final fields = terminalDefinitionFields(linearGraph(), '#failure');
|
||||
expect(
|
||||
fields.single.value,
|
||||
'plan · error* → FAILURE\nship · error → FAILURE',
|
||||
);
|
||||
expect(fields.single.block, isTrue);
|
||||
expect(
|
||||
terminalDefinitionFields(linearGraph(), '#success').single.value,
|
||||
'ship · success → SUCCESS',
|
||||
);
|
||||
});
|
||||
|
||||
test('a terminal with no routes has no fields to invent', () {
|
||||
expect(
|
||||
terminalDefinitionFields(<String, dynamic>{}, '#success'),
|
||||
isEmpty,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,286 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/graph/domain/stage_definition.dart';
|
||||
import 'package:pipelines_app/features/graph/widgets/stage_definition_view.dart';
|
||||
|
||||
JsonMap _graph() => <String, dynamic>{
|
||||
'stages': <dynamic>[
|
||||
<String, dynamic>{
|
||||
'key': 'plan',
|
||||
'type': 'model',
|
||||
'prompt': 'Plan the change.',
|
||||
'edges': <String, String?>{'success': 'build', 'error': '#'},
|
||||
'fallback_error': true,
|
||||
'configs': <String, dynamic>{'provider': 'openai', 'model': 'gpt-5'},
|
||||
'limits': <String, dynamic>{
|
||||
'max_visits': 2,
|
||||
'on': <String>['error'],
|
||||
},
|
||||
'future_field': <String, dynamic>{'kept': true},
|
||||
},
|
||||
<String, dynamic>{
|
||||
'key': 'build',
|
||||
'type': 'shell',
|
||||
'edges': <String, String?>{'success': '#success', 'error': '#failure'},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
Widget _material(Widget child) => MaterialApp(
|
||||
home: Scaffold(
|
||||
appBar: AppBar(title: const Text('plan definition')),
|
||||
body: child,
|
||||
),
|
||||
);
|
||||
|
||||
Widget _cupertino(Widget child, {bool dark = false}) => CupertinoApp(
|
||||
theme: CupertinoThemeData(
|
||||
brightness: dark ? Brightness.dark : Brightness.light,
|
||||
),
|
||||
home: CupertinoPageScaffold(child: child),
|
||||
);
|
||||
|
||||
StageDefinitionView _view({String key = 'plan'}) => StageDefinitionView(
|
||||
graph: _graph(),
|
||||
stageKey: key,
|
||||
pipelineId: 41,
|
||||
pipelineName: 'Demo pipeline',
|
||||
version: 7,
|
||||
);
|
||||
|
||||
/// Finds visible text, including SelectableText's editable body.
|
||||
Finder _text(String value) => find.byWidgetPredicate(
|
||||
(widget) =>
|
||||
(widget is Text && widget.data == value) ||
|
||||
(widget is SelectableText && widget.data == value),
|
||||
);
|
||||
|
||||
void main() {
|
||||
testWidgets('a declared stage shows pinned identity and web field values', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(_material(_view()));
|
||||
|
||||
expect(_text('Demo pipeline · v7'), findsOneWidget);
|
||||
expect(_text('model'), findsOneWidget);
|
||||
expect(_text('Plan the change.'), findsOneWidget);
|
||||
expect(
|
||||
_text('success → build\nerror → FAILURE (terminal)'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(_text('Provider'), findsOneWidget);
|
||||
expect(_text('openai'), findsOneWidget);
|
||||
expect(_text('Model'), findsOneWidget);
|
||||
expect(_text('gpt-5'), findsOneWidget);
|
||||
expect(_text('Max visits'), findsOneWidget);
|
||||
expect(_text('2'), findsOneWidget);
|
||||
expect(_text('Limit on'), findsOneWidget);
|
||||
expect(_text('error'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('the raw section keeps unknown fields exact and selectable', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(_material(_view()));
|
||||
|
||||
expect(_text(rawStageDefinitionTitle), findsOneWidget);
|
||||
final raw = tester
|
||||
.widgetList<SelectableText>(find.byType(SelectableText))
|
||||
.map((widget) => widget.data ?? '')
|
||||
.join('\n');
|
||||
expect(raw, contains('"future_field": {'));
|
||||
expect(raw, contains('"kept": true'));
|
||||
expect(raw, contains('"fallback_error": true'));
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('unknown stages get an explicit missing state, never defaults', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(_material(_view(key: 'ghost')));
|
||||
|
||||
expect(_text(unknownStageDefinition), findsOneWidget);
|
||||
expect(_text('model'), findsNothing);
|
||||
expect(_text(rawStageDefinitionTitle), findsNothing);
|
||||
expect(find.byType(SelectableText), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('terminals explain definition targets and incoming routes', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(_material(_view(key: '#failure')));
|
||||
|
||||
expect(_text(terminalDefinitionNote), findsOneWidget);
|
||||
expect(_text('Incoming routes'), findsOneWidget);
|
||||
expect(
|
||||
_text('plan · error* → FAILURE\nbuild · error → FAILURE'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(_text(rawStageDefinitionTitle), findsNothing);
|
||||
expect(_text('successful'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('Cupertino uses its theme roles in dark mode', (tester) async {
|
||||
late Color secondary;
|
||||
await tester.pumpWidget(
|
||||
_cupertino(
|
||||
Builder(
|
||||
builder: (context) {
|
||||
secondary = CupertinoColors.secondaryLabel.resolveFrom(context);
|
||||
return _view();
|
||||
},
|
||||
),
|
||||
dark: true,
|
||||
),
|
||||
);
|
||||
|
||||
final identity = tester.widget<Text>(_text('Demo pipeline · v7'));
|
||||
expect(identity.style?.color, secondary);
|
||||
expect(_text('Plan the change.'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('the Material helper opens one bar and Back closes it', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Builder(
|
||||
builder: (context) => Scaffold(
|
||||
body: TextButton(
|
||||
onPressed: () => openStageDefinition(
|
||||
context,
|
||||
graph: _graph(),
|
||||
stageKey: 'plan',
|
||||
pipelineId: 41,
|
||||
pipelineName: 'Demo pipeline',
|
||||
version: 7,
|
||||
),
|
||||
child: const Text('Open definition'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.text('Open definition'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(_text('plan definition'), findsOneWidget);
|
||||
expect(find.byType(AppBar), findsOneWidget);
|
||||
expect(find.byType(BackButton), findsOneWidget);
|
||||
final route = ModalRoute.of(
|
||||
tester.element(find.byType(StageDefinitionView)),
|
||||
);
|
||||
expect(route?.settings.name, 'stage-definition/41/7/plan');
|
||||
|
||||
await tester.pageBack();
|
||||
await tester.pumpAndSettle();
|
||||
expect(_text('Open definition'), findsOneWidget);
|
||||
expect(find.byType(StageDefinitionView), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('the Cupertino helper opens one native bar and Back closes it', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
CupertinoApp(
|
||||
home: Builder(
|
||||
builder: (context) => CupertinoPageScaffold(
|
||||
child: CupertinoButton(
|
||||
onPressed: () => openStageDefinition(
|
||||
context,
|
||||
graph: _graph(),
|
||||
stageKey: '#success',
|
||||
pipelineId: 41,
|
||||
pipelineName: 'Demo pipeline',
|
||||
version: 7,
|
||||
),
|
||||
child: const Text('Open terminal'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.text('Open terminal'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(_text('Success definition'), findsOneWidget);
|
||||
expect(_text('#success definition'), findsNothing);
|
||||
expect(find.byType(CupertinoNavigationBar), findsOneWidget);
|
||||
expect(find.byType(CupertinoNavigationBarBackButton), findsOneWidget);
|
||||
expect(_text('Incoming routes'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byType(CupertinoNavigationBarBackButton));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_text('Open terminal'), findsOneWidget);
|
||||
expect(find.byType(StageDefinitionView), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('the Material helper titles a terminal with its display label', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Builder(
|
||||
builder: (context) => Scaffold(
|
||||
body: TextButton(
|
||||
onPressed: () => openStageDefinition(
|
||||
context,
|
||||
graph: _graph(),
|
||||
stageKey: '#failure',
|
||||
pipelineId: 41,
|
||||
pipelineName: 'Demo pipeline',
|
||||
version: 7,
|
||||
),
|
||||
child: const Text('Open failure'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.text('Open failure'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(_text('Failure definition'), findsOneWidget);
|
||||
expect(_text('#failure definition'), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('selectable blocks force the host strut for one line rhythm', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(_cupertino(_view()));
|
||||
|
||||
final selectable = tester
|
||||
.widgetList<SelectableText>(find.byType(SelectableText))
|
||||
.toList();
|
||||
expect(selectable.length, greaterThanOrEqualTo(2));
|
||||
for (final widget in selectable) {
|
||||
final strut = widget.strutStyle;
|
||||
expect(strut, isNotNull);
|
||||
// The host's own metrics, forced: a fallback glyph cannot widen a block.
|
||||
expect(strut!.forceStrutHeight, isTrue);
|
||||
expect(strut.fontFamily, widget.style?.fontFamily);
|
||||
expect(strut.fontSize, widget.style?.fontSize);
|
||||
}
|
||||
final outcomes = selectable.firstWhere(
|
||||
(widget) => (widget.data ?? '').contains('success → build'),
|
||||
);
|
||||
final raw = selectable.firstWhere(
|
||||
(widget) => (widget.data ?? '').startsWith('{'),
|
||||
);
|
||||
expect(outcomes.strutStyle, raw.strutStyle);
|
||||
});
|
||||
|
||||
test('field labels are the web words', () {
|
||||
expect(stageConfigLabel('budget_usd'), 'Budget (USD)');
|
||||
expect(stageConfigLabel('budget_tokens'), 'Budget (tokens)');
|
||||
expect(stageConfigLabel('custom'), 'custom');
|
||||
});
|
||||
}
|
||||
@@ -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 });
|
||||
}
|
||||
Reference in New Issue
Block a user