Open Search artifact hits in the viewer over the run's Artifacts tab

On a phone-width window the open run is its own page pushed on the app
navigator, so RunDetailTabs was not a descendant of the shell's
RunSearchSelectionScope (which wraps only the Runs tab body). The field or
artifact selection was never seen and the run opened at its plain Summary.
The previous widget tests injected the scope directly above RunDetailView at
900 px, where the detail is an inline pane, so they could not catch it.

- RunsScreen relays the shell's search scope into the detail it builds, so
  the pushed page sees the selection too (also fixes field hits on phones).
- An artifact hit now opens the run's Artifacts tab and the gallery opens
  that artifact exactly as a tap there does: selected, scrolled into view
  (ArtifactVisitReveal) and in the viewer. Back returns to the tab with the
  artifact highlighted. An unknown URL leaves the tab open with the existing
  "That artifact is no longer available." notice.
- New test/application/search_artifact_open_test.dart drives the real Search
  tab -> typed query -> result tap -> run read -> viewer on a 390x844 phone,
  Material and Cupertino; it fails without the scope relay.
This commit is contained in:
2026-11-02 18:34:53 +00:00
parent 37b67c84df
commit 8d2ca95057
9 changed files with 519 additions and 147 deletions
@@ -0,0 +1,118 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/core/transport/pipelines_client.dart';
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_page.dart';
import 'package:pipelines_app/features/search/search_screen.dart';
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
import 'search_wiring_test.dart'
show
closeViewer,
expectArtifactsTabSelecting,
openArtifactHit,
pumpApp,
replyRunDetailFor,
replyRunList,
searchSelectionDetail;
/// The real Search screen, tapped on a phone-sized window.
///
/// On a narrow window the open run is its own page on the app's navigator
/// rather than a pane under the shell, which is where the search selection
/// once went missing: the run opened at its plain Summary. These tests drive
/// the whole path (Search tab, typed query, server results, row tap, run
/// read) rather than injecting a selection into the detail.
void main() {
Future<PlatformRouteInformationProvider> openPhoneApp(
WidgetTester tester,
FakeChannel channel, {
required bool cupertino,
}) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(uri: Uri.parse('/runs')),
);
addTearDown(provider.dispose);
await pumpApp(
tester,
channel: channel,
client: PipelinesClient(channelFactory: (_) => channel),
provider: provider,
cupertino: cupertino,
);
await replyRunList(tester, channel);
return provider;
}
for (final cupertino in [false, true]) {
final platform = cupertino ? 'Cupertino' : 'Material';
testWidgets('$platform phone: an artifact hit opens that artifact in the '
'viewer, and Back shows it on the run Artifacts tab', (tester) async {
final channel = FakeChannel()..readyCompleter.complete();
final provider = await openPhoneApp(
tester,
channel,
cupertino: cupertino,
);
await openArtifactHit(tester, channel);
expect(provider.value.uri.path, '/runs/7');
await replyRunDetailFor(tester, channel, searchSelectionDetail());
await tester.pumpAndSettle();
expect(find.byType(SearchScreen), findsNothing);
final viewer = tester.widget<ArtifactViewerPage>(
find.byType(ArtifactViewerPage),
);
expect(viewer.selectedIdentity, contains('report.txt'));
expect(find.text('report.txt'), findsWidgets);
await closeViewer(tester);
expectArtifactsTabSelecting(tester, '/artifacts/7/2/report.txt');
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
});
testWidgets('$platform phone: an artifact the run no longer lists opens '
'its Artifacts tab with a notice', (tester) async {
final channel = FakeChannel()..readyCompleter.complete();
await openPhoneApp(tester, channel, cupertino: cupertino);
await openArtifactHit(tester, channel);
final detail = searchSelectionDetail();
final steps = [
for (final step in detail['steps'] as List)
Map<String, dynamic>.from(step as Map),
];
steps[1]['artifacts'] = <JsonMap>[
{
'name': 'other.txt',
'content_type': 'text/plain',
'size_bytes': 3,
'url': '/artifacts/7/2/other.txt',
},
];
await replyRunDetailFor(tester, channel, {...detail, 'steps': steps});
await tester.pumpAndSettle();
expect(find.byType(ArtifactViewerPage), findsNothing);
expect(
find.byKey(const ValueKey('run-detail-artifacts-7')),
findsOneWidget,
);
expect(
find.text('That artifact is no longer available.'),
findsOneWidget,
);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
});
}
}
+40 -17
View File
@@ -2,7 +2,6 @@ import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import '../features/runs/ui/run_detail_finders.dart';
import '../native_back.dart';
import 'package:pipelines_app/application/app_route.dart';
import 'package:pipelines_app/application/app_router.dart';
@@ -11,6 +10,8 @@ import 'package:pipelines_app/application/search_destination.dart';
import 'package:pipelines_app/application/server_endpoint.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/core/transport/pipelines_client.dart';
import 'package:pipelines_app/features/artifacts/ui/artifact_tile.dart';
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_page.dart';
import 'package:pipelines_app/features/search/search_screen.dart';
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
@@ -190,10 +191,35 @@ JsonMap searchSelectionDetail() => {
'sequence': 2,
'status': 'completed',
'outcome': 'success',
'artifacts': [
{
'name': 'report.txt',
'content_type': 'text/plain',
'size_bytes': 12,
'url': '/artifacts/7/2/report.txt',
},
],
},
],
};
/// Closes the open artifact viewer the way its own Back does.
Future<void> closeViewer(WidgetTester tester) async {
Navigator.of(tester.element(find.byType(ArtifactViewerPage))).pop();
await tester.pumpAndSettle();
}
/// Run 7's Artifacts tab is shown with the hit's artifact selected.
void expectArtifactsTabSelecting(WidgetTester tester, String url) {
expect(find.byType(ArtifactViewerPage), findsNothing);
expect(find.byKey(const ValueKey('run-detail-artifacts-7')), findsOneWidget);
final tile = find.byWidgetPredicate(
(widget) => widget is ArtifactTile && widget.artifact.url == url,
);
expect(tile, findsOneWidget);
expect(tester.widget<ArtifactTile>(tile).selected, isTrue);
}
JsonMap artifactHit() => {
'kind': 'artifact',
'target': '/artifacts/7/2/report.txt',
@@ -480,24 +506,21 @@ void main() {
await tester.pump();
}
// An artifact hit opens the run and selects the visit that recorded it.
// An artifact hit opens the run's Artifacts tab and that artifact's viewer.
await sendSearch(query: 'report', index: 0, hit: artifactHit());
await tester.tap(
find.byKey(const ValueKey('search.result./artifacts/7/2/report.txt')),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
await tester.pump(const Duration(milliseconds: 400));
await tester.pumpAndSettle();
expect(provider.value.uri.path, '/runs/7');
expect(find.byType(SearchScreen), findsNothing);
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
expectVisitHeading(tester, 'build', 1);
expect(find.byType(ArtifactViewerPage), findsOneWidget);
// Leave the visit page (it covers the shell), then a retired field hit
// opens the plain Summary with no visit.
await tester.tap(find.byKey(const Key('run-visit-back')));
await tester.pumpAndSettle();
// Leave the viewer for the Artifacts tab, then a retired field hit opens
// the plain Summary with no visit.
await closeViewer(tester);
expectArtifactsTabSelecting(tester, '/artifacts/7/2/report.txt');
await sendSearch(query: 'retired', index: 1, hit: retiredFieldHit());
await tester.tap(
find.byKey(const ValueKey('search.result.run:7:5:evidence')),
@@ -536,7 +559,7 @@ void main() {
await tester.pump();
});
testWidgets('an artifact hit selects its visit after the run detail loads', (
testWidgets('an artifact hit opens its viewer after the run detail loads', (
tester,
) async {
tester.view.physicalSize = const Size(900, 1000);
@@ -602,8 +625,9 @@ void main() {
await replyRunDetailFor(tester, channel, searchSelectionDetail(), index: 0);
await tester.pumpAndSettle();
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
expectVisitHeading(tester, 'build', 1);
expect(find.byType(ArtifactViewerPage), findsOneWidget);
await closeViewer(tester);
expectArtifactsTabSelecting(tester, '/artifacts/7/2/report.txt');
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
@@ -693,10 +717,9 @@ void main() {
await openArtifactHit(tester, channel);
await replyRunDetailFor(tester, channel, searchSelectionDetail(), index: 0);
await tester.pumpAndSettle();
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
expect(find.byType(ArtifactViewerPage), findsOneWidget);
await tester.tap(find.byKey(const Key('run-visit-back')));
await tester.pumpAndSettle();
await closeViewer(tester);
await provider.didPushRouteInformation(
RouteInformation(uri: Uri.parse('/runs')),
);
@@ -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_tile.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';
@@ -103,6 +104,8 @@ void _expectSummarySection(RunSearchTarget target, RunSummarySection? section) {
expect((target as RunSummaryTarget).section, section);
}
const _origin = 'http://127.0.0.1:8096';
void main() {
for (final platform in RunDetailTestPlatform.values) {
testWidgets('${platform.name} artifact hit opens its recorded visit', (
@@ -120,6 +123,11 @@ void main() {
}
/// The search fixture with one recorded artifact on build (sequence 2).
///
/// The fake gateway configures no server, so the recorded URLs are absolute:
/// a relative one would not resolve and the gallery would show its facts
/// dialog instead of the viewer. The app-level search wiring test covers the
/// server-relative URLs a real server records.
JsonMap runWithArtifact() {
final run = searchSelectionRun();
final steps = [
@@ -131,33 +139,40 @@ void main() {
'name': 'release-report.txt',
'content_type': 'text/plain',
'size_bytes': 12,
'url': '/artifacts/77/2/release-report.txt',
'url': '$_origin/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 {
testWidgets('${platform.name} artifact hit opens that artifact over the '
'Artifacts tab, 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',
artifactUrl: '$_origin/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.
// Back from the viewer lands on the run's Artifacts tab, the artifact
// shown there selected, exactly as after tapping it in the gallery.
Navigator.of(tester.element(find.byType(ArtifactViewerPage))).pop();
await tester.pumpAndSettle();
expect(find.byType(ArtifactViewerPage), findsNothing);
expectVisitHeading(tester, 'build', 1);
expect(find.byKey(const Key('run-visit-pane')), findsNothing);
expect(find.byKey(const ValueKey('run-detail-artifacts-77')), findsOne);
final tile = tester.widget<ArtifactTile>(find.byType(ArtifactTile));
expect(tile.artifact.url, '$_origin/artifacts/77/2/release-report.txt');
expect(tile.selected, isTrue);
// Selecting another visit afterwards still opens it.
pending.value = const RunSearchSelection(runId: 77, sequence: 5);
@@ -166,20 +181,78 @@ void main() {
});
}
testWidgets('a missing artifact opens the run with a notice', (tester) async {
await pumpSelection(
testWidgets('a missing artifact opens the Artifacts tab with a notice', (
tester,
) async {
await pumpLiveSelection(
tester,
RunDetailTestPlatform.material,
const RunSearchSelection(
runId: 77,
sequence: 2,
artifactUrl: '/artifacts/77/2/gone.txt',
artifactUrl: '$_origin/artifacts/77/2/gone.txt',
),
run: runWithArtifact(),
);
expect(find.byType(ArtifactViewerPage), findsNothing);
expect(find.byKey(const ValueKey('run-detail-artifacts-77')), findsOne);
expect(find.text('That artifact is no longer available.'), findsOneWidget);
});
testWidgets('an artifact far down the gallery is scrolled into view', (
tester,
) async {
final run = runWithArtifact();
final steps = [
for (final step in run['steps'] as List)
Map<String, dynamic>.from(step as Map),
];
// Both plan visits list many files ahead of the build visit's, which
// pushes the requested build artifact well below the fold.
for (final index in [0, 2]) {
final sequence = steps[index]['sequence'];
steps[index]['artifacts'] = <dynamic>[
for (var i = 0; i < 30; i++)
<String, dynamic>{
'name': 'filler-$i.bin',
'content_type': 'application/octet-stream',
'size_bytes': 1,
'url': '$_origin/artifacts/77/$sequence/filler-$i.bin',
},
];
}
(steps[1]['artifacts'] as List).add(<String, dynamic>{
'name': 'late-notes.txt',
'content_type': 'text/plain',
'size_bytes': 3,
'url': '$_origin/artifacts/77/2/late-notes.txt',
});
await pumpLiveSelection(
tester,
RunDetailTestPlatform.material,
const RunSearchSelection(
runId: 77,
sequence: 2,
artifactUrl: '$_origin/artifacts/77/2/late-notes.txt',
),
run: {...run, 'steps': steps},
);
expect(find.byType(ArtifactViewerPage), findsOneWidget);
Navigator.of(tester.element(find.byType(ArtifactViewerPage))).pop();
await tester.pumpAndSettle();
final late = find.byWidgetPredicate(
(widget) =>
widget is ArtifactTile &&
widget.artifact.url == '$_origin/artifacts/77/2/late-notes.txt',
);
expect(late, findsOneWidget);
expect(tester.widget<ArtifactTile>(late).selected, isTrue);
final rect = tester.getRect(late);
expect(rect.top, greaterThanOrEqualTo(0));
expect(rect.bottom, lessThanOrEqualTo(1000));
});
testWidgets('an unknown artifact sequence opens the plain run', (
tester,
) async {
@@ -333,21 +406,19 @@ void main() {
expect(target.timelineIndex, 1);
});
test('an artifact selection keeps its URL while naming the visit', () {
test('an artifact selection names its recorded URL', () {
final target = resolveRunSearchSelection(
const RunSearchSelection(
runId: 77,
sequence: 2,
artifactUrl: '/artifacts/77/2/release-report.txt',
artifactUrl: '$_origin/artifacts/77/2/release-report.txt',
),
searchSelectionRun(),
);
expect(target, isA<RunArtifactTarget>());
final artifact = target as RunArtifactTarget;
expect(artifact.url, '/artifacts/77/2/release-report.txt');
expect(artifact.visit.stageKey, 'build');
expect(artifact.visit.timelineIndex, 1);
expect(artifact.url, '$_origin/artifacts/77/2/release-report.txt');
});
test('an unrecorded sequence falls back to the plain Summary', () {