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

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

- RunsScreen relays the shell's search scope into the detail it builds, so
  the pushed page sees the selection too (also fixes field hits on phones).
- An artifact hit now opens the run's Artifacts tab and the gallery opens
  that artifact exactly as a tap there does: selected, scrolled into view
  (ArtifactVisitReveal) and in the viewer. Back returns to the tab with the
  artifact highlighted. An unknown URL leaves the tab open with the existing
  "That artifact is no longer available." notice.
- New test/application/search_artifact_open_test.dart drives the real Search
  tab -> typed query -> result tap -> run read -> viewer on a 390x844 phone,
  Material and Cupertino; it fails without the scope relay.
This commit is contained in:
2026-11-02 18:34:53 +00:00
parent 37b67c84df
commit 8d2ca95057
9 changed files with 519 additions and 147 deletions
+26 -61
View File
@@ -13,10 +13,6 @@ import '../../../core/api_gateway.dart';
import '../../graph/widgets/run_graph_view.dart';
import '../../artifacts/ui/artifact_gallery_action.dart';
import '../../artifacts/ui/artifact_gallery_page.dart';
import '../../artifacts/domain/artifact_groups.dart';
import '../../artifacts/domain/artifact_record.dart';
import '../../artifacts/domain/gallery_navigation.dart';
import '../../artifacts/ui/artifact_viewer_page.dart';
import '../../changes/changes.dart';
import 'run_changes_action.dart';
import 'run_detail_content.dart';
@@ -116,9 +112,8 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
/// request never reopens a pane the operator closed in the meantime.
RunSearchSelection? _appliedSearchSelection;
/// Search artifacts open above their visit, so the normal visit-page sync
/// must wait for the search callback to install both routes.
bool _searchArtifactVisitPending = false;
/// The artifact a search hit asked the Artifacts tab to open, until it has.
String? _searchArtifactUrl;
@override
void initState() {
@@ -249,62 +244,30 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
_selectedStage = stageKey;
_selectedVisit = timelineIndex;
_tab = RunDetailTab.timeline;
case RunArtifactTarget(:final visit, :final url):
if (detailVisitStepAt(widget.run, visit.timelineIndex) == null) return;
// The viewer is opened above the visit. Prevent build() from opening
// that visit first in its own callback; the search callback installs
// the visit route and then the viewer route in that order.
_selectedStage = visit.stageKey;
_selectedVisit = visit.timelineIndex;
_tab = RunDetailTab.timeline;
_searchArtifactVisitPending = true;
WidgetsBinding.instance.addPostFrameCallback(
(_) => mounted ? _openSearchArtifact(url, visit.timelineIndex) : null,
);
case RunArtifactTarget(:final url):
_selectedStage = null;
_selectedVisit = null;
if (!_tabsFor(widget.run).contains(RunDetailTab.artifacts)) {
// A run with no recorded steps has no gallery to open it in.
_tab = RunDetailTab.summary;
WidgetsBinding.instance.addPostFrameCallback(
(_) => mounted ? _showSearchArtifactMissingNotice() : null,
);
return;
}
// The gallery opens it as if tapped there: highlighted, scrolled into
// view and in the viewer, so Back returns to the Artifacts tab.
_tab = RunDetailTab.artifacts;
_searchArtifactUrl = url;
}
}
void _openSearchArtifact(String url, int visitIndex) {
// _pushVisit reaches Navigator.push before its first await. Install the
// visit first so it remains the run-detail destination on Back, including
// when the recorded artifact has disappeared.
unawaited(_pushVisit(visitIndex));
// The visit page is now the shown one (_pushVisit records it before its
// first await), so later visit selections sync normally again.
_searchArtifactVisitPending = false;
final steps = detailRunSteps(widget.run);
final groups = galleryGroups(steps);
ArtifactGroup? selectedGroup;
ArtifactRecord? selectedArtifact;
for (final group in groups) {
for (final artifact in [
...group.artifacts,
...group.documents.map((document) => document.record),
]) {
if (artifact == null || artifact.url != url) continue;
selectedGroup = group;
selectedArtifact = artifact;
break;
}
if (selectedArtifact != null) break;
}
if (selectedGroup == null || selectedArtifact == null) {
_showSearchArtifactMissingNotice();
return;
}
final group = selectedGroup;
final artifact = selectedArtifact;
final page = ArtifactViewerPage(
groups: groups,
selectedIdentity: artifactVisitIdentityOf(group, artifact),
includeExternalDocuments: true,
configuredEndpoint: widget.configuredEndpoint,
);
Navigator.of(context).push<void>(
widget.cupertino
? CupertinoPageRoute<void>(builder: (_) => page)
: MaterialPageRoute<void>(builder: (_) => page),
);
/// The Artifacts tab handled the search request: it opened the artifact, or
/// found no recorded file with that URL.
void _searchArtifactHandled(bool found) {
if (!mounted) return;
setState(() => _searchArtifactUrl = null);
if (!found) _showSearchArtifactMissingNotice();
}
void _showSearchArtifactMissingNotice() {
@@ -439,7 +402,7 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
@override
Widget build(BuildContext context) {
// A selected visit opens on its own page; the tab keeps the list.
if (_selectedVisit != _shownVisit && !_searchArtifactVisitPending) {
if (_selectedVisit != _shownVisit) {
_syncVisitPage();
}
final tabs = _tabsFor(widget.run);
@@ -558,6 +521,8 @@ class _RunDetailTabsState extends State<RunDetailTabs> {
executing: runDetailExecuting(widget.run),
configuredEndpoint: widget.configuredEndpoint,
embedded: true,
openArtifactUrl: _searchArtifactUrl,
onOpenArtifactHandled: _searchArtifactHandled,
);
case RunDetailTab.changes:
final viewer = ChangesViewer(
@@ -66,12 +66,12 @@ final class RunVisitTarget extends RunSearchTarget {
final int timelineIndex;
}
/// A recorded artifact hit selects its visit first, then opens the artifact
/// viewer on the exact recorded file.
/// A recorded artifact hit opens the run's Artifacts tab and that tab opens
/// the exact recorded file, exactly as tapping it in the gallery does.
final class RunArtifactTarget extends RunSearchTarget {
const RunArtifactTarget({required this.visit, required this.url});
const RunArtifactTarget({required this.url});
final RunVisitTarget visit;
/// The recorded artifact URL, matched against the gallery's own records.
final String url;
}
@@ -82,7 +82,8 @@ final class RunArtifactTarget extends RunSearchTarget {
/// 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.
/// hit never leaves an unrelated visit pane open. An artifact hit names the
/// Artifacts tab and its recorded URL.
RunSearchTarget resolveRunSearchSelection(
RunSearchSelection selection,
JsonMap run,
@@ -97,13 +98,11 @@ RunSearchTarget resolveRunSearchSelection(
},
);
}
// The URL is the artifact's identity; the gallery matches it among every
// recorded visit, so a sequence the detail numbers differently still opens
// the file, and a file the run no longer lists reports itself as gone.
final artifactUrl = selection.artifactUrl?.trim() ?? '';
if (artifactUrl.isNotEmpty) {
final visit = _visitTarget(selection, run);
return visit == null
? const RunSummaryTarget()
: RunArtifactTarget(visit: visit, url: artifactUrl);
}
if (artifactUrl.isNotEmpty) return RunArtifactTarget(url: artifactUrl);
final visit = _visitTarget(selection, run);
if (visit != null) return visit;
return const RunSummaryTarget();