From 133df9301d556bab3e5d57523a109a3e35a85200 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Thu, 22 Oct 2026 15:34:48 +0100 Subject: [PATCH 1/2] feat(app): select a search hit's recorded run section or visit --- app/PARITY.md | 2 +- app/lib/application/pipelines_app.dart | 90 +++++-- .../runs/ui/run_detail_tab_bodies.dart | 10 + app/lib/features/runs/ui/run_detail_tabs.dart | 76 ++++++ .../runs/ui/run_search_selection.dart | 121 +++++++++ app/test/application/search_wiring_test.dart | 230 ++++++++++++++++++ .../runs/ui/run_search_selection_test.dart | 174 +++++++++++++ 7 files changed, 676 insertions(+), 27 deletions(-) create mode 100644 app/lib/features/runs/ui/run_search_selection.dart create mode 100644 app/test/features/runs/ui/run_search_selection_test.dart diff --git a/app/PARITY.md b/app/PARITY.md index 82a80c56..09ff7002 100644 --- a/app/PARITY.md +++ b/app/PARITY.md @@ -51,7 +51,7 @@ or scratch servers only, never real operator sessions/runs/workflows. | Chat commands/notices/scroll | Preview: dismissible local notices with reconnect clearing | slash palette/actions, unknown-command send-as-message, saved scroll/follow intent | | Saved schedule list | Preview: Settings row, /schedules route, read-only list; a row opens the owning pipeline detail (Summary by default) | authenticated smoke | | Schedule editor | Preview: pipeline Summary creates/edits/pauses/deletes with the lossless draft and revision guard; conflict keeps the draft and shows the server words | Schedule-this-run seeding | -| Search | Preview: exact target model and navigation to pipeline, pinned version, run and recorded stage; unresolvable hits stay read-only | field/artifact hits open the run (their pane selection is a later slice) | +| Search | Preview: exact target model and navigation to pipeline, pinned version, run and recorded stage; field/artifact hits select the recorded Summary section/visit; unresolvable hits stay read-only | authenticated smoke | | Needs you | Preview: runs-list bell/count, native sheet, dismiss/clear persistence, live fold, transition notifications, Settings permission tile | authenticated preview smoke | | Notifications | Preview: Settings permission tile over live platform state, transition-only dedupe, tap opens the run | background question notices; permission/browser smoke only in fixtures | | Mobile replacement build | Scaffold only | Android build at end; all source portable to iOS, isolated IDs; device/OS behavior clearly separate | diff --git a/app/lib/application/pipelines_app.dart b/app/lib/application/pipelines_app.dart index 321be5a9..36f7426b 100644 --- a/app/lib/application/pipelines_app.dart +++ b/app/lib/application/pipelines_app.dart @@ -10,6 +10,7 @@ import '../shell/adaptive_shell.dart'; import '../shell/destination.dart'; import '../features/attention/notify/notification_controller.dart'; import '../features/attention/notify/notification_store.dart'; +import '../features/runs/ui/run_search_selection.dart'; import '../features/search/domain/search_target.dart'; import '../features/settings/settings_screen.dart'; import 'app.dart'; @@ -65,6 +66,12 @@ class _PipelinesAppState extends State { /// list once; the run itself is then opened from its route. int _runsRefresh = 0; + /// One run detail request from Search, delivered through the shell so the + /// mounted run detail can resolve it once the named run's steps have loaded. + /// A field or artifact hit names no addressable URL of its own, so the request + /// is not route state; it is consumed and cleared after it is applied. + RunSearchSelection? _pendingRunSearch; + /// One notification capability for the app: the Runs attention surface /// publishes live transitions and Settings renders the same permission. late final NotificationController _notifications = NotificationController( @@ -145,25 +152,50 @@ class _PipelinesAppState extends State { /// Open a result through the exact identity the hit records. An unresolvable /// hit navigates nowhere: the screen already presents it read-only rather than /// guessing a destination. + /// + /// A field or artifact hit has no URL of its own: both open the run and leave + /// a resolved-once request for the mounted detail, which selects the recorded + /// Summary section or visit as soon as that run's steps are available. A + /// sequence or field the run did not record leaves the plain detail. void _openSearchResult(JsonMap hit) { final resolved = searchTargetFor(hit); if (resolved is! ResolvedSearchTarget) return; - final route = switch (resolved.target) { - SearchPipelineTarget(:final pipelineId) => AppRoute.pipeline(pipelineId), - SearchVersionTarget(:final pipelineId, :final version) => - AppRoute.pipeline(pipelineId, version: version), - SearchRunTarget(:final runId) => AppRoute.run(runId), - SearchStepTarget(:final runId, :final stage, :final visit) => - stage == null + AppRoute? route; + RunSearchSelection? selection; + switch (resolved.target) { + case SearchPipelineTarget(:final pipelineId): + route = AppRoute.pipeline(pipelineId); + case SearchVersionTarget(:final pipelineId, :final version): + route = AppRoute.pipeline(pipelineId, version: version); + case SearchRunTarget(:final runId): + route = AppRoute.run(runId); + case SearchStepTarget(:final runId, :final stage, :final visit): + route = stage == null ? AppRoute.run(runId) - : AppRoute.run.stage(runId, stage, visit: visit), - // A field or artifact names a visit inside the run; the run detail owns - // that pane, so open the run rather than inventing a stage route. - SearchFieldTarget(:final runId) => AppRoute.run(runId), - SearchArtifactTarget(:final runId) => - runId == null ? null : AppRoute.run(runId), - }; - if (route != null) _delegate.goTo(route); + : AppRoute.run.stage(runId, stage, visit: visit); + case SearchFieldTarget(:final runId, :final sequence, :final field): + selection = RunSearchSelection( + runId: runId, + sequence: sequence, + field: field, + ); + route = AppRoute.run(runId); + case SearchArtifactTarget(:final runId, :final sequence): + if (runId != null) { + selection = RunSearchSelection(runId: runId, sequence: sequence); + route = AppRoute.run(runId); + } + } + if (route == null) return; + setState(() => _pendingRunSearch = selection); + _delegate.goTo(route); + } + + /// The mounted run detail applied the pending request; reopening the same run + /// later starts from its plain detail and never replays the search selection. + void _runSearchConsumed() { + if (!mounted || _pendingRunSearch == null) return; + setState(() => _pendingRunSearch = null); } /// The Templates page above Settings. Closing it restores the same Settings @@ -217,17 +249,23 @@ class _PipelinesAppState extends State { initialVersion: route.version, initialStageKey: route.stageKey, ), - AppDestination.runs: (_) => RunsDestination( - session: _session, - server: widget.server, - initialRunId: route.runId, - initialStageKey: route.stageKey, - initialVisit: route.visit, - initialDecide: route.decide, - listRefreshToken: _runsRefresh, - notifications: _notifications, - onRunSelected: (id) => _delegate.goTo(AppRoute.run(id)), - onBack: () => _delegate.goTo(AppRoute.runs), + // The one place a field or artifact hit's selection can be resolved: the + // run detail owns the recorded visit and Summary section. + AppDestination.runs: (_) => RunSearchSelectionScope( + selection: _pendingRunSearch, + onConsumed: _runSearchConsumed, + child: RunsDestination( + session: _session, + server: widget.server, + initialRunId: route.runId, + initialStageKey: route.stageKey, + initialVisit: route.visit, + initialDecide: route.decide, + listRefreshToken: _runsRefresh, + notifications: _notifications, + onRunSelected: (id) => _delegate.goTo(AppRoute.run(id)), + onBack: () => _delegate.goTo(AppRoute.runs), + ), ), AppDestination.chat: (_) => ChatDestination( session: _session, diff --git a/app/lib/features/runs/ui/run_detail_tab_bodies.dart b/app/lib/features/runs/ui/run_detail_tab_bodies.dart index 333c5b96..0b0ebfb3 100644 --- a/app/lib/features/runs/ui/run_detail_tab_bodies.dart +++ b/app/lib/features/runs/ui/run_detail_tab_bodies.dart @@ -21,6 +21,8 @@ Widget runDetailSummaryTab({ required bool copying, required String? copyStatus, required VoidCallback onCopy, + ExpansibleController? inputController, + ExpansibleController? outputController, }) { final rows = detailSummaryRows(run); final identity = detailSummaryIdentity(run); @@ -55,6 +57,7 @@ Widget runDetailSummaryTab({ title: 'Input', value: run['input'], empty: visitEmptyInput, + controller: inputController, ), _cupertinoFieldSection( context, @@ -62,6 +65,7 @@ Widget runDetailSummaryTab({ title: 'Output', value: run['output'], empty: visitEmptyOutput, + controller: outputController, ), ], ); @@ -96,6 +100,7 @@ Widget runDetailSummaryTab({ title: 'Input', value: run['input'], empty: visitEmptyInput, + controller: inputController, ), _materialFieldSection( context, @@ -103,6 +108,7 @@ Widget runDetailSummaryTab({ title: 'Output', value: run['output'], empty: visitEmptyOutput, + controller: outputController, ), ], ); @@ -196,9 +202,11 @@ Widget _materialFieldSection( required String title, required dynamic value, required String empty, + ExpansibleController? controller, }) { return ExpansionTile( key: ValueKey(key), + controller: controller, title: Text(title), expandedCrossAxisAlignment: CrossAxisAlignment.start, childrenPadding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 16), @@ -314,12 +322,14 @@ Widget _cupertinoFieldSection( required String title, required dynamic value, required String empty, + ExpansibleController? controller, }) { return CupertinoListSection.insetGrouped( key: ValueKey(key), children: [ CupertinoExpansionTile( title: Text(title), + controller: controller, child: Padding( padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 16), child: Align( diff --git a/app/lib/features/runs/ui/run_detail_tabs.dart b/app/lib/features/runs/ui/run_detail_tabs.dart index 65ca3c4e..829f8331 100644 --- a/app/lib/features/runs/ui/run_detail_tabs.dart +++ b/app/lib/features/runs/ui/run_detail_tabs.dart @@ -11,6 +11,7 @@ import 'run_detail_tab_strip.dart'; import 'run_detail_timeline.dart'; import 'run_detail_visit.dart'; import 'run_detail_visit_facts.dart'; +import 'run_search_selection.dart'; /// The least height the selected tab keeps for its own content. /// @@ -81,12 +82,36 @@ class _RunDetailTabsState extends State { String? _selectedStage; int? _selectedVisit; + /// The Summary's collapsible Input and Output sections. A search text hit + /// expands the one its recorded field names, exactly as the browser opens the + /// matching Summary section. The detail owns them so the tab body stays a + /// presentation widget. + final _inputSection = ExpansibleController(); + final _outputSection = ExpansibleController(); + + /// The search request last applied by this detail, so a rebuild of the same + /// request never reopens a pane the operator closed in the meantime. + RunSearchSelection? _appliedSearchSelection; + @override void initState() { super.initState(); _applyInitialVisit(); } + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _applySearchSelection(); + } + + @override + void dispose() { + _inputSection.dispose(); + _outputSection.dispose(); + super.dispose(); + } + @override void didUpdateWidget(covariant RunDetailTabs oldWidget) { super.didUpdateWidget(oldWidget); @@ -100,6 +125,8 @@ class _RunDetailTabsState extends State { _tab = RunDetailTab.summary; _selectedStage = null; _selectedVisit = null; + _inputSection.collapse(); + _outputSection.collapse(); _applyInitialVisit(); } else if (!sameTarget) { // A route that names another stage or visit is applied to the same run. @@ -146,6 +173,53 @@ class _RunDetailTabsState extends State { } } + /// Selects the recorded visit a search result names, without presenting any + /// visit the run did not record. + /// + /// The request is applied once per loaded run. A visit the run did not record, + /// an unknown field or a bare run hit resolves to nothing, which leaves the + /// plain run detail; either way the request is consumed so it never replays. + void _applySearchSelection() { + final scope = RunSearchSelectionScope.maybeOf(context); + final selection = scope?.selection; + if (scope == null || selection == null) { + _appliedSearchSelection = null; + return; + } + if (selection == _appliedSearchSelection) return; + final id = widget.run['id']; + if (id is! num || id.toInt() != selection.runId) return; + _appliedSearchSelection = selection; + final resolved = resolveRunSearchSelection(selection, widget.run); + if (resolved != null) _selectSearchTarget(resolved); + final consumed = scope.onConsumed; + WidgetsBinding.instance.addPostFrameCallback((_) { + if (mounted) consumed(); + }); + } + + void _selectSearchTarget(RunSearchTarget target) { + if (target.section case final section?) { + _tab = RunDetailTab.summary; + _selectedStage = null; + _selectedVisit = null; + switch (section) { + case 'input': + _inputSection.expand(); + case 'output': + _outputSection.expand(); + } + return; + } + final stageKey = target.stageKey; + final index = target.timelineIndex; + if (stageKey == null || index == null) return; + if (detailVisitStepAt(widget.run, index) == null) return; + _selectedStage = stageKey; + _selectedVisit = index; + _tab = RunDetailTab.timeline; + } + /// Selects the stage's latest recorded visit. An unvisited stage has none, /// so the detail stays where it is rather than fabricating a visit. void _openStage(String stageKey) { @@ -214,6 +288,8 @@ class _RunDetailTabsState extends State { copying: widget.copying, copyStatus: widget.copyStatus, onCopy: widget.onCopy, + inputController: _inputSection, + outputController: _outputSection, ); case RunDetailTab.graph: return RunGraphView( diff --git a/app/lib/features/runs/ui/run_search_selection.dart b/app/lib/features/runs/ui/run_search_selection.dart new file mode 100644 index 00000000..a4cfda2c --- /dev/null +++ b/app/lib/features/runs/ui/run_search_selection.dart @@ -0,0 +1,121 @@ +import 'package:flutter/widgets.dart'; + +import '../../../core/api_gateway.dart'; +import 'run_detail_visit_facts.dart'; + +/// A search hit's requested selection inside one run's detail. +/// +/// A recorded hit names only the run's own recorded [sequence] and, for a text +/// hit, the [field] it matched; the stage and timeline position are resolved +/// against the loaded detail, exactly as the browser client does. A request is +/// consumed once, so reopening the run later never replays it. +@immutable +class RunSearchSelection { + const RunSearchSelection({required this.runId, this.sequence, this.field}); + + final int runId; + + /// The server's recorded visit number, or null when the hit names no visit. + final int? sequence; + + /// The matched step field (`input`, `output`, …), or null for a visit hit. + final String? field; + + @override + bool operator ==(Object other) => + other is RunSearchSelection && + other.runId == runId && + other.sequence == sequence && + other.field == field; + + @override + int get hashCode => Object.hash(runId, sequence, field); +} + +/// What a resolved search request selects in the loaded run detail. +/// +/// A [section] names one collapsible Summary section; [stageKey] and +/// [timelineIndex] name one recorded visit, using the same row index the +/// Timeline and the Graph selection use. +@immutable +class RunSearchTarget { + const RunSearchTarget.section(this.section) + : stageKey = null, + timelineIndex = null; + + const RunSearchTarget.visit({ + required this.stageKey, + required this.timelineIndex, + }) : section = null; + + final String? section; + final String? stageKey; + final int? timelineIndex; +} + +/// Resolves [selection] against the loaded [run], or null when the run recorded +/// nothing the request names. +/// +/// A text hit selects the Summary section holding the matched field, mirroring +/// the browser's `searchFieldTab`: a retired or unknown field resolves to the +/// plain Summary instead of guessing a section. A visit hit selects the step +/// with the recorded sequence and its own row in the Timeline; a sequence the +/// run did not record resolves to nothing. Either null leaves the plain run +/// detail in place. +RunSearchTarget? resolveRunSearchSelection( + RunSearchSelection selection, + JsonMap run, +) { + final field = selection.field?.trim() ?? ''; + if (field.isNotEmpty) { + return switch (field) { + 'input' => const RunSearchTarget.section('input'), + 'output' => const RunSearchTarget.section('output'), + _ => null, + }; + } + final sequence = selection.sequence; + if (sequence == null || sequence <= 0) return null; + + final steps = detailRunSteps(run); + for (var index = 0; index < steps.length; index++) { + if (_sequence(steps[index]) != sequence) continue; + final stage = '${steps[index]['stage'] ?? ''}'.trim(); + if (stage.isEmpty) return null; + // The row index is the Timeline's own index, the identity the visit pane + // reads back through detailVisitStepAt, so no ordinal is guessed here. + return RunSearchTarget.visit(stageKey: stage, timelineIndex: index); + } + return null; +} + +int? _sequence(JsonMap step) { + final value = step['sequence']; + final number = value is num ? value.toInt() : int.tryParse('${value ?? ''}'); + return number != null && number > 0 ? number : null; +} + +/// Carries the shell's one pending search request to the mounted run detail. +/// +/// The composition mounts it around the shell; [RunDetailTabs] reads it and +/// reports [onConsumed] once the request has been applied, so a later visit to +/// the same run starts plain. Keeping the request here means a field or artifact +/// hit needs no invented URL: the browser has no route for either selection. +class RunSearchSelectionScope extends InheritedWidget { + const RunSearchSelectionScope({ + super.key, + required this.selection, + required this.onConsumed, + required super.child, + }); + + final RunSearchSelection? selection; + final VoidCallback onConsumed; + + static RunSearchSelectionScope? maybeOf(BuildContext context) => + context.dependOnInheritedWidgetOfExactType(); + + @override + bool updateShouldNotify(RunSearchSelectionScope oldWidget) => + oldWidget.selection != selection || oldWidget.onConsumed != onConsumed; +} diff --git a/app/test/application/search_wiring_test.dart b/app/test/application/search_wiring_test.dart index 005b1479..20dfabb3 100644 --- a/app/test/application/search_wiring_test.dart +++ b/app/test/application/search_wiring_test.dart @@ -89,6 +89,68 @@ Future replyRunDetail( }, ); +Future 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 runHit(int id) => { 'kind': 'run', 'target': 'run:$id', @@ -285,6 +347,174 @@ 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 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 field hit opens the same run at the Summary section holding the match. + await sendSearch(query: 'release', index: 1, 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); + + 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('Cupertino uses its native bar action and Back', (tester) async { tester.view.physicalSize = const Size(390, 844); tester.view.devicePixelRatio = 1; diff --git a/app/test/features/runs/ui/run_search_selection_test.dart b/app/test/features/runs/ui/run_search_selection_test.dart new file mode 100644 index 00000000..09a6d76d --- /dev/null +++ b/app/test/features/runs/ui/run_search_selection_test.dart @@ -0,0 +1,174 @@ +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() => { + 'id': 77, + 'title': 'Search selection run', + 'name': 'release', + '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', + }, + { + 'stage': 'plan', + 'sequence': 1, + 'status': 'completed', + 'outcome': 'success', + }, + ], +}; + +Future pumpSelection( + 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 page = MediaQuery( + data: MediaQueryData.fromView(tester.view), + child: RunSearchSelectionScope( + selection: selection, + 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(); +} + +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, + ); + }); + + 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', ( + 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); + }); + } + + 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); + }); + + 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); + }); +} From 2d1cd743eeb53267943c9b8ab63f375c44019c2d Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Thu, 22 Oct 2026 16:03:18 +0100 Subject: [PATCH 2/2] 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. --- app/PARITY.md | 2 +- app/lib/application/app_router.dart | 9 + app/lib/application/pipelines_app.dart | 20 +- app/lib/features/runs/ui/run_detail_tabs.dart | 49 ++--- .../runs/ui/run_search_selection.dart | 91 ++++---- app/test/application/search_wiring_test.dart | 206 +++++++++++++++++- .../runs/ui/run_search_selection_test.dart | 162 +++++++++++--- 7 files changed, 440 insertions(+), 99 deletions(-) diff --git a/app/PARITY.md b/app/PARITY.md index 09ff7002..77fb6823 100644 --- a/app/PARITY.md +++ b/app/PARITY.md @@ -51,7 +51,7 @@ or scratch servers only, never real operator sessions/runs/workflows. | Chat commands/notices/scroll | Preview: dismissible local notices with reconnect clearing | slash palette/actions, unknown-command send-as-message, saved scroll/follow intent | | Saved schedule list | Preview: Settings row, /schedules route, read-only list; a row opens the owning pipeline detail (Summary by default) | authenticated smoke | | Schedule editor | Preview: pipeline Summary creates/edits/pauses/deletes with the lossless draft and revision guard; conflict keeps the draft and shows the server words | Schedule-this-run seeding | -| Search | Preview: exact target model and navigation to pipeline, pinned version, run and recorded stage; field/artifact hits select the recorded Summary section/visit; unresolvable hits stay read-only | authenticated smoke | +| Search | Preview: exact target model and navigation to pipeline, pinned version, run and recorded stage; field/artifact hits select the recorded Summary section/visit (artifact hits follow web S2/Android and open the recorded visit, where the current browser source opens the artifact externally); a retired field or unknown visit selects the plain Summary; unresolvable hits stay read-only | authenticated smoke; rendered capture of the field/artifact selection | | Needs you | Preview: runs-list bell/count, native sheet, dismiss/clear persistence, live fold, transition notifications, Settings permission tile | authenticated preview smoke | | Notifications | Preview: Settings permission tile over live platform state, transition-only dedupe, tap opens the run | background question notices; permission/browser smoke only in fixtures | | Mobile replacement build | Scaffold only | Android build at end; all source portable to iOS, isolated IDs; device/OS behavior clearly separate | diff --git a/app/lib/application/app_router.dart b/app/lib/application/app_router.dart index a99d08df..18899cc1 100644 --- a/app/lib/application/app_router.dart +++ b/app/lib/application/app_router.dart @@ -97,6 +97,15 @@ class AppRouterDelegate extends RouterDelegate with ChangeNotifier { /// The saved-schedule list page, opened above Settings. bool get schedulesOpen => _route.kind == AppRouteKind.schedules; + /// The route the shell renders underneath the transient Search, Templates + /// and Schedules pages. Those pages keep the shell mounted, so the route the + /// operator last opened there is still the shell's own destination. + AppRoute get shellRoute => searchOpen + ? _searchReturn + : templatesOpen || schedulesOpen + ? _templatesReturn + : _route; + @override AppRoute get currentConfiguration => _route; diff --git a/app/lib/application/pipelines_app.dart b/app/lib/application/pipelines_app.dart index 36f7426b..c53ebba6 100644 --- a/app/lib/application/pipelines_app.dart +++ b/app/lib/application/pipelines_app.dart @@ -69,7 +69,8 @@ class _PipelinesAppState extends State { /// One run detail request from Search, delivered through the shell so the /// mounted run detail can resolve it once the named run's steps have loaded. /// A field or artifact hit names no addressable URL of its own, so the request - /// is not route state; it is consumed and cleared after it is applied. + /// is not route state; it is cleared after the detail applies it or when the + /// shell leaves that run, so an abandoned hit never replays later. RunSearchSelection? _pendingRunSearch; /// One notification capability for the app: the Runs attention surface @@ -113,6 +114,7 @@ class _PipelinesAppState extends State { schedulesBuilder: _buildSchedules, builder: _buildShell, ); + _delegate.addListener(_routeChanged); _config = RouterConfig( routeInformationParser: const AppRouteParser(), routerDelegate: _delegate, @@ -124,6 +126,7 @@ class _PipelinesAppState extends State { @override void dispose() { _notifications.dispose(); + _delegate.removeListener(_routeChanged); _delegate.dispose(); if (_ownsProvider) { (_provider as PlatformRouteInformationProvider).dispose(); @@ -198,6 +201,21 @@ class _PipelinesAppState extends State { setState(() => _pendingRunSearch = null); } + /// Drops a pending request once the shell leaves the run it names. + /// + /// The mounted detail is the only consumer, and it exists only after the run's + /// detail has loaded. Backing out while that read is still pending, or leaving + /// a failed detail, would otherwise keep the request for the next unrelated + /// visit to the same run. Search/Templates/Schedules pages above the run keep + /// it, because the shell route underneath them still names that run. + void _routeChanged() { + final pending = _pendingRunSearch; + if (!mounted || pending == null) return; + final route = _delegate.shellRoute; + if (route.kind == AppRouteKind.runs && route.runId == pending.runId) return; + setState(() => _pendingRunSearch = null); + } + /// The Templates page above Settings. Closing it restores the same Settings /// screen instance, so an edited field or an open connection state survives. Widget _buildSchedules(BuildContext context) => SchedulesDestination( diff --git a/app/lib/features/runs/ui/run_detail_tabs.dart b/app/lib/features/runs/ui/run_detail_tabs.dart index 829f8331..c7a1627e 100644 --- a/app/lib/features/runs/ui/run_detail_tabs.dart +++ b/app/lib/features/runs/ui/run_detail_tabs.dart @@ -173,12 +173,12 @@ class _RunDetailTabsState extends State { } } - /// Selects the recorded visit a search result names, without presenting any - /// visit the run did not record. + /// Selects the Summary section or recorded visit a search result names. /// - /// The request is applied once per loaded run. A visit the run did not record, - /// an unknown field or a bare run hit resolves to nothing, which leaves the - /// plain run detail; either way the request is consumed so it never replays. + /// The request is applied once per loaded run and is consumed afterwards. A + /// retired or unknown field still selects the plain Summary, exactly as the + /// browser's `searchFieldTab` does, and a visit the run did not record falls + /// back to the plain Summary, so no stale hit leaves an unrelated pane open. void _applySearchSelection() { final scope = RunSearchSelectionScope.maybeOf(context); final selection = scope?.selection; @@ -190,8 +190,7 @@ class _RunDetailTabsState extends State { final id = widget.run['id']; if (id is! num || id.toInt() != selection.runId) return; _appliedSearchSelection = selection; - final resolved = resolveRunSearchSelection(selection, widget.run); - if (resolved != null) _selectSearchTarget(resolved); + _selectSearchTarget(resolveRunSearchSelection(selection, widget.run)); final consumed = scope.onConsumed; WidgetsBinding.instance.addPostFrameCallback((_) { if (mounted) consumed(); @@ -199,25 +198,25 @@ class _RunDetailTabsState extends State { } void _selectSearchTarget(RunSearchTarget target) { - if (target.section case final section?) { - _tab = RunDetailTab.summary; - _selectedStage = null; - _selectedVisit = null; - switch (section) { - case 'input': - _inputSection.expand(); - case 'output': - _outputSection.expand(); - } - return; + switch (target) { + case RunSummaryTarget(:final section): + _tab = RunDetailTab.summary; + _selectedStage = null; + _selectedVisit = null; + switch (section) { + case RunSummarySection.input: + _inputSection.expand(); + case RunSummarySection.output: + _outputSection.expand(); + case null: + break; + } + case RunVisitTarget(:final stageKey, :final timelineIndex): + if (detailVisitStepAt(widget.run, timelineIndex) == null) return; + _selectedStage = stageKey; + _selectedVisit = timelineIndex; + _tab = RunDetailTab.timeline; } - final stageKey = target.stageKey; - final index = target.timelineIndex; - if (stageKey == null || index == null) return; - if (detailVisitStepAt(widget.run, index) == null) return; - _selectedStage = stageKey; - _selectedVisit = index; - _tab = RunDetailTab.timeline; } /// Selects the stage's latest recorded visit. An unvisited stage has none, diff --git a/app/lib/features/runs/ui/run_search_selection.dart b/app/lib/features/runs/ui/run_search_selection.dart index a4cfda2c..ccb8bb5a 100644 --- a/app/lib/features/runs/ui/run_search_selection.dart +++ b/app/lib/features/runs/ui/run_search_selection.dart @@ -32,61 +32,66 @@ class RunSearchSelection { int get hashCode => Object.hash(runId, sequence, field); } +/// The collapsible Summary section a text hit names. +enum RunSummarySection { input, output } + /// What a resolved search request selects in the loaded run detail. -/// -/// A [section] names one collapsible Summary section; [stageKey] and -/// [timelineIndex] name one recorded visit, using the same row index the -/// Timeline and the Graph selection use. -@immutable -class RunSearchTarget { - const RunSearchTarget.section(this.section) - : stageKey = null, - timelineIndex = null; - - const RunSearchTarget.visit({ - required this.stageKey, - required this.timelineIndex, - }) : section = null; - - final String? section; - final String? stageKey; - final int? timelineIndex; +sealed class RunSearchTarget { + const RunSearchTarget(); } -/// Resolves [selection] against the loaded [run], or null when the run recorded -/// nothing the request names. +/// The run Summary, optionally with the matched field's section expanded. +final class RunSummaryTarget extends RunSearchTarget { + const RunSummaryTarget({this.section}); + + /// The section a text hit matched, or null for the plain Summary. + final RunSummarySection? section; +} + +/// One recorded visit: [stageKey] plus the detail row index the Timeline and +/// the Graph selection also use. +final class RunVisitTarget extends RunSearchTarget { + const RunVisitTarget({required this.stageKey, required this.timelineIndex}); + + final String stageKey; + final int timelineIndex; +} + +/// Resolves [selection] against the loaded [run] into the detail state to show. /// -/// A text hit selects the Summary section holding the matched field, mirroring -/// the browser's `searchFieldTab`: a retired or unknown field resolves to the -/// plain Summary instead of guessing a section. A visit hit selects the step -/// with the recorded sequence and its own row in the Timeline; a sequence the -/// run did not record resolves to nothing. Either null leaves the plain run -/// detail in place. -RunSearchTarget? resolveRunSearchSelection( +/// A text hit always selects the Summary, using the browser's `searchFieldTab` +/// mapping: `input` and `output` expand that section, while a retired or +/// unknown field leaves the plain Summary instead of guessing a section. A +/// visit hit selects the step with the recorded sequence; a sequence the run did +/// not record falls back to the plain Summary, as the browser does, so a stale +/// hit never leaves an unrelated visit pane open. +RunSearchTarget resolveRunSearchSelection( RunSearchSelection selection, JsonMap run, ) { final field = selection.field?.trim() ?? ''; if (field.isNotEmpty) { - return switch (field) { - 'input' => const RunSearchTarget.section('input'), - 'output' => const RunSearchTarget.section('output'), - _ => null, - }; + return RunSummaryTarget( + section: switch (field) { + 'input' => RunSummarySection.input, + 'output' => RunSummarySection.output, + _ => null, + }, + ); } final sequence = selection.sequence; - if (sequence == null || sequence <= 0) return null; - - final steps = detailRunSteps(run); - for (var index = 0; index < steps.length; index++) { - if (_sequence(steps[index]) != sequence) continue; - final stage = '${steps[index]['stage'] ?? ''}'.trim(); - if (stage.isEmpty) return null; - // The row index is the Timeline's own index, the identity the visit pane - // reads back through detailVisitStepAt, so no ordinal is guessed here. - return RunSearchTarget.visit(stageKey: stage, timelineIndex: index); + if (sequence != null && sequence > 0) { + final steps = detailRunSteps(run); + for (var index = 0; index < steps.length; index++) { + if (_sequence(steps[index]) != sequence) continue; + final stage = '${steps[index]['stage'] ?? ''}'.trim(); + if (stage.isEmpty) break; + // The row index is the Timeline's own index, the identity the visit pane + // reads back through detailVisitStepAt, so no ordinal is guessed here. + return RunVisitTarget(stageKey: stage, timelineIndex: index); + } } - return null; + return const RunSummaryTarget(); } int? _sequence(JsonMap step) { diff --git a/app/test/application/search_wiring_test.dart b/app/test/application/search_wiring_test.dart index 20dfabb3..86de29eb 100644 --- a/app/test/application/search_wiring_test.dart +++ b/app/test/application/search_wiring_test.dart @@ -73,6 +73,66 @@ Future replyRunList(WidgetTester tester, FakeChannel channel) => reply( }, ); +Future 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 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 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 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)); diff --git a/app/test/features/runs/ui/run_search_selection_test.dart b/app/test/features/runs/ui/run_search_selection_test.dart index 09a6d76d..188955b6 100644 --- a/app/test/features/runs/ui/run_search_selection_test.dart +++ b/app/test/features/runs/ui/run_search_selection_test.dart @@ -40,7 +40,9 @@ JsonMap searchSelectionRun() => { ], }; -Future pumpSelection( +/// Pumps one mounted detail under a mutable search scope, returning the notifier +/// that applies a later request to the same detail state. +Future> pumpLiveSelection( WidgetTester tester, RunDetailTestPlatform platform, RunSearchSelection selection, { @@ -53,15 +55,20 @@ Future pumpSelection( final controller = RunsController(RunsRepository(gateway)); addTearDown(controller.dispose); await controller.select(77); + final pending = ValueNotifier(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( + valueListenable: pending, + builder: (context, current, _) => RunSearchSelectionScope( + selection: current, + onConsumed: onConsumed ?? () {}, + child: RunDetailView( + controller: controller, + gateway: gateway, + onBack: () {}, + ), ), ), ); @@ -74,6 +81,23 @@ Future pumpSelection( ), ); await tester.pumpAndSettle(); + return pending; +} + +Future 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()); + 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()); + 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, + ); + }); + }); }