feat(app): open a pipeline stage from its URL

The route `/pipelines/:id[/:version]/stage/:key` now opens the pipeline
detail's Graph tab with the named stage selected and its authored
definition pane for the pinned version. A key the pinned definition does
not declare opens the Graph tab with nothing selected and no pane; no key
keeps the ordinary Summary tab.

The request is scoped to the pipeline and version the URL names, consumed
once the named pin's first reply is shown, and never replayed by a re-read,
a later version switch or a different pipeline. A route change from a pin
to latest re-reads latest, matching the web's requested-version rule.
This commit is contained in:
2026-10-22 11:42:11 +01:00
parent fc573e8743
commit eb16a4caba
7 changed files with 885 additions and 24 deletions
@@ -0,0 +1,94 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/application/pipelines_app.dart';
import 'package:pipelines_app/core/transport/pipelines_client.dart';
import 'package:pipelines_app/features/graph/widgets/stage_definition_view.dart';
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
import '../features/pipelines/fixtures.dart';
import 'pipelines_app_test.dart' show webServer;
import 'pipelines_replies.dart';
/// Answers every outstanding `get_pipeline` request.
///
/// A deep-linked mount asks twice (the route's initial open, then the list
/// read's in-place reload), and the transport serializes requests, so a single
/// reply would leave the second read unanswered.
Future<void> _replyEveryDetail(
WidgetTester tester,
FakeChannel channel,
PipelineFixture fixture,
) async {
final answered = <Object?>{};
for (var round = 0; round < 8; round++) {
await tester.pump(const Duration(milliseconds: 10));
final pending = channel.outgoing
.map((frame) => jsonDecode(frame as String) as Map<String, dynamic>)
.where((frame) => frame['type'] == 'get_pipeline')
.where((frame) => !answered.contains(frame['id']))
.toList(growable: false);
if (pending.isEmpty) continue;
for (final request in pending) {
answered.add(request['id']);
final detail = fixture.detailFor(
request['pipeline_id'] as int,
request['version'] as int,
)!;
channel.incoming.add(
jsonEncode({'id': request['id'], 'type': 'pipeline', 'detail': detail}),
);
}
await tester.pump();
}
}
/// The application route carries a stage key all the way to the landed pane.
void main() {
testWidgets('the stage route opens the pinned definition through the app', (
tester,
) async {
tester.view.physicalSize = const Size(1100, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final fixture = PipelineFixture();
final channel = FakeChannel()..readyCompleter.complete();
final client = PipelinesClient(channelFactory: (_) => channel);
final provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(
uri: Uri.parse('/pipelines/1/1/stage/review'),
),
);
addTearDown(provider.dispose);
await tester.pumpWidget(
PipelinesApp(
server: webServer(),
client: client,
cupertino: false,
routeInformationProvider: provider,
),
);
await tester.pump();
await replyPipelines(tester, channel, fixture);
await tester.pump();
await _replyEveryDetail(tester, channel, fixture);
await tester.pumpAndSettle();
// The route names pipeline 1's v1 `review` stage; the app's wiring must
// reach the same authored definition the screen opens for that pin.
final pane = tester.widget<StageDefinitionView>(
find.byType(StageDefinitionView),
);
expect(pane.stageKey, 'review');
expect(pane.pipelineId, 1);
expect(pane.pipelineName, 'Alpha review');
expect(pane.version, 1);
expect(pane.graph, reviewGraphV1());
expect(find.text('review definition'), findsOneWidget);
expect(find.text('Alpha review · v1'), findsOneWidget);
});
}