From 629c8c609158f2bf62141f9125a7e6d7cda6d31b Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Mon, 2 Nov 2026 00:40:38 +0000 Subject: [PATCH] Search artifact hit: clear the pending visit flag; tests for opening After opening an artifact from search the pending flag was never cleared, so later visit selections stopped syncing. It is cleared once the visit page is installed. Adds widget tests: the hit opens the viewer on that artifact, Back lands on its visit and another visit still opens, and a missing artifact shows the notice. Finishes run #231. --- app/lib/features/runs/ui/run_detail_tabs.dart | 3 + .../runs/ui/run_search_selection_test.dart | 65 ++++++++++++++++++- 2 files changed, 67 insertions(+), 1 deletion(-) 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 {