merge(app): land pipeline Graph tab after retained-deadline recovery

This commit is contained in:
2026-10-22 00:07:56 +01:00
15 changed files with 1562 additions and 140 deletions
+56
View File
@@ -65,6 +65,8 @@ Map<String, dynamic> pipelineDetail({
int? scheduleCount = 0,
bool? scheduled = false,
List<Map<String, dynamic>> versions = const [],
Map<String, dynamic>? graph,
Map<String, dynamic>? shape,
}) => {
...pipelineSummary(
id: id,
@@ -79,6 +81,50 @@ Map<String, dynamic> pipelineDetail({
'content_hash': contentHash,
'source': source,
'versions': versions,
'graph': ?graph,
'shape': ?shape,
};
/// The two-stage definition pinned into the Alpha detail fixture.
Map<String, dynamic> reviewGraph() => {
'name': 'Alpha review',
'settings': {'schedules': <dynamic>[]},
'stages': <dynamic>[
{
'key': 'review',
'type': 'model',
'prompt': 'Review the change.',
'output': 'notes',
'edges': {'success': 'publish', 'error': '#'},
'fallback_error': true,
'future_field': {'kept': true},
},
{
'key': 'publish',
'type': 'model',
'output': 'release',
'edges': {'success': '#success', 'error': '#failure'},
},
],
};
/// The one-stage definition pinned by Alpha review v1.
///
/// A real version pin never reuses the newer graph, so the fixture keeps a
/// distinct v1 definition too: a version switch must not keep a newer node's
/// selection merely because the node key survived.
Map<String, dynamic> reviewGraphV1() => {
'name': 'Alpha review',
'settings': {'schedules': <dynamic>[]},
'stages': <dynamic>[
{
'key': 'review',
'type': 'model',
'prompt': 'Review the change.',
'output': 'notes',
'edges': {'success': '#success', 'error': '#'},
},
],
};
Map<String, dynamic> versionSummary(
@@ -166,6 +212,8 @@ class PipelineFixture {
scheduled: true,
source: 'name: Alpha review\nstages:\n review:\n type: model',
versions: [versionSummary(1, stages: 1), versionSummary(2, stages: 2)],
graph: reviewGraph(),
shape: reviewGraph(),
),
pipelineDetail(
id: 2,
@@ -201,6 +249,12 @@ class PipelineFixture {
),
];
/// The graph pinned by each recorded version, when it differs from latest.
late final Map<String, Map<String, dynamic>> versionGraphs = {
'1@1': reviewGraphV1(),
'1@2': reviewGraph(),
};
Map<String, dynamic>? detailFor(int id, int version) {
final match = details.where((detail) => detail['id'] == id);
if (match.isEmpty) return null;
@@ -210,6 +264,8 @@ class PipelineFixture {
for (final row in detail['versions'] as List<Map<String, dynamic>>) {
if (row['version'] == version) detail['stages'] = row['stages'];
}
final graph = versionGraphs['$id@$version'];
if (graph != null) detail['graph'] = graph;
if (version < (detail['latest_version'] as int)) {
detail['source'] = '${detail['source']}\n# selected version $version';
}
@@ -0,0 +1,152 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/graph/widgets/definition_graph_view.dart';
import 'package:pipelines_app/features/pipelines/pipeline_models.dart';
import 'package:pipelines_app/features/pipelines/widgets/pipeline_graph_tab.dart';
import 'fixtures.dart';
/// The note is measured and clipped by this tab, so these cases pump it at the
/// tab slots the real panel gives it (390x312 and 660x168 are the measured
/// slots at 390x600 and 1100x400 on a 2x text scale).
Future<void> _pumpTab(
WidgetTester tester,
Size size, {
double scale = 2,
}) async {
await tester.pumpWidget(
MaterialApp(
builder: (context, child) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: TextScaler.linear(scale)),
child: child!,
),
home: Scaffold(
body: Center(
child: SizedBox(
width: size.width,
height: size.height,
child: PipelineGraphTab(
detail: _detail(),
selectedStage: null,
onSelected: (_) {},
),
),
),
),
),
);
await tester.pumpAndSettle();
}
PipelineDetail _detail() => PipelineDetail.fromJson(
pipelineDetail(
id: 1,
name: 'Alpha review',
version: 2,
latestVersion: 2,
graph: reviewGraph(),
),
);
/// The line heights the rendered [Text] actually uses at the current scale.
List<double> _lineHeights(WidgetTester tester) {
final note = tester.widget<Text>(find.text(pipelineGraphNote));
final noteSize = tester.getSize(find.byKey(const Key('pipeline-graph-note')));
final painter = TextPainter(
text: TextSpan(text: pipelineGraphNote, style: note.style),
textDirection: TextDirection.ltr,
textScaler: MediaQuery.textScalerOf(
tester.element(find.byType(PipelineGraphTab)),
),
)..layout(maxWidth: noteSize.width - 32);
return [for (final line in painter.computeLineMetrics()) line.height];
}
void main() {
for (final (size, tabSlot, scale, withinShare) in <(Size, double, double, bool)>[
(const Size(390, 312), 312, 2, true),
// Two whole lines are kept even though a third of the slot is only 56 px,
// so the note stays readable and the canvas keeps over half.
(const Size(660, 168), 168, 2, false),
// A 4x line is taller than a third of this tab; one whole line is kept and
// the canvas still gets more than half.
(const Size(390, 160), 160, 4, false),
]) {
testWidgets('a clipped note keeps whole lines and a visible scrollbar at '
'${size.width.toInt()}x${tabSlot.toInt()} @${scale}x', (tester) async {
await _pumpTab(tester, size, scale: scale);
final noteSize = tester.getSize(
find.byKey(const Key('pipeline-graph-note')),
);
final canvas = tester.getSize(find.byType(DefinitionGraphView));
expect(noteSize.height, greaterThan(0));
expect(
find.byKey(const Key('pipeline-graph-note-scrollbar')),
findsOneWidget,
);
if (withinShare) {
expect(
noteSize.height,
lessThanOrEqualTo(tabSlot * pipelineGraphNoteShare + 0.5),
);
}
// The clipped viewport ends on a line boundary: no half-drawn row.
final heights = _lineHeights(tester);
var whole = 0.0;
for (final height in heights) {
if (whole + height > noteSize.height + 0.5) break;
whole += height;
}
expect(whole, greaterThan(0));
expect(noteSize.height, closeTo(whole, 0.5));
expect(
noteSize.height,
lessThan(heights.fold<double>(0, (a, b) => a + b)),
);
// The hidden tail is really scrollable: a standard scrollbar plus wheel
// and drag, not an inert clipped label.
final scrollbar = tester.widget<Scrollbar>(
find.byKey(const Key('pipeline-graph-note-scrollbar')),
);
final controller = scrollbar.controller!;
expect(controller.position.maxScrollExtent, greaterThan(0));
await tester.drag(
find.byKey(const Key('pipeline-graph-note-scroll')),
const Offset(0, -400),
);
await tester.pumpAndSettle();
expect(controller.position.pixels, greaterThan(0));
// The canvas keeps the rest of the slot throughout.
expect(canvas.height, greaterThan(0));
expect(canvas.height, greaterThanOrEqualTo(tabSlot * 0.5));
expect(tester.takeException(), isNull);
});
}
testWidgets('a note that fits keeps its natural height and no scrollbar', (
tester,
) async {
await _pumpTab(tester, const Size(1000, 700), scale: 1);
expect(
find.byKey(const Key('pipeline-graph-note-scrollbar')),
findsNothing,
);
expect(find.byKey(const Key('pipeline-graph-note-scroll')), findsNothing);
expect(
tester.getSize(find.byKey(const Key('pipeline-graph-note'))).height,
lessThan(120),
);
expect(
tester.getSize(find.byType(DefinitionGraphView)).height,
greaterThan(500),
);
expect(tester.takeException(), isNull);
});
}
@@ -0,0 +1,293 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/graph/widgets/definition_graph_view.dart';
import 'package:pipelines_app/features/graph/widgets/graph_stage_node.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_graph_tab.dart';
import 'fixtures.dart';
import 'test_helpers.dart';
Finder _node(String key) => find.byWidgetPredicate(
(widget) => widget is GraphStageNode && widget.node.key == key,
);
/// Taps a node, panning the stock canvas first when the node starts offscreen.
Future<void> _tapNode(WidgetTester tester, String key) async {
final viewport = tester.getRect(find.byType(InteractiveViewer));
final node = tester.getRect(_node(key));
if (!viewport.contains(node.center)) {
await tester.drag(
find.byType(InteractiveViewer),
viewport.center - node.center,
);
await tester.pumpAndSettle();
}
await tester.tap(_node(key));
await tester.pump();
}
Future<void> _pumpScreen(
WidgetTester tester,
Size size, {
double scale = 1,
FakeGateway? gateway,
int syncToken = 0,
}) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(
MaterialApp(
builder: (context, child) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: TextScaler.linear(scale)),
child: child!,
),
home: PipelinesScreen(
gateway: gateway ?? gatewayFor(PipelineFixture()),
syncToken: syncToken,
),
),
);
await tester.pumpAndSettle();
}
Future<void> _openGraphTab(WidgetTester tester, int pipelineId) async {
await tester.tap(find.byKey(Key('pipeline-row-$pipelineId')));
await tester.pumpAndSettle();
await tester.tap(find.text('Graph'));
await tester.pump();
await tester.pump();
}
void main() {
test('detail keeps the pinned graph verbatim without touching source', () {
final graph = reviewGraph();
final detail = PipelineDetail.fromJson(
pipelineDetail(
id: 9,
name: 'Pinned review',
version: 4,
latestVersion: 5,
source: 'exact: authored source',
stages: 2,
versions: [versionSummary(4, stages: 2)],
graph: graph,
shape: graph,
),
);
expect(detail.graph, graph);
expect(detail.shape, graph);
expect(detail.graph!['settings'], {'schedules': <dynamic>[]});
expect((detail.graph!['stages'] as List<dynamic>).first['future_field'], {
'kept': true,
});
expect(detail.source, 'exact: authored source');
expect(detail.versions.single.version, 4);
expect(detail.resolvedVersion, 4);
});
test('a reply without a graph keeps null instead of inventing one', () {
final detail = PipelineDetail.fromJson(
pipelineDetail(id: 2, name: 'Beta deploy', version: 1, latestVersion: 1),
);
expect(detail.graph, isNull);
expect(detail.shape, isNull);
});
// The note must never take the canvas away: a short window (390x600), a short
// wide split pane (1100x400) and a large accessibility text scale (3x) all
// used to overflow the tab and lay the canvas out at zero height.
for (final (size, scale) in <(Size, double)>[
(const Size(390, 844), 2),
(const Size(390, 600), 2),
(const Size(1100, 400), 2),
(const Size(1100, 900), 3),
]) {
testWidgets('graph tab keeps a usable canvas at '
'${size.width.toInt()}x${size.height.toInt()} @${scale}x', (
tester,
) async {
await _pumpScreen(tester, size, scale: scale);
await _openGraphTab(tester, 1);
expect(tester.takeException(), isNull);
expect(find.text(pipelineGraphNote), findsOneWidget);
expect(find.byType(DefinitionGraphView), findsOneWidget);
final tab = tester.getSize(find.byType(PipelineGraphTab));
final note = tester.getSize(find.byKey(const Key('pipeline-graph-note')));
final canvas = tester.getSize(find.byType(DefinitionGraphView));
expect(canvas.height, greaterThan(0));
expect(
note.height,
lessThanOrEqualTo(tab.height * 0.5 + 1),
reason: 'the guidance note may never take more than half the tab',
);
expect(
canvas.height,
greaterThanOrEqualTo(tab.height * 0.5 - 1),
reason: 'the canvas keeps at least half of the tab slot',
);
expect(canvas.height, lessThan(tab.height));
});
}
testWidgets('an empty definition keeps its message in a short slot', (
tester,
) async {
final detail = PipelineDetail.fromJson(
pipelineDetail(
id: 4,
name: 'Empty definition',
version: 1,
latestVersion: 1,
graph: {'name': 'Empty definition', 'stages': <dynamic>[]},
),
);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Center(
child: SizedBox(
width: 390,
height: 200,
child: PipelineGraphTab(
detail: detail,
selectedStage: null,
onSelected: (_) {},
),
),
),
),
),
);
await tester.pumpAndSettle();
expect(find.text(definitionGraphEmpty), findsOneWidget);
expect(find.byType(GraphStageNode), findsNothing);
expect(tester.takeException(), isNull);
});
testWidgets('selecting a node opens its exact pinned definition', (
tester,
) async {
await _pumpScreen(tester, const Size(1100, 900));
await _openGraphTab(tester, 1);
await _tapNode(tester, 'review');
await tester.pumpAndSettle();
final stagePane = tester.widget<StageDefinitionView>(
find.byType(StageDefinitionView),
);
expect(stagePane.stageKey, 'review');
expect(stagePane.pipelineId, 1);
expect(stagePane.pipelineName, 'Alpha review');
expect(stagePane.version, 2);
expect(stagePane.graph, reviewGraph());
expect(find.text('review definition'), findsOneWidget);
expect(find.text('Alpha review · v2'), findsOneWidget);
await tester.pageBack();
await tester.pumpAndSettle();
expect(find.byType(StageDefinitionView), findsNothing);
expect(tester.widget<GraphStageNode>(_node('review')).selected, isTrue);
// The selection belongs to the panel, so an in-place tab round trip keeps
// the same node marked (the web keeps its graph selection across tabs).
await tester.tap(find.text('Summary'));
await tester.pumpAndSettle();
await tester.tap(find.text('Graph'));
await tester.pump();
await tester.pump();
expect(tester.widget<GraphStageNode>(_node('review')).selected, isTrue);
// Terminals are definition targets too: they open the same pane with the
// pinned identity, not a visit.
await _tapNode(tester, '#success');
await tester.pumpAndSettle();
final terminalPane = tester.widget<StageDefinitionView>(
find.byType(StageDefinitionView),
);
expect(terminalPane.stageKey, '#success');
expect(terminalPane.pipelineId, 1);
expect(terminalPane.version, 2);
expect(find.text('Success definition'), findsOneWidget);
await tester.pageBack();
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
// The selection belongs to the pinned definition: changing version must not
// carry a same-named node's mark into the other version.
await tester.tap(find.text('Summary'));
await tester.pumpAndSettle();
await tester.ensureVisible(find.byKey(const Key('pipeline-version-1')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('pipeline-version-1')));
await tester.pumpAndSettle();
expect(find.text('Viewing v1 (latest v2).'), findsOneWidget);
await tester.tap(find.text('Graph'));
await tester.pump();
await tester.pump();
expect(tester.widget<GraphStageNode>(_node('review')).selected, isFalse);
expect(
tester
.widget<DefinitionGraphView>(find.byType(DefinitionGraphView))
.graph,
reviewGraphV1(),
);
});
testWidgets('a reconnect that replaces the detail clears the old mark', (
tester,
) async {
var latest = 2;
final fixture = PipelineFixture();
final gateway = FakeGateway(
(type, fields) => switch (type) {
'list_pipelines' => pipelineListReply(fixture.summaries),
'list_runs' => runListReply(fixture.runs),
'get_pipeline' => pipelineDetailReply(
fixture.detailFor(fields['pipeline_id'] as int, latest)!,
),
_ => errorReply('unexpected $type'),
},
);
await _pumpScreen(tester, const Size(1100, 900), gateway: gateway);
await _openGraphTab(tester, 1);
await _tapNode(tester, 'review');
await tester.pumpAndSettle();
await tester.pageBack();
await tester.pumpAndSettle();
expect(tester.widget<GraphStageNode>(_node('review')).selected, isTrue);
// A reconnect reloads the selected detail in place (it is not nulled), so
// this is the path the old tab-state guard existed for. The newer pin must
// not inherit the previous version's mark.
latest = 3;
await _pumpScreen(
tester,
const Size(1100, 900),
gateway: gateway,
syncToken: 1,
);
expect(find.byType(GraphStageNode), findsWidgets);
expect(tester.widget<GraphStageNode>(_node('review')).selected, isFalse);
expect(tester.takeException(), isNull);
});
testWidgets('a missing definition graph is stated, never drawn', (
tester,
) async {
await _pumpScreen(tester, const Size(1100, 900));
await _openGraphTab(tester, 2);
expect(find.text(pipelineGraphMissing), findsOneWidget);
expect(find.byType(DefinitionGraphView), findsNothing);
expect(find.byType(GraphStageNode), findsNothing);
});
}
@@ -2,7 +2,11 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/graph/widgets/definition_graph_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/screen.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';
@@ -142,37 +146,45 @@ void main() {
}
});
testWidgets('hosted graph hook receives the selected pipeline and stage', (
testWidgets('3x text in a very short panel keeps the tabs reachable', (
tester,
) async {
final fixture = PipelineFixture();
PipelineStageRef? selected;
tester.view.physicalSize = const Size(390, 300);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final controller = PipelinesController(
PipelinesRepository(gatewayFor(PipelineFixture())),
);
addTearDown(controller.dispose);
await controller.openPipeline(1);
await tester.pumpWidget(
MaterialApp(
home: PipelinesScreen(
gateway: gatewayFor(fixture),
graphBuilder: (context, detail, onStageSelected) => Column(
children: [
Text('HOSTED GRAPH ${detail.id} v${detail.resolvedVersion}'),
TextButton(
onPressed: () => onStageSelected('review'),
child: const Text('Stage review'),
),
],
),
onStageSelected: (ref) => selected = ref,
builder: (context, child) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: const TextScaler.linear(3)),
child: child!,
),
home: Scaffold(
body: PipelineDetailPanel(controller: controller, showBack: true),
),
),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('pipeline-row-1')));
// The header scrolls instead of squeezing the tab out; the tabs stay
// reachable inside it and the tab keeps a bounded slot.
expect(tester.takeException(), isNull);
await tester.ensureVisible(find.text('Graph'));
await tester.pumpAndSettle();
await tester.tap(find.text('Graph'));
await tester.pump();
expect(find.text('HOSTED GRAPH 1 v2'), findsOneWidget);
await tester.tap(find.text('Stage review'));
expect(selected?.pipelineId, 1);
expect(selected?.version, 2);
expect(selected?.stageKey, 'review');
await tester.pump();
expect(tester.takeException(), isNull);
expect(find.byType(DefinitionGraphView), findsOneWidget);
expect(
tester.getSize(find.byType(DefinitionGraphView)).height,
greaterThan(0),
);
});
}
@@ -153,14 +153,4 @@ void main() {
await tester.pumpAndSettle();
expect(gateway.callsOf('list_pipelines').length, lists + 1);
});
testWidgets('graph tab states it is pending without a hook', (tester) async {
final fixture = PipelineFixture();
await pumpWide(tester, gatewayFor(fixture));
await tester.tap(find.byKey(const Key('pipeline-row-1')));
await tester.pumpAndSettle();
await tester.tap(find.text('Graph'));
await tester.pump();
expect(find.text('Graph rendering is pending (P2).'), findsOneWidget);
});
}