feat(app): show the run's recorded facts in its Summary

Stage, Started, Finished, Duration, Provider/model, Target and Verdict
come from the run reply and the current stage's latest recorded visit.
An absent fact reads Unavailable; tokens and cost keep their Metrics
home.
This commit is contained in:
2026-10-22 02:29:57 +01:00
parent 8cfc4443df
commit 3da570e647
3 changed files with 294 additions and 3 deletions
@@ -0,0 +1,89 @@
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.
///
/// 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';
/// 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 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<DetailMetric> 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<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
/// estimate and never a zero for an unfinished run.
String? _duration(JsonMap run) {
final seconds = durationSeconds(
_text(run['created_at']),
_text(run['finished_at']),
);
return seconds == null ? null : formatDuration(seconds);
}
/// 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<String>();
return parts.isEmpty ? null : parts.join('\n');
}
String? _text(dynamic value) {
if (value == null) return null;
final text = '$value'.trim();
return text.isEmpty ? null : text;
}
@@ -3,10 +3,11 @@ import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import 'run_detail_content.dart';
import 'run_detail_summary_fields.dart';
/// The Summary tab: the stored original prompt with its copy control and the
/// reported usage metrics. Neither the prompt nor a metric is replaced by a
/// fallback value.
/// 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.
Widget runDetailSummaryTab({
required BuildContext context,
required JsonMap run,
@@ -16,6 +17,7 @@ Widget runDetailSummaryTab({
required VoidCallback onCopy,
}) {
final prompt = detailPrompt(run);
final facts = detailSummaryFields(run);
final metrics = detailUsageMetrics(run['usage']);
if (cupertino) {
final theme = CupertinoTheme.of(context);
@@ -55,6 +57,7 @@ Widget runDetailSummaryTab({
),
),
_cupertinoMetrics(metrics),
_cupertinoFacts(facts),
],
);
}
@@ -89,6 +92,7 @@ Widget runDetailSummaryTab({
const SizedBox(height: 12),
],
_materialMetrics(metrics),
_materialFacts(facts),
],
);
}
@@ -123,6 +127,24 @@ Widget runDetailFieldTab({
);
}
Widget _materialFacts(List<DetailMetric> facts) => Column(
children: [
for (final fact in facts)
ListTile(title: Text(fact.label), subtitle: Text(fact.value)),
],
);
Widget _cupertinoFacts(List<DetailMetric> facts) =>
CupertinoListSection.insetGrouped(
children: [
for (final fact in facts)
CupertinoListTile(
title: Text(fact.label),
subtitle: Text(fact.value),
),
],
);
Widget _materialMetrics(List<DetailMetric> metrics) => ExpansionTile(
title: const Text('Metrics'),
children: [
@@ -0,0 +1,180 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/pipelines/pipeline_format.dart';
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.
JsonMap recordedRunFixture() => <String, dynamic>{
'id': 51,
'title': 'Summary run',
'name': 'release',
'status': 'succeeded',
'current_stage': 'review',
'created_at': '2026-10-19T09:30:00Z',
'finished_at': '2026-10-19T09:32:05Z',
'input': <String, dynamic>{'prompt': 'ship it'},
'steps': <dynamic>[
<String, dynamic>{
'stage': 'build',
'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>{
'stages': 1,
'tokens_total': 123,
'tokens_known_stages': 1,
'tokens_in': 100,
'tokens_out': 23,
'split_known': true,
'cost_known_stages': 1,
'cost_usd': 0.5,
},
};
/// A run that recorded none of the summary facts and reported no usage.
JsonMap absentRunFixture() => <String, dynamic>{
'id': 51,
'title': 'Sparse run',
'name': 'release',
'status': 'succeeded',
'current_stage': ' ',
'created_at': '',
'finished_at': '',
'input': <String, dynamic>{'prompt': 'ship it'},
'steps': <dynamic>[
<String, dynamic>{
'stage': 'build',
'sequence': 1,
'status': 'completed',
'provider': ' ',
'model': '',
'target': ' ',
'verdict': null,
},
],
};
const summaryFacts = [
'Stage',
'Started',
'Finished',
'Duration',
'Provider/model',
'Target',
'Verdict',
];
void main() {
for (final platform in RunDetailTestPlatform.values) {
testWidgets('${platform.name} summary renders each recorded field', (
tester,
) async {
await pumpRunDetail(
tester,
platform,
run: recordedRunFixture(),
size: const Size(900, 1600),
);
for (final label in summaryFacts) {
expect(find.text(label), findsOneWidget, reason: label);
}
expect(find.text('review'), 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);
// 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);
});
testWidgets('${platform.name} summary states absent facts as unknown', (
tester,
) async {
await pumpRunDetail(
tester,
platform,
run: absentRunFixture(),
size: const Size(900, 1600),
);
for (final label in summaryFacts) {
expect(find.text(label), findsOneWidget, reason: label);
}
expect(
find.text(summaryUnknownValue),
findsNWidgets(summaryFacts.length),
);
expect(find.text('0'), findsNothing);
expect(find.text('false'), findsNothing);
await tester.ensureVisible(find.text('Metrics'));
await tester.tap(find.text('Metrics'));
await tester.pumpAndSettle();
expect(find.text('No reported usage.'), findsOneWidget);
expect(find.text('0'), findsNothing);
});
}
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);
});
}