Merge: timeline rows show cached share and cost; no-patch reasons
This commit is contained in:
@@ -100,8 +100,31 @@ String noChangeDetail(RunChanges changes) {
|
|||||||
return emptyCaptureDetail;
|
return emptyCaptureDetail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The message for the server's `no_patch_reason`, or null when it sent none
|
||||||
|
/// or one this client does not know (the generic wording then applies).
|
||||||
|
String? noPatchReasonMessage(String? reason) => switch (reason) {
|
||||||
|
'binary' => 'Binary file; only its metadata was recorded.',
|
||||||
|
'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.',
|
||||||
|
_ => null,
|
||||||
|
};
|
||||||
|
|
||||||
/// Why a file has no patch to render, in the entry's own recorded terms.
|
/// Why a file has no patch to render, in the entry's own recorded terms.
|
||||||
String patchUnavailableReason(FileChange file) {
|
String patchUnavailableReason(FileChange file) {
|
||||||
|
final reason = noPatchReasonMessage(file.noPatchReason);
|
||||||
|
if (reason != null) return reason;
|
||||||
if (file.truncated) {
|
if (file.truncated) {
|
||||||
return "The server truncated this file's patch at its capture limit; no "
|
return "The server truncated this file's patch at its capture limit; no "
|
||||||
'diff text was recorded.';
|
'diff text was recorded.';
|
||||||
|
|||||||
@@ -12,12 +12,14 @@ class FileChange {
|
|||||||
String? patch,
|
String? patch,
|
||||||
this.binary = false,
|
this.binary = false,
|
||||||
this.truncated = false,
|
this.truncated = false,
|
||||||
|
String? noPatchReason,
|
||||||
String? beforeMode,
|
String? beforeMode,
|
||||||
String? afterMode,
|
String? afterMode,
|
||||||
this.steps = const [],
|
this.steps = const [],
|
||||||
ParsedPatch? parsedPatch,
|
ParsedPatch? parsedPatch,
|
||||||
}) : patch = _nonBlank(patch),
|
}) : patch = _nonBlank(patch),
|
||||||
beforeMode = _nonBlank(beforeMode),
|
beforeMode = _nonBlank(beforeMode),
|
||||||
|
noPatchReason = _nonBlank(noPatchReason),
|
||||||
afterMode = _nonBlank(afterMode),
|
afterMode = _nonBlank(afterMode),
|
||||||
// Aggregate copies pass their already-parsed patch through instead of
|
// Aggregate copies pass their already-parsed patch through instead of
|
||||||
// re-parsing the same recorded bytes for every stage that touched a path.
|
// re-parsing the same recorded bytes for every stage that touched a path.
|
||||||
@@ -32,6 +34,11 @@ class FileChange {
|
|||||||
final String? patch;
|
final String? patch;
|
||||||
final bool binary;
|
final bool binary;
|
||||||
final bool truncated;
|
final bool truncated;
|
||||||
|
|
||||||
|
/// Why the server recorded no (complete) patch: `binary`, `file_size`,
|
||||||
|
/// `budget`, `lines`, `evidence_size`, `git_status` or `baseline`. Null from
|
||||||
|
/// an older server or when a patch was recorded.
|
||||||
|
final String? noPatchReason;
|
||||||
final String? beforeMode;
|
final String? beforeMode;
|
||||||
final String? afterMode;
|
final String? afterMode;
|
||||||
|
|
||||||
@@ -68,6 +75,7 @@ class FileChange {
|
|||||||
patch: patch,
|
patch: patch,
|
||||||
binary: binary,
|
binary: binary,
|
||||||
truncated: truncated,
|
truncated: truncated,
|
||||||
|
noPatchReason: noPatchReason,
|
||||||
beforeMode: beforeMode,
|
beforeMode: beforeMode,
|
||||||
afterMode: afterMode,
|
afterMode: afterMode,
|
||||||
steps: List.unmodifiable(value),
|
steps: List.unmodifiable(value),
|
||||||
@@ -88,6 +96,9 @@ class FileChange {
|
|||||||
patch: json['patch'] is String ? json['patch'] as String : null,
|
patch: json['patch'] is String ? json['patch'] as String : null,
|
||||||
binary: json['binary'] == true,
|
binary: json['binary'] == true,
|
||||||
truncated: json['truncated'] == true,
|
truncated: json['truncated'] == true,
|
||||||
|
noPatchReason: json['no_patch_reason'] is String
|
||||||
|
? json['no_patch_reason'] as String
|
||||||
|
: null,
|
||||||
beforeMode: _textOrNull(json['before_mode']),
|
beforeMode: _textOrNull(json['before_mode']),
|
||||||
afterMode: _textOrNull(json['after_mode']),
|
afterMode: _textOrNull(json['after_mode']),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -211,7 +211,11 @@ class _FileDiffViewerState extends State<FileDiffViewer> {
|
|||||||
|
|
||||||
Widget _body(BuildContext context, TextStyle mono) {
|
Widget _body(BuildContext context, TextStyle mono) {
|
||||||
final file = widget.file;
|
final file = widget.file;
|
||||||
if (file.binary) return _message(context, binaryDiffMessage);
|
// A recorded reason is more specific than the generic binary message.
|
||||||
|
final reason = noPatchReasonMessage(file.noPatchReason);
|
||||||
|
if (file.binary && reason == null) {
|
||||||
|
return _message(context, binaryDiffMessage);
|
||||||
|
}
|
||||||
if (!file.hasPatch) {
|
if (!file.hasPatch) {
|
||||||
return _message(context, patchUnavailableReason(file));
|
return _message(context, patchUnavailableReason(file));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,6 +122,21 @@ String formatTokenCount(int tokens) {
|
|||||||
String tokenUsageLabel(TokenUsage usage) =>
|
String tokenUsageLabel(TokenUsage usage) =>
|
||||||
'${usage.partial ? '≥' : ''}${formatTokenCount(usage.total)} tokens';
|
'${usage.partial ? '≥' : ''}${formatTokenCount(usage.total)} tokens';
|
||||||
|
|
||||||
|
/// A stage row's compact label: the total, the cached share when the stage
|
||||||
|
/// recorded its cache split, and the cost when a positive one was reported.
|
||||||
|
/// `20.1M tokens · 95% cached · $0.42`. A missing figure is omitted, never
|
||||||
|
/// shown as zero.
|
||||||
|
String stageTokenRowLabel(TokenUsage usage) {
|
||||||
|
final cacheRead = usage.cacheRead;
|
||||||
|
final cost = usage.cost;
|
||||||
|
return [
|
||||||
|
tokenUsageLabel(usage),
|
||||||
|
if (cacheRead != null && usage.total > 0)
|
||||||
|
'${(cacheRead * 100 / usage.total).round()}% cached',
|
||||||
|
if (cost != null) cost < 0.005 ? '<\$0.01' : '\$${cost.toStringAsFixed(2)}',
|
||||||
|
].join(' · ');
|
||||||
|
}
|
||||||
|
|
||||||
/// The detail's token value: the compact total, then fresh versus cached
|
/// The detail's token value: the compact total, then fresh versus cached
|
||||||
/// when every stage reported its cache components, the in/out split when
|
/// when every stage reported its cache components, the in/out split when
|
||||||
/// reported, and how many stages reported when the total is partial.
|
/// reported, and how many stages reported when the total is partial.
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ List<DetailVisit> detailTimeline(dynamic steps) {
|
|||||||
target: '${step['target'] ?? ''}'.trim(),
|
target: '${step['target'] ?? ''}'.trim(),
|
||||||
duration: _visitDuration(step),
|
duration: _visitDuration(step),
|
||||||
tokens: switch (stageTokenUsage(JsonMap.from(step))) {
|
tokens: switch (stageTokenUsage(JsonMap.from(step))) {
|
||||||
final usage? => tokenUsageLabel(usage),
|
final usage? => stageTokenRowLabel(usage),
|
||||||
null => null,
|
null => null,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# Changes: why a file has no patch
|
||||||
|
|
||||||
|
The server's `FileChange.no_patch_reason` (`binary`, `file_size`, `budget`,
|
||||||
|
`lines`, `evidence_size`, `git_status`, `baseline`) is parsed into
|
||||||
|
`FileChange.noPatchReason` and worded by `noPatchReasonMessage` in
|
||||||
|
`lib/features/changes/domain/change_wording.dart`. The file viewer shows it in
|
||||||
|
place of the generic truncated/binary message. A missing, blank or unknown
|
||||||
|
reason (older server) keeps the old wording. Tests:
|
||||||
|
`test/features/changes/no_patch_reason_test.dart`.
|
||||||
@@ -31,8 +31,11 @@ Runs that spend 20M+ tokens now show it the way they show disk size.
|
|||||||
- Summary: `Size on disk`, `Tokens` (`22.4M · 2.1M fresh, 20.3M cached ·
|
- Summary: `Size on disk`, `Tokens` (`22.4M · 2.1M fresh, 20.3M cached ·
|
||||||
1.8M in, 240K out`; fresh is total minus cache reads, shown only when
|
1.8M in, 240K out`; fresh is total minus cache reads, shown only when
|
||||||
`cache_known`) and `Cost`.
|
`cache_known`) and `Cost`.
|
||||||
- Stage rows: the Timeline row subtitle adds `· 20.1M tokens`. The visit facts
|
- Stage rows: the Timeline row subtitle adds `· 20.1M tokens · 97% cached ·
|
||||||
add `Tokens` and `Cost`.
|
$1.42` (`stageTokenRowLabel`). The cached share (cache reads over the total,
|
||||||
|
rounded) appears only when the stage recorded `cache_known`; the cost only
|
||||||
|
when positive, to two places, `<$0.01` below half a cent. The visit facts
|
||||||
|
add `Tokens` and `Cost` (`Not reported` stays there).
|
||||||
- Cost is shown only when a positive `cost_usd` was reported. Subscription
|
- Cost is shown only when a positive `cost_usd` was reported. Subscription
|
||||||
models report `cost_known` with no amount, which shows as `Not reported`.
|
models report `cost_known` with no amount, which shows as `Not reported`.
|
||||||
The stats page's `Reported cost` uses the same rule.
|
The stats page's `Reported cost` uses the same rule.
|
||||||
|
|||||||
@@ -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', () {
|
test('a stage row carries its compact token total', () {
|
||||||
final visits = detailTimeline([_reported, _unreported]);
|
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);
|
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