Run card mini-map and stage strip; graph edge hover highlight

The show_run card carries the run's graph and per-stage progress (bounded by
the graph, not the run length) and draws a still mini-map with the run graph
plus a stage strip with status, visits and time. Hovering or tapping an edge
in the pipeline and run graphs highlights it, its label and endpoints, with a
tooltip naming from -> to, the outcome and, for runs, how often it was taken.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 12:56:51 +00:00
parent c4de1de27b
commit 7872e57d40
17 changed files with 1709 additions and 51 deletions
@@ -0,0 +1,273 @@
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/chat/chat_run_opener.dart';
import 'package:pipelines_app/features/chat/domain/chat_shown_run.dart';
import 'package:pipelines_app/features/chat/ui/transcript/shown/chat_shown_run_card.dart';
import 'package:pipelines_app/features/chat/ui/transcript/shown/chat_shown_run_map_view.dart';
import 'package:pipelines_app/features/graph/widgets/graph_stage_node.dart';
import 'package:pipelines_app/features/graph/widgets/run_graph_canvas.dart';
final _start = DateTime.utc(2026, 12, 1, 9);
int _at(int seconds) =>
_start.add(Duration(seconds: seconds)).millisecondsSinceEpoch;
/// plan → implement ⇄ review → #success, as the server sends a card's map.
JsonMap _map({
required String review,
int reviewVisits = 1,
int? reviewRunningSince,
List<JsonMap> extraVisits = const [],
}) => {
'stages': [
{
'key': 'plan',
'edges': {'success': 'implement'},
'visits': 1,
'status': 'completed',
'seconds': 65,
},
{
'key': 'implement',
'edges': {'success': 'review'},
'visits': 2,
'status': 'completed',
'seconds': 600,
},
{
'key': 'review',
'edges': {'success': '#', 'changes': 'implement'},
'fallback_error': true,
'visits': reviewVisits,
'status': review,
'seconds': 30,
'running_since': ?reviewRunningSince,
},
],
'visits': [
{
'sequence': 1,
'stage': 'plan',
'status': 'completed',
'outcome': 'success',
'target': 'implement',
},
{
'sequence': 3,
'stage': 'review',
'status': 'completed',
'outcome': 'changes',
'target': 'implement',
},
{
'sequence': 4,
'stage': 'implement',
'status': 'completed',
'outcome': 'success',
'target': 'review',
},
...extraVisits,
],
};
JsonMap _item(String status, JsonMap map, {int? finishedAt}) => {
'id': 'r',
'kind': 'run',
'run': {
'id': 42,
'pipeline': 'Feature',
'title': 'Add the mini-map',
'status': status,
'current_stage': 'review',
'started_at': _start.millisecondsSinceEpoch,
'finished_at': ?finishedAt,
'map': map,
},
};
Finder _stage(String key) => find.byKey(ValueKey('chat-shown-run-stage:$key'));
void main() {
final opened = <int>[];
Future<void> pump(WidgetTester tester, JsonMap item, {int now = 0}) async {
await tester.binding.setSurfaceSize(const Size(480, 900));
addTearDown(() => tester.binding.setSurfaceSize(null));
await tester.pumpWidget(
ChatRunOpener(
openRun: opened.add,
child: MaterialApp(
home: Scaffold(
body: SingleChildScrollView(
child: ChatShownRunCard(
key: const ValueKey('card'),
item: item,
now: () => DateTime.fromMillisecondsSinceEpoch(now),
),
),
),
),
),
);
for (var i = 0; i < 3; i += 1) {
await tester.pump();
}
}
test('the map reads stages, progress and route evidence', () {
final map = ChatShownRunMap.of(
_map(review: 'running', reviewRunningSince: _at(0)),
)!;
expect(map.stages.map((s) => s.key), ['plan', 'implement', 'review']);
expect(map.stages[1].visits, 2);
expect(map.stages[2].duration(_at(15)), '45s');
expect(map.graph['stages'], hasLength(3));
expect(map.steps.map((s) => s['sequence']), [1, 3, 4]);
expect(ChatShownRunMap.of(null), isNull);
expect(ChatShownRunMap.of({'stages': []}), isNull);
});
testWidgets('a running run draws its graph and stage strip, live', (
tester,
) async {
final item = _item(
'running',
_map(
review: 'running',
reviewVisits: 2,
reviewRunningSince: _at(100),
extraVisits: [
{'sequence': 5, 'stage': 'review', 'status': 'running'},
],
),
);
await pump(tester, item, now: _at(110));
expect(find.byKey(const Key('chat-shown-run-map')), findsOneWidget);
expect(find.byKey(const Key('run-graph-still')), findsOneWidget);
// The still graph is the run graph: review is the live stage.
final review = tester.widget<RunGraphNode>(
find.byWidgetPredicate(
(w) => w is RunGraphNode && w.node.key == 'review',
),
);
expect(review.active, isTrue);
expect(review.recordedStatus, 'running');
// The taken loop is drawn solid, the untaken success route dashed.
final edges = tester.widget<RunGraphEdgeLayer>(
find.byType(RunGraphEdgeLayer),
);
expect(
edges.executedRoutes.map((r) => '${r.source}>${r.outcome}'),
containsAll(['plan>success', 'implement>success', 'review>changes']),
);
expect(
edges.untakenRoutes.map((r) => '${r.source}>${r.outcome}'),
contains('review>success'),
);
// The stage strip: visits, durations, the current stage emphasized.
expect(find.text('1m 5s'), findsOneWidget);
expect(find.text('×2 · 10m 0s'), findsOneWidget);
expect(find.text('×2 · 40s'), findsOneWidget);
expect(
find.descendant(
of: _stage('review'),
matching: find.byIcon(Icons.play_circle),
),
findsOneWidget,
);
final name = tester.widget<Text>(
find.descendant(of: _stage('review'), matching: find.text('review')),
);
expect(name.style?.fontWeight, FontWeight.w700);
// The mini-map is a picture: the card still opens the run.
await tester.tap(
find.byKey(const Key('chat-shown-run-map')),
warnIfMissed: false,
);
expect(opened, [42]);
});
testWidgets('a failed run marks the failed stage and has no live stage', (
tester,
) async {
await pump(
tester,
_item(
'failed',
_map(
review: 'failed',
extraVisits: [
{
'sequence': 5,
'stage': 'review',
'status': 'failed',
'outcome': 'error',
'target': '#',
},
],
),
finishedAt: _at(700),
),
now: _at(900),
);
expect(
find.descendant(of: _stage('review'), matching: find.byIcon(Icons.error)),
findsOneWidget,
);
final review = tester.widget<RunGraphNode>(
find.byWidgetPredicate(
(w) => w is RunGraphNode && w.node.key == 'review',
),
);
expect(review.active, isFalse);
expect(review.recordedStatus, 'failed');
final failure = find.byWidgetPredicate(
(w) => w is GraphStageNode && w.node.key == '#failure',
);
expect(failure, findsOneWidget);
final name = tester.widget<Text>(
find.descendant(of: _stage('review'), matching: find.text('review')),
);
expect(name.style?.fontWeight, isNot(FontWeight.w700));
});
testWidgets('a succeeded run checks every stage; no map, no strip', (
tester,
) async {
await pump(
tester,
_item('succeeded', _map(review: 'completed'), finishedAt: _at(700)),
now: _at(900),
);
for (final key in ['plan', 'implement', 'review']) {
expect(
find.descendant(
of: _stage(key),
matching: find.byIcon(Icons.check_circle),
),
findsOneWidget,
);
}
final item = _item('running', _map(review: 'running'));
(item['run'] as Map).remove('map');
await pump(tester, item, now: _at(10));
expect(find.byKey(const Key('chat-shown-run-map')), findsNothing);
expect(find.byType(ChatShownRunMapView), findsNothing);
});
testWidgets('a stage that never ran reads as not run', (tester) async {
final map = _map(review: '');
((map['stages'] as List)[2] as Map)
..['visits'] = 0
..remove('seconds');
await pump(tester, _item('running', map), now: _at(10));
expect(
find.descendant(
of: _stage('review'),
matching: find.byIcon(Icons.radio_button_unchecked),
),
findsOneWidget,
);
expect(find.bySemanticsLabel(RegExp('^review, not run')), findsOneWidget);
});
}