Stage rows show cached share and cost; Changes explain no_patch_reason
Timeline stage rows add the cached share (when cache_known) and a positive cost: 20.1M tokens · 97% cached · $1.42. The file viewer words each server no_patch_reason, keeping the old truncated/binary text as the fallback.
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/changes/changes.dart';
|
||||
|
||||
import 'widget_hosts.dart';
|
||||
|
||||
const _legacy =
|
||||
"The server truncated this file's patch at its capture limit; no diff "
|
||||
'text was recorded.';
|
||||
|
||||
const _expected = {
|
||||
'file_size': 'This file is over 1 MiB, so no diff text was recorded.',
|
||||
'budget':
|
||||
'The workspace snapshot ran out of text budget, so no diff text was '
|
||||
'recorded.',
|
||||
'lines': 'The change is over 5,000 lines, so no diff text was recorded.',
|
||||
'evidence_size':
|
||||
"This visit's recorded changes reached their size limit, so this patch "
|
||||
'was dropped.',
|
||||
'git_status':
|
||||
"This change was seen only in Git status, so the file's contents weren't "
|
||||
'compared.',
|
||||
'baseline':
|
||||
"The file's content at stage start couldn't be recovered from Git, so no "
|
||||
'diff was recorded.',
|
||||
'binary': 'Binary file; only its metadata was recorded.',
|
||||
};
|
||||
|
||||
FileChange _noPatch(Object? reason, {bool binary = false}) =>
|
||||
FileChange.fromJson({
|
||||
'path': 'big.txt',
|
||||
'kind': 'modified',
|
||||
'truncated': true,
|
||||
'no_patch': true,
|
||||
'binary': binary,
|
||||
'no_patch_reason': ?reason,
|
||||
});
|
||||
|
||||
void main() {
|
||||
test('each recorded no-patch reason has its own message', () {
|
||||
for (final entry in _expected.entries) {
|
||||
final file = _noPatch(entry.key, binary: entry.key == 'binary');
|
||||
expect(file.noPatchReason, entry.key);
|
||||
expect(patchUnavailableReason(file), entry.value, reason: entry.key);
|
||||
}
|
||||
});
|
||||
|
||||
test('no reason, a blank one or an unknown one keeps the old wording', () {
|
||||
expect(patchUnavailableReason(_noPatch(null)), _legacy);
|
||||
expect(patchUnavailableReason(_noPatch('')), _legacy);
|
||||
expect(patchUnavailableReason(_noPatch('future_reason')), _legacy);
|
||||
expect(patchUnavailableReason(_noPatch(42)), _legacy);
|
||||
});
|
||||
|
||||
test('the reason survives aggregation across stages', () {
|
||||
final file = _noPatch('budget').withSteps(const ['build']);
|
||||
expect(file.noPatchReason, 'budget');
|
||||
});
|
||||
|
||||
testWidgets('the viewer shows the reason, binary included', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
materialHost(
|
||||
Column(
|
||||
children: [
|
||||
Expanded(child: FileDiffViewer(file: _noPatch('lines'))),
|
||||
Expanded(
|
||||
child: FileDiffViewer(file: _noPatch('binary', binary: true)),
|
||||
),
|
||||
Expanded(
|
||||
child: FileDiffViewer(
|
||||
file: FileChange(
|
||||
path: 'logo.bin',
|
||||
kind: ChangeKind.modified,
|
||||
binary: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(find.text(_expected['lines']!), findsOneWidget);
|
||||
expect(find.text(_expected['binary']!), findsOneWidget);
|
||||
expect(find.text(binaryDiffMessage), findsOneWidget);
|
||||
expect(find.text(_legacy), findsNothing);
|
||||
});
|
||||
}
|
||||
@@ -40,7 +40,52 @@ void main() {
|
||||
|
||||
test('a stage row carries its compact token total', () {
|
||||
final visits = detailTimeline([_reported, _unreported]);
|
||||
expect(visits[0].tokens, '1.5M tokens');
|
||||
expect(visits[0].tokens, '1.5M tokens · \$0.42');
|
||||
expect(visits[1].tokens, isNull);
|
||||
});
|
||||
|
||||
String? rowLabel(Map<String, dynamic> usage) => detailTimeline([
|
||||
{..._unreported, 'usage': usage},
|
||||
])[0].tokens;
|
||||
|
||||
test('a stage row adds its cached share and cost when reported', () {
|
||||
const base = {'tokens_known': true, 'tokens_total': 20100000};
|
||||
expect(
|
||||
rowLabel({
|
||||
...base,
|
||||
'cache_known': true,
|
||||
'cache_read': 19100000,
|
||||
'cost_known': true,
|
||||
'cost_usd': 0.4249,
|
||||
}),
|
||||
'20.1M tokens · 95% cached · \$0.42',
|
||||
);
|
||||
// A known split with no reads is a real 0%, not an absence.
|
||||
expect(
|
||||
rowLabel({...base, 'cache_known': true}),
|
||||
'20.1M tokens · 0% cached',
|
||||
);
|
||||
// An older row without cache_known, or a cache read alone, shows no share.
|
||||
expect(rowLabel({...base, 'cache_read': 19100000}), '20.1M tokens');
|
||||
// Tiny costs stay visible; zero or unknown costs are omitted on the row.
|
||||
expect(
|
||||
rowLabel({...base, 'cost_known': true, 'cost_usd': 0.0042}),
|
||||
'20.1M tokens · <\$0.01',
|
||||
);
|
||||
expect(
|
||||
rowLabel({...base, 'cost_known': true, 'cost_usd': 0.005}),
|
||||
'20.1M tokens · \$0.01',
|
||||
);
|
||||
expect(
|
||||
rowLabel({...base, 'cost_known': true, 'cost_usd': 0}),
|
||||
'20.1M tokens',
|
||||
);
|
||||
expect(rowLabel({...base, 'cost_usd': 1.5}), '20.1M tokens');
|
||||
// The stage detail still says the cost was not reported.
|
||||
final facts = detailVisitFacts({
|
||||
..._unreported,
|
||||
'usage': {...base, 'cost_known': true},
|
||||
});
|
||||
expect(facts, contains((label: 'Cost', value: 'Not reported')));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user