feat(app): match the web run detail tabs and summary shape

This commit is contained in:
2026-10-22 14:13:38 +01:00
parent dc0a52380b
commit be6b6239fc
7 changed files with 561 additions and 326 deletions
@@ -1,85 +1,85 @@
import '../../../core/api_gateway.dart'; import '../../../core/api_gateway.dart';
import '../../pipelines/pipeline_format.dart'; import '../../pipelines/pipeline_format.dart';
import 'run_detail_content.dart';
import 'run_detail_visit_facts.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 /// [monospace] marks a value the web renders as a code identifier (the content
/// value, so one absent fact never reads as `0`, `false` or an empty field. /// hash); [block] marks a multi-line recorded document (the diagnostic) that is
const String summaryUnknownValue = 'Unavailable'; /// 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 /// The run Summary's rows, in the web summary's order: Pipeline, Stage,
/// stage and the run's timing, then the latest recorded visit's effective /// Workspace, Content hash, Started, Finished, Duration, Retry of and the
/// provider/model, target and verdict. /// Diagnostic block.
/// ///
/// The latest visit is the one the Graph tab opens for the current stage, so /// Only values the server actually recorded are rows: a blank field is omitted
/// the Summary and the recorded-visit pane describe the same evidence. Tokens /// rather than drawn as an empty or invented placeholder, exactly as
/// and cost stay in [detailUsageMetrics], their existing Summary home. A fact /// `summaryRows` in the web client does. A run with no pipeline id shows its
/// the server did not record reads [summaryUnknownValue]. /// recorded pipeline name, and shows no Pipeline row at all when it recorded
List<DetailMetric> detailSummaryFields(JsonMap run) { /// neither.
final steps = detailRunSteps(run); List<DetailSummaryRow> detailSummaryRows(JsonMap run) {
final stage = _text(run['current_stage']); final rows = <DetailSummaryRow>[];
final latest = _latestVisit(steps, stage); void add(
return [ String label,
(label: 'Stage', value: stage ?? summaryUnknownValue), String? value, {
( bool monospace = false,
label: 'Started', bool block = false,
value: }) {
formatLocalTimestamp(_text(run['created_at'])) ?? summaryUnknownValue, final text = value?.trim() ?? '';
), if (text.isEmpty) return;
( rows.add((label: label, value: text, monospace: monospace, block: block));
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<JsonMap> steps, String? stage) {
JsonMap? latest;
for (final step in steps) {
if (stage == null || _text(step['stage']) == stage) latest = step;
} }
return latest;
}
/// The run's stored duration from its own start and finish, never a live final pipelineId = _number(run['pipeline_id'])?.toInt() ?? 0;
/// estimate and never a zero for an unfinished run. if (pipelineId > 0) {
String? _duration(JsonMap run) { 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( final seconds = durationSeconds(
_text(run['created_at']), _text(run['created_at']),
_text(run['finished_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 /// The run's identity line: `run {id} · {n} recorded visits · {m} completed
/// reason, one part when only one was recorded, nothing when neither was. /// visits`, the same recorded/completed vocabulary the web summary and the
String? _verdict(JsonMap? step) { /// server use.
if (step == null) return null; String detailSummaryIdentity(JsonMap run) {
final verdict = detailVisitVerdict(step); final recorded = detailRunSteps(run).length;
if (verdict == null) return null; final completedValue = _number(run['completed_steps'])?.toInt() ?? 0;
final parts = [verdict.option, verdict.reason].whereType<String>(); final completed = completedValue < 0 ? 0 : completedValue;
return parts.isEmpty ? null : parts.join('\n'); 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) { String? _text(dynamic value) {
@@ -87,3 +87,6 @@ String? _text(dynamic value) {
final text = '$value'.trim(); final text = '$value'.trim();
return text.isEmpty ? null : text; return text.isEmpty ? null : text;
} }
num? _number(dynamic value) =>
value is num ? value : num.tryParse('${value ?? ''}'.trim());
+2 -1
View File
@@ -2,7 +2,8 @@
/// second, then the recorded Input, Output and Timeline. /// second, then the recorded Input, Output and Timeline.
/// ///
/// The stable keys match the web client's `RUN_DETAIL_TABS`; the visible labels /// 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 { enum RunDetailTab {
summary('Summary'), summary('Summary'),
graph('Graph'), graph('Graph'),
@@ -4,10 +4,16 @@ import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart'; import '../../../core/api_gateway.dart';
import 'run_detail_content.dart'; import 'run_detail_content.dart';
import 'run_detail_summary_fields.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 /// The Summary tab: the run's identity, the recorded facts as key/value rows,
/// run's recorded facts and the reported usage metrics. Neither the prompt nor /// the stored original prompt with its copy control and the collapsible Input
/// a fact is replaced by a fallback value. /// 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({ Widget runDetailSummaryTab({
required BuildContext context, required BuildContext context,
required JsonMap run, required JsonMap run,
@@ -16,88 +22,93 @@ Widget runDetailSummaryTab({
required String? copyStatus, required String? copyStatus,
required VoidCallback onCopy, required VoidCallback onCopy,
}) { }) {
final rows = detailSummaryRows(run);
final identity = detailSummaryIdentity(run);
final prompt = detailPrompt(run); final prompt = detailPrompt(run);
final facts = detailSummaryFields(run);
final metrics = detailUsageMetrics(run['usage']);
if (cupertino) { if (cupertino) {
final theme = CupertinoTheme.of(context);
return ListView( return ListView(
key: const Key('run-detail-tab-body-summary'), key: const Key('run-detail-tab-body-summary'),
children: [ children: [
if (prompt != null) _cupertinoIdentity(context, identity),
Padding( if (rows.any((row) => !row.block))
padding: const EdgeInsetsDirectional.fromSTEB(16, 16, 16, 0), CupertinoListSection.insetGrouped(
child: Column( children: [
crossAxisAlignment: CrossAxisAlignment.start, for (final row in rows.where((row) => !row.block))
children: [ _cupertinoRow(context, row),
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)),
),
],
),
), ),
_cupertinoMetrics(metrics), for (final row in rows.where((row) => row.block))
_cupertinoFacts(facts), 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); final theme = Theme.of(context);
return ListView( return ListView(
key: const Key('run-detail-tab-body-summary'), key: const Key('run-detail-tab-body-summary'),
padding: const EdgeInsets.all(16), padding: const EdgeInsets.only(bottom: 16),
children: [ children: [
if (prompt != null) ...[ Padding(
Row( padding: const EdgeInsets.fromLTRB(16, 12, 16, 0),
crossAxisAlignment: CrossAxisAlignment.start, child: Text(
children: [ identity,
Expanded( style: theme.textTheme.bodySmall?.copyWith(
child: Text( color: theme.colorScheme.onSurfaceVariant,
'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)),
), ),
const SizedBox(height: 12), ),
], ),
_materialMetrics(metrics), for (final row in rows)
_materialFacts(facts), 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({ Widget runDetailFieldTab({
required String tabKey, required String tabKey,
required dynamic value, required dynamic value,
@@ -127,64 +138,241 @@ Widget runDetailFieldTab({
); );
} }
Widget _materialFacts(List<DetailMetric> facts) => Column( // --- Material --------------------------------------------------------------
children: [
for (final fact in facts)
ListTile(title: Text(fact.label), subtitle: Text(fact.value)),
],
);
Widget _cupertinoFacts(List<DetailMetric> facts) => Widget _materialRow(BuildContext context, DetailSummaryRow row) {
CupertinoListSection.insetGrouped( final theme = Theme.of(context);
children: [ final base = theme.textTheme.bodyMedium;
for (final fact in facts) return ListTile(
CupertinoListTile( key: ValueKey('run-detail-summary-${_slug(row.label)}'),
title: Text(fact.label), title: Text(
subtitle: Text(fact.value), row.label,
), style: theme.textTheme.bodySmall?.copyWith(
], color: theme.colorScheme.onSurfaceVariant,
);
Widget _materialMetrics(List<DetailMetric> 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)),
), ),
], ),
); subtitle: SelectableText(
row.value,
style: row.monospace ? base?.copyWith(fontFamily: 'monospace') : base,
),
);
}
Widget _cupertinoMetrics(List<DetailMetric> metrics) => Widget _materialBlock(BuildContext context, DetailSummaryRow row) {
CupertinoListSection.insetGrouped( 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: [ children: [
CupertinoExpansionTile( Text(
title: const Text('Metrics'), row.label,
child: Padding( style: theme.textTheme.bodySmall?.copyWith(
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 16), color: theme.colorScheme.onSurfaceVariant,
child: Column( ),
crossAxisAlignment: CrossAxisAlignment.stretch, ),
children: [ const SizedBox(height: 4),
if (metrics.isEmpty) Container(
const Text('No reported usage.') width: double.infinity,
else padding: const EdgeInsets.all(12),
for (final metric in metrics) decoration: BoxDecoration(
CupertinoListTile( color: theme.colorScheme.surfaceContainerHighest,
title: Text(metric.label), borderRadius: BorderRadius.circular(8),
subtitle: Text(metric.value), ),
), 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 /// A read-only Cupertino text control: plain, selectable text without a
/// Material dependency, while keeping native selection and copy affordances. /// Material dependency, while keeping native selection and copy affordances.
@@ -5,9 +5,18 @@ import 'package:flutter/material.dart';
import '../../../ui/adaptive/host.dart'; import '../../../ui/adaptive/host.dart';
import 'run_detail_tab.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<RunDetailTab> renderedRunDetailTabs = [
RunDetailTab.summary,
RunDetailTab.graph,
RunDetailTab.timeline,
];
/// The run detail's platform tab strip: a Material segmented button or a /// The run detail's platform tab strip: a Material segmented button or a
/// Cupertino segmented control, in the web's Summary/Graph/Input/Output/ /// Cupertino segmented control, in the web's Summary/Graph/Timeline order.
/// Timeline order.
/// ///
/// The native control keeps every label at its intrinsic width: a narrow pane /// The native control keeps every label at its intrinsic width: a narrow pane
/// or scaled text scrolls the strip horizontally instead of squeezing or /// or scaled text scrolls the strip horizontally instead of squeezing or
@@ -29,7 +38,7 @@ class RunDetailTabStrip extends StatefulWidget {
class _RunDetailTabStripState extends State<RunDetailTabStrip> { class _RunDetailTabStripState extends State<RunDetailTabStrip> {
final Map<RunDetailTab, GlobalKey> _labels = { final Map<RunDetailTab, GlobalKey> _labels = {
for (final tab in RunDetailTab.values) tab: GlobalKey(), for (final tab in renderedRunDetailTabs) tab: GlobalKey(),
}; };
@override @override
@@ -66,7 +75,7 @@ class _RunDetailTabStripState extends State<RunDetailTabStrip> {
Widget _materialControl() => SegmentedButton<RunDetailTab>( Widget _materialControl() => SegmentedButton<RunDetailTab>(
segments: [ segments: [
for (final tab in RunDetailTab.values) for (final tab in renderedRunDetailTabs)
ButtonSegment(value: tab, label: _label(tab)), ButtonSegment(value: tab, label: _label(tab)),
], ],
selected: {widget.selected}, selected: {widget.selected},
@@ -78,7 +87,7 @@ class _RunDetailTabStripState extends State<RunDetailTabStrip> {
groupValue: widget.selected, groupValue: widget.selected,
onValueChanged: widget.onSelected, onValueChanged: widget.onSelected,
children: { children: {
for (final tab in RunDetailTab.values) for (final tab in renderedRunDetailTabs)
tab: Padding( tab: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8), padding: const EdgeInsets.symmetric(horizontal: 8),
child: _label(tab), child: _label(tab),
@@ -7,39 +7,27 @@ import 'package:pipelines_app/features/runs/ui/run_detail_summary_fields.dart';
import 'run_detail_graph_support.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() => <String, dynamic>{ JsonMap recordedRunFixture() => <String, dynamic>{
'id': 51, 'id': 51,
'title': 'Summary run', 'title': 'Summary run',
'name': 'release', 'name': 'release',
'pipeline_id': 3,
'version': 2,
'status': 'succeeded', 'status': 'succeeded',
'current_stage': 'review', 'current_stage': 'review',
'workspace': '/srv/workspaces/run-51',
'content_hash': 'abc123def456',
'created_at': '2026-10-19T09:30:00Z', 'created_at': '2026-10-19T09:30:00Z',
'finished_at': '2026-10-19T09:32:05Z', 'finished_at': '2026-10-19T09:32:05Z',
'retry_of': 12,
'diagnostic': 'Traceback: boom',
'completed_steps': 2,
'input': <String, dynamic>{'prompt': 'ship it'}, 'input': <String, dynamic>{'prompt': 'ship it'},
'output': <String, dynamic>{'result': 'ok'},
'steps': <dynamic>[ 'steps': <dynamic>[
<String, dynamic>{ <String, dynamic>{'stage': 'build', 'sequence': 1, 'status': 'completed'},
'stage': 'build', <String, dynamic>{'stage': 'review', 'sequence': 2, 'status': 'completed'},
'sequence': 1,
'status': 'completed',
'outcome': 'success',
'provider': 'openai',
'model': 'gpt-luna',
'target': 'review',
},
<String, dynamic>{
'stage': 'review',
'sequence': 2,
'status': 'completed',
'outcome': 'success',
'provider': 'anthropic',
'model': 'claude-x',
'target': '#success',
'verdict': <String, dynamic>{
'option': 'approve',
'reason': 'Looks good.',
},
},
], ],
'usage': <String, dynamic>{ 'usage': <String, dynamic>{
'stages': 1, 'stages': 1,
@@ -53,42 +41,88 @@ JsonMap recordedRunFixture() => <String, dynamic>{
}, },
}; };
/// 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() => <String, dynamic>{ JsonMap absentRunFixture() => <String, dynamic>{
'id': 51, 'id': 51,
'title': 'Sparse run', 'title': 'Sparse run',
'name': 'release',
'status': 'succeeded', 'status': 'succeeded',
'current_stage': ' ', 'current_stage': ' ',
'workspace': '',
'content_hash': ' ',
'created_at': '', 'created_at': '',
'finished_at': '', 'finished_at': '',
'input': <String, dynamic>{'prompt': 'ship it'}, 'diagnostic': ' ',
'steps': <dynamic>[ 'steps': <dynamic>[],
<String, dynamic>{
'stage': 'build',
'sequence': 1,
'status': 'completed',
'provider': ' ',
'model': '',
'target': ' ',
'verdict': null,
},
],
}; };
const summaryFacts = [ const recordedLabels = [
'Pipeline',
'Stage', 'Stage',
'Workspace',
'Content hash',
'Started', 'Started',
'Finished', 'Finished',
'Duration', 'Duration',
'Provider/model', 'Retry of',
'Target', 'Diagnostic',
'Verdict',
]; ];
void main() { 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) { for (final platform in RunDetailTestPlatform.values) {
testWidgets('${platform.name} summary renders each recorded field', ( testWidgets('${platform.name} summary renders the recorded rows only', (
tester, tester,
) async { ) async {
await pumpRunDetail( await pumpRunDetail(
@@ -98,32 +132,41 @@ void main() {
size: const Size(900, 1600), 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(label), findsOneWidget, reason: label);
} }
expect(find.text('id 3 · v2'), findsOneWidget);
expect(find.text('review'), 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 started = formatLocalTimestamp('2026-10-19T09:30:00Z');
final finished = formatLocalTimestamp('2026-10-19T09:32:05Z'); final finished = formatLocalTimestamp('2026-10-19T09:32:05Z');
expect(find.text(started!), findsOneWidget); expect(find.text(started!), findsOneWidget);
expect(find.text(finished!), findsOneWidget); expect(find.text(finished!), findsOneWidget);
expect(find.text('2m 5s'), findsOneWidget); expect(find.text('2m 5s'), findsOneWidget);
expect(find.text('anthropic / claude-x'), findsOneWidget); expect(find.text('run 12'), findsOneWidget);
expect(find.text('#success'), findsOneWidget); expect(find.text('Traceback: boom'), findsOneWidget);
expect(find.text('approve\nLooks good.'), findsOneWidget);
// Tokens and cost keep their existing Summary home and exact values. // The web run detail has no usage block, so no metrics tile is drawn.
await tester.ensureVisible(find.text('Metrics')); expect(find.text('Metrics'), findsNothing);
await tester.tap(find.text('Metrics')); expect(find.text('Unavailable'), findsNothing);
await tester.pumpAndSettle(); expect(find.text('Original prompt'), findsOneWidget);
expect(find.text('123'), findsOneWidget);
expect(find.text('100'), findsOneWidget); if (platform == RunDetailTestPlatform.material) {
expect(find.text('23'), findsOneWidget); final hash = tester.widget<SelectableText>(
expect(find.text('\$0.500000'), findsOneWidget); find.widgetWithText(SelectableText, 'abc123def456'),
);
expect(hash.style?.fontFamily, 'monospace');
} else {
final tile = tester.widget<CupertinoListTile>(
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', ( testWidgets('${platform.name} summary sections state their exact empty '
tester, 'wording', (tester) async {
) async {
await pumpRunDetail( await pumpRunDetail(
tester, tester,
platform, platform,
@@ -131,50 +174,39 @@ void main() {
size: const Size(900, 1600), 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(label), findsNothing, reason: label);
} }
expect( expect(find.text('Unavailable'), findsNothing);
find.text(summaryUnknownValue), expect(find.text('Metrics'), findsNothing);
findsNWidgets(summaryFacts.length),
);
expect(find.text('0'), findsNothing);
expect(find.text('false'), findsNothing);
await tester.ensureVisible(find.text('Metrics')); await tester.ensureVisible(find.text('Input'));
await tester.tap(find.text('Metrics'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('No reported usage.'), findsOneWidget); await tester.tap(find.text('Input'));
expect(find.text('0'), findsNothing); 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);
});
} }
@@ -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/graph/widgets/run_graph_view.dart';
import 'package:pipelines_app/features/runs/actions/title_wording.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.dart';
import 'package:pipelines_app/features/runs/ui/run_detail_tab_strip.dart';
import 'run_detail_graph_support.dart'; import 'run_detail_graph_support.dart';
@@ -13,11 +14,24 @@ void main() {
) async { ) async {
await pumpRunDetail(tester, platform); 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); 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; var previous = double.negativeInfinity;
for (final tab in RunDetailTab.values) { for (final tab in renderedRunDetailTabs) {
final center = tester.getCenter(runDetailTab(tab)); final center = tester.getCenter(runDetailTab(tab));
expect(center.dx, greaterThan(previous)); expect(center.dx, greaterThan(previous));
previous = center.dx; previous = center.dx;
@@ -26,8 +40,6 @@ void main() {
for (final tab in [ for (final tab in [
RunDetailTab.graph, RunDetailTab.graph,
RunDetailTab.input,
RunDetailTab.output,
RunDetailTab.timeline, RunDetailTab.timeline,
RunDetailTab.summary, RunDetailTab.summary,
]) { ]) {
@@ -31,7 +31,7 @@ class FakeGateway implements ApiGateway {
const prompt = ' keep\n\nspacing '; const prompt = ' keep\n\nspacing ';
JsonMap runFixture({JsonMap? usage, int steps = 2}) { JsonMap runFixture({int steps = 2}) {
final run = <String, dynamic>{ final run = <String, dynamic>{
'id': 7, 'id': 7,
'title': 'Nightly build', 'title': 'Nightly build',
@@ -58,20 +58,9 @@ JsonMap runFixture({JsonMap? usage, int steps = 2}) {
}, },
], ],
}; };
if (usage != null) run['usage'] = usage;
return run; 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<void> pumpDetail( Future<void> pumpDetail(
WidgetTester tester, WidgetTester tester,
AppPlatform platform, AppPlatform platform,
@@ -160,11 +149,14 @@ void main() {
expect(find.textContaining('Original prompt'), findsOneWidget); expect(find.textContaining('Original prompt'), findsOneWidget);
if (platform == AppPlatform.material) { if (platform == AppPlatform.material) {
expect(find.byType(Chip), findsOneWidget); expect(find.byType(Chip), findsOneWidget);
expect(find.byType(ExpansionTile), findsOneWidget); expect(
tester.widget(find.byKey(const ValueKey('run-detail-summary-input'))),
isA<ExpansionTile>(),
);
} else { } else {
expect(find.byType(Material), findsNothing); expect(find.byType(Material), findsNothing);
expect(find.byType(Chip), findsNothing); expect(find.byType(Chip), findsNothing);
expect(find.byType(CupertinoExpansionTile), findsOneWidget); expect(find.byType(CupertinoExpansionTile), findsWidgets);
} }
Future<void> tapTab(String label) async { Future<void> tapTab(String label) async {
@@ -174,10 +166,25 @@ void main() {
await tester.pumpAndSettle(); await tester.pumpAndSettle();
} }
await tapTab('Input'); Future<void> 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); expect(find.textContaining('"alpha": 1'), findsOneWidget);
await tapTab('Output'); await openSummarySection('Output');
expect(find.textContaining('"ok": true'), findsOneWidget); expect(find.textContaining('"ok": true'), findsOneWidget);
await tapTab('Timeline'); await tapTab('Timeline');
@@ -275,21 +282,4 @@ void main() {
expect(find.text('Could not copy prompt to clipboard.'), findsOneWidget); 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);
});
} }