feat(app): open a recorded run visit from its URL

`/runs/:id/stage/:key?visit=N` now selects that stage's N-th recorded
visit in the run detail Timeline, matching the web client's stage-local
visit ordering. A stage key without a visit opens the latest recorded
visit, an out-of-range index clamps to the last one, and a stage with no
recorded visit selects only its Graph node instead of inventing a visit.

Route plumbing carries the query end to end: boot seeds the router from
path and query, the parser reads path plus query, and restore keeps `?`
a query separator instead of percent-encoding it. That also repairs the
existing `?action=decide` and `/runs?pipeline=` URLs.

The Graph node click and the stage route share one sequence-ordered
resolver, so both open the same latest visit.
This commit is contained in:
2026-10-22 10:48:36 +01:00
parent 7aa7007aee
commit f57d8eeb76
12 changed files with 623 additions and 18 deletions
@@ -2,6 +2,8 @@ import 'dart:convert';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/application/app_route.dart';
import 'package:pipelines_app/application/app_router.dart';
import 'package:pipelines_app/application/pipelines_app.dart';
import 'package:pipelines_app/application/server_endpoint.dart';
import 'package:pipelines_app/core/transport/pipelines_client.dart';
@@ -84,6 +86,57 @@ Future<void> replyDetail(
await tester.pump();
}
/// A run whose plan visits are deliberately not in sequence order, so a route
/// visit index must follow the recorded sequence, not the reply's row order.
Future<void> replyVisitDetail(
WidgetTester tester,
FakeChannel channel,
num id,
) async {
for (
var attempt = 0;
attempt < 40 && requestOf(channel, 'get_run') == null;
attempt++
) {
await tester.pump(const Duration(milliseconds: 5));
}
final request = requestOf(channel, 'get_run')!;
expect(request['run_id'], id);
channel.incoming.add(
jsonEncode({
'id': request['id'],
'type': 'run',
'run_detail': {
'id': id,
'title': 'Deep link run',
'name': 'release',
'status': 'succeeded',
'graph': {
'stages': [
{
'key': 'plan',
'type': 'model',
'edges': {'success': 'build'},
},
{
'key': 'build',
'type': 'model',
'edges': {'success': '#success'},
},
],
},
'steps': [
{'stage': 'plan', 'sequence': 5, 'status': 'completed'},
{'stage': 'build', 'sequence': 2, 'status': 'completed'},
{'stage': 'plan', 'sequence': 1, 'status': 'completed'},
],
},
}),
);
await tester.pump();
await tester.pump();
}
void main() {
testWidgets('a /runs/1 boot link opens that run and Back returns to /runs', (
tester,
@@ -195,4 +248,47 @@ void main() {
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
});
testWidgets('a queried stage boot link opens that exact recorded visit', (
tester,
) async {
final channel = FakeChannel()..readyCompleter.complete();
final client = PipelinesClient(channelFactory: (_) => channel);
final provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(
uri: Uri.parse('/runs/77/stage/plan?visit=0'),
),
);
addTearDown(provider.dispose);
await pumpApp(tester, channel: channel, client: client, provider: provider);
await replyList(
tester,
channel,
runs: [
{'id': 77, 'name': 'Deep link run', 'status': 'succeeded'},
],
);
await replyVisitDetail(tester, channel, 77);
// The query reached the detail: visit 0 is the earlier plan visit (seq 1),
// not the latest one the pane would show without a visit.
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
expect(find.text('plan · visit 1'), findsOneWidget);
expect(find.text('plan · visit 5'), findsNothing);
expect(provider.value.uri.toString(), '/runs/77/stage/plan?visit=0');
// A history entry the app itself writes is parsed back as a query, so
// Back/Forward (and a reload) open the visit instead of a bogus stage key.
final restored = const AppRouteParser()
.restoreRouteInformation(AppRoute.run.stage(77, 'plan', visit: 1))
.uri;
expect(restored.toString(), '/runs/77/stage/plan?visit=1');
await provider.didPushRouteInformation(RouteInformation(uri: restored));
await tester.pump();
await tester.pump();
expect(find.text('plan · visit 5'), findsOneWidget);
expect(provider.value.uri.path, '/runs/77/stage/plan');
expect(provider.value.uri.query, 'visit=1');
});
}