App: findings ledger tab, retry extra visits and exhaustion decisions

Run detail gains a Findings tab (open-count badge) listing the server's
findings ledger with status and minimum-severity filters and expandable
event history; visit grants show as an Extra visits summary fact. The
resume retry prompt can grant 1-5 extra visits to the exhausted stage or a
chosen graph stage (never sent on restart), suggested when the run failed
on a visit limit. A loop-exhaustion decision waiting on a model stage is
now decidable from its recorded options, with readable labels, targets and
the visit count.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 12:45:43 +00:00
parent c4de1de27b
commit ebe79ebed0
27 changed files with 1255 additions and 14 deletions
@@ -0,0 +1,59 @@
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/runs/actions/decision_action.dart';
import 'package:pipelines_app/features/runs/actions/decision_wording.dart';
import '../domain/run_exhausted_decision_fixture.dart';
import 'retry_test_support.dart' show FakeRetryGateway;
void main() {
testWidgets('an exhaustion decision shows readable options and the visit '
'count, and sends the option key for the exhausted stage', (
tester,
) async {
final gateway = FakeRetryGateway(
(type, fields) async => {
'run_detail': {...exhaustedDecisionRun(), 'status': 'running'},
},
);
final changed = <JsonMap>[];
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Center(
child: HumanDecisionAction(
run: exhaustedDecisionRun(),
gateway: gateway,
onRunChanged: changed.add,
),
),
),
),
);
await tester.tap(find.byKey(decisionActionKey));
await tester.pumpAndSettle();
expect(find.text('Accept as is'), findsOneWidget);
expect(find.text('One more round'), findsOneWidget);
expect(find.text('Abort'), findsOneWidget);
expect(find.text('→ implement'), findsOneWidget);
expect(
find.text('review reached its visit limit: visit 3 of 3'),
findsOneWidget,
);
await tester.tap(find.text('One more round'));
await tester.pump();
await tester.tap(find.text(decisionConfirmLabel));
await tester.pumpAndSettle();
final decide = gateway.calls.singleWhere((c) => c.type == 'decide_run');
expect(decide.fields, {
'run_id': 9,
'option': 'continue',
'stage': 'review',
});
expect(changed, isNotEmpty);
});
}
@@ -0,0 +1,168 @@
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/runs/actions/retry_extra_visits.dart';
import 'package:pipelines_app/features/runs/actions/retry_intent.dart';
import 'package:pipelines_app/features/runs/actions/retry_wording.dart';
import 'package:pipelines_app/features/runs/data/runs_repository.dart';
import 'retry_test_support.dart';
JsonMap exhaustedRun() => {
...failedRun(),
'diagnostic': 'review: visit limit reached (3 of 3)',
'graph': {
'stages': [
{'key': 'implement', 'type': 'model'},
{'key': 'review', 'type': 'model'},
],
},
};
Future<void> pick(WidgetTester tester, Key menu, String label) async {
await tester.tap(find.byKey(menu));
await tester.pumpAndSettle();
await tester.tap(find.text(label).last);
await tester.pumpAndSettle();
}
void main() {
test('exhausted loops are recognised from the diagnostic or a step', () {
expect(runExhaustedVisits(exhaustedRun()), isTrue);
for (final phrase in [
'Visit budget exceeded',
'total stage budget exceeded',
]) {
expect(runExhaustedVisits({'diagnostic': phrase}), isTrue);
}
expect(
runExhaustedVisits({
'steps': [
{
'stage': 'review',
'control': {'limit_reached': true},
},
],
}),
isTrue,
);
expect(runExhaustedVisits(failedRun()), isFalse);
expect(retryStageKeys(exhaustedRun()), ['implement', 'review']);
expect(retryStageKeys(failedRun()), isEmpty);
});
test('extra visits are only on the wire for a resume within 1-5', () {
RetryIntent intent(RetryMode mode, int? visits, [String? stage]) =>
RetryIntent(
mode: mode,
requestKey: 'k',
extraVisits: visits,
extraStage: stage,
);
expect(intent(RetryMode.resume, 2, 'review').wireExtraVisits, 2);
expect(intent(RetryMode.resume, 2, 'review').wireExtraStage, 'review');
expect(intent(RetryMode.resume, 2).wireExtraStage, isNull);
expect(intent(RetryMode.resume, 0).wireExtraVisits, isNull);
expect(intent(RetryMode.resume, 6).wireExtraVisits, isNull);
expect(intent(RetryMode.resume, null, 'review').wireExtraStage, isNull);
expect(intent(RetryMode.restart, 2, 'review').wireExtraVisits, isNull);
expect(intent(RetryMode.restart, 2, 'review').wireExtraStage, isNull);
});
test('the repository sends extra visits on resume only', () async {
final gateway = FakeRetryGateway(
(type, fields) async => {'run_detail': retriedRun()},
);
final repo = RunsRepository(gateway);
await repo.retryRun(7, requestKey: 'a', extraVisits: 2);
expect(gateway.calls.last.fields, {
'run_id': 7,
'request_key': 'a',
'retry_extra_visits': 2,
});
await repo.retryRun(7, requestKey: 'b', extraVisits: 1, extraStage: 'x');
expect(gateway.calls.last.fields['retry_extra_stage'], 'x');
await repo.retryRun(
7,
requestKey: 'c',
mode: 'restart',
extraVisits: 2,
extraStage: 'x',
);
expect(gateway.calls.last.fields, {
'run_id': 7,
'request_key': 'c',
'retry_mode': 'restart',
});
await repo.retryRun(7, requestKey: 'd', extraVisits: 9);
expect(gateway.calls.last.fields.containsKey('retry_extra_visits'), false);
});
testWidgets('an exhausted run suggests extra visits; chosen ones are sent', (
tester,
) async {
final gateway = FakeRetryGateway(
(type, fields) async => {'run_detail': retriedRun()},
);
await pumpRetry(tester, gateway: gateway, changed: [], run: exhaustedRun());
await tester.tap(find.byKey(retryActionKey));
await tester.pumpAndSettle();
expect(find.byKey(retryExhaustedHintKey), findsOneWidget);
// Suggested, but off until the operator chooses it.
expect(find.byKey(retryExtraCountKey), findsNothing);
await tester.tap(find.byKey(retryExtraVisitsKey));
await tester.pumpAndSettle();
await pick(tester, retryExtraCountKey, '+3');
await pick(tester, retryExtraStageKey, 'review');
await tester.tap(find.byKey(retryConfirmKey));
await tester.pumpAndSettle();
final fields = gateway.retries.single.fields;
expect(fields['retry_extra_visits'], 3);
expect(fields['retry_extra_stage'], 'review');
expect(fields.containsKey('retry_mode'), isFalse);
});
testWidgets('a plain failure offers extra visits without a hint, and the '
'default stage is left to the server', (tester) async {
final gateway = FakeRetryGateway(
(type, fields) async => {'run_detail': retriedRun()},
);
await pumpRetry(tester, gateway: gateway, changed: []);
await tester.tap(find.byKey(retryActionKey));
await tester.pumpAndSettle();
expect(find.byKey(retryExhaustedHintKey), findsNothing);
await tester.tap(find.byKey(retryExtraVisitsKey));
await tester.pumpAndSettle();
expect(find.text(retryExhaustedStageLabel), findsWidgets);
await tester.tap(find.byKey(retryConfirmKey));
await tester.pumpAndSettle();
final fields = gateway.retries.single.fields;
expect(fields['retry_extra_visits'], 1);
expect(fields.containsKey('retry_extra_stage'), isFalse);
});
testWidgets('restart hides and never sends extra visits', (tester) async {
final gateway = FakeRetryGateway(
(type, fields) async => {'run_detail': retriedRun()},
);
await pumpRetry(tester, gateway: gateway, changed: [], run: exhaustedRun());
await tester.tap(find.byKey(retryActionKey));
await tester.pumpAndSettle();
await tester.tap(find.byKey(retryExtraVisitsKey));
await tester.pumpAndSettle();
await tester.tap(find.byKey(retryRestartKey));
await tester.pumpAndSettle();
expect(find.byKey(retryExtraVisitsKey), findsNothing);
await tester.tap(find.byKey(retryConfirmKey));
await tester.pumpAndSettle();
final fields = gateway.retries.single.fields;
expect(fields['retry_mode'], 'restart');
expect(fields.containsKey('retry_extra_visits'), isFalse);
expect(fields.containsKey('retry_extra_stage'), isFalse);
});
}
@@ -0,0 +1,43 @@
import 'package:pipelines_app/core/api_gateway.dart';
/// A run waiting on the server-created decision of an exhausted review loop:
/// the waiting stage is the model stage, not a human stage in the graph.
JsonMap exhaustedDecisionRun({dynamic output}) => {
'id': 9,
'status': 'waiting',
'current_stage': 'review',
'name': 'Build',
'graph': {
'stages': [
{
'key': 'review',
'type': 'model',
'edges': {'pass': '#', 'fail': 'implement'},
},
{'key': 'implement', 'type': 'model'},
],
},
'steps': [
{
'stage': 'review',
'sequence': 6,
'status': 'waiting',
'output':
output ??
{
'prompt': 'Review used all its visits.',
'options': ['accept', 'continue', 'abort'],
'exhausted': {
'stage': 'review',
'visit': 3,
'max_visits': 3,
'targets': {
'accept': '#success',
'continue': 'implement',
'abort': '#failure',
},
},
},
},
],
};
@@ -0,0 +1,70 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/runs/actions/decision_wording.dart';
import 'package:pipelines_app/features/runs/domain/run_decisions.dart';
import 'run_exhausted_decision_fixture.dart';
void main() {
test('an exhaustion decision on a model stage uses the recorded options', () {
final decision = pendingDecision(exhaustedDecisionRun())!;
expect(decision.stageKey, 'review');
expect(decision.instructions, 'Review used all its visits.');
expect(decision.options.map((o) => o.key), ['accept', 'continue', 'abort']);
expect(decision.options.map((o) => o.displayLabel), [
'Accept as is',
'One more round',
'Abort',
]);
expect(decision.options.map((o) => o.target), [
'SUCCESS',
'implement',
'FAILURE',
]);
expect(decision.exhausted?.visit, 3);
expect(decision.exhausted?.maxVisits, 3);
expect(
decisionExhaustedText(decision),
'review reached its visit limit: visit 3 of 3',
);
});
test('unknown option keys keep their recorded wording', () {
final decision = pendingDecision(
exhaustedDecisionRun(
output: {
'options': ['accept', 'extend'],
'exhausted': {'stage': 'review'},
},
),
)!;
expect(decision.options.map((o) => o.displayLabel), [
'Accept as is',
'extend',
]);
expect(decision.options.last.target, '');
expect(decisionExhaustedText(decision), 'review reached its visit limit');
});
test('a model stage waiting without an exhaustion record is no decision', () {
expect(
pendingDecision(
exhaustedDecisionRun(
output: {
'options': ['accept'],
},
),
),
isNull,
);
expect(
pendingDecision(
exhaustedDecisionRun(
output: {
'exhausted': {'stage': 'review'},
},
),
),
isNull,
);
});
}
@@ -0,0 +1,48 @@
import 'package:pipelines_app/core/api_gateway.dart';
/// A run detail with a small findings ledger: one open, one fixed with its
/// event history, one dismissed, and a malformed entry.
JsonMap findingsRun() => {
'id': 4,
'findings': [
{
'id': 'F1',
'severity': 'critical',
'origin': 'introduced',
'location': 'internal/cache.go:42',
'summary': 'Cache never evicts',
'status': 'open',
'raised_by': 'review',
'raised_sequence': 4,
},
{
'id': 'F2',
'severity': 'minor',
'origin': 'pre-existing',
'location': '',
'summary': 'Typo in log',
'status': 'fixed',
'reason': 'Corrected',
'raised_by': 'review',
'raised_sequence': 4,
'updated_by': 'implement',
'updated_sequence': 5,
'events': [
{
'sequence': 5,
'stage': 'implement',
'status': 'fixed',
'reason': 'Corrected',
},
],
},
{
'id': 'F3',
'severity': 'nit',
'origin': 'introduced',
'summary': 'Naming',
'status': 'dismissed',
},
'not a finding',
],
};
@@ -0,0 +1,65 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/runs/domain/run_findings.dart';
import 'run_findings_fixture.dart';
void main() {
test('parses the recorded ledger and skips malformed items', () {
final findings = runFindings(findingsRun());
expect(findings.map((f) => f.id), ['F1', 'F2', 'F3']);
final fixed = findings[1];
expect(fixed.severity, FindingSeverity.minor);
expect(fixed.origin, 'pre-existing');
expect(fixed.location, '');
expect(fixed.reason, 'Corrected');
expect(fixed.updatedBy, 'implement');
expect(fixed.updatedSequence, 5);
expect(fixed.events.single.stage, 'implement');
expect(fixed.events.single.sequence, 5);
expect(findings.first.events, isEmpty);
expect(findings.first.raisedSequence, 4);
});
test('older servers without findings show nothing', () {
expect(runFindings({'id': 1}), isEmpty);
expect(runFindings({'findings': []}), isEmpty);
expect(runFindings(null), isEmpty);
});
test('filters by status and minimum severity', () {
final findings = runFindings(findingsRun());
expect(openFindingCount(findings), 1);
expect(defaultFindingStatus(findings), 'open');
expect(defaultFindingStatus(findings.skip(1)), isNull);
ids(List<RunFinding> list) => list.map((f) => f.id).toList();
expect(ids(filterFindings(findings)), ['F1', 'F2', 'F3']);
expect(ids(filterFindings(findings, status: 'fixed')), ['F2']);
expect(ids(filterFindings(findings, minSeverity: FindingSeverity.minor)), [
'F1',
'F2',
]);
expect(
ids(filterFindings(findings, minSeverity: FindingSeverity.critical)),
['F1'],
);
expect(
filterFindings(
findings,
status: 'fixed',
minSeverity: FindingSeverity.important,
),
isEmpty,
);
});
test('visit grants summarise as stage +n', () {
expect(
visitGrantsSummary({
'visit_grants': {'review': 1, 'implement': 2, 'idle': 0},
}),
'review +1, implement +2',
);
expect(visitGrantsSummary({'visit_grants': {}}), isNull);
expect(visitGrantsSummary({}), isNull);
});
}
@@ -0,0 +1,43 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/runs/ui/run_detail_tab.dart';
import '../domain/run_findings_fixture.dart';
import 'run_detail_graph_support.dart';
void main() {
testWidgets('a run without findings has no Findings tab', (tester) async {
await pumpRunDetail(tester, RunDetailTestPlatform.material);
expect(runDetailTab(RunDetailTab.findings), findsNothing);
});
for (final size in const [Size(900, 1000), Size(390, 844)]) {
testWidgets('a run with findings offers the tab with its open count at '
'${size.width}', (tester) async {
await pumpRunDetail(
tester,
RunDetailTestPlatform.material,
size: size,
run: {
...graphRunFixture(),
'findings': findingsRun()['findings'],
'visit_grants': {'review': 1},
},
);
expect(runDetailTab(RunDetailTab.findings), findsOneWidget);
expect(
find.byKey(const ValueKey('run-detail-findings-count')),
findsOneWidget,
);
expect(find.text('review +1'), findsOneWidget);
await openRunDetailTab(tester, RunDetailTab.findings);
await tester.pumpAndSettle();
expect(
find.byKey(const Key('run-detail-tab-body-findings')),
findsOneWidget,
);
expect(find.byKey(const ValueKey('run-finding-F1')), findsOneWidget);
});
}
}
@@ -0,0 +1,64 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/runs/domain/run_findings.dart';
import 'package:pipelines_app/features/runs/ui/run_findings_tab.dart';
import '../domain/run_findings_fixture.dart';
Future<void> pumpFindings(WidgetTester tester, List<RunFinding> findings) =>
tester.pumpWidget(
MaterialApp(
home: Scaffold(body: RunFindingsTab(findings: findings)),
),
);
Finder finding(String id) => find.byKey(ValueKey('run-finding-$id'));
void main() {
testWidgets('starts on open findings and filters by status', (tester) async {
await pumpFindings(tester, runFindings(findingsRun()));
expect(finding('F1'), findsOneWidget);
expect(finding('F2'), findsNothing);
expect(find.text('F1 · Cache never evicts'), findsOneWidget);
expect(find.text('critical · introduced · open'), findsOneWidget);
expect(find.text('internal/cache.go:42'), findsOneWidget);
expect(find.text('Open (1)'), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('run-findings-status-all')));
await tester.pumpAndSettle();
for (final id in ['F1', 'F2', 'F3']) {
expect(finding(id), findsOneWidget);
}
await tester.tap(find.byKey(const ValueKey('run-findings-status-settled')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('run-findings-empty')), findsOneWidget);
});
testWidgets('filters by minimum severity and expands events', (tester) async {
await pumpFindings(tester, runFindings(findingsRun()));
await tester.tap(find.byKey(const ValueKey('run-findings-status-all')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('run-findings-severity')));
await tester.pumpAndSettle();
await tester.tap(find.text('minor').last);
await tester.pumpAndSettle();
expect(finding('F2'), findsOneWidget);
expect(finding('F3'), findsNothing);
expect(find.text('Corrected'), findsOneWidget);
await tester.tap(finding('F2'));
await tester.pumpAndSettle();
expect(find.text('Raised by review (visit #4)'), findsOneWidget);
expect(find.text('Updated by implement (visit #5)'), findsOneWidget);
expect(find.text('#5 · implement · fixed: Corrected'), findsOneWidget);
});
testWidgets('with nothing open, all findings show', (tester) async {
await pumpFindings(tester, runFindings(findingsRun()).skip(1).toList());
expect(finding('F2'), findsOneWidget);
expect(finding('F3'), findsOneWidget);
});
}