merge(app): land pipeline-stage-deeplink micro-slice

This commit is contained in:
2026-10-22 11:44:32 +01:00
7 changed files with 885 additions and 24 deletions
@@ -1,10 +1,106 @@
import 'dart:async';
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/graph/widgets/definition_graph_view.dart';
import 'package:pipelines_app/features/graph/widgets/stage_definition_view.dart';
import 'package:pipelines_app/features/pipelines/screen.dart';
import 'package:pipelines_app/features/pipelines/widgets/pipeline_tabs.dart';
import 'fixtures.dart';
import 'test_helpers.dart';
Future<void> _pumpPipelines(
WidgetTester tester, {
required FakeGateway gateway,
int? pipelineId,
int version = 0,
String? stageKey,
Size size = const Size(1100, 900),
}) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(
MaterialApp(
home: PipelinesScreen(
gateway: gateway,
initialPipelineId: pipelineId,
initialVersion: version,
initialStageKey: stageKey,
),
),
);
await tester.pumpAndSettle();
}
Map<String, dynamic> _alpha(int version) => pipelineDetail(
id: 1,
name: 'Alpha review',
version: version,
latestVersion: 2,
stages: 2,
graph: version == 1 ? reviewGraphV1() : reviewGraph(),
versions: [versionSummary(1), versionSummary(2)],
);
Map<String, dynamic> _beta() => pipelineDetail(
id: 2,
name: 'Beta deploy',
version: 1,
latestVersion: 1,
graph: reviewGraph(),
versions: [versionSummary(1)],
);
JsonMap _detailReply(JsonMap fields) {
if (fields['pipeline_id'] != 1) return pipelineDetailReply(_beta());
final version = fields['version'] as int? ?? 0;
return pipelineDetailReply(_alpha(version > 0 ? version : 2));
}
/// Two pipelines that both declare `review`, so a pane on Beta can only come
/// from a leaked route request rather than from the graph itself.
FakeGateway _twoReviewPipelines() => FakeGateway(
(type, fields) => switch (type) {
'list_pipelines' => pipelineListReply([
pipelineSummary(id: 1, name: 'Alpha review', version: 2),
pipelineSummary(id: 2, name: 'Beta deploy'),
]),
'list_runs' => runListReply(const <Map<String, dynamic>>[]),
'get_pipeline' => _detailReply(fields),
_ => errorReply('unexpected $type'),
},
);
/// Alpha whose latest pin is v5, so "latest" and "v1" are visibly different
/// definitions. A reply can therefore prove which version was requested.
FakeGateway _versionedAlpha() => FakeGateway(
(type, fields) => switch (type) {
'list_pipelines' => pipelineListReply([
pipelineSummary(id: 1, name: 'Alpha review', version: 5),
]),
'list_runs' => runListReply(const <Map<String, dynamic>>[]),
'get_pipeline' => pipelineDetailReply(_alphaReplyFor(fields)),
_ => errorReply('unexpected $type'),
},
);
Map<String, dynamic> _alphaReplyFor(JsonMap fields) {
final requested = fields['version'] as int? ?? 0;
final version = requested > 0 ? requested : 5;
return pipelineDetail(
id: 1,
name: 'Alpha review',
version: version,
latestVersion: 5,
stages: version == 1 ? 1 : 2,
graph: version == 1 ? reviewGraphV1() : reviewGraph(),
versions: [versionSummary(1), versionSummary(5)],
);
}
/// A deep link opens the pipeline and version it names, not the list.
void main() {
testWidgets('an initial pipeline route opens that pinned detail', (
@@ -12,33 +108,376 @@ void main() {
) async {
final fixture = PipelineFixture();
final gateway = gatewayFor(fixture);
tester.view.physicalSize = const Size(1100, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
MaterialApp(
home: PipelinesScreen(
gateway: gateway,
initialPipelineId: 1,
initialVersion: 2,
),
),
);
await tester.pumpAndSettle();
await _pumpPipelines(tester, gateway: gateway, pipelineId: 1, version: 2);
// The detail is open (not the "Select a pipeline." placeholder), and the
// detail request names the route's pinned version.
expect(find.text('Select a pipeline.'), findsNothing);
expect(find.text('Alpha review'), findsWidgets);
expect(
gateway.callsOf('get_pipeline').where(
(call) =>
'${call.fields['pipeline_id']}' == '1' &&
'${call.fields['version']}' == '2',
),
gateway
.callsOf('get_pipeline')
.where(
(call) =>
'${call.fields['pipeline_id']}' == '1' &&
'${call.fields['version']}' == '2',
),
isNotEmpty,
);
// No stage key: the detail keeps its ordinary default tab.
expect(
tester
.widget<PipelineDetailTabs>(find.byType(PipelineDetailTabs))
.selected,
PipelineDetailTab.summary,
);
expect(find.byType(DefinitionGraphView), findsNothing);
expect(find.byType(StageDefinitionView), findsNothing);
});
testWidgets('a routed stage opens its authored definition for the pin', (
tester,
) async {
final gateway = gatewayFor(PipelineFixture());
await _pumpPipelines(
tester,
gateway: gateway,
pipelineId: 1,
version: 1,
stageKey: 'review',
);
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());
// The pane is the landed definition view: the authored prompt for v1, its
// pinned identity, and no invented run evidence.
expect(find.text('review definition'), findsOneWidget);
expect(find.text('Alpha review · v1'), findsOneWidget);
expect(find.text('Review the change.'), findsWidgets);
expect(
gateway
.callsOf('get_pipeline')
.where(
(call) =>
'${call.fields['pipeline_id']}' == '1' &&
'${call.fields['version']}' == '1',
),
isNotEmpty,
);
// Back lands on the Graph tab with the same pinned node selected.
await tester.pageBack();
await tester.pumpAndSettle();
expect(find.byType(StageDefinitionView), findsNothing);
expect(
tester
.widget<PipelineDetailTabs>(find.byType(PipelineDetailTabs))
.selected,
PipelineDetailTab.graph,
);
expect(
tester
.widget<DefinitionGraphView>(find.byType(DefinitionGraphView))
.selectedStage,
'review',
);
});
testWidgets('an unknown routed stage opens the graph with no selection', (
tester,
) async {
final gateway = gatewayFor(PipelineFixture());
await _pumpPipelines(
tester,
gateway: gateway,
pipelineId: 1,
version: 2,
stageKey: 'not_a_stage',
);
expect(
tester
.widget<PipelineDetailTabs>(find.byType(PipelineDetailTabs))
.selected,
PipelineDetailTab.graph,
);
expect(find.byType(DefinitionGraphView), findsOneWidget);
expect(
tester
.widget<DefinitionGraphView>(find.byType(DefinitionGraphView))
.selectedStage,
isNull,
);
expect(find.byType(StageDefinitionView), findsNothing);
expect(find.text(unknownStageDefinition), findsNothing);
});
testWidgets('another pipeline never inherits the routed stage', (
tester,
) async {
// Narrow: Back to the list destroys the detail, then the operator opens a
// pipeline the URL never named.
await _pumpPipelines(
tester,
gateway: _twoReviewPipelines(),
pipelineId: 1,
version: 1,
stageKey: 'review',
size: const Size(390, 844),
);
expect(
tester
.widget<StageDefinitionView>(find.byType(StageDefinitionView))
.pipelineId,
1,
);
await tester.pageBack();
await tester.pumpAndSettle();
await tester.tap(find.byTooltip('Back to pipelines'));
await tester.pumpAndSettle();
expect(find.byKey(const Key('pipeline-list')), findsOneWidget);
await tester.tap(find.byKey(const Key('pipeline-row-2')));
await tester.pumpAndSettle();
expect(
tester
.widget<PipelineDetailTabs>(find.byType(PipelineDetailTabs))
.selected,
PipelineDetailTab.summary,
reason: 'the request names pipeline 1, so pipeline 2 keeps its own tab',
);
expect(find.byType(DefinitionGraphView), findsNothing);
expect(find.byType(StageDefinitionView), findsNothing);
});
testWidgets('a spent routed stage does not replay on its named pipeline', (
tester,
) async {
// Latest (`version: 0`) matches the row's own version, so only consuming
// the request stops a second pane; the pin alone would still match.
await _pumpPipelines(
tester,
gateway: _twoReviewPipelines(),
pipelineId: 1,
stageKey: 'review',
size: const Size(390, 844),
);
expect(
tester
.widget<StageDefinitionView>(find.byType(StageDefinitionView))
.pipelineId,
1,
);
await tester.pageBack();
await tester.pumpAndSettle();
await tester.tap(find.byTooltip('Back to pipelines'));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('pipeline-row-1')));
await tester.pumpAndSettle();
expect(
tester
.widget<PipelineDetailTabs>(find.byType(PipelineDetailTabs))
.selected,
PipelineDetailTab.summary,
);
expect(find.byType(DefinitionGraphView), findsNothing);
expect(find.byType(StageDefinitionView), findsNothing);
});
testWidgets('a late deep-link reply cannot open a pane over another choice', (
tester,
) async {
// Wide: pipeline 1's routed detail is still in flight when the operator
// opens pipeline 2. Its late reply must not apply the abandoned request.
final alphaReply = Completer<JsonMap>();
final gateway = FakeGateway(
(type, fields) => switch (type) {
'list_pipelines' => pipelineListReply([
pipelineSummary(id: 1, name: 'Alpha review', version: 2),
pipelineSummary(id: 2, name: 'Beta deploy'),
]),
'list_runs' => runListReply(const <Map<String, dynamic>>[]),
'get_pipeline' =>
fields['pipeline_id'] == 1
? alphaReply.future
: pipelineDetailReply(_beta()),
_ => errorReply('unexpected $type'),
},
);
tester.view.physicalSize = const Size(1100, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(
MaterialApp(
home: PipelinesScreen(
gateway: gateway,
initialPipelineId: 1,
initialVersion: 1,
initialStageKey: 'review',
),
),
);
await tester.pump();
await tester.pump();
expect(find.byKey(const Key('pipeline-row-2')), findsOneWidget);
await tester.tap(find.byKey(const Key('pipeline-row-2')));
await tester.pump();
await tester.pump();
expect(find.text('Beta deploy'), findsWidgets);
alphaReply.complete(pipelineDetailReply(_alpha(1)));
await tester.pumpAndSettle();
expect(
tester
.widget<PipelineDetailTabs>(find.byType(PipelineDetailTabs))
.selected,
PipelineDetailTab.summary,
);
expect(find.byType(DefinitionGraphView), findsNothing);
expect(find.byType(StageDefinitionView), findsNothing);
});
testWidgets('a new stage key on the shown pin swaps the pane in place', (
tester,
) async {
final gateway = _twoReviewPipelines();
await _pumpPipelines(
tester,
gateway: gateway,
pipelineId: 1,
stageKey: 'review',
);
expect(
tester
.widget<StageDefinitionView>(find.byType(StageDefinitionView))
.stageKey,
'review',
);
final reads = gateway.callsOf('get_pipeline').length;
expect(reads, greaterThan(0));
await tester.pageBack();
await tester.pumpAndSettle();
// The app pushes another stage URL for the pin already on screen.
await tester.pumpWidget(
MaterialApp(
home: PipelinesScreen(
gateway: gateway,
initialPipelineId: 1,
initialStageKey: 'publish',
),
),
);
await tester.pumpAndSettle();
final pane = tester.widget<StageDefinitionView>(
find.byType(StageDefinitionView),
);
expect(pane.stageKey, 'publish');
expect(pane.pipelineId, 1);
// The same pin is already shown, so the new request must not re-read it.
expect(gateway.callsOf('get_pipeline'), hasLength(reads));
});
testWidgets('a same-pipeline route change to latest re-reads latest', (
tester,
) async {
// A latest route is not "whatever version is on screen": the pinned detail
// was requested for v1, so moving the route to latest must ask again.
final gateway = _versionedAlpha();
await _pumpPipelines(tester, gateway: gateway, pipelineId: 1, version: 1);
expect(find.text('id 1 · v1 · 1 stage'), findsOneWidget);
await tester.pumpWidget(
MaterialApp(
home: PipelinesScreen(gateway: gateway, initialPipelineId: 1),
),
);
await tester.pumpAndSettle();
expect(
gateway.callsOf('get_pipeline').last.fields['version'],
0,
reason: 'the latest route re-reads latest instead of keeping the v1 pin',
);
expect(find.text('id 1 · v5 · 2 stages'), findsWidgets);
});
testWidgets('a routed stage follows a route change from a pin to latest', (
tester,
) async {
final gateway = _versionedAlpha();
await _pumpPipelines(
tester,
gateway: gateway,
pipelineId: 1,
version: 1,
stageKey: 'review',
);
final pinned = tester.widget<StageDefinitionView>(
find.byType(StageDefinitionView),
);
expect(pinned.version, 1);
expect(pinned.graph, reviewGraphV1());
await tester.pageBack();
await tester.pumpAndSettle();
// The same pipeline and stage, now at latest.
await tester.pumpWidget(
MaterialApp(
home: PipelinesScreen(
gateway: gateway,
initialPipelineId: 1,
initialStageKey: 'review',
),
),
);
await tester.pumpAndSettle();
expect(gateway.callsOf('get_pipeline').last.fields['version'], 0);
final pane = tester.widget<StageDefinitionView>(
find.byType(StageDefinitionView),
);
expect(pane.stageKey, 'review');
expect(pane.pipelineId, 1);
expect(
pane.version,
5,
reason: 'a latest stage URL cannot open the stale v1 definition',
);
expect(pane.graph, reviewGraph());
// Back lands on the latest definition's graph with the node selected.
await tester.pageBack();
await tester.pumpAndSettle();
expect(
tester
.widget<PipelineDetailTabs>(find.byType(PipelineDetailTabs))
.selected,
PipelineDetailTab.graph,
);
expect(
tester
.widget<DefinitionGraphView>(find.byType(DefinitionGraphView))
.selectedStage,
'review',
);
});
}
@@ -0,0 +1,168 @@
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/graph/widgets/stage_definition_view.dart';
import 'package:pipelines_app/features/pipelines/pipeline_repository.dart';
import 'package:pipelines_app/features/pipelines/pipelines_controller.dart';
import 'package:pipelines_app/features/pipelines/widgets/pipeline_detail_panel.dart';
import 'package:pipelines_app/features/pipelines/widgets/pipeline_tabs.dart';
import 'fixtures.dart';
/// A route stage request belongs to the pipeline and version it names.
void main() {
testWidgets('a stage request applies only to the pin it names', (
tester,
) async {
tester.view.physicalSize = const Size(1100, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
// Both fixtures declare `review`: the pipeline alone cannot explain a pane.
final gateway = FakeGateway(
(type, fields) => switch (type) {
'get_pipeline' => pipelineDetailReply(
fields['pipeline_id'] == 1
? pipelineDetail(
id: 1,
name: 'Alpha review',
version: fields['version'] as int,
latestVersion: 2,
stages: 2,
graph: (fields['version'] as int) == 1
? reviewGraphV1()
: reviewGraph(),
versions: [versionSummary(1), versionSummary(2)],
)
: pipelineDetail(
id: 2,
name: 'Beta deploy',
version: 1,
latestVersion: 1,
graph: reviewGraph(),
versions: [versionSummary(1)],
),
),
_ => errorReply('unexpected $type'),
},
);
final controller = PipelinesController(PipelinesRepository(gateway));
addTearDown(controller.dispose);
PipelineDetailTab shownTab() => tester
.widget<PipelineDetailTabs>(find.byType(PipelineDetailTabs))
.selected;
// The request names pipeline 1 v1, but the detail shows pipeline 2.
await controller.openPipeline(2);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: AnimatedBuilder(
animation: controller,
builder: (context, _) => PipelineDetailPanel(
controller: controller,
gateway: gateway,
showBack: true,
stageKey: 'review',
stagePipelineId: 1,
stageVersion: 1,
),
),
),
),
);
await tester.pumpAndSettle();
expect(shownTab(), PipelineDetailTab.summary);
expect(find.byType(StageDefinitionView), findsNothing);
// The named pipeline at another version is a different definition too.
await controller.openPipeline(1, version: 2);
await tester.pumpAndSettle();
expect(shownTab(), PipelineDetailTab.summary);
expect(find.byType(StageDefinitionView), findsNothing);
// The exact pin the request names is where it applies, once.
await controller.openPipeline(1, version: 1);
await tester.pumpAndSettle();
final pane = tester.widget<StageDefinitionView>(
find.byType(StageDefinitionView),
);
expect(pane.stageKey, 'review');
expect(pane.pipelineId, 1);
expect(pane.version, 1);
expect(find.text('review definition'), findsOneWidget);
});
testWidgets('a latest stage request waits for a latest reply', (
tester,
) async {
tester.view.physicalSize = const Size(1100, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final gateway = FakeGateway(
(type, fields) => switch (type) {
'get_pipeline' => pipelineDetailReply(_versionedDetail(fields)),
_ => errorReply('unexpected $type'),
},
);
final controller = PipelinesController(PipelinesRepository(gateway));
addTearDown(controller.dispose);
PipelineDetailTab shownTab() => tester
.widget<PipelineDetailTabs>(find.byType(PipelineDetailTabs))
.selected;
// The route asks for latest, but the panel currently shows a detail it
// requested for v1: latest is a different request, not "any version".
await controller.openPipeline(1, version: 1);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: AnimatedBuilder(
animation: controller,
builder: (context, _) => PipelineDetailPanel(
controller: controller,
gateway: gateway,
showBack: true,
stageKey: 'review',
stagePipelineId: 1,
stageVersion: 0,
),
),
),
),
);
await tester.pumpAndSettle();
expect(shownTab(), PipelineDetailTab.summary);
expect(find.byType(StageDefinitionView), findsNothing);
// Once the latest reply is shown, the request applies to that pin.
await controller.openPipeline(1);
await tester.pumpAndSettle();
final pane = tester.widget<StageDefinitionView>(
find.byType(StageDefinitionView),
);
expect(pane.stageKey, 'review');
expect(pane.pipelineId, 1);
expect(pane.version, 5);
expect(pane.graph, reviewGraph());
});
}
/// Alpha whose latest is v5 and whose v1 definition differs, so the pane's
/// version proves which pin the request applied to.
Map<String, dynamic> _versionedDetail(JsonMap fields) {
final requested = fields['version'] as int? ?? 0;
final version = requested > 0 ? requested : 5;
return pipelineDetail(
id: 1,
name: 'Alpha review',
version: version,
latestVersion: 5,
stages: version == 1 ? 1 : 2,
graph: version == 1 ? reviewGraphV1() : reviewGraph(),
versions: [versionSummary(1), versionSummary(5)],
);
}