413c923e77
Tapping or pressing Enter on a stage in the pipeline or run graph (inline and full screen) opens a card anchored to the node: type, config chips, tools, collapsed permissions, the prompt clamped with Show all (commands, gate or operator instructions by type), limits and routes, and for runs the status, visits, time, verdict, handoff and failure. Open definition keeps the old tap target; Open visit the old run tap. It follows pan and zoom, closes on outside tap, Escape or the same node, and opens as a bottom sheet on a narrow viewport. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
422 lines
12 KiB
Dart
422 lines
12 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/semantics.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:pipelines_app/core/api_gateway.dart';
|
|
import 'package:pipelines_app/features/graph/domain/graph_protocol.dart';
|
|
import 'package:pipelines_app/features/graph/viewport/graph_expanded_view.dart';
|
|
import 'package:pipelines_app/features/graph/widgets/graph_stage_node.dart';
|
|
import 'package:pipelines_app/features/graph/widgets/run_graph_canvas.dart';
|
|
import 'package:pipelines_app/features/graph/widgets/run_graph_view.dart';
|
|
|
|
import '../domain/graph_fixtures.dart';
|
|
|
|
JsonMap _runningRun() => <String, dynamic>{
|
|
'id': 42,
|
|
'steps': <dynamic>[
|
|
step(
|
|
sequence: 1,
|
|
stage: 'plan',
|
|
status: 'completed',
|
|
outcome: 'success',
|
|
target: 'build',
|
|
),
|
|
step(
|
|
sequence: 2,
|
|
stage: 'build',
|
|
status: 'running',
|
|
startedAt: '2026-10-21T10:00:00Z',
|
|
),
|
|
],
|
|
'current_stage': 'build',
|
|
'executing': true,
|
|
};
|
|
|
|
JsonMap _finishedRun({String outcome = 'success', String target = '#'}) =>
|
|
<String, dynamic>{
|
|
'id': 43,
|
|
'steps': <dynamic>[
|
|
step(
|
|
sequence: 1,
|
|
stage: 'plan',
|
|
status: 'completed',
|
|
outcome: outcome,
|
|
target: target,
|
|
),
|
|
],
|
|
'current_stage': '',
|
|
'executing': false,
|
|
};
|
|
|
|
/// plan -> build -> ship, with the last recorded outcome resolving a terminal.
|
|
JsonMap _completedPath({bool failure = false}) => <String, dynamic>{
|
|
'id': 45,
|
|
'steps': <dynamic>[
|
|
step(
|
|
sequence: 1,
|
|
stage: 'plan',
|
|
status: 'completed',
|
|
outcome: 'success',
|
|
target: 'build',
|
|
),
|
|
step(
|
|
sequence: 2,
|
|
stage: 'build',
|
|
status: 'completed',
|
|
outcome: 'success',
|
|
target: 'ship',
|
|
),
|
|
step(
|
|
sequence: 3,
|
|
stage: 'ship',
|
|
status: 'completed',
|
|
outcome: failure ? 'error' : 'success',
|
|
target: '#',
|
|
),
|
|
],
|
|
'current_stage': '',
|
|
'executing': false,
|
|
};
|
|
|
|
Widget _materialHost(
|
|
JsonMap? graph,
|
|
JsonMap run, {
|
|
ValueChanged<String>? onSelected,
|
|
String? selected,
|
|
double scale = 1,
|
|
Size size = const Size(900, 700),
|
|
DateTime Function()? now,
|
|
bool disableAnimations = false,
|
|
}) {
|
|
return MaterialApp(
|
|
builder: (context, child) => MediaQuery(
|
|
data: MediaQuery.of(context).copyWith(
|
|
textScaler: TextScaler.linear(scale),
|
|
disableAnimations: disableAnimations,
|
|
),
|
|
child: child!,
|
|
),
|
|
home: Scaffold(
|
|
body: SizedBox(
|
|
width: size.width,
|
|
height: size.height,
|
|
child: RunGraphView(
|
|
graph: graph,
|
|
run: run,
|
|
selectedStage: selected,
|
|
onStageSelected: onSelected ?? (_) {},
|
|
now: now,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> _settle(WidgetTester tester) async {
|
|
await tester.pump();
|
|
await tester.pump();
|
|
await tester.pump();
|
|
}
|
|
|
|
Finder _node(String key) => find.byWidgetPredicate(
|
|
(widget) => widget is GraphStageNode && widget.node.key == key,
|
|
);
|
|
|
|
void _expectNoOverlaps(WidgetTester tester) {
|
|
final rects = <Rect>[
|
|
for (final element in find.byType(GraphStageNode).evaluate())
|
|
tester.getRect(find.byWidget(element.widget)),
|
|
];
|
|
for (var a = 0; a < rects.length; a += 1) {
|
|
for (var b = a + 1; b < rects.length; b += 1) {
|
|
expect(
|
|
rects[a].overlaps(rects[b]),
|
|
isFalse,
|
|
reason: 'nodes $a and $b overlap: ${rects[a]} and ${rects[b]}',
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
testWidgets('visited stages show recorded status and the legend', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(
|
|
_materialHost(
|
|
linearGraph(),
|
|
_runningRun(),
|
|
now: () => DateTime.utc(2026, 10, 21, 10, 2, 5),
|
|
),
|
|
);
|
|
await _settle(tester);
|
|
|
|
expect(find.text(runGraphExecuted), findsOneWidget);
|
|
expect(find.text(runGraphNotExecuted), findsOneWidget);
|
|
expect(
|
|
tester.widget<GraphStageNode>(_node('plan')).recordedStatus,
|
|
'completed',
|
|
);
|
|
expect(
|
|
tester.widget<GraphStageNode>(_node('build')).recordedStatus,
|
|
'running',
|
|
);
|
|
expect(tester.widget<GraphStageNode>(_node('ship')).recordedStatus, isNull);
|
|
expect(
|
|
tester.widget<GraphStageNode>(_node(failureEnd)).recordedStatus,
|
|
isNull,
|
|
);
|
|
expect(
|
|
tester.widget<GraphStageNode>(_node(successEnd)).recordedStatus,
|
|
isNull,
|
|
);
|
|
// The elapsed line exists only because this run is still executing.
|
|
expect(find.text('Current stage build · elapsed 2m 5s'), findsOneWidget);
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
|
|
testWidgets('the expanded run graph keeps the route legend', (tester) async {
|
|
await tester.pumpWidget(
|
|
_materialHost(linearGraph(), _runningRun(), disableAnimations: true),
|
|
);
|
|
await _settle(tester);
|
|
await tester.tap(find.byKey(const Key('graph-expand')));
|
|
await tester.pumpAndSettle();
|
|
|
|
final expanded = find.byType(GraphExpandedView);
|
|
expect(expanded, findsOneWidget);
|
|
for (final label in [runGraphExecuted, runGraphNotExecuted]) {
|
|
expect(
|
|
find.descendant(of: expanded, matching: find.text(label)),
|
|
findsOneWidget,
|
|
reason: 'the full-screen canvas must explain its routes: $label',
|
|
);
|
|
}
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
|
|
testWidgets('only routes the run took are executed and labelled', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(
|
|
_materialHost(
|
|
linearGraph(),
|
|
_runningRun(),
|
|
now: () => DateTime.utc(2026, 10, 21, 10, 2, 5),
|
|
),
|
|
);
|
|
await _settle(tester);
|
|
|
|
final layer = tester.widget<RunGraphEdgeLayer>(
|
|
find.byType(RunGraphEdgeLayer),
|
|
);
|
|
expect(
|
|
layer.executedRoutes.map((route) => '${route.source}/${route.target}'),
|
|
['plan/build'],
|
|
);
|
|
expect(layer.untakenRoutes, isNotEmpty);
|
|
expect(
|
|
layer.executedRoutes.every(
|
|
(route) => route.source == 'plan' && route.target == 'build',
|
|
),
|
|
isTrue,
|
|
);
|
|
// A run labels only what happened: the untaken success/error routes on
|
|
// build/ship carry no chips, including the implicit fallback `error*`.
|
|
expect(find.text('success'), findsOneWidget);
|
|
expect(find.text('error*'), findsNothing);
|
|
expect(find.text('error'), findsNothing);
|
|
});
|
|
|
|
testWidgets('a terminal is executed only when a visit resolved there', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(_materialHost(linearGraph(), _completedPath()));
|
|
await _settle(tester);
|
|
|
|
expect(
|
|
tester.widget<GraphStageNode>(_node(successEnd)).recordedStatus,
|
|
'success',
|
|
);
|
|
expect(
|
|
tester.widget<GraphStageNode>(_node(failureEnd)).recordedStatus,
|
|
isNull,
|
|
);
|
|
// A finished run has no active-stage line even with a current_stage value.
|
|
expect(find.textContaining('Current stage'), findsNothing);
|
|
|
|
await tester.pumpWidget(
|
|
_materialHost(linearGraph(), _completedPath(failure: true)),
|
|
);
|
|
await _settle(tester);
|
|
expect(
|
|
tester.widget<GraphStageNode>(_node(failureEnd)).recordedStatus,
|
|
'error',
|
|
);
|
|
expect(
|
|
tester.widget<GraphStageNode>(_node(successEnd)).recordedStatus,
|
|
isNull,
|
|
);
|
|
});
|
|
|
|
testWidgets(
|
|
'a visited stage opens its visit from the popover; an unvisited one has none',
|
|
(tester) async {
|
|
final picked = <String>[];
|
|
await tester.pumpWidget(
|
|
_materialHost(
|
|
linearGraph(),
|
|
_finishedRun(),
|
|
onSelected: picked.add,
|
|
selected: 'plan',
|
|
),
|
|
);
|
|
await _settle(tester);
|
|
|
|
final handle = tester.ensureSemantics();
|
|
expect(tester.widget<GraphStageNode>(_node('plan')).selected, isTrue);
|
|
final visited = tester.getSemantics(_node('plan')).getSemanticsData();
|
|
expect(visited.flagsCollection.isButton, isTrue);
|
|
expect(visited.hasAction(SemanticsAction.tap), isTrue);
|
|
// An unvisited stage still opens its declaration, with no status.
|
|
final unvisited = tester.getSemantics(_node('build')).getSemanticsData();
|
|
expect(unvisited.flagsCollection.isButton, isTrue);
|
|
expect(unvisited.label, 'build');
|
|
|
|
await tester.tap(_node('plan'));
|
|
await tester.pump();
|
|
expect(picked, isEmpty);
|
|
await tester.tap(find.byKey(const Key('stage-popover-open-visit')));
|
|
await tester.pump();
|
|
expect(picked, ['plan']);
|
|
|
|
// `build` was never recorded in this run: its popover offers no visit,
|
|
// so nothing is ever fabricated.
|
|
await tester.tap(_node('build'));
|
|
await tester.pump();
|
|
expect(find.byKey(const Key('graph-stage-popover')), findsOneWidget);
|
|
expect(find.byKey(const Key('stage-popover-open-visit')), findsNothing);
|
|
expect(find.byKey(const Key('stage-popover-status')), findsNothing);
|
|
expect(picked, ['plan']);
|
|
handle.dispose();
|
|
},
|
|
);
|
|
|
|
testWidgets('a changed recorded status remeasures instead of keeping a box', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(_materialHost(linearGraph(), _runningRun()));
|
|
await _settle(tester);
|
|
expect(
|
|
tester.widget<GraphStageNode>(_node('build')).recordedStatus,
|
|
'running',
|
|
);
|
|
|
|
final changed = _runningRun();
|
|
(changed['steps'] as List)[1] = step(
|
|
sequence: 2,
|
|
stage: 'build',
|
|
status: 'blocked',
|
|
);
|
|
await tester.pumpWidget(_materialHost(linearGraph(), changed));
|
|
await _settle(tester);
|
|
expect(
|
|
tester.widget<GraphStageNode>(_node('build')).recordedStatus,
|
|
'blocked',
|
|
);
|
|
expect(find.byType(GraphStageNode), findsNWidgets(5));
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
|
|
testWidgets('a missing or stage-less graph states the server wording', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(_materialHost(null, _finishedRun()));
|
|
await tester.pump();
|
|
expect(find.text(runGraphMissing), findsOneWidget);
|
|
expect(find.byType(InteractiveViewer), findsNothing);
|
|
|
|
await tester.pumpWidget(
|
|
_materialHost(<String, dynamic>{'stages': <dynamic>[]}, _finishedRun()),
|
|
);
|
|
await tester.pump();
|
|
expect(find.text(runGraphMissing), findsOneWidget);
|
|
expect(find.byType(InteractiveViewer), findsNothing);
|
|
});
|
|
|
|
testWidgets('executed routes keep success-first, error-last order', (
|
|
tester,
|
|
) async {
|
|
final graph = <String, dynamic>{
|
|
'stages': <dynamic>[
|
|
stage('a', edges: <String, String?>{'error': 'b', 'success': 'c'}),
|
|
stage('b', edges: <String, String?>{'success': '#failure'}),
|
|
stage('c', edges: <String, String?>{'success': '#success'}),
|
|
],
|
|
};
|
|
final run = <String, dynamic>{
|
|
'id': 44,
|
|
'steps': <dynamic>[
|
|
step(sequence: 1, stage: 'a', outcome: 'error', target: 'b'),
|
|
step(sequence: 2, stage: 'a', outcome: 'success', target: 'c'),
|
|
],
|
|
'current_stage': 'a',
|
|
'executing': false,
|
|
};
|
|
await tester.pumpWidget(_materialHost(graph, run));
|
|
await _settle(tester);
|
|
|
|
final layer = tester.widget<RunGraphEdgeLayer>(
|
|
find.byType(RunGraphEdgeLayer),
|
|
);
|
|
expect(layer.executedRoutes.map((route) => route.outcome), [
|
|
'success',
|
|
'error',
|
|
]);
|
|
});
|
|
|
|
testWidgets('320px at 2x text re-measures and keeps a deterministic layout', (
|
|
tester,
|
|
) async {
|
|
tester.view.physicalSize = const Size(320, 700);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.reset);
|
|
await tester.pumpWidget(
|
|
_materialHost(
|
|
linearGraph(),
|
|
_runningRun(),
|
|
scale: 2,
|
|
size: const Size(320, 700),
|
|
),
|
|
);
|
|
await _settle(tester);
|
|
final first = {
|
|
for (final element in find.byType(GraphStageNode).evaluate())
|
|
(element.widget as GraphStageNode).node.key: tester.getRect(
|
|
find.byWidget(element.widget),
|
|
),
|
|
};
|
|
_expectNoOverlaps(tester);
|
|
expect(first.values.every((rect) => rect.width <= 320), isTrue);
|
|
|
|
await tester.pumpWidget(
|
|
_materialHost(
|
|
linearGraph(),
|
|
_runningRun(),
|
|
scale: 2,
|
|
size: const Size(320, 700),
|
|
),
|
|
);
|
|
await _settle(tester);
|
|
final second = {
|
|
for (final element in find.byType(GraphStageNode).evaluate())
|
|
(element.widget as GraphStageNode).node.key: tester.getRect(
|
|
find.byWidget(element.widget),
|
|
),
|
|
};
|
|
expect(second, first);
|
|
_expectNoOverlaps(tester);
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
}
|