diff --git a/app/lib/features/runs/ui/run_detail_tabs.dart b/app/lib/features/runs/ui/run_detail_tabs.dart index 2106602d..0f595410 100644 --- a/app/lib/features/runs/ui/run_detail_tabs.dart +++ b/app/lib/features/runs/ui/run_detail_tabs.dart @@ -269,6 +269,9 @@ class _RunDetailTabsState extends State { // visit first so it remains the run-detail destination on Back, including // when the recorded artifact has disappeared. unawaited(_pushVisit(visitIndex)); + // The visit page is now the shown one (_pushVisit records it before its + // first await), so later visit selections sync normally again. + _searchArtifactVisitPending = false; final steps = detailRunSteps(widget.run); final groups = galleryGroups(steps); ArtifactGroup? selectedGroup; diff --git a/app/test/features/runs/ui/run_search_selection_test.dart b/app/test/features/runs/ui/run_search_selection_test.dart index cd5e8576..a68481f5 100644 --- a/app/test/features/runs/ui/run_search_selection_test.dart +++ b/app/test/features/runs/ui/run_search_selection_test.dart @@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'run_detail_finders.dart'; +import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_page.dart'; import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/features/runs/data/runs_repository.dart'; import 'package:pipelines_app/features/runs/ui/run_detail_view.dart'; @@ -48,11 +49,12 @@ Future> pumpLiveSelection( RunDetailTestPlatform platform, RunSearchSelection selection, { VoidCallback? onConsumed, + JsonMap? run, }) async { tester.view.physicalSize = const Size(900, 1000); tester.view.devicePixelRatio = 1; addTearDown(tester.view.reset); - final gateway = RunDetailFakeGateway(searchSelectionRun()); + final gateway = RunDetailFakeGateway(run ?? searchSelectionRun()); final controller = RunsController(RunsRepository(gateway)); addTearDown(controller.dispose); await controller.select(77); @@ -117,6 +119,67 @@ void main() { }); } + /// The search fixture with one recorded artifact on build (sequence 2). + JsonMap runWithArtifact() { + final run = searchSelectionRun(); + final steps = [ + for (final step in run['steps'] as List) + Map.from(step as Map), + ]; + steps[1]['artifacts'] = [ + { + 'name': 'release-report.txt', + 'content_type': 'text/plain', + 'size_bytes': 12, + 'url': '/artifacts/77/2/release-report.txt', + }, + ]; + return {...run, 'steps': steps}; + } + + for (final platform in RunDetailTestPlatform.values) { + testWidgets('${platform.name} artifact hit opens that artifact, and the ' + 'timeline keeps working afterwards', (tester) async { + final pending = await pumpLiveSelection( + tester, + platform, + const RunSearchSelection( + runId: 77, + sequence: 2, + artifactUrl: '/artifacts/77/2/release-report.txt', + ), + run: runWithArtifact(), + ); + expect(find.byType(ArtifactViewerPage), findsOneWidget); + expect(find.text('release-report.txt'), findsWidgets); + + // Back from the viewer lands on the artifact's visit. + Navigator.of(tester.element(find.byType(ArtifactViewerPage))).pop(); + await tester.pumpAndSettle(); + expect(find.byType(ArtifactViewerPage), findsNothing); + expectVisitHeading(tester, 'build', 1); + + // Selecting another visit afterwards still opens it. + pending.value = const RunSearchSelection(runId: 77, sequence: 5); + await tester.pumpAndSettle(); + expectVisitHeading(tester, 'plan', 2); + }); + } + + testWidgets('a missing artifact opens the run with a notice', (tester) async { + await pumpSelection( + tester, + RunDetailTestPlatform.material, + const RunSearchSelection( + runId: 77, + sequence: 2, + artifactUrl: '/artifacts/77/2/gone.txt', + ), + ); + expect(find.byType(ArtifactViewerPage), findsNothing); + expect(find.text('That artifact is no longer available.'), findsOneWidget); + }); + testWidgets('an unknown artifact sequence opens the plain run', ( tester, ) async {