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:
@@ -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);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user