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,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);
});
}