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
@@ -40,7 +40,9 @@ JsonMap searchSelectionRun() => <String, dynamic>{
],
};
Future<void> pumpSelection(
/// Pumps one mounted detail under a mutable search scope, returning the notifier
/// that applies a later request to the same detail state.
Future<ValueNotifier<RunSearchSelection?>> pumpLiveSelection(
WidgetTester tester,
RunDetailTestPlatform platform,
RunSearchSelection selection, {
@@ -53,15 +55,20 @@ Future<void> pumpSelection(
final controller = RunsController(RunsRepository(gateway));
addTearDown(controller.dispose);
await controller.select(77);
final pending = ValueNotifier<RunSearchSelection?>(selection);
addTearDown(pending.dispose);
final page = MediaQuery(
data: MediaQueryData.fromView(tester.view),
child: RunSearchSelectionScope(
selection: selection,
onConsumed: onConsumed ?? () {},
child: RunDetailView(
controller: controller,
gateway: gateway,
onBack: () {},
child: ValueListenableBuilder<RunSearchSelection?>(
valueListenable: pending,
builder: (context, current, _) => RunSearchSelectionScope(
selection: current,
onConsumed: onConsumed ?? () {},
child: RunDetailView(
controller: controller,
gateway: gateway,
onBack: () {},
),
),
),
);
@@ -74,6 +81,23 @@ Future<void> pumpSelection(
),
);
await tester.pumpAndSettle();
return pending;
}
Future<void> pumpSelection(
WidgetTester tester,
RunDetailTestPlatform platform,
RunSearchSelection selection, {
VoidCallback? onConsumed,
}) async {
await pumpLiveSelection(tester, platform, selection, onConsumed: onConsumed);
}
/// The browser's `searchFieldTab` mapping, independent of whether a detail is
/// mounted: every text hit names a Summary, expanding only a current section.
void _expectSummarySection(RunSearchTarget target, RunSummarySection? section) {
expect(target, isA<RunSummaryTarget>());
expect((target as RunSummaryTarget).section, section);
}
void main() {
@@ -108,38 +132,41 @@ void main() {
);
});
testWidgets('an input field hit expands the Summary input section', (
tester,
) async {
await pumpSelection(
tester,
RunDetailTestPlatform.material,
const RunSearchSelection(runId: 77, sequence: 5, field: 'input'),
);
expect(
find.byKey(const Key('run-detail-tab-body-summary')),
findsOneWidget,
);
expect(find.textContaining('"prompt": "ship it"'), findsOneWidget);
});
for (final platform in RunDetailTestPlatform.values) {
testWidgets('${platform.name} output field expands the Summary section', (
testWidgets('${platform.name} input field expands only the input section', (
tester,
) async {
await pumpSelection(
tester,
platform,
const RunSearchSelection(runId: 77, sequence: 5, field: 'output'),
const RunSearchSelection(runId: 77, sequence: 5, field: 'input'),
);
expect(
find.byKey(const Key('run-detail-tab-body-summary')),
findsOneWidget,
);
expect(find.textContaining('"result": "ok"'), findsOneWidget);
expect(find.textContaining('"prompt": "ship it"'), findsOneWidget);
expect(find.textContaining('"result": "ok"'), findsNothing);
});
testWidgets(
'${platform.name} output field expands only the output section',
(tester) async {
await pumpSelection(
tester,
platform,
const RunSearchSelection(runId: 77, sequence: 5, field: 'output'),
);
expect(
find.byKey(const Key('run-detail-tab-body-summary')),
findsOneWidget,
);
expect(find.textContaining('"result": "ok"'), findsOneWidget);
expect(find.textContaining('"prompt": "ship it"'), findsNothing);
},
);
}
testWidgets('a retired field opens the plain Summary', (tester) async {
@@ -157,6 +184,35 @@ void main() {
expect(find.textContaining('"result": "ok"'), findsNothing);
});
for (final platform in RunDetailTestPlatform.values) {
testWidgets(
'${platform.name} retired field replaces an open visit with Summary',
(tester) async {
final pending = await pumpLiveSelection(
tester,
platform,
const RunSearchSelection(runId: 77, sequence: 2),
);
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
pending.value = const RunSearchSelection(
runId: 77,
sequence: 5,
field: 'evidence',
);
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('"prompt": "ship it"'), findsNothing);
expect(find.textContaining('"result": "ok"'), findsNothing);
},
);
}
testWidgets('the search request is consumed once it has been applied', (
tester,
) async {
@@ -171,4 +227,56 @@ void main() {
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
expect(consumed, 1);
});
group('resolveRunSearchSelection', () {
test('input and output name their Summary section', () {
_expectSummarySection(
resolveRunSearchSelection(
const RunSearchSelection(runId: 77, field: 'input'),
searchSelectionRun(),
),
RunSummarySection.input,
);
_expectSummarySection(
resolveRunSearchSelection(
const RunSearchSelection(runId: 77, field: 'output'),
searchSelectionRun(),
),
RunSummarySection.output,
);
});
test('a retired or unknown field still names the plain Summary', () {
for (final field in ['evidence', 'transcript', 'unknown']) {
_expectSummarySection(
resolveRunSearchSelection(
RunSearchSelection(runId: 77, field: field),
searchSelectionRun(),
),
null,
);
}
});
test('a recorded sequence names its own detail row', () {
final target = resolveRunSearchSelection(
const RunSearchSelection(runId: 77, sequence: 2),
searchSelectionRun(),
);
expect(target, isA<RunVisitTarget>());
expect((target as RunVisitTarget).stageKey, 'build');
expect(target.timelineIndex, 1);
});
test('an unrecorded sequence falls back to the plain Summary', () {
_expectSummarySection(
resolveRunSearchSelection(
const RunSearchSelection(runId: 77, sequence: 99),
searchSelectionRun(),
),
null,
);
});
});
}