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.
This commit is contained in:
2026-11-02 00:40:38 +00:00
parent 7e00cedd00
commit 629c8c6091
2 changed files with 67 additions and 1 deletions
@@ -269,6 +269,9 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
// 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;
@@ -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<ValueNotifier<RunSearchSelection?>> 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<String, dynamic>.from(step as Map),
];
steps[1]['artifacts'] = <dynamic>[
<String, dynamic>{
'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 {