merge(app): land search-pane

This commit is contained in:
2026-10-22 16:15:50 +01:00
8 changed files with 1017 additions and 27 deletions
@@ -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,
@@ -89,6 +149,80 @@ Future<void> replyRunDetail(
},
);
Future<void> replyRunDetailFor(
WidgetTester tester,
FakeChannel channel,
JsonMap detail, {
int index = 0,
}) => reply(
tester,
channel,
'get_run',
index: index,
body: {'type': 'run', 'run_detail': detail},
);
/// A run whose recorded sequences are the search target's identity: a plan
/// visit 5 and a build visit 2, with run-level input and output sections.
JsonMap searchSelectionDetail() => {
'id': 7,
'title': 'Run 7',
'status': 'succeeded',
'input': {'prompt': 'ship it'},
'output': {'result': 'ok'},
'steps': [
{
'stage': 'plan',
'sequence': 5,
'status': 'completed',
'outcome': 'success',
},
{
'stage': 'build',
'sequence': 2,
'status': 'completed',
'outcome': 'success',
},
],
};
JsonMap artifactHit() => {
'kind': 'artifact',
'target': '/artifacts/7/2/report.txt',
'artifact': {
'run_id': 7,
'sequence': 2,
'name': 'report.txt',
'content_type': 'text/plain',
'size_bytes': 12,
'url': '/artifacts/7/2/report.txt',
},
};
JsonMap fieldHit() => {
'kind': 'field',
'target': 'run:7:5:output',
'matched_field': 'output',
'field': {
'run_id': 7,
'sequence': 5,
'field': 'output',
'snippet': 'release',
},
};
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',
@@ -285,6 +419,302 @@ void main() {
await tester.pump();
});
testWidgets('field and artifact hits select their run detail selection', (
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/7')),
);
addTearDown(provider.dispose);
await pumpApp(
tester,
channel: channel,
client: client,
provider: provider,
cupertino: false,
);
await replyRunList(tester, channel);
await replyRunDetailFor(tester, channel, searchSelectionDetail());
expect(find.text('Run 7'), findsWidgets);
Future<void> sendSearch({
required String query,
required int index,
required JsonMap hit,
}) 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')), query);
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': query,
'kind': '',
'results': [hit],
'truncated': false,
'scanned_steps': 2,
'scanned_bytes': 64,
'cap': 50,
'scan_bound_bytes': 1 << 20,
},
}),
);
await tester.pump();
await tester.pump();
}
// An artifact hit opens the run and selects the visit that recorded it.
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));
expect(provider.value.uri.path, '/runs/7');
expect(find.byType(SearchScreen), findsNothing);
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
expect(find.text('build · visit 2'), findsOneWidget);
// 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')),
);
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.textContaining('"result": "ok"'), findsOneWidget);
expect(find.textContaining('"prompt": "ship it"'), findsNothing);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
});
testWidgets('an artifact hit selects its visit after the run detail loads', (
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 replyRunList(tester, channel);
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');
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();
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));
expect(provider.value.uri.path, '/runs/7');
// The run detail is still loading when the request arrives; the selection
// is applied by the detail that mounts from this reply.
await replyRunDetailFor(tester, channel, searchSelectionDetail(), index: 0);
await tester.pumpAndSettle();
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
expect(find.text('build · visit 2'), findsOneWidget);
await tester.pumpWidget(const SizedBox.shrink());
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;
@@ -397,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));
@@ -0,0 +1,282 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.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';
import 'package:pipelines_app/features/runs/ui/run_search_selection.dart';
import 'package:pipelines_app/features/runs/ui/runs_controller.dart';
import 'run_detail_graph_support.dart';
/// plan visits 5 and 1 around one build visit 2: the server's sequence is not
/// the step's row index, so resolution must read the recorded sequence.
JsonMap searchSelectionRun() => <String, dynamic>{
'id': 77,
'title': 'Search selection run',
'name': 'release',
'status': 'succeeded',
'input': <String, dynamic>{'prompt': 'ship it'},
'output': <String, dynamic>{'result': 'ok'},
'steps': <dynamic>[
<String, dynamic>{
'stage': 'plan',
'sequence': 5,
'status': 'completed',
'outcome': 'success',
},
<String, dynamic>{
'stage': 'build',
'sequence': 2,
'status': 'completed',
'outcome': 'success',
},
<String, dynamic>{
'stage': 'plan',
'sequence': 1,
'status': 'completed',
'outcome': 'success',
},
],
};
/// 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, {
VoidCallback? onConsumed,
}) async {
tester.view.physicalSize = const Size(900, 1000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final gateway = RunDetailFakeGateway(searchSelectionRun());
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: ValueListenableBuilder<RunSearchSelection?>(
valueListenable: pending,
builder: (context, current, _) => RunSearchSelectionScope(
selection: current,
onConsumed: onConsumed ?? () {},
child: RunDetailView(
controller: controller,
gateway: gateway,
onBack: () {},
),
),
),
);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pumpWidget(
platform == RunDetailTestPlatform.material
? MaterialApp(home: Scaffold(body: page))
: CupertinoApp(
home: CupertinoPageScaffold(child: SafeArea(child: page)),
),
);
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() {
for (final platform in RunDetailTestPlatform.values) {
testWidgets('${platform.name} artifact hit opens its recorded visit', (
tester,
) async {
await pumpSelection(
tester,
platform,
const RunSearchSelection(runId: 77, sequence: 2),
);
expect(find.byKey(const Key('run-visit-pane')), findsOneWidget);
expect(find.text('build · visit 2'), findsOneWidget);
});
}
testWidgets('an unknown artifact sequence opens the plain run', (
tester,
) async {
await pumpSelection(
tester,
RunDetailTestPlatform.material,
const RunSearchSelection(runId: 77, sequence: 99),
);
expect(find.byKey(const Key('run-visit-pane')), findsNothing);
expect(
find.byKey(const Key('run-detail-tab-body-summary')),
findsOneWidget,
);
});
for (final platform in RunDetailTestPlatform.values) {
testWidgets('${platform.name} input field expands only the input section', (
tester,
) async {
await pumpSelection(
tester,
platform,
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);
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 {
await pumpSelection(
tester,
RunDetailTestPlatform.material,
const RunSearchSelection(runId: 77, sequence: 5, field: 'evidence'),
);
expect(
find.byKey(const Key('run-detail-tab-body-summary')),
findsOneWidget,
);
expect(find.textContaining('"prompt": "ship it"'), findsNothing);
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 {
var consumed = 0;
await pumpSelection(
tester,
RunDetailTestPlatform.material,
const RunSearchSelection(runId: 77, sequence: 2),
onConsumed: () => consumed++,
);
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,
);
});
});
}