f57d8eeb76
`/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.
295 lines
9.3 KiB
Dart
295 lines
9.3 KiB
Dart
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';
|
|
import 'package:pipelines_app/features/pipelines/screen.dart';
|
|
|
|
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
|
|
import '../features/pipelines/fixtures.dart';
|
|
import 'pipelines_replies.dart';
|
|
|
|
ServerEndpoint webServer() => ServerEndpoint.resolve(
|
|
base: Uri.parse('http://127.0.0.1:8096/'),
|
|
web: true,
|
|
);
|
|
|
|
Map<String, dynamic>? requestOf(FakeChannel channel, String type) => channel
|
|
.outgoing
|
|
.map((frame) => jsonDecode(frame as String) as Map<String, dynamic>)
|
|
.where((frame) => frame['type'] == type)
|
|
.firstOrNull;
|
|
|
|
Future<void> pumpApp(
|
|
WidgetTester tester, {
|
|
required FakeChannel channel,
|
|
required PipelinesClient client,
|
|
required PlatformRouteInformationProvider provider,
|
|
}) async {
|
|
await tester.pumpWidget(
|
|
PipelinesApp(
|
|
server: webServer(),
|
|
client: client,
|
|
cupertino: false,
|
|
routeInformationProvider: provider,
|
|
),
|
|
);
|
|
await tester.pump();
|
|
}
|
|
|
|
Future<void> replyList(
|
|
WidgetTester tester,
|
|
FakeChannel channel, {
|
|
required List<Map<String, dynamic>> runs,
|
|
}) async {
|
|
for (
|
|
var attempt = 0;
|
|
attempt < 40 && requestOf(channel, 'list_runs') == null;
|
|
attempt++
|
|
) {
|
|
await tester.pump(const Duration(milliseconds: 5));
|
|
}
|
|
final request = requestOf(channel, 'list_runs')!;
|
|
channel.incoming.add(
|
|
jsonEncode({'id': request['id'], 'type': 'runs', 'runs': runs}),
|
|
);
|
|
await tester.pump();
|
|
await tester.pump();
|
|
}
|
|
|
|
Future<void> replyDetail(
|
|
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': 'Run $id', 'status': 'running'},
|
|
}),
|
|
);
|
|
await tester.pump();
|
|
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,
|
|
) async {
|
|
final channel = FakeChannel()..readyCompleter.complete();
|
|
final client = PipelinesClient(channelFactory: (_) => channel);
|
|
final provider = PlatformRouteInformationProvider(
|
|
initialRouteInformation: RouteInformation(uri: Uri.parse('/runs/1')),
|
|
);
|
|
addTearDown(provider.dispose);
|
|
|
|
await pumpApp(tester, channel: channel, client: client, provider: provider);
|
|
await replyList(
|
|
tester,
|
|
channel,
|
|
runs: [
|
|
{'id': 1, 'name': 'Deep-linked run', 'status': 'running'},
|
|
],
|
|
);
|
|
await replyDetail(tester, channel, 1);
|
|
|
|
expect(find.text('Run 1'), findsWidgets);
|
|
expect(find.text('Back to list'), findsOneWidget);
|
|
expect(provider.value.uri.path, '/runs/1');
|
|
expect(find.text('Pipelines — Not implemented'), findsNothing);
|
|
|
|
await tester.tap(find.text('Back to list'));
|
|
await tester.pump();
|
|
expect(provider.value.uri.path, '/runs');
|
|
expect(find.text('Deep-linked run'), findsWidgets);
|
|
});
|
|
|
|
testWidgets('tabs and run selection update the route; browser Back pops it', (
|
|
tester,
|
|
) async {
|
|
final channel = FakeChannel()..readyCompleter.complete();
|
|
final client = PipelinesClient(channelFactory: (_) => channel);
|
|
final provider = PlatformRouteInformationProvider(
|
|
initialRouteInformation: RouteInformation(uri: Uri.parse('/pipelines')),
|
|
);
|
|
addTearDown(provider.dispose);
|
|
|
|
await pumpApp(tester, channel: channel, client: client, provider: provider);
|
|
expect(provider.value.uri.path, '/pipelines');
|
|
final fixture = PipelineFixture();
|
|
await replyPipelines(tester, channel, fixture);
|
|
final pipelinesRunsId =
|
|
pipelineRequest(channel, 'list_runs')!['id'] as String;
|
|
|
|
await tester.tap(find.text('Runs').last);
|
|
await tester.pump();
|
|
expect(provider.value.uri.path, '/runs');
|
|
|
|
final runsRequest = await waitForLaterRequest(
|
|
tester,
|
|
channel,
|
|
'list_runs',
|
|
pipelinesRunsId,
|
|
);
|
|
channel.incoming.add(
|
|
jsonEncode({
|
|
'id': runsRequest['id'],
|
|
'type': 'runs',
|
|
'runs': [
|
|
{'id': 2, 'name': 'Beta run', 'status': 'failed'},
|
|
],
|
|
}),
|
|
);
|
|
await tester.pump();
|
|
await tester.pump();
|
|
await tester.tap(find.text('Beta run'));
|
|
await tester.pump();
|
|
expect(provider.value.uri.path, '/runs/2');
|
|
await replyDetail(tester, channel, 2);
|
|
expect(find.text('Back to list'), findsOneWidget);
|
|
|
|
// The engine's browser Back arrives as new route information.
|
|
await provider.didPushRouteInformation(
|
|
RouteInformation(uri: Uri.parse('/runs')),
|
|
);
|
|
await tester.pump();
|
|
expect(find.text('Beta run'), findsWidgets);
|
|
expect(find.text('Back to list'), findsNothing);
|
|
|
|
// Forward re-opens the same run.
|
|
await provider.didPushRouteInformation(
|
|
RouteInformation(uri: Uri.parse('/runs/2')),
|
|
);
|
|
await tester.pump();
|
|
await replyDetail(tester, channel, 2);
|
|
expect(find.text('Back to list'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('a malformed boot path is corrected to /pipelines', (
|
|
tester,
|
|
) async {
|
|
final channel = FakeChannel()..readyCompleter.complete();
|
|
final client = PipelinesClient(channelFactory: (_) => channel);
|
|
final provider = PlatformRouteInformationProvider(
|
|
initialRouteInformation: RouteInformation(uri: Uri.parse('/runs/abc')),
|
|
);
|
|
addTearDown(provider.dispose);
|
|
|
|
await pumpApp(tester, channel: channel, client: client, provider: provider);
|
|
expect(provider.value.uri.path, '/pipelines');
|
|
await replyPipelines(tester, channel, PipelineFixture());
|
|
expect(find.byType(PipelinesScreen), findsOneWidget);
|
|
expect(find.text('Pipelines — Not implemented'), findsNothing);
|
|
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');
|
|
});
|
|
}
|