Runs list carries per-run token usage; app shows tokens beside size, Most tokens sort, Summary and stage tokens
This commit is contained in:
@@ -24,6 +24,7 @@ JsonMap recordedRunFixture() => <String, dynamic>{
|
||||
'retry_of': 12,
|
||||
'diagnostic': 'Traceback: boom',
|
||||
'completed_steps': 2,
|
||||
'size_bytes': 5 * 1024 * 1024,
|
||||
'input': <String, dynamic>{'prompt': 'ship it'},
|
||||
'output': <String, dynamic>{'result': 'ok'},
|
||||
'steps': <dynamic>[
|
||||
@@ -64,6 +65,9 @@ const recordedLabels = [
|
||||
'Started',
|
||||
'Finished',
|
||||
'Duration',
|
||||
'Size on disk',
|
||||
'Tokens',
|
||||
'Cost',
|
||||
'Retry of',
|
||||
'Diagnostic',
|
||||
];
|
||||
@@ -91,6 +95,12 @@ void main() {
|
||||
formatLocalTimestamp('2026-10-19T09:32:05Z'),
|
||||
);
|
||||
expect(rows.firstWhere((row) => row.label == 'Duration').value, '2m 5s');
|
||||
expect(rows.firstWhere((row) => row.label == 'Size on disk').value, '5 MB');
|
||||
expect(
|
||||
rows.firstWhere((row) => row.label == 'Tokens').value,
|
||||
'123 (100 in, 23 out)',
|
||||
);
|
||||
expect(rows.firstWhere((row) => row.label == 'Cost').value, '\$0.50');
|
||||
expect(rows.firstWhere((row) => row.label == 'Retry of').value, 'run 12');
|
||||
final diagnostic = rows.firstWhere((row) => row.label == 'Diagnostic');
|
||||
expect(diagnostic.value, 'Traceback: boom');
|
||||
|
||||
@@ -86,6 +86,48 @@ void main() {
|
||||
expect(find.text('Pipeline unavailable · 2m 5s · 3 steps'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('shows reported tokens beside the size, and nothing without', (
|
||||
tester,
|
||||
) async {
|
||||
Future<void> pump(JsonMap run) => tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: RunListRow(run: run, now: DateTime.utc(2026, 10, 22)),
|
||||
),
|
||||
),
|
||||
);
|
||||
final sized = {..._finished, 'size_bytes': 340 * 1024 * 1024};
|
||||
await pump({
|
||||
...sized,
|
||||
'usage': {
|
||||
'stages': 3,
|
||||
'tokens_known_stages': 3,
|
||||
'tokens_total': 22400015,
|
||||
},
|
||||
});
|
||||
expect(
|
||||
find.text('release · 2m 5s · 3 steps · 340 MB · 22.4M tokens'),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
await pump({
|
||||
...sized,
|
||||
'usage': {
|
||||
'stages': 3,
|
||||
'tokens_known_stages': 2,
|
||||
'tokens_total': 22400015,
|
||||
},
|
||||
});
|
||||
expect(
|
||||
find.text('release · 2m 5s · 3 steps · 340 MB · ≥22.4M tokens'),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
// An older server's list carries no usage: the row is unchanged.
|
||||
await pump(sized);
|
||||
expect(find.text('release · 2m 5s · 3 steps · 340 MB'), findsOneWidget);
|
||||
});
|
||||
|
||||
test('the run action sheet is titled with the run', () {
|
||||
expect(runMoreMenuTitle(_finished), 'Ship the release notes');
|
||||
expect(runMoreMenuTitle({'id': 5, 'name': 'nightly'}), 'nightly');
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_content.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_visit_facts.dart';
|
||||
|
||||
final _reported = <String, dynamic>{
|
||||
'stage': 'build',
|
||||
'sequence': 1,
|
||||
'status': 'completed',
|
||||
'outcome': 'success',
|
||||
'target': 'review',
|
||||
'usage': {
|
||||
'tokens_total': 1500000,
|
||||
'tokens_known': true,
|
||||
'split_known': true,
|
||||
'tokens_in': 1200000,
|
||||
'tokens_out': 300000,
|
||||
'cost_known': true,
|
||||
'cost_usd': 0.42,
|
||||
},
|
||||
};
|
||||
|
||||
final _unreported = <String, dynamic>{
|
||||
'stage': 'gate',
|
||||
'sequence': 2,
|
||||
'status': 'completed',
|
||||
};
|
||||
|
||||
void main() {
|
||||
test('a visit lists its reported tokens and cost as facts', () {
|
||||
final facts = detailVisitFacts(_reported);
|
||||
expect(
|
||||
facts,
|
||||
contains((label: 'Tokens', value: '1.5M (1.2M in, 300K out)')),
|
||||
);
|
||||
expect(facts, contains((label: 'Cost', value: '\$0.42')));
|
||||
final none = detailVisitFacts(_unreported);
|
||||
expect(none.any((fact) => fact.label == 'Tokens'), isFalse);
|
||||
expect(none.any((fact) => fact.label == 'Cost'), isFalse);
|
||||
});
|
||||
|
||||
test('a stage row carries its compact token total', () {
|
||||
final visits = detailTimeline([_reported, _unreported]);
|
||||
expect(visits[0].tokens, '1.5M tokens');
|
||||
expect(visits[1].tokens, isNull);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user