fix(app): show run action refusals before resyncing

This commit is contained in:
2026-10-21 14:47:59 +01:00
parent 610e23baa3
commit 54493704c1
9 changed files with 484 additions and 47 deletions
@@ -84,6 +84,101 @@ void main() {
expect(find.byKey(cancelActionKey), findsOneWidget);
});
testWidgets('a refusal and Keep do not wait for the resync', (tester) async {
const refusal = 'run 7 is already stopping';
final resync = Completer<JsonMap>();
final gateway = FakeCancelGateway((type, fields) {
if (type == 'cancel_run') throw const ProtocolError(refusal);
return resync.future;
});
final changed = <JsonMap>[];
await _pump(tester, gateway, changed);
await _openAndConfirm(tester);
await tester.pump();
expect(find.text(refusal), findsOneWidget);
expect(
tester.widget<TextButton>(find.byKey(cancelKeepKey)).onPressed,
isNotNull,
);
expect(
tester.widget<FilledButton>(find.byKey(cancelConfirmKey)).onPressed,
isNull,
);
expect(changed, isEmpty);
await tester.tap(find.byKey(cancelKeepKey));
await tester.pumpAndSettle();
expect(find.byType(AlertDialog), findsNothing);
resync.complete({
'run_detail': executingRun(executing: false, status: 'succeeded'),
});
await tester.pump();
expect(tester.takeException(), isNull);
expect(changed.single['status'], 'succeeded');
});
testWidgets('a late resync after disposal is ignored safely', (tester) async {
final resync = Completer<JsonMap>();
final gateway = FakeCancelGateway((type, fields) {
if (type == 'cancel_run') throw const ProtocolError('already stopped');
return resync.future;
});
final changed = <JsonMap>[];
await _pump(tester, gateway, changed);
await _openAndConfirm(tester);
await tester.pump();
expect(gateway.calls.map((call) => call.type), ['cancel_run', 'get_run']);
await tester.pumpWidget(const SizedBox());
resync.complete({'run_detail': acceptedCancelRun()});
await tester.pump();
expect(tester.takeException(), isNull);
expect(changed, isEmpty);
});
testWidgets('an ineligible resync disables confirm but keeps the refusal', (
tester,
) async {
const refusal = 'run 7 already completed; nothing to cancel';
final finished = executingRun(executing: false, status: 'succeeded');
final gateway = FakeCancelGateway((type, fields) async {
if (type == 'cancel_run') throw const ProtocolError(refusal);
return {'run_detail': finished};
});
final changed = <JsonMap>[];
await _pump(tester, gateway, changed);
await _openAndConfirm(tester);
await tester.pumpAndSettle();
expect(gateway.calls.map((call) => call.type), ['cancel_run', 'get_run']);
expect(find.text(refusal), findsOneWidget);
expect(
tester.widget<FilledButton>(find.byKey(cancelConfirmKey)).onPressed,
isNull,
);
expect(
tester.widget<TextButton>(find.byKey(cancelKeepKey)).onPressed,
isNotNull,
);
await tester.tap(find.byKey(cancelConfirmKey));
await tester.pump();
expect(gateway.calls.map((call) => call.type), ['cancel_run', 'get_run']);
await tester.tap(find.byKey(cancelKeepKey));
await tester.pumpAndSettle();
expect(find.byType(AlertDialog), findsNothing);
expect(find.byKey(cancelActionKey), findsNothing);
expect(changed.single, equals(finished));
});
testWidgets(
'confirm cannot submit twice while the cancellation is in flight',
(tester) async {
@@ -212,6 +212,34 @@ void main() {
},
);
testWidgets('Cancel dismisses the draft without sending anything', (
tester,
) async {
final gateway = _FakeGateway(
(type, fields) async => {'run_detail': _decided()},
);
final changed = <JsonMap>[];
await _pump(
tester,
gateway,
_waitingRun(),
cupertino: false,
changed: changed,
);
await _open(tester);
await tester.tap(find.text('go'));
await tester.pump();
await tester.enterText(find.byKey(decisionFeedbackKey), 'not sent');
await tester.tap(find.widgetWithText(TextButton, decisionCancelLabel));
await tester.pumpAndSettle();
expect(find.byType(AlertDialog), findsNothing);
expect(gateway.calls, isEmpty);
expect(changed, isEmpty);
expect(find.byKey(decisionActionKey), findsOneWidget);
});
testWidgets('the action is absent unless a run is genuinely waiting', (
tester,
) async {
@@ -154,6 +154,117 @@ void main() {
expect(find.byKey(decisionActionKey), findsNothing);
});
testWidgets('a refusal is shown before the resync keeps the draft', (
tester,
) async {
const refusal = 'option "go" is no longer valid';
final resync = Completer<JsonMap>();
final gateway = _FakeGateway((type, fields) {
if (type == 'decide_run') throw const ProtocolError(refusal);
return resync.future;
});
final changed = <JsonMap>[];
await _pump(tester, gateway, changed);
await _chooseGo(tester, feedback: ' keep me ');
await tester.tap(find.text(decisionConfirmLabel));
await tester.pump();
expect(find.text(refusal), findsOneWidget);
expect(find.byType(AlertDialog), findsOneWidget);
expect(
tester
.widget<RadioGroup<String>>(find.byType(RadioGroup<String>))
.groupValue,
'go',
);
expect(
tester
.widget<TextField>(find.byKey(decisionFeedbackKey))
.controller
?.text,
' keep me ',
);
expect(
tester
.widget<TextButton>(
find.widgetWithText(TextButton, decisionCancelLabel),
)
.onPressed,
isNotNull,
);
expect(changed, isEmpty);
resync.complete({'run_detail': _decided()});
await tester.pumpAndSettle();
expect(find.text(refusal), findsOneWidget);
expect(
tester
.widget<FilledButton>(
find.widgetWithText(FilledButton, decisionConfirmLabel),
)
.onPressed,
isNull,
);
expect(changed.single['status'], 'succeeded');
});
testWidgets('a failed resync keeps the draft and allows a retry', (
tester,
) async {
const refusal = 'server refused the decision';
final gateway = _FakeGateway((type, fields) async {
if (type == 'decide_run') throw const ProtocolError(refusal);
throw const NotConnectedError();
});
final changed = <JsonMap>[];
await _pump(tester, gateway, changed);
await _chooseGo(tester, feedback: ' keep me ');
await tester.tap(find.text(decisionConfirmLabel));
await tester.pumpAndSettle();
expect(gateway.calls.map((call) => call.type), ['decide_run', 'get_run']);
expect(find.text(refusal), findsOneWidget);
expect(
tester
.widget<RadioGroup<String>>(find.byType(RadioGroup<String>))
.groupValue,
'go',
);
expect(
tester
.widget<FilledButton>(
find.widgetWithText(FilledButton, decisionConfirmLabel),
)
.onPressed,
isNotNull,
);
expect(changed, isEmpty);
});
testWidgets('a late resync after disposal is ignored safely', (tester) async {
final resync = Completer<JsonMap>();
final gateway = _FakeGateway((type, fields) {
if (type == 'decide_run') throw const ProtocolError('no longer waiting');
return resync.future;
});
final changed = <JsonMap>[];
await _pump(tester, gateway, changed);
await _chooseGo(tester);
await tester.tap(find.text(decisionConfirmLabel));
await tester.pump();
expect(gateway.calls.map((call) => call.type), ['decide_run', 'get_run']);
await tester.pumpWidget(const SizedBox());
resync.complete({'run_detail': _decided()});
await tester.pump();
expect(tester.takeException(), isNull);
expect(changed, isEmpty);
});
testWidgets('confirm cannot submit twice while the decision is in flight', (
tester,
) async {