diff --git a/app/lib/application/pipelines_destination.dart b/app/lib/application/pipelines_destination.dart index 5720c3e6..bf11fa06 100644 --- a/app/lib/application/pipelines_destination.dart +++ b/app/lib/application/pipelines_destination.dart @@ -77,6 +77,7 @@ class PipelinesDestination extends StatelessWidget { Widget _pipelinesScreen() => PipelinesScreen( gateway: session.gateway, + endpoint: server.uri?.toString() ?? '', embedded: true, onRunStarted: onRunStarted, onViewPipelineRuns: onViewPipelineRuns, diff --git a/app/lib/features/pipelines/screen.dart b/app/lib/features/pipelines/screen.dart index 0aefb55e..1dfaa318 100644 --- a/app/lib/features/pipelines/screen.dart +++ b/app/lib/features/pipelines/screen.dart @@ -26,6 +26,7 @@ class PipelinesScreen extends StatefulWidget { const PipelinesScreen({ super.key, required this.gateway, + this.endpoint = '', this.embedded = false, this.syncToken = 0, this.onRunStarted, @@ -37,6 +38,9 @@ class PipelinesScreen extends StatefulWidget { final ApiGateway gateway; + /// Validated websocket endpoint used to isolate stored launch intents. + final String endpoint; + /// True under the application shell, which owns the single navigation bar. final bool embedded; @@ -84,7 +88,7 @@ class _PipelinesScreenState extends State { super.initState(); _controller = PipelinesController( PipelinesRepository(widget.gateway), - pendingRunStore: const SharedPreferencesPendingRunStore(''), + pendingRunStore: SharedPreferencesPendingRunStore(widget.endpoint), )..load(); final id = widget.initialPipelineId; if (id != null) { @@ -96,11 +100,12 @@ class _PipelinesScreenState extends State { @override void didUpdateWidget(PipelinesScreen oldWidget) { super.didUpdateWidget(oldWidget); - if (oldWidget.gateway != widget.gateway) { + if (oldWidget.gateway != widget.gateway || + oldWidget.endpoint != widget.endpoint) { _controller.dispose(); _controller = PipelinesController( PipelinesRepository(widget.gateway), - pendingRunStore: const SharedPreferencesPendingRunStore(''), + pendingRunStore: SharedPreferencesPendingRunStore(widget.endpoint), )..load(); } else if (oldWidget.syncToken != widget.syncToken) { // The socket was replaced; re-read through the existing controller so the 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 f065fbcb..a7448236 100644 --- a/app/test/features/pipelines/ui/run_pipeline_launch_test.dart +++ b/app/test/features/pipelines/ui/run_pipeline_launch_test.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:convert'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -7,6 +8,8 @@ import 'package:shared_preferences/shared_preferences.dart'; import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/core/transport/connection_state.dart'; import 'package:pipelines_app/features/pipelines/screen.dart'; +import 'package:pipelines_app/features/pipelines/pending_run_store.dart'; +import 'package:pipelines_app/features/pipelines/run_pipeline_intent.dart'; import 'package:pipelines_app/features/pipelines/ui/run_pipeline_wording.dart'; import '../fixtures.dart'; @@ -81,6 +84,53 @@ Future fillFields( void main() { TestWidgetsFlutterBinding.ensureInitialized(); SharedPreferences.setMockInitialValues({}); + testWidgets('pending launch intent is scoped to its server endpoint', ( + tester, + ) async { + const intent = RunPipelineIntent( + pipelineId: 1, + version: 2, + prompt: 'pending', + workspace: '/work/alpha', + notifyMode: RunNotifyMode.notify, + requestKey: 'endpoint-intent', + ); + SharedPreferences.setMockInitialValues({ + pendingRunStorageKey('ws://server-a/connect', 1, 2): + jsonEncode(intent.toJson()), + }); + final fixture = PipelineFixture(); + final gateway = launchGateway(fixture, onLaunch: (_) => noRun()); + + await tester.pumpWidget( + MaterialApp( + home: PipelinesScreen( + gateway: gateway, + endpoint: 'ws://server-b/connect', + ), + ), + ); + await tester.pumpAndSettle(); + await openDetail(tester); + await tester.tap(find.byKey(runPipelineActionKey)); + await tester.pumpAndSettle(); + expect(find.text(runPipelineCheckRetryLabel), findsNothing); + await tester.tap(find.byKey(runPipelineCancelKey)); + await tester.pumpAndSettle(); + await tester.pumpWidget( + MaterialApp( + home: PipelinesScreen( + gateway: gateway, + endpoint: 'ws://server-a/connect', + ), + ), + ); + await tester.pumpAndSettle(); + await openDetail(tester); + await tester.tap(find.byKey(runPipelineActionKey)); + await tester.pumpAndSettle(); + expect(find.text(runPipelineCheckRetryLabel), findsOneWidget); + }); testWidgets( 'workspace directory suggestions load on open and selection is local', (tester) async {