Merge branch 'worktree-agent-a3cb3553b5c91a345'
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:pipelines_app/features/graph/painting/edge_hit_test.dart';
|
||||
import 'package:pipelines_app/features/graph/routing/route_models.dart';
|
||||
import 'package:pipelines_app/features/graph/widgets/definition_graph_view.dart';
|
||||
import 'package:pipelines_app/features/graph/widgets/graph_edge_hover.dart';
|
||||
import 'package:pipelines_app/features/graph/widgets/run_graph_view.dart';
|
||||
|
||||
import '../domain/graph_fixtures.dart';
|
||||
|
||||
Widget _host(Widget graph) => MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: SizedBox(width: 900, height: 600, child: graph),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Future<void> _settle(WidgetTester tester) async {
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
GraphEdgeHover _hover(WidgetTester tester) =>
|
||||
tester.widget<GraphEdgeHover>(find.byType(GraphEdgeHover).first);
|
||||
|
||||
EdgeRoute _route(WidgetTester tester, String source, String outcome) =>
|
||||
_hover(tester).routing.routes.firstWhere(
|
||||
(route) => route.source == source && route.outcome == outcome,
|
||||
);
|
||||
|
||||
/// A global point on [route] that hits only it: sampled along its segments,
|
||||
/// clear of nodes, labels and other routes.
|
||||
Offset _onRoute(WidgetTester tester, EdgeRoute route) {
|
||||
final hover = _hover(tester);
|
||||
final box = tester.renderObject<RenderBox>(find.byType(GraphEdgeHover).first);
|
||||
for (var index = 0; index + 1 < route.points.length; index += 1) {
|
||||
final a = Offset(route.points[index].x, route.points[index].y);
|
||||
final b = Offset(route.points[index + 1].x, route.points[index + 1].y);
|
||||
for (final t in const [0.5, 0.3, 0.7, 0.2, 0.8]) {
|
||||
final point = Offset.lerp(a, b, t)!;
|
||||
final others = hover.routing.routes.where((r) => r.id != route.id);
|
||||
final clear = others.every((r) => distanceToRoute(r, point) > 10);
|
||||
final hit = hitTestEdge(
|
||||
routes: hover.routing.routes,
|
||||
labels: const [],
|
||||
nodes: hover.layout.nodes,
|
||||
point: point,
|
||||
tolerance: 1,
|
||||
);
|
||||
final inLabel = hover.routing.labels.any(
|
||||
(l) =>
|
||||
l.edgeId != route.id &&
|
||||
Rect.fromLTWH(
|
||||
l.x,
|
||||
l.y,
|
||||
l.width,
|
||||
l.height,
|
||||
).inflate(4).contains(point),
|
||||
);
|
||||
if (clear && !inLabel && hit == route.id) return box.localToGlobal(point);
|
||||
}
|
||||
}
|
||||
throw StateError('no clear point on route ${route.id}');
|
||||
}
|
||||
|
||||
Finder _highlight(int id) => find.byKey(ValueKey('graph-edge-highlight:$id'));
|
||||
|
||||
void main() {
|
||||
test('hit testing follows bends, prefers nodes and labels', () {
|
||||
final loop = EdgeRoute(
|
||||
id: 1,
|
||||
source: 'a',
|
||||
outcome: 'retry',
|
||||
target: 'a',
|
||||
label: 'retry',
|
||||
fallback: false,
|
||||
kind: RouteKind.values.first,
|
||||
straight: false,
|
||||
sourcePort: const RoutePort(
|
||||
side: RoutePortSide.top,
|
||||
point: RoutePoint(10, 0),
|
||||
),
|
||||
targetPort: const RoutePort(
|
||||
side: RoutePortSide.top,
|
||||
point: RoutePoint(40, 0),
|
||||
),
|
||||
points: const [
|
||||
RoutePoint(10, 0),
|
||||
RoutePoint(10, -30),
|
||||
RoutePoint(40, -30),
|
||||
RoutePoint(40, 0),
|
||||
],
|
||||
);
|
||||
int? hit(Offset point, {double tolerance = 4}) => hitTestEdge(
|
||||
routes: [loop],
|
||||
labels: const [
|
||||
EdgeLabelBox(edgeId: 1, x: 100, y: 100, width: 30, height: 12),
|
||||
],
|
||||
nodes: const [],
|
||||
point: point,
|
||||
tolerance: tolerance,
|
||||
);
|
||||
expect(distanceToRoute(loop, const Offset(25, -27)), 3);
|
||||
expect(hit(const Offset(25, -27)), 1, reason: 'the loop top is hit');
|
||||
expect(hit(const Offset(13, -15)), 1, reason: 'the loop side is hit');
|
||||
expect(hit(const Offset(25, -15)), isNull, reason: 'inside the loop');
|
||||
expect(hit(const Offset(110, 105)), 1, reason: 'the label is the edge');
|
||||
});
|
||||
|
||||
testWidgets('hovering a definition edge highlights it with a tooltip', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
_host(DefinitionGraphView(graph: linearGraph(), onSelected: (_) {})),
|
||||
);
|
||||
await _settle(tester);
|
||||
final route = _route(tester, 'plan', 'success');
|
||||
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
await mouse.addPointer(location: Offset.zero);
|
||||
addTearDown(mouse.removePointer);
|
||||
await mouse.moveTo(_onRoute(tester, route));
|
||||
await tester.pump();
|
||||
|
||||
expect(_highlight(route.id), findsOneWidget);
|
||||
expect(find.byKey(const Key('graph-edge-tooltip')), findsOneWidget);
|
||||
expect(find.text('plan → build\nOutcome: success'), findsOneWidget);
|
||||
|
||||
// Over a node the edge is let go: nodes keep their own pointer.
|
||||
final node = _hover(tester).layout.nodeFor('build')!;
|
||||
final box = tester.renderObject<RenderBox>(find.byType(GraphEdgeHover));
|
||||
await mouse.moveTo(
|
||||
box.localToGlobal(
|
||||
Offset(node.x + node.width / 2, node.y + node.height / 2),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(_highlight(route.id), findsNothing);
|
||||
expect(find.byKey(const Key('graph-edge-tooltip')), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('tapping a run edge pins it and counts how often it was taken', (
|
||||
tester,
|
||||
) async {
|
||||
final run = <String, dynamic>{
|
||||
'steps': [
|
||||
step(sequence: 1, stage: 'a', outcome: 'retry', target: 'a'),
|
||||
step(sequence: 2, stage: 'a', outcome: 'retry', target: 'a'),
|
||||
step(sequence: 3, stage: 'a', outcome: 'success', target: 'b'),
|
||||
step(sequence: 4, stage: 'b', status: 'running'),
|
||||
],
|
||||
'current_stage': 'b',
|
||||
'executing': true,
|
||||
};
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
RunGraphView(
|
||||
graph: selfLoopGraph(),
|
||||
run: run,
|
||||
onStageSelected: (_) {},
|
||||
showHeader: false,
|
||||
),
|
||||
),
|
||||
);
|
||||
await _settle(tester);
|
||||
final loop = _route(tester, 'a', 'retry');
|
||||
await tester.tapAt(_onRoute(tester, loop));
|
||||
await tester.pump();
|
||||
expect(_highlight(loop.id), findsOneWidget);
|
||||
expect(find.text('a → a\nOutcome: retry\nTaken 2 times'), findsOneWidget);
|
||||
|
||||
final untaken = _route(tester, 'b', 'error');
|
||||
await tester.tapAt(_onRoute(tester, untaken));
|
||||
await tester.pump();
|
||||
expect(_highlight(loop.id), findsNothing);
|
||||
expect(_highlight(untaken.id), findsOneWidget);
|
||||
expect(find.text('b → Failure\nOutcome: error\nNot taken'), findsOneWidget);
|
||||
|
||||
// Tapping it again lets it go.
|
||||
await tester.tapAt(_onRoute(tester, untaken));
|
||||
await tester.pump();
|
||||
expect(_highlight(untaken.id), findsNothing);
|
||||
expect(find.byKey(const Key('graph-edge-tooltip')), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('edge labels name their edge for screen readers', (tester) async {
|
||||
final handle = tester.ensureSemantics();
|
||||
await tester.pumpWidget(
|
||||
_host(DefinitionGraphView(graph: linearGraph(), onSelected: (_) {})),
|
||||
);
|
||||
await _settle(tester);
|
||||
expect(
|
||||
find.bySemanticsLabel('build → ship\nOutcome: success'),
|
||||
findsOneWidget,
|
||||
);
|
||||
handle.dispose();
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user