merge(app): land run-decide-deeplink micro-slice

This commit is contained in:
2026-10-22 12:30:43 +01:00
5 changed files with 328 additions and 71 deletions
@@ -0,0 +1,156 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
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/runs/actions/decision_wording.dart';
import 'package:pipelines_app/features/runs/screen.dart';
JsonMap _waitingRun() => {
'id': 9,
'title': 'Human checkpoint',
'name': 'fixture',
'status': 'waiting',
'executing': false,
'current_stage': 'gate',
'graph': {
'stages': [
{
'key': 'gate',
'type': 'human',
'edges': {'approve': '#success'},
},
],
},
'steps': [
{
'sequence': 1,
'stage': 'gate',
'status': 'waiting',
'output': {
'prompt': 'Please review this recorded checkpoint.',
'options': ['approve'],
},
},
],
};
JsonMap _finishedRun() => {
..._waitingRun(),
'status': 'succeeded',
'steps': [
{
'sequence': 1,
'stage': 'gate',
'status': 'completed',
'outcome': 'success',
},
],
};
class _Gateway implements ApiGateway {
_Gateway(this.run);
final JsonMap run;
final _events = StreamController<JsonMap>.broadcast();
@override
Stream<JsonMap> get frames => _events.stream;
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) =>
switch (type) {
'list_runs' => Future.value({
'runs': [run],
}),
'get_run' => Future.value({'run_detail': run}),
_ => Future.error(UnsupportedError(type)),
};
void close() => _events.close();
}
Future<void> _pump(
WidgetTester tester,
_Gateway gateway, {
required bool decide,
}) async {
tester.view.physicalSize = const Size(900, 1000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final screen = RunsScreen(
gateway: gateway,
initialRunId: 9,
initialDecide: decide,
);
await tester.pumpWidget(MaterialApp(home: Scaffold(body: screen)));
await tester.pumpAndSettle();
}
void main() {
for (final cupertino in [false, true]) {
testWidgets('a decide route opens the waiting prompt ($cupertino)', (
tester,
) async {
final gateway = _Gateway(_waitingRun());
addTearDown(gateway.close);
tester.view.physicalSize = const Size(900, 1000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final screen = RunsScreen(
gateway: gateway,
initialRunId: 9,
initialDecide: true,
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: screen))
: MaterialApp(home: Scaffold(body: screen)),
);
await tester.pumpAndSettle();
expect(find.byKey(decisionFeedbackKey), findsOneWidget);
expect(
find.text('Please review this recorded checkpoint.'),
findsOneWidget,
);
// Closing the prompt leaves the loaded detail underneath.
await tester.tap(find.text(decisionCancelLabel));
await tester.pumpAndSettle();
expect(find.byKey(decisionFeedbackKey), findsNothing);
expect(find.text('Human checkpoint'), findsOneWidget);
expect(find.byKey(decisionActionKey), findsOneWidget);
});
}
testWidgets('a decide route on a non-waiting run invents no prompt', (
tester,
) async {
final gateway = _Gateway(_finishedRun());
addTearDown(gateway.close);
await _pump(tester, gateway, decide: true);
expect(find.byKey(decisionFeedbackKey), findsNothing);
expect(find.byKey(decisionActionKey), findsNothing);
expect(find.text('Human checkpoint'), findsOneWidget);
});
testWidgets('a route without decide keeps the plain waiting detail', (
tester,
) async {
final gateway = _Gateway(_waitingRun());
addTearDown(gateway.close);
await _pump(tester, gateway, decide: false);
expect(find.byKey(decisionFeedbackKey), findsNothing);
expect(find.text('Human checkpoint'), findsOneWidget);
expect(find.byKey(decisionActionKey), findsOneWidget);
// The landed button still opens the same prompt deliberately.
await tester.tap(find.byKey(decisionActionKey));
await tester.pumpAndSettle();
expect(find.byKey(decisionFeedbackKey), findsOneWidget);
});
}