From a82560be1aa37387ef6a4a1597f142b280787988 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Thu, 22 Oct 2026 23:50:18 +0100 Subject: [PATCH] fix(app): the Run dialog waits for the stored pending intent after a reload --- .../pipelines/pipelines_controller.dart | 17 ++++++++ .../pipelines/ui/run_pipeline_action.dart | 7 ++- .../ui/run_pipeline_launch_test.dart | 43 +++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/app/lib/features/pipelines/pipelines_controller.dart b/app/lib/features/pipelines/pipelines_controller.dart index 29455a72..e95817ba 100644 --- a/app/lib/features/pipelines/pipelines_controller.dart +++ b/app/lib/features/pipelines/pipelines_controller.dart @@ -218,6 +218,23 @@ class PipelinesController extends ChangeNotifier { _notify(); } + /// The unresolved launch for one pinned definition, read from the device + /// store first, so the Run dialog opened right after a reload offers the + /// same request key instead of minting a new one. + Future loadPendingRun(int pipelineId, int version) async { + final key = '$pipelineId@$version'; + if (_loadedPendingRuns.add(key)) { + final generation = _pendingRunGenerations[key] ?? 0; + final intent = await _pendingRunStore.read(pipelineId, version); + if (!_disposed && + (_pendingRunGenerations[key] ?? 0) == generation && + intent != null) { + _pendingRuns[key] = intent; + } + } + return _pendingRuns[key]; + } + /// The unresolved launch for one pinned definition, if any. RunPipelineIntent? pendingRunFor(int pipelineId, int version) { final key = '$pipelineId@$version'; diff --git a/app/lib/features/pipelines/ui/run_pipeline_action.dart b/app/lib/features/pipelines/ui/run_pipeline_action.dart index 7a58cde5..c8e953fe 100644 --- a/app/lib/features/pipelines/ui/run_pipeline_action.dart +++ b/app/lib/features/pipelines/ui/run_pipeline_action.dart @@ -48,11 +48,16 @@ class _RunPipelineActionState extends State { if (_dialogOpen) return; _dialogOpen = true; try { + final pending = await widget.controller.loadPendingRun( + _pipelineId, + _version, + ); + if (!mounted) return; await showRunPipelineDialog( context: context, detail: widget.detail, gateway: widget.gateway, - pending: widget.controller.pendingRunFor(_pipelineId, _version), + pending: pending, onSubmit: _submit, onPendingChanged: (intent) { if (intent == null) { diff --git a/app/test/features/pipelines/ui/run_pipeline_launch_test.dart b/app/test/features/pipelines/ui/run_pipeline_launch_test.dart index c1724324..f065fbcb 100644 --- a/app/test/features/pipelines/ui/run_pipeline_launch_test.dart +++ b/app/test/features/pipelines/ui/run_pipeline_launch_test.dart @@ -435,6 +435,49 @@ void main() { expect(find.byType(AlertDialog), findsNothing); }); + testWidgets('an unknown launch survives a reload with the same key', ( + tester, + ) async { + SharedPreferences.setMockInitialValues({}); + final fixture = PipelineFixture(); + final navigated = []; + final keys = []; + var attempts = 0; + final gateway = launchGateway( + fixture, + onLaunch: (fields) { + attempts++; + keys.add(fields['request_key'] as String); + if (attempts == 1) throw StateError('Connection closed'); + return acceptedRun(87); + }, + onLookup: (_) => noRun(), + ); + await pumpScreen(tester, gateway, navigated); + await openDetail(tester); + await tester.tap(find.byKey(runPipelineActionKey)); + await tester.pumpAndSettle(); + await fillFields(tester); + await tester.tap(find.byKey(runPipelineConfirmKey)); + await tester.pumpAndSettle(); + expect(find.text(runPipelineCheckRetryLabel), findsOneWidget); + + // A reload: the screen and its controller are gone; only the device + // store remains. + await tester.pumpWidget(const SizedBox()); + await pumpScreen(tester, gateway, navigated); + await openDetail(tester); + await tester.tap(find.byKey(runPipelineActionKey)); + await tester.pumpAndSettle(); + expect(find.text(runPipelineCheckRetryLabel), findsOneWidget); + + await tester.tap(find.byKey(runPipelineConfirmKey)); + await tester.pumpAndSettle(); + expect(keys, hasLength(2)); + expect(keys[1], keys[0]); + expect(navigated, [87]); + }); + testWidgets('closing and reopening an unknown launch restores check/retry', ( tester, ) async {