fix(app): keep a search selection one-shot and always reach Summary

A retired or unknown field hit now selects the plain Summary instead of
leaving an open visit pane in place, matching the browser's searchFieldTab
and Android. The resolved target is a sealed Summary/visit value, so the
field mapping lives in one place.

An unapplied request is dropped when the shell leaves the run it names, so
Backing out of a loading detail no longer replays the selection on a later,
unrelated visit. Search/Templates/Schedules pages above the run keep it.
This commit is contained in:
2026-10-22 16:03:18 +01:00
parent 133df9301d
commit 2d1cd743ee
7 changed files with 440 additions and 99 deletions
+204 -2
View File
@@ -73,6 +73,66 @@ Future<void> replyRunList(WidgetTester tester, FakeChannel channel) => reply(
},
);
Future<void> replyRun7List(WidgetTester tester, FakeChannel channel) => reply(
tester,
channel,
'list_runs',
body: {
'type': 'runs',
'runs': [
{'id': 7, 'title': 'Run 7', 'status': 'succeeded'},
],
},
);
/// Opens Search, sends `report` and answers with the artifact hit for run 7.
Future<void> searchArtifactHit(
WidgetTester tester,
FakeChannel channel, {
int index = 0,
}) async {
await tester.tap(find.byKey(const ValueKey('shell.search')));
await tester.pump();
await tester.pump(const Duration(milliseconds: 600));
await tester.pump(const Duration(milliseconds: 100));
await tester.enterText(find.byKey(const ValueKey('search.field')), 'report');
await tester.pump(const Duration(milliseconds: 300));
final request = await waitForRequest(tester, channel, 'search', index: index);
channel.incoming.add(
jsonEncode({
'id': request['id'],
'type': 'search_results',
'search_results': {
'query': 'report',
'kind': '',
'results': [artifactHit()],
'truncated': false,
'scanned_steps': 2,
'scanned_bytes': 64,
'cap': 50,
'scan_bound_bytes': 1 << 20,
},
}),
);
await tester.pump();
await tester.pump();
}
/// Selects the artifact hit, leaving run 7's `get_run` request unanswered.
Future<void> openArtifactHit(
WidgetTester tester,
FakeChannel channel, {
int index = 0,
}) async {
await searchArtifactHit(tester, channel, index: index);
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));
}
Future<void> replyRunDetail(
WidgetTester tester,
FakeChannel channel,
@@ -151,6 +211,18 @@ JsonMap fieldHit() => {
},
};
JsonMap retiredFieldHit() => {
'kind': 'field',
'target': 'run:7:5:evidence',
'matched_field': 'evidence',
'field': {
'run_id': 7,
'sequence': 5,
'field': 'evidence',
'snippet': 'retired',
},
};
JsonMap runHit(int id) => {
'kind': 'run',
'target': 'run:$id',
@@ -424,8 +496,28 @@ void main() {
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
expect(find.text('build · visit 2'), findsOneWidget);
// A field hit opens the same run at the Summary section holding the match.
await sendSearch(query: 'release', index: 1, hit: fieldHit());
// A retired field hit replaces that open visit with the plain Summary.
await sendSearch(query: 'retired', index: 1, hit: retiredFieldHit());
await tester.tap(
find.byKey(const ValueKey('search.result.run:7:5:evidence')),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
await tester.pump(const Duration(milliseconds: 400));
expect(provider.value.uri.path, '/runs/7');
expect(find.byType(SearchScreen), findsNothing);
expect(find.byKey(const Key('run-visit-pane')), findsNothing);
expect(
find.byKey(const Key('run-detail-tab-body-summary')),
findsOneWidget,
);
expect(find.textContaining('"prompt": "ship it"'), findsNothing);
expect(find.textContaining('"result": "ok"'), findsNothing);
// A current field hit opens the same run at the Summary section holding the
// match, leaving the other section collapsed.
await sendSearch(query: 'release', index: 2, hit: fieldHit());
await tester.tap(
find.byKey(const ValueKey('search.result.run:7:5:output')),
);
@@ -437,6 +529,7 @@ void main() {
expect(find.byType(SearchScreen), findsNothing);
expect(find.byKey(const Key('run-visit-pane')), findsNothing);
expect(find.textContaining('"result": "ok"'), findsOneWidget);
expect(find.textContaining('"prompt": "ship it"'), findsNothing);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
@@ -515,6 +608,113 @@ void main() {
await tester.pump();
});
testWidgets('an abandoned selection does not replay on run reopen', (
tester,
) async {
tester.view.physicalSize = const Size(900, 1000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final channel = FakeChannel()..readyCompleter.complete();
final client = PipelinesClient(channelFactory: (_) => channel);
final provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(uri: Uri.parse('/runs')),
);
addTearDown(provider.dispose);
await pumpApp(
tester,
channel: channel,
client: client,
provider: provider,
cupertino: false,
);
await replyRun7List(tester, channel);
// The hit navigates to run 7, but its detail is never loaded: the operator
// leaves from the loading placeholder instead.
await openArtifactHit(tester, channel);
expect(provider.value.uri.path, '/runs/7');
expect(find.text('Back to list'), findsOneWidget);
await tester.tap(find.text('Back to list'));
await tester.pump();
await tester.pump();
expect(provider.value.uri.path, '/runs');
// The abandoned read's late reply is ignored; the request queue is free for
// the ordinary reopen.
await replyRunDetailFor(tester, channel, searchSelectionDetail(), index: 0);
await tester.pump();
// Reopening the same run is an ordinary visit: no search named this visit.
await tester.tap(find.text('Run 7'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
await replyRunDetailFor(tester, channel, searchSelectionDetail(), index: 1);
await tester.pumpAndSettle();
expect(find.byKey(const Key('run-visit-pane')), findsNothing);
expect(
find.byKey(const Key('run-detail-tab-body-summary')),
findsOneWidget,
);
expect(find.textContaining('"result": "ok"'), findsNothing);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
});
testWidgets('a consumed selection does not replay on run reopen', (
tester,
) async {
tester.view.physicalSize = const Size(900, 1000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final channel = FakeChannel()..readyCompleter.complete();
final client = PipelinesClient(channelFactory: (_) => channel);
final provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(uri: Uri.parse('/runs')),
);
addTearDown(provider.dispose);
await pumpApp(
tester,
channel: channel,
client: client,
provider: provider,
cupertino: false,
);
await replyRun7List(tester, channel);
await openArtifactHit(tester, channel);
await replyRunDetailFor(tester, channel, searchSelectionDetail(), index: 0);
await tester.pumpAndSettle();
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
await tester.tap(find.text('Back to list'));
await tester.pump();
await tester.pump();
expect(provider.value.uri.path, '/runs');
await tester.tap(find.text('Run 7'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
await replyRunDetailFor(tester, channel, searchSelectionDetail(), index: 1);
await tester.pumpAndSettle();
expect(find.byKey(const Key('run-visit-pane')), findsNothing);
expect(
find.byKey(const Key('run-detail-tab-body-summary')),
findsOneWidget,
);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
});
testWidgets('Cupertino uses its native bar action and Back', (tester) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
@@ -627,6 +827,8 @@ void main() {
router.openSearch();
expect(router.route, AppRoute.search);
expect(router.searchOpen, isTrue);
// Search is a page above the shell; the open run stays under it.
expect(router.shellRoute, AppRoute.run(3));
expect(await router.popRoute(), isTrue);
expect(router.route, AppRoute.run(3));