diff --git a/app/lib/features/artifacts/domain/artifact_summary.dart b/app/lib/features/artifacts/domain/artifact_summary.dart index 8ef878fb..dda496aa 100644 --- a/app/lib/features/artifacts/domain/artifact_summary.dart +++ b/app/lib/features/artifacts/domain/artifact_summary.dart @@ -15,17 +15,28 @@ String artifactsEmptyMessage(bool executing) => executing ? 'Artifacts · $artifactCapturePending' : 'No artifacts recorded for this run.'; +/// How many deliverables the run recorded: the stage-published files the +/// gallery lists by default, each shared `public/` file counted once. The run +/// detail's Artifacts badge and the gallery header both use this count, so a +/// run whose visits recorded only debugging files never advertises them. +int runDeliverableCount(List steps) => artifactGroups( + steps, +).fold(0, (sum, group) => sum + group.artifacts.length); + +/// How many debugging files the run recorded (turn documents, history, +/// private scratch, session exports): the gallery's secondary section. +int debugFileCount(List steps) => + steps.fold(0, (sum, step) => sum + systemArtifacts(step).length); + /// The run summary's Artifacts section header. /// -/// The recorded count is the number of recorded entries [galleryGroups] yields: -/// stage files plus the turn documents the server actually recorded, never an -/// absent slot. The title takes its singular form for one. A run whose capture is -/// unavailable says so instead of claiming that nothing was recorded. Partial -/// capture is flagged when any visit excluded or omitted files. +/// The recorded count is the run's deliverables ([runDeliverableCount]); +/// debugging files are not counted as artifacts. The title takes its singular +/// form for one. A run whose capture is unavailable says so instead of claiming +/// that nothing was recorded. Partial capture is flagged when any visit +/// excluded or omitted files. String artifactsHeader(List steps, {required bool executing}) { - final recorded = galleryGroups( - steps, - ).fold(0, (sum, group) => sum + group.recordedCount); + final recorded = runDeliverableCount(steps); if (recorded == 0) { if (executing) return artifactsEmptyMessage(true); final unavailable = steps.any( diff --git a/app/lib/features/artifacts/ui/artifact_debug_reveal.dart b/app/lib/features/artifacts/ui/artifact_debug_reveal.dart new file mode 100644 index 00000000..8c354e47 --- /dev/null +++ b/app/lib/features/artifacts/ui/artifact_debug_reveal.dart @@ -0,0 +1,43 @@ +import 'package:flutter/material.dart'; + +import '../../../ui/text/plural.dart'; + +/// The gallery's secondary, collapsed entry for a run's debugging files. +/// +/// It follows the deliverables (or stands alone when there are none), so a +/// run that recorded only runner-internal files says how many there are and +/// opens them in place instead of leaving the page apparently empty. +class ArtifactDebugReveal extends StatelessWidget { + const ArtifactDebugReveal({ + super.key, + required this.count, + required this.showing, + required this.onToggle, + }); + + /// The recorded debugging files the section holds. + final int count; + + /// Whether the debugging files are currently listed. + final bool showing; + + final VoidCallback onToggle; + + @override + Widget build(BuildContext context) { + return Material( + type: MaterialType.transparency, + child: ListTile( + key: const Key('artifact-debug-reveal'), + leading: Icon(showing ? Icons.bug_report : Icons.bug_report_outlined), + title: Text(showing ? 'Hide debugging files' : 'Show debugging files'), + subtitle: Text( + '${countLabel(count, 'file')}: turn documents, history and ' + 'private scratch', + ), + trailing: Icon(showing ? Icons.expand_less : Icons.expand_more), + onTap: onToggle, + ), + ); + } +} diff --git a/app/lib/features/artifacts/ui/artifact_gallery_action.dart b/app/lib/features/artifacts/ui/artifact_gallery_action.dart index dbce6232..b87de489 100644 --- a/app/lib/features/artifacts/ui/artifact_gallery_action.dart +++ b/app/lib/features/artifacts/ui/artifact_gallery_action.dart @@ -3,7 +3,7 @@ import 'package:flutter/material.dart'; import '../../../core/api_gateway.dart'; import '../../../core/transport/pipelines_client.dart'; import '../domain/artifact_chat_context.dart'; -import '../domain/artifact_groups.dart'; +import '../domain/artifact_summary.dart'; import 'artifact_external_open.dart'; import 'artifact_gallery_page.dart'; @@ -34,11 +34,14 @@ List runDetailArtifactSteps(JsonMap run) { bool showRunArtifactsAction(JsonMap run) => runDetailArtifactSteps(run).isNotEmpty; -/// How many recorded entries the run's gallery lists (stage files plus -/// recorded turn documents), as the gallery header counts them. -int runArtifactCount(JsonMap run) => galleryGroups( - runDetailArtifactSteps(run), -).fold(0, (sum, group) => sum + group.recordedCount); +/// How many deliverables the run's gallery lists by default, as its header +/// counts them. Debugging files are not artifacts and are never badged. +int runArtifactCount(JsonMap run) => + runDeliverableCount(runDetailArtifactSteps(run)); + +/// How many debugging files the gallery's secondary section holds. +int runDebugFileCount(JsonMap run) => + debugFileCount(runDetailArtifactSteps(run)); /// Whether the run is still executing, so the page can say capture pending /// instead of claiming nothing was recorded. diff --git a/app/lib/features/artifacts/ui/artifact_gallery_page.dart b/app/lib/features/artifacts/ui/artifact_gallery_page.dart index 1b6cfc7b..46892225 100644 --- a/app/lib/features/artifacts/ui/artifact_gallery_page.dart +++ b/app/lib/features/artifacts/ui/artifact_gallery_page.dart @@ -16,6 +16,7 @@ import '../domain/artifact_selection.dart'; import '../domain/artifact_summary.dart'; import '../domain/artifact_url.dart'; import '../domain/artifact_chat_context.dart'; +import 'artifact_debug_reveal.dart'; import 'artifact_external_open.dart'; import 'artifact_selection_facts.dart'; import 'artifact_viewer_content.dart'; @@ -572,12 +573,28 @@ class _ArtifactGalleryPageState extends State { _summary(groups), action: widget.embedded ? _debugToggle(context) : null, ); + // Debugging files are a secondary section after the deliverables, never + // counted as artifacts, so a run with only those still shows where they are. + final debugCount = groups.fold( + 0, + (sum, group) => + sum + group.documents.where((doc) => doc.record != null).length, + ); + final footer = debugCount == 0 + ? null + : ArtifactDebugReveal( + count: debugCount, + showing: _showTurnDocuments, + onToggle: () => + setState(() => _showTurnDocuments = !_showTurnDocuments), + ); // Header, status and rows share one scroll view: the page never splits a // fixed header from a shrinking list, so a long header always stays usable. final body = visibleGroups.isEmpty - ? ListView(children: [header]) + ? ListView(children: [header, ?footer]) : ArtifactVisitList( header: header, + footer: footer, groups: visibleGroups, selectedIdentity: _selectedIdentity, onSelected: _select, diff --git a/app/lib/features/artifacts/ui/artifact_visit_list.dart b/app/lib/features/artifacts/ui/artifact_visit_list.dart index 6aef1c5e..0de06728 100644 --- a/app/lib/features/artifacts/ui/artifact_visit_list.dart +++ b/app/lib/features/artifacts/ui/artifact_visit_list.dart @@ -39,6 +39,7 @@ class ArtifactVisitList extends StatefulWidget { super.key, required this.groups, this.header, + this.footer, this.selectedIdentity, this.onSelected, this.configuredEndpoint = '', @@ -51,6 +52,10 @@ class ArtifactVisitList extends StatefulWidget { final Widget? header; + /// Follows the last group in the same scroll view (the gallery's secondary + /// Debugging files entry). + final Widget? footer; + final List groups; final String? selectedIdentity; @@ -226,6 +231,7 @@ class _ArtifactVisitListState extends State { slivers: [ const SliverTopBarClearance(), ...slivers, + if (widget.footer != null) SliverToBoxAdapter(child: widget.footer), const SliverFloatingBarClearance(), ], ); diff --git a/app/lib/features/runs/ui/run_detail_tabs.dart b/app/lib/features/runs/ui/run_detail_tabs.dart index c655c0ce..c01d6f18 100644 --- a/app/lib/features/runs/ui/run_detail_tabs.dart +++ b/app/lib/features/runs/ui/run_detail_tabs.dart @@ -403,9 +403,12 @@ class _RunDetailTabsState extends State { if (runFindings(run).isNotEmpty) RunDetailTab.findings, ]; - /// Artifacts stays in place but disabled while the run recorded none. + /// Artifacts stays in place but disabled while the run recorded no file at + /// all. A run with only debugging files keeps it open (badged `0`) so its + /// secondary Debugging files section stays reachable. Set _disabledTabs(JsonMap run) => { - if (runArtifactCount(run) == 0) RunDetailTab.artifacts, + if (runArtifactCount(run) == 0 && runDebugFileCount(run) == 0) + RunDetailTab.artifacts, }; @override diff --git a/app/test/features/artifacts/domain/artifact_document_test.dart b/app/test/features/artifacts/domain/artifact_document_test.dart index f0e1761a..519e2ced 100644 --- a/app/test/features/artifacts/domain/artifact_document_test.dart +++ b/app/test/features/artifacts/domain/artifact_document_test.dart @@ -243,7 +243,7 @@ void main() { expect(galleryGroups(steps), isEmpty); }); - test('the header counts recorded documents and stage artifacts', () { + test('the header counts deliverables, never debugging documents', () { final steps = >[ step( stage: 'review', @@ -256,10 +256,7 @@ void main() { ], ), ]; - expect( - artifactsHeader(steps, executing: false), - 'Artifacts · 3 recorded', - ); + expect(artifactsHeader(steps, executing: false), 'Artifact · 1 recorded'); }); test( diff --git a/app/test/features/artifacts/ui/artifact_gallery_debug_files_test.dart b/app/test/features/artifacts/ui/artifact_gallery_debug_files_test.dart index 73e7baec..78d05904 100644 --- a/app/test/features/artifacts/ui/artifact_gallery_debug_files_test.dart +++ b/app/test/features/artifacts/ui/artifact_gallery_debug_files_test.dart @@ -64,10 +64,14 @@ void main() { expect(find.text(name), findsNothing, reason: name); } expect(find.text('Debugging files'), findsNothing); + // The secondary entry after the deliverables names how many are hidden. + expect(find.text('Show debugging files'), findsOneWidget); + expect(find.textContaining('5 files'), findsOneWidget); await tester.tap(find.byKey(const Key('artifact-debug-toggle'))); await tester.pumpAndSettle(); expect(find.text('Debugging files'), findsOneWidget); + expect(find.text('Hide debugging files'), findsOneWidget); for (final name in [ 'history.md', 'memory.md', @@ -79,4 +83,41 @@ void main() { } expect(find.text('public/report.md'), findsOneWidget); }); + + testWidgets('a run with only debugging files says so and reveals them', ( + tester, + ) async { + tester.view.physicalSize = const Size(900, 2600); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.resetPhysicalSize); + addTearDown(tester.view.resetDevicePixelRatio); + final steps = [ + step( + stage: 'build', + artifacts: [ + for (final name in ['input.md', 'output.md', 'history.md']) + _file(name, 'debug'), + ], + ), + ]; + await tester.pumpWidget( + MaterialApp( + home: ArtifactGalleryPage( + steps: steps, + embedded: true, + openExternal: (_) async => true, + markdownBuilder: (context, value) => Text(value), + ), + ), + ); + await tester.pumpAndSettle(); + expect(find.text('No artifacts recorded for this run.'), findsOneWidget); + expect(find.text('output.md'), findsNothing); + + await tester.tap(find.byKey(const Key('artifact-debug-reveal'))); + await tester.pumpAndSettle(); + for (final name in ['input.md', 'output.md', 'history.md']) { + expect(find.text(name), findsOneWidget, reason: name); + } + }); } diff --git a/app/test/features/runs/ui/run_artifacts_action_test.dart b/app/test/features/runs/ui/run_artifacts_action_test.dart index 970ec49c..a69fba2a 100644 --- a/app/test/features/runs/ui/run_artifacts_action_test.dart +++ b/app/test/features/runs/ui/run_artifacts_action_test.dart @@ -98,6 +98,122 @@ void main() { expect(find.text('reviewer · visit 1'), findsOneWidget); }); + /// Shaped like the live Caplens ticket runs (133-139): every visit recorded + /// only server-grouped debugging files (turn documents, history, private + /// scratch) and no `public/` deliverable. + JsonMap debugOnly(String name, {String url = ''}) => artifact( + name, + url: url.isEmpty ? null : url, + contentType: 'text/markdown; charset=utf-8', + sizeBytes: 3000, + extra: const {'group': 'debug'}, + ); + + testWidgets('debugging files are never badged as artifacts', (tester) async { + final gateway = _FakeGateway( + _run( + steps: [ + for (final (index, stage) in ['build', 'review', 'verify'].indexed) + step( + stage: stage, + sequence: index + 1, + artifacts: [ + for (final name in [ + 'input.md', + 'memory.md', + 'history.md', + 'output.md', + 'session.html', + 'private/notes.md', + ]) + debugOnly(name, url: '/artifacts/21/${index + 1}/$name'), + ], + ), + ], + ), + ); + final controller = await _loaded(gateway); + addTearDown(controller.dispose); + await _pumpDetail(tester, controller, gateway); + + final tab = find.byKey(const ValueKey('run-detail-tab-artifacts')); + // The badge says 0: none of the 18 recorded files is a deliverable. + expect(find.descendant(of: tab, matching: find.text('0')), findsOneWidget); + expect(find.descendant(of: tab, matching: find.text('18')), findsNothing); + // The tab still opens, to an honest summary and a collapsed debug entry. + expect(tester.widget(tab).enabled, isTrue); + await tester.ensureVisible(tab); + await tester.pumpAndSettle(); + await tester.tap(tab); + await tester.pumpAndSettle(); + expect(find.text('No artifacts recorded for this run.'), findsOneWidget); + final reveal = find.byKey(const Key('artifact-debug-reveal')); + expect(reveal, findsOneWidget); + expect(find.textContaining('18 files'), findsOneWidget); + expect(find.text('history.md'), findsNothing); + + await tester.tap(reveal); + await tester.pumpAndSettle(); + expect(find.text('build · visit 1'), findsOneWidget); + expect(find.text('history.md'), findsWidgets); + }); + + testWidgets('deliverables are badged and listed before debugging files', ( + tester, + ) async { + // Shaped like the live Research run 132: public/ deliverables beside + // stage-root copies and turn files the server groups as debug. + JsonMap deliverable(String name, int sequence) => artifact( + name, + url: '/artifacts/21/$sequence/$name', + contentType: 'text/markdown; charset=utf-8', + extra: const {'group': 'deliverable'}, + ); + final gateway = _FakeGateway( + _run( + steps: [ + step( + stage: 'ground', + sequence: 1, + artifacts: [ + debugOnly('input.md', url: '/artifacts/21/1/input.md'), + debugOnly('output.md', url: '/artifacts/21/1/output.md'), + debugOnly('ground.md', url: '/artifacts/21/1/ground.md'), + deliverable('public/ground.md', 1), + ], + ), + step( + stage: 'research', + sequence: 2, + artifacts: [ + debugOnly('input.md', url: '/artifacts/21/2/input.md'), + debugOnly('output.md', url: '/artifacts/21/2/output.md'), + deliverable('public/ground.md', 2), + deliverable('public/research.md', 2), + ], + ), + ], + ), + ); + final controller = await _loaded(gateway); + addTearDown(controller.dispose); + await _pumpDetail(tester, controller, gateway); + + final tab = find.byKey(const ValueKey('run-detail-tab-artifacts')); + // public/ground.md is shared, so it counts once: 2 deliverables. + expect(find.descendant(of: tab, matching: find.text('2')), findsOneWidget); + await tester.ensureVisible(tab); + await tester.pumpAndSettle(); + await tester.tap(tab); + await tester.pumpAndSettle(); + expect(find.text('Artifacts · 2 recorded'), findsOneWidget); + expect(find.text('public/ground.md'), findsOneWidget); + expect(find.text('public/research.md'), findsOneWidget); + expect(find.text('ground.md'), findsNothing); + expect(find.text('input.md'), findsNothing); + expect(find.textContaining('5 files'), findsOneWidget); + }); + /// The Artifacts tab keeps its place on a run with none: disabled, badged /// `0`, and its tooltip (and accessibility hint) says why. Future expectDisabledArtifacts(WidgetTester tester, String why) async { diff --git a/app/tool/search_selection_probe_entry.dart b/app/tool/search_selection_probe_entry.dart index 2b19f3ec..ccba74fd 100644 --- a/app/tool/search_selection_probe_entry.dart +++ b/app/tool/search_selection_probe_entry.dart @@ -84,6 +84,7 @@ JsonMap probeRunDetail() => { 'finished_at': '2026-10-20T08:31:00Z', 'diagnostic': 'release plan accepted', 'file_changes': _probeChanges(['docs/release-plan.md']), + if (_debugOnly) 'artifacts': _turnArtifacts(5), }, { 'stage': 'build', @@ -94,12 +95,13 @@ JsonMap probeRunDetail() => { 'started_at': '2026-10-20T08:16:00Z', 'finished_at': '2026-10-20T08:24:00Z', 'artifacts': [ - { - 'name': 'release-report.txt', - 'content_type': 'text/plain', - 'size_bytes': 12, - 'url': '/artifacts/7/2/release-report.txt', - }, + if (!_debugOnly) + { + 'name': 'release-report.txt', + 'content_type': 'text/plain', + 'size_bytes': 12, + 'url': '/artifacts/7/2/release-report.txt', + }, if (_htmlArtifact) { 'name': 'release-dashboard.html', @@ -107,15 +109,7 @@ JsonMap probeRunDetail() => { 'size_bytes': 4096, 'url': '/artifacts/7/2/release-dashboard.html', }, - if (_turnFiles) - for (final name in _turnFileNames) - { - 'name': name, - 'content_type': 'text/markdown', - 'size_bytes': 640, - 'url': '/artifacts/7/2/', - 'group': 'debug', - }, + if (_turnFiles) ..._turnArtifacts(2), ], 'file_changes': _probeChanges([ 'lib/release/train.dart', @@ -131,6 +125,7 @@ JsonMap probeRunDetail() => { 'target': 'build', 'started_at': '2026-10-20T08:12:00Z', 'finished_at': '2026-10-20T08:14:00Z', + if (_debugOnly) 'artifacts': _turnArtifacts(1), }, ..._fillerSteps(), ], @@ -212,6 +207,23 @@ void _installUiReviewChats() { }; } +/// `?debugOnly=1`: every run 7 visit records only the server-grouped debugging +/// files and no deliverable, as the live ticket runs do, so the Artifacts badge +/// and tab can be reviewed for a run with nothing published. +bool _debugOnly = false; + +/// One visit's debugging files, each at its own recorded url. +List _turnArtifacts(int sequence) => [ + for (final name in _turnFileNames) + { + 'name': name, + 'content_type': 'text/markdown', + 'size_bytes': 640, + 'url': '/artifacts/7/$sequence/$name', + 'group': 'debug', + }, +]; + const List _turnFileNames = [ 'input.md', 'memory.md', @@ -961,6 +973,7 @@ class _FixtureSink implements WebSocketSink { /// `?running=1` adds an executing run 8 whose duration ticks; /// `?html=1` adds an HTML artifact to run 7 (`release-dashboard.html`); /// `?turn=1` adds run 7's debug turn files (input/memory/history/output.md); +/// `?debugOnly=1` gives every run 7 visit only debug files, no deliverable; /// `?q=release` types that query into Search once its field is shown; /// `?perf=1` prints frame timings (tool/perf/frame_log.dart); /// `?hits=N`, `?chats=N` and `?graph=1` add bench data @@ -1028,7 +1041,8 @@ Future main() async { _htmlArtifact = params['html'] == '1'; _warnings = params['warnings'] == '1'; _harnesses = params['harnesses'] == '1'; - _turnFiles = params['turn'] == '1'; + _debugOnly = params['debugOnly'] == '1'; + _turnFiles = params['turn'] == '1' || _debugOnly; final route = params['route']; final opensRoute = route != null && route.startsWith('/'); if (opensRoute) openFixtureRoute(route);