From be6b6239fc4bfecb0b533ba2d522e6e8dfbd8042 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Thu, 22 Oct 2026 14:13:38 +0100 Subject: [PATCH] feat(app): match the web run detail tabs and summary shape --- .../runs/ui/run_detail_summary_fields.dart | 137 +++--- app/lib/features/runs/ui/run_detail_tab.dart | 3 +- .../runs/ui/run_detail_tab_bodies.dart | 424 +++++++++++++----- .../runs/ui/run_detail_tab_strip.dart | 19 +- .../ui/run_detail_summary_fields_test.dart | 228 ++++++---- .../runs/ui/run_detail_tabs_test.dart | 20 +- .../runs/ui/run_detail_widget_test.dart | 56 +-- 7 files changed, 561 insertions(+), 326 deletions(-) diff --git a/app/lib/features/runs/ui/run_detail_summary_fields.dart b/app/lib/features/runs/ui/run_detail_summary_fields.dart index e57c13cc..0234eb57 100644 --- a/app/lib/features/runs/ui/run_detail_summary_fields.dart +++ b/app/lib/features/runs/ui/run_detail_summary_fields.dart @@ -1,85 +1,85 @@ import '../../../core/api_gateway.dart'; import '../../pipelines/pipeline_format.dart'; -import 'run_detail_content.dart'; import 'run_detail_visit_facts.dart'; -/// The exact wording for a Summary fact the reply did not record. +/// One recorded Summary row: the web run summary's key/value shape. /// -/// It is the same word the Summary's usage rows already use for an unreported -/// value, so one absent fact never reads as `0`, `false` or an empty field. -const String summaryUnknownValue = 'Unavailable'; +/// [monospace] marks a value the web renders as a code identifier (the content +/// hash); [block] marks a multi-line recorded document (the diagnostic) that is +/// drawn as its own block rather than a short row. +typedef DetailSummaryRow = ({ + String label, + String value, + bool monospace, + bool block, +}); -/// The run Summary's recorded facts, in the web summary's order: the current -/// stage and the run's timing, then the latest recorded visit's effective -/// provider/model, target and verdict. +/// The run Summary's rows, in the web summary's order: Pipeline, Stage, +/// Workspace, Content hash, Started, Finished, Duration, Retry of and the +/// Diagnostic block. /// -/// The latest visit is the one the Graph tab opens for the current stage, so -/// the Summary and the recorded-visit pane describe the same evidence. Tokens -/// and cost stay in [detailUsageMetrics], their existing Summary home. A fact -/// the server did not record reads [summaryUnknownValue]. -List detailSummaryFields(JsonMap run) { - final steps = detailRunSteps(run); - final stage = _text(run['current_stage']); - final latest = _latestVisit(steps, stage); - return [ - (label: 'Stage', value: stage ?? summaryUnknownValue), - ( - label: 'Started', - value: - formatLocalTimestamp(_text(run['created_at'])) ?? summaryUnknownValue, - ), - ( - label: 'Finished', - value: - formatLocalTimestamp(_text(run['finished_at'])) ?? - summaryUnknownValue, - ), - (label: 'Duration', value: _duration(run) ?? summaryUnknownValue), - ( - label: 'Provider/model', - value: latest == null - ? summaryUnknownValue - : detailVisitProviderModel(latest) ?? summaryUnknownValue, - ), - ( - label: 'Target', - value: latest == null - ? summaryUnknownValue - : _text(latest['target']) ?? summaryUnknownValue, - ), - (label: 'Verdict', value: _verdict(latest) ?? summaryUnknownValue), - ]; -} - -/// The latest recorded visit of [stage], or the latest visit when the reply -/// records no current stage. It is the same visit the Graph tab opens for that -/// stage, so a fact and its Stage row never come from different visits. -JsonMap? _latestVisit(List steps, String? stage) { - JsonMap? latest; - for (final step in steps) { - if (stage == null || _text(step['stage']) == stage) latest = step; +/// Only values the server actually recorded are rows: a blank field is omitted +/// rather than drawn as an empty or invented placeholder, exactly as +/// `summaryRows` in the web client does. A run with no pipeline id shows its +/// recorded pipeline name, and shows no Pipeline row at all when it recorded +/// neither. +List detailSummaryRows(JsonMap run) { + final rows = []; + void add( + String label, + String? value, { + bool monospace = false, + bool block = false, + }) { + final text = value?.trim() ?? ''; + if (text.isEmpty) return; + rows.add((label: label, value: text, monospace: monospace, block: block)); } - return latest; -} -/// The run's stored duration from its own start and finish, never a live -/// estimate and never a zero for an unfinished run. -String? _duration(JsonMap run) { + final pipelineId = _number(run['pipeline_id'])?.toInt() ?? 0; + if (pipelineId > 0) { + final version = _number(run['version'])?.toInt() ?? 0; + add('Pipeline', 'id $pipelineId · v$version'); + } else { + add('Pipeline', _text(run['name'])); + } + add('Stage', _text(run['current_stage'])); + add('Workspace', _text(run['workspace'])); + add('Content hash', _text(run['content_hash']), monospace: true); + add('Started', formatLocalTimestamp(_text(run['created_at']))); + add('Finished', formatLocalTimestamp(_text(run['finished_at']))); final seconds = durationSeconds( _text(run['created_at']), _text(run['finished_at']), ); - return seconds == null ? null : formatDuration(seconds); + if (seconds != null) add('Duration', formatDuration(seconds)); + final retryOf = _number(run['retry_of'])?.toInt() ?? 0; + if (retryOf > 0) add('Retry of', 'run $retryOf'); + // A diagnostic is a recorded document: its own whitespace is preserved, but a + // blank one is not a row. + final diagnostic = '${run['diagnostic'] ?? ''}'; + if (diagnostic.trim().isNotEmpty) { + rows.add(( + label: 'Diagnostic', + value: diagnostic, + monospace: false, + block: true, + )); + } + return rows; } -/// The recorded verdict as the web pane spells it: the option above its -/// reason, one part when only one was recorded, nothing when neither was. -String? _verdict(JsonMap? step) { - if (step == null) return null; - final verdict = detailVisitVerdict(step); - if (verdict == null) return null; - final parts = [verdict.option, verdict.reason].whereType(); - return parts.isEmpty ? null : parts.join('\n'); +/// The run's identity line: `run {id} · {n} recorded visits · {m} completed +/// visits`, the same recorded/completed vocabulary the web summary and the +/// server use. +String detailSummaryIdentity(JsonMap run) { + final recorded = detailRunSteps(run).length; + final completedValue = _number(run['completed_steps'])?.toInt() ?? 0; + final completed = completedValue < 0 ? 0 : completedValue; + String visits(int count, String adjective) => + '$count $adjective ${count == 1 ? 'visit' : 'visits'}'; + return 'run ${run['id'] ?? ''} · ${visits(recorded, 'recorded')} · ' + '${visits(completed, 'completed')}'; } String? _text(dynamic value) { @@ -87,3 +87,6 @@ String? _text(dynamic value) { final text = '$value'.trim(); return text.isEmpty ? null : text; } + +num? _number(dynamic value) => + value is num ? value : num.tryParse('${value ?? ''}'.trim()); diff --git a/app/lib/features/runs/ui/run_detail_tab.dart b/app/lib/features/runs/ui/run_detail_tab.dart index 44a13e4e..196caa8f 100644 --- a/app/lib/features/runs/ui/run_detail_tab.dart +++ b/app/lib/features/runs/ui/run_detail_tab.dart @@ -2,7 +2,8 @@ /// second, then the recorded Input, Output and Timeline. /// /// The stable keys match the web client's `RUN_DETAIL_TABS`; the visible labels -/// are the same words. +/// are the same words. `renderedRunDetailTabs` decides which keys the strip +/// draws, so Input and Output stay addressable without being tabs. enum RunDetailTab { summary('Summary'), graph('Graph'), 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 91957a60..333c5b96 100644 --- a/app/lib/features/runs/ui/run_detail_tab_bodies.dart +++ b/app/lib/features/runs/ui/run_detail_tab_bodies.dart @@ -4,10 +4,16 @@ import 'package:flutter/material.dart'; import '../../../core/api_gateway.dart'; import 'run_detail_content.dart'; import 'run_detail_summary_fields.dart'; +import 'run_detail_visit_facts.dart'; -/// The Summary tab: the stored original prompt with its copy control, the -/// run's recorded facts and the reported usage metrics. Neither the prompt nor -/// a fact is replaced by a fallback value. +/// The Summary tab: the run's identity, the recorded facts as key/value rows, +/// the stored original prompt with its copy control and the collapsible Input +/// and Output sections. +/// +/// The web run detail has no usage block, so no metrics are drawn here. A fact +/// the server did not record is omitted rather than shown as an invented or +/// `Unavailable` row; only the Input/Output empty sentences remain, and only +/// when that section recorded nothing. Widget runDetailSummaryTab({ required BuildContext context, required JsonMap run, @@ -16,88 +22,93 @@ Widget runDetailSummaryTab({ required String? copyStatus, required VoidCallback onCopy, }) { + final rows = detailSummaryRows(run); + final identity = detailSummaryIdentity(run); final prompt = detailPrompt(run); - final facts = detailSummaryFields(run); - final metrics = detailUsageMetrics(run['usage']); if (cupertino) { - final theme = CupertinoTheme.of(context); return ListView( key: const Key('run-detail-tab-body-summary'), children: [ - if (prompt != null) - Padding( - padding: const EdgeInsetsDirectional.fromSTEB(16, 16, 16, 0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Wrap( - alignment: WrapAlignment.spaceBetween, - crossAxisAlignment: WrapCrossAlignment.center, - spacing: 8, - runSpacing: 4, - children: [ - Text( - 'Original prompt', - style: theme.textTheme.navTitleTextStyle, - ), - CupertinoButton( - padding: EdgeInsets.zero, - onPressed: copying ? null : onCopy, - child: const Text('Copy prompt'), - ), - ], - ), - _CupertinoSelectableText(prompt), - if (copyStatus != null) - Padding( - padding: const EdgeInsets.only(top: 4), - child: Semantics(liveRegion: true, child: Text(copyStatus)), - ), - ], - ), + _cupertinoIdentity(context, identity), + if (rows.any((row) => !row.block)) + CupertinoListSection.insetGrouped( + children: [ + for (final row in rows.where((row) => !row.block)) + _cupertinoRow(context, row), + ], ), - _cupertinoMetrics(metrics), - _cupertinoFacts(facts), + for (final row in rows.where((row) => row.block)) + CupertinoListSection.insetGrouped( + children: [_cupertinoBlock(context, row)], + ), + if (prompt != null) + _cupertinoPrompt( + context, + prompt: prompt, + copying: copying, + copyStatus: copyStatus, + onCopy: onCopy, + ), + _cupertinoFieldSection( + context, + key: 'run-detail-summary-input', + title: 'Input', + value: run['input'], + empty: visitEmptyInput, + ), + _cupertinoFieldSection( + context, + key: 'run-detail-summary-output', + title: 'Output', + value: run['output'], + empty: visitEmptyOutput, + ), ], ); } final theme = Theme.of(context); return ListView( key: const Key('run-detail-tab-body-summary'), - padding: const EdgeInsets.all(16), + padding: const EdgeInsets.only(bottom: 16), children: [ - if (prompt != null) ...[ - Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded( - child: Text( - 'Original prompt', - style: theme.textTheme.titleMedium, - ), - ), - IconButton( - tooltip: 'Copy prompt', - onPressed: copying ? null : onCopy, - icon: const Icon(Icons.copy), - ), - ], - ), - SelectableText(prompt), - if (copyStatus != null) - Padding( - padding: const EdgeInsets.only(top: 4), - child: Semantics(liveRegion: true, child: Text(copyStatus)), + Padding( + padding: const EdgeInsets.fromLTRB(16, 12, 16, 0), + child: Text( + identity, + style: theme.textTheme.bodySmall?.copyWith( + color: theme.colorScheme.onSurfaceVariant, ), - const SizedBox(height: 12), - ], - _materialMetrics(metrics), - _materialFacts(facts), + ), + ), + for (final row in rows) + row.block ? _materialBlock(context, row) : _materialRow(context, row), + if (prompt != null) + _materialPrompt( + context, + prompt: prompt, + copying: copying, + copyStatus: copyStatus, + onCopy: onCopy, + ), + _materialFieldSection( + context, + key: 'run-detail-summary-input', + title: 'Input', + value: run['input'], + empty: visitEmptyInput, + ), + _materialFieldSection( + context, + key: 'run-detail-summary-output', + title: 'Output', + value: run['output'], + empty: visitEmptyOutput, + ), ], ); } -/// One recorded Input or Output field as its own tab. +/// One recorded Input or Output field as its own tab, used by a visit pane. Widget runDetailFieldTab({ required String tabKey, required dynamic value, @@ -127,64 +138,241 @@ Widget runDetailFieldTab({ ); } -Widget _materialFacts(List facts) => Column( - children: [ - for (final fact in facts) - ListTile(title: Text(fact.label), subtitle: Text(fact.value)), - ], -); +// --- Material -------------------------------------------------------------- -Widget _cupertinoFacts(List facts) => - CupertinoListSection.insetGrouped( - children: [ - for (final fact in facts) - CupertinoListTile( - title: Text(fact.label), - subtitle: Text(fact.value), - ), - ], - ); - -Widget _materialMetrics(List metrics) => ExpansionTile( - title: const Text('Metrics'), - children: [ - if (metrics.isEmpty) - const Padding( - padding: EdgeInsets.all(16), - child: Text('No reported usage.'), - ) - else - ...metrics.map( - (metric) => - ListTile(title: Text(metric.label), subtitle: Text(metric.value)), +Widget _materialRow(BuildContext context, DetailSummaryRow row) { + final theme = Theme.of(context); + final base = theme.textTheme.bodyMedium; + return ListTile( + key: ValueKey('run-detail-summary-${_slug(row.label)}'), + title: Text( + row.label, + style: theme.textTheme.bodySmall?.copyWith( + color: theme.colorScheme.onSurfaceVariant, ), - ], -); + ), + subtitle: SelectableText( + row.value, + style: row.monospace ? base?.copyWith(fontFamily: 'monospace') : base, + ), + ); +} -Widget _cupertinoMetrics(List metrics) => - CupertinoListSection.insetGrouped( +Widget _materialBlock(BuildContext context, DetailSummaryRow row) { + final theme = Theme.of(context); + return Padding( + key: ValueKey('run-detail-summary-${_slug(row.label)}'), + padding: const EdgeInsets.fromLTRB(16, 8, 16, 8), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - CupertinoExpansionTile( - title: const Text('Metrics'), - child: Padding( - padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 16), - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - if (metrics.isEmpty) - const Text('No reported usage.') - else - for (final metric in metrics) - CupertinoListTile( - title: Text(metric.label), - subtitle: Text(metric.value), - ), - ], - ), + Text( + row.label, + style: theme.textTheme.bodySmall?.copyWith( + color: theme.colorScheme.onSurfaceVariant, + ), + ), + const SizedBox(height: 4), + Container( + width: double.infinity, + padding: const EdgeInsets.all(12), + decoration: BoxDecoration( + color: theme.colorScheme.surfaceContainerHighest, + borderRadius: BorderRadius.circular(8), + ), + child: SelectableText( + row.value, + style: theme.textTheme.bodySmall?.copyWith(fontFamily: 'monospace'), ), ), ], - ); + ), + ); +} + +Widget _materialFieldSection( + BuildContext context, { + required String key, + required String title, + required dynamic value, + required String empty, +}) { + return ExpansionTile( + key: ValueKey(key), + title: Text(title), + expandedCrossAxisAlignment: CrossAxisAlignment.start, + childrenPadding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 16), + children: [SelectableText(detailEmpty(value) ? empty : detailJson(value))], + ); +} + +Widget _materialPrompt( + BuildContext context, { + required String prompt, + required bool copying, + required String? copyStatus, + required VoidCallback onCopy, +}) { + final theme = Theme.of(context); + return Padding( + padding: const EdgeInsets.fromLTRB(16, 12, 16, 0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + child: Padding( + padding: const EdgeInsets.only(top: 12), + child: Text( + 'Original prompt', + style: theme.textTheme.titleMedium, + ), + ), + ), + IconButton( + tooltip: 'Copy prompt', + onPressed: copying ? null : onCopy, + icon: const Icon(Icons.copy), + ), + ], + ), + SelectableText(prompt), + if (copyStatus != null) + Padding( + padding: const EdgeInsets.only(top: 4), + child: Semantics(liveRegion: true, child: Text(copyStatus)), + ), + ], + ), + ); +} + +// --- Cupertino ------------------------------------------------------------- + +Widget _cupertinoIdentity(BuildContext context, String identity) { + final theme = CupertinoTheme.of(context); + return Padding( + padding: const EdgeInsetsDirectional.fromSTEB(16, 12, 16, 8), + child: Text( + identity, + style: theme.textTheme.tabLabelTextStyle.copyWith( + color: CupertinoColors.secondaryLabel.resolveFrom(context), + ), + ), + ); +} + +Widget _cupertinoRow(BuildContext context, DetailSummaryRow row) { + final style = CupertinoTheme.of(context).textTheme.textStyle; + return CupertinoListTile( + key: ValueKey('run-detail-summary-${_slug(row.label)}'), + title: Text(row.label), + subtitle: Text( + row.value, + style: row.monospace ? style.copyWith(fontFamily: 'monospace') : null, + ), + ); +} + +Widget _cupertinoBlock(BuildContext context, DetailSummaryRow row) { + final theme = CupertinoTheme.of(context); + return Padding( + key: ValueKey('run-detail-summary-${_slug(row.label)}'), + padding: const EdgeInsetsDirectional.fromSTEB(16, 12, 16, 12), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + row.label, + style: theme.textTheme.tabLabelTextStyle.copyWith( + color: CupertinoColors.secondaryLabel.resolveFrom(context), + ), + ), + const SizedBox(height: 4), + Container( + width: double.infinity, + padding: const EdgeInsets.all(12), + decoration: BoxDecoration( + color: CupertinoColors.tertiarySystemFill.resolveFrom(context), + borderRadius: BorderRadius.circular(8), + ), + child: Text( + row.value, + style: theme.textTheme.textStyle.copyWith(fontFamily: 'monospace'), + ), + ), + ], + ), + ); +} + +Widget _cupertinoFieldSection( + BuildContext context, { + required String key, + required String title, + required dynamic value, + required String empty, +}) { + return CupertinoListSection.insetGrouped( + key: ValueKey(key), + children: [ + CupertinoExpansionTile( + title: Text(title), + child: Padding( + padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 16), + child: Align( + alignment: AlignmentDirectional.centerStart, + child: _CupertinoSelectableText( + detailEmpty(value) ? empty : detailJson(value), + ), + ), + ), + ), + ], + ); +} + +Widget _cupertinoPrompt( + BuildContext context, { + required String prompt, + required bool copying, + required String? copyStatus, + required VoidCallback onCopy, +}) { + final theme = CupertinoTheme.of(context); + return Padding( + padding: const EdgeInsetsDirectional.fromSTEB(16, 16, 16, 0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Wrap( + alignment: WrapAlignment.spaceBetween, + crossAxisAlignment: WrapCrossAlignment.center, + spacing: 8, + runSpacing: 4, + children: [ + Text('Original prompt', style: theme.textTheme.navTitleTextStyle), + CupertinoButton( + padding: EdgeInsets.zero, + onPressed: copying ? null : onCopy, + child: const Text('Copy prompt'), + ), + ], + ), + _CupertinoSelectableText(prompt), + if (copyStatus != null) + Padding( + padding: const EdgeInsets.only(top: 4), + child: Semantics(liveRegion: true, child: Text(copyStatus)), + ), + ], + ), + ); +} + +String _slug(String label) => label.toLowerCase().replaceAll(' ', '-'); /// A read-only Cupertino text control: plain, selectable text without a /// Material dependency, while keeping native selection and copy affordances. diff --git a/app/lib/features/runs/ui/run_detail_tab_strip.dart b/app/lib/features/runs/ui/run_detail_tab_strip.dart index c55e7f3f..a5126e93 100644 --- a/app/lib/features/runs/ui/run_detail_tab_strip.dart +++ b/app/lib/features/runs/ui/run_detail_tab_strip.dart @@ -5,9 +5,18 @@ import 'package:flutter/material.dart'; import '../../../ui/adaptive/host.dart'; import 'run_detail_tab.dart'; +/// The tabs the strip renders, in the web's order: Summary first so it is the +/// default, then the run Graph and the Timeline. Input and Output are +/// collapsible Summary sections now, so their stable enum keys stay available +/// for old routes but they are not separate tabs. +const List renderedRunDetailTabs = [ + RunDetailTab.summary, + RunDetailTab.graph, + RunDetailTab.timeline, +]; + /// The run detail's platform tab strip: a Material segmented button or a -/// Cupertino segmented control, in the web's Summary/Graph/Input/Output/ -/// Timeline order. +/// Cupertino segmented control, in the web's Summary/Graph/Timeline order. /// /// The native control keeps every label at its intrinsic width: a narrow pane /// or scaled text scrolls the strip horizontally instead of squeezing or @@ -29,7 +38,7 @@ class RunDetailTabStrip extends StatefulWidget { class _RunDetailTabStripState extends State { final Map _labels = { - for (final tab in RunDetailTab.values) tab: GlobalKey(), + for (final tab in renderedRunDetailTabs) tab: GlobalKey(), }; @override @@ -66,7 +75,7 @@ class _RunDetailTabStripState extends State { Widget _materialControl() => SegmentedButton( segments: [ - for (final tab in RunDetailTab.values) + for (final tab in renderedRunDetailTabs) ButtonSegment(value: tab, label: _label(tab)), ], selected: {widget.selected}, @@ -78,7 +87,7 @@ class _RunDetailTabStripState extends State { groupValue: widget.selected, onValueChanged: widget.onSelected, children: { - for (final tab in RunDetailTab.values) + for (final tab in renderedRunDetailTabs) tab: Padding( padding: const EdgeInsets.symmetric(horizontal: 8), child: _label(tab), diff --git a/app/test/features/runs/ui/run_detail_summary_fields_test.dart b/app/test/features/runs/ui/run_detail_summary_fields_test.dart index dc070074..795e427d 100644 --- a/app/test/features/runs/ui/run_detail_summary_fields_test.dart +++ b/app/test/features/runs/ui/run_detail_summary_fields_test.dart @@ -7,39 +7,27 @@ import 'package:pipelines_app/features/runs/ui/run_detail_summary_fields.dart'; import 'run_detail_graph_support.dart'; -/// A run whose latest visit recorded every summary fact, plus reported usage. +/// A run whose recorded facts fill every Summary row. JsonMap recordedRunFixture() => { 'id': 51, 'title': 'Summary run', 'name': 'release', + 'pipeline_id': 3, + 'version': 2, 'status': 'succeeded', 'current_stage': 'review', + 'workspace': '/srv/workspaces/run-51', + 'content_hash': 'abc123def456', 'created_at': '2026-10-19T09:30:00Z', 'finished_at': '2026-10-19T09:32:05Z', + 'retry_of': 12, + 'diagnostic': 'Traceback: boom', + 'completed_steps': 2, 'input': {'prompt': 'ship it'}, + 'output': {'result': 'ok'}, 'steps': [ - { - 'stage': 'build', - 'sequence': 1, - 'status': 'completed', - 'outcome': 'success', - 'provider': 'openai', - 'model': 'gpt-luna', - 'target': 'review', - }, - { - 'stage': 'review', - 'sequence': 2, - 'status': 'completed', - 'outcome': 'success', - 'provider': 'anthropic', - 'model': 'claude-x', - 'target': '#success', - 'verdict': { - 'option': 'approve', - 'reason': 'Looks good.', - }, - }, + {'stage': 'build', 'sequence': 1, 'status': 'completed'}, + {'stage': 'review', 'sequence': 2, 'status': 'completed'}, ], 'usage': { 'stages': 1, @@ -53,42 +41,88 @@ JsonMap recordedRunFixture() => { }, }; -/// A run that recorded none of the summary facts and reported no usage. +/// A run that recorded no summary fact and no input or output. JsonMap absentRunFixture() => { 'id': 51, 'title': 'Sparse run', - 'name': 'release', 'status': 'succeeded', 'current_stage': ' ', + 'workspace': '', + 'content_hash': ' ', 'created_at': '', 'finished_at': '', - 'input': {'prompt': 'ship it'}, - 'steps': [ - { - 'stage': 'build', - 'sequence': 1, - 'status': 'completed', - 'provider': ' ', - 'model': '', - 'target': ' ', - 'verdict': null, - }, - ], + 'diagnostic': ' ', + 'steps': [], }; -const summaryFacts = [ +const recordedLabels = [ + 'Pipeline', 'Stage', + 'Workspace', + 'Content hash', 'Started', 'Finished', 'Duration', - 'Provider/model', - 'Target', - 'Verdict', + 'Retry of', + 'Diagnostic', ]; void main() { + test('recorded facts become the web summary rows in order', () { + final rows = detailSummaryRows(recordedRunFixture()); + + expect(rows.map((row) => row.label), recordedLabels); + expect(rows.first.value, 'id 3 · v2'); + expect(rows.firstWhere((row) => row.label == 'Stage').value, 'review'); + expect( + rows.firstWhere((row) => row.label == 'Workspace').value, + '/srv/workspaces/run-51', + ); + final hash = rows.firstWhere((row) => row.label == 'Content hash'); + expect(hash.value, 'abc123def456'); + expect(hash.monospace, isTrue); + expect( + rows.firstWhere((row) => row.label == 'Started').value, + formatLocalTimestamp('2026-10-19T09:30:00Z'), + ); + expect( + rows.firstWhere((row) => row.label == 'Finished').value, + formatLocalTimestamp('2026-10-19T09:32:05Z'), + ); + expect(rows.firstWhere((row) => row.label == 'Duration').value, '2m 5s'); + expect(rows.firstWhere((row) => row.label == 'Retry of').value, 'run 12'); + final diagnostic = rows.firstWhere((row) => row.label == 'Diagnostic'); + expect(diagnostic.value, 'Traceback: boom'); + expect(diagnostic.block, isTrue); + }); + + test('a blank fact is omitted, never an Unavailable row', () { + final rows = detailSummaryRows(absentRunFixture()); + + expect(rows, isEmpty); + expect(rows.any((row) => row.value == 'Unavailable'), isFalse); + }); + + test('an absent pipeline id falls back to the recorded name', () { + final rows = detailSummaryRows(absentRunFixture()..['name'] = 'release'); + + expect(rows.single.label, 'Pipeline'); + expect(rows.single.value, 'release'); + }); + + test('identity uses the recorded and completed visit wording', () { + expect( + detailSummaryIdentity(recordedRunFixture()), + 'run 51 · 2 recorded visits · 2 completed visits', + ); + expect( + detailSummaryIdentity(absentRunFixture()), + 'run 51 · 0 recorded visits · 0 completed visits', + ); + }); + for (final platform in RunDetailTestPlatform.values) { - testWidgets('${platform.name} summary renders each recorded field', ( + testWidgets('${platform.name} summary renders the recorded rows only', ( tester, ) async { await pumpRunDetail( @@ -98,32 +132,41 @@ void main() { size: const Size(900, 1600), ); - for (final label in summaryFacts) { + for (final label in recordedLabels) { expect(find.text(label), findsOneWidget, reason: label); } + expect(find.text('id 3 · v2'), findsOneWidget); expect(find.text('review'), findsOneWidget); + expect(find.text('/srv/workspaces/run-51'), findsOneWidget); + expect(find.text('abc123def456'), findsOneWidget); final started = formatLocalTimestamp('2026-10-19T09:30:00Z'); final finished = formatLocalTimestamp('2026-10-19T09:32:05Z'); expect(find.text(started!), findsOneWidget); expect(find.text(finished!), findsOneWidget); expect(find.text('2m 5s'), findsOneWidget); - expect(find.text('anthropic / claude-x'), findsOneWidget); - expect(find.text('#success'), findsOneWidget); - expect(find.text('approve\nLooks good.'), findsOneWidget); + expect(find.text('run 12'), findsOneWidget); + expect(find.text('Traceback: boom'), findsOneWidget); - // Tokens and cost keep their existing Summary home and exact values. - await tester.ensureVisible(find.text('Metrics')); - await tester.tap(find.text('Metrics')); - await tester.pumpAndSettle(); - expect(find.text('123'), findsOneWidget); - expect(find.text('100'), findsOneWidget); - expect(find.text('23'), findsOneWidget); - expect(find.text('\$0.500000'), findsOneWidget); + // The web run detail has no usage block, so no metrics tile is drawn. + expect(find.text('Metrics'), findsNothing); + expect(find.text('Unavailable'), findsNothing); + expect(find.text('Original prompt'), findsOneWidget); + + if (platform == RunDetailTestPlatform.material) { + final hash = tester.widget( + find.widgetWithText(SelectableText, 'abc123def456'), + ); + expect(hash.style?.fontFamily, 'monospace'); + } else { + final tile = tester.widget( + find.byKey(const ValueKey('run-detail-summary-content-hash')), + ); + expect((tile.subtitle! as Text).style?.fontFamily, 'monospace'); + } }); - testWidgets('${platform.name} summary states absent facts as unknown', ( - tester, - ) async { + testWidgets('${platform.name} summary sections state their exact empty ' + 'wording', (tester) async { await pumpRunDetail( tester, platform, @@ -131,50 +174,39 @@ void main() { size: const Size(900, 1600), ); - for (final label in summaryFacts) { - expect(find.text(label), findsOneWidget, reason: label); + for (final label in recordedLabels) { + expect(find.text(label), findsNothing, reason: label); } - expect( - find.text(summaryUnknownValue), - findsNWidgets(summaryFacts.length), - ); - expect(find.text('0'), findsNothing); - expect(find.text('false'), findsNothing); + expect(find.text('Unavailable'), findsNothing); + expect(find.text('Metrics'), findsNothing); - await tester.ensureVisible(find.text('Metrics')); - await tester.tap(find.text('Metrics')); + await tester.ensureVisible(find.text('Input')); await tester.pumpAndSettle(); - expect(find.text('No reported usage.'), findsOneWidget); - expect(find.text('0'), findsNothing); + await tester.tap(find.text('Input')); + await tester.pumpAndSettle(); + expect(find.text('No input recorded.'), findsOneWidget); + + await tester.ensureVisible(find.text('Output')); + await tester.pumpAndSettle(); + await tester.tap(find.text('Output')); + await tester.pumpAndSettle(); + expect(find.text('No output recorded.'), findsOneWidget); + }); + + testWidgets('${platform.name} summary input section shows the recorded ' + 'field', (tester) async { + await pumpRunDetail( + tester, + platform, + run: recordedRunFixture(), + size: const Size(900, 1600), + ); + + await tester.ensureVisible(find.text('Input')); + await tester.pumpAndSettle(); + await tester.tap(find.text('Input')); + await tester.pumpAndSettle(); + expect(find.textContaining('"prompt": "ship it"'), findsOneWidget); }); } - - test('visit facts come from the current stage latest visit', () { - final run = recordedRunFixture()..['current_stage'] = 'build'; - final fields = detailSummaryFields(run); - String value(String label) => - fields.firstWhere((field) => field.label == label).value; - expect(value('Provider/model'), 'openai / gpt-luna'); - expect(value('Target'), 'review'); - expect(value('Verdict'), 'Unavailable'); - }); - - test('a current stage without a visit records no visit facts', () { - final run = recordedRunFixture()..['current_stage'] = 'audit'; - final fields = detailSummaryFields(run); - for (final label in ['Provider/model', 'Target', 'Verdict']) { - expect( - fields.firstWhere((field) => field.label == label).value, - 'Unavailable', - reason: label, - ); - } - }); - - test('unknown wording is the web usage word and never zero', () { - expect(summaryUnknownValue, 'Unavailable'); - final fields = detailSummaryFields(absentRunFixture()); - expect(fields.map((field) => field.label), summaryFacts); - expect(fields.every((field) => field.value == 'Unavailable'), isTrue); - }); } diff --git a/app/test/features/runs/ui/run_detail_tabs_test.dart b/app/test/features/runs/ui/run_detail_tabs_test.dart index 78aa1adf..01d6db25 100644 --- a/app/test/features/runs/ui/run_detail_tabs_test.dart +++ b/app/test/features/runs/ui/run_detail_tabs_test.dart @@ -3,6 +3,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/graph/widgets/run_graph_view.dart'; import 'package:pipelines_app/features/runs/actions/title_wording.dart'; import 'package:pipelines_app/features/runs/ui/run_detail_tab.dart'; +import 'package:pipelines_app/features/runs/ui/run_detail_tab_strip.dart'; import 'run_detail_graph_support.dart'; @@ -13,11 +14,24 @@ void main() { ) async { await pumpRunDetail(tester, platform); - for (final label in ['Summary', 'Graph', 'Input', 'Output', 'Timeline']) { + expect(renderedRunDetailTabs, [ + RunDetailTab.summary, + RunDetailTab.graph, + RunDetailTab.timeline, + ]); + for (final label in ['Summary', 'Graph', 'Timeline']) { expect(find.text(label), findsOneWidget); } + // Input and Output are Summary sections now, never separate tabs. + final strip = find.byKey(const Key('run-detail-tabs')); + for (final label in ['Input', 'Output']) { + expect( + find.descendant(of: strip, matching: find.text(label)), + findsNothing, + ); + } var previous = double.negativeInfinity; - for (final tab in RunDetailTab.values) { + for (final tab in renderedRunDetailTabs) { final center = tester.getCenter(runDetailTab(tab)); expect(center.dx, greaterThan(previous)); previous = center.dx; @@ -26,8 +40,6 @@ void main() { for (final tab in [ RunDetailTab.graph, - RunDetailTab.input, - RunDetailTab.output, RunDetailTab.timeline, RunDetailTab.summary, ]) { diff --git a/app/test/features/runs/ui/run_detail_widget_test.dart b/app/test/features/runs/ui/run_detail_widget_test.dart index c000c592..337fa3c9 100644 --- a/app/test/features/runs/ui/run_detail_widget_test.dart +++ b/app/test/features/runs/ui/run_detail_widget_test.dart @@ -31,7 +31,7 @@ class FakeGateway implements ApiGateway { const prompt = ' keep\n\nspacing '; -JsonMap runFixture({JsonMap? usage, int steps = 2}) { +JsonMap runFixture({int steps = 2}) { final run = { 'id': 7, 'title': 'Nightly build', @@ -58,20 +58,9 @@ JsonMap runFixture({JsonMap? usage, int steps = 2}) { }, ], }; - if (usage != null) run['usage'] = usage; return run; } -JsonMap usageFixture({int known = 1}) => { - 'stages': 1, - 'tokens_total': 0, - 'tokens_known_stages': known, - 'tokens_in': 0, - 'tokens_out': 0, - 'split_known': true, - 'cost_known_stages': known, -}; - Future pumpDetail( WidgetTester tester, AppPlatform platform, @@ -160,11 +149,14 @@ void main() { expect(find.textContaining('Original prompt'), findsOneWidget); if (platform == AppPlatform.material) { expect(find.byType(Chip), findsOneWidget); - expect(find.byType(ExpansionTile), findsOneWidget); + expect( + tester.widget(find.byKey(const ValueKey('run-detail-summary-input'))), + isA(), + ); } else { expect(find.byType(Material), findsNothing); expect(find.byType(Chip), findsNothing); - expect(find.byType(CupertinoExpansionTile), findsOneWidget); + expect(find.byType(CupertinoExpansionTile), findsWidgets); } Future tapTab(String label) async { @@ -174,10 +166,25 @@ void main() { await tester.pumpAndSettle(); } - await tapTab('Input'); + Future openSummarySection(String label) async { + final summaryScroll = find.descendant( + of: find.byKey(const Key('run-detail-tab-body-summary')), + matching: find.byType(Scrollable), + ); + await tester.scrollUntilVisible( + find.text(label), + 200, + scrollable: summaryScroll.first, + ); + await tester.pumpAndSettle(); + await tester.tap(find.text(label)); + await tester.pumpAndSettle(); + } + + await openSummarySection('Input'); expect(find.textContaining('"alpha": 1'), findsOneWidget); - await tapTab('Output'); + await openSummarySection('Output'); expect(find.textContaining('"ok": true'), findsOneWidget); await tapTab('Timeline'); @@ -275,21 +282,4 @@ void main() { expect(find.text('Could not copy prompt to clipboard.'), findsOneWidget); }); } - - testWidgets('reported zero and missing usage stay distinct', (tester) async { - gateway.detail = runFixture(usage: usageFixture()); - await controller.select(1); - await pumpDetail(tester, AppPlatform.material, controller, gateway); - await tester.tap(find.text('Metrics')); - await tester.pumpAndSettle(); - expect(find.text('Unavailable'), findsNothing); - expect(find.text('0'), findsNWidgets(3)); - expect(find.text('\$0.000000'), findsOneWidget); - - gateway.detail = runFixture(usage: usageFixture(known: 0)); - await controller.select(1); - await tester.pumpAndSettle(); - expect(find.text('Unavailable'), findsNWidgets(4)); - expect(find.text('0'), findsNothing); - }); }