merge(app): bring main into flutter/t1-data candidate
Keep main's landed retry action and saved-schedules slices alongside the templates data slice. Resolve app/.gitignore by keeping the single test/**/data/ negation both sides added, with the explanatory comment. Checks after merge: dart format clean, flutter analyze clean, 111 tests pass, flutter build web succeeds.
This commit is contained in:
@@ -0,0 +1,245 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
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_eligibility.dart';
|
||||
import 'package:pipelines_app/features/runs/actions/retry_intent.dart';
|
||||
import 'package:pipelines_app/features/runs/actions/retry_wording.dart';
|
||||
|
||||
import 'retry_test_support.dart';
|
||||
|
||||
void main() {
|
||||
test('retry eligibility matches the web canRetry exactly', () {
|
||||
final cases = <(String, JsonMap, bool)>[
|
||||
('failed and stopped', failedRun(), true),
|
||||
('failed but still executing', failedRun(executing: true), false),
|
||||
('running', failedRun(status: 'running'), false),
|
||||
('waiting', failedRun(status: 'waiting'), false),
|
||||
('succeeded', failedRun(status: 'succeeded'), false),
|
||||
('canceled', failedRun(status: 'canceled'), false),
|
||||
];
|
||||
for (final (label, run, expected) in cases) {
|
||||
expect(canRetryRun(run), expected, reason: label);
|
||||
}
|
||||
expect(canRetryRun(null), isFalse);
|
||||
expect(retryRunId(failedRun()), 7);
|
||||
expect(retryRunId({'id': '7'}), isNull);
|
||||
});
|
||||
|
||||
test('a generated retry key is bounded, run-scoped and fresh', () {
|
||||
final first = newRetryRequestKey(7);
|
||||
final second = newRetryRequestKey(7);
|
||||
|
||||
expect(first, startsWith('app-retry-7-'));
|
||||
expect(first.length, lessThanOrEqualTo(128));
|
||||
expect(second.length, lessThanOrEqualTo(128));
|
||||
expect(first, isNot(second));
|
||||
expect(
|
||||
newRetryRequestKey(7, now: DateTime.utc(2026, 1, 1), random: 36),
|
||||
'app-retry-7-${DateTime.utc(2026, 1, 1).microsecondsSinceEpoch}-10',
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'material retry asks first, Keep sends nothing, then omits retry_mode',
|
||||
(tester) async {
|
||||
final accepted = retriedRun();
|
||||
final gateway = FakeRetryGateway(
|
||||
(type, fields) async => {'run_detail': accepted},
|
||||
);
|
||||
final changed = <JsonMap>[];
|
||||
await pumpRetry(tester, gateway: gateway, changed: changed);
|
||||
|
||||
expect(find.byKey(retryActionKey), findsOneWidget);
|
||||
expect(find.byType(FilledButton), findsOneWidget);
|
||||
expect(gateway.calls, isEmpty);
|
||||
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(AlertDialog), findsOneWidget);
|
||||
expect(find.text(retryDialogTitle(7)), findsOneWidget);
|
||||
expect(find.text(retryDialogMessage), findsOneWidget);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byType(AlertDialog),
|
||||
matching: find.text(retryConfirmLabel),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text(restartConfirmLabel), findsOneWidget);
|
||||
expect(gateway.calls, isEmpty);
|
||||
|
||||
await tester.tap(find.byKey(retryKeepKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(AlertDialog), findsNothing);
|
||||
expect(find.byKey(retryActionKey), findsOneWidget);
|
||||
expect(gateway.calls, isEmpty);
|
||||
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(retryConfirmKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.retries, hasLength(1));
|
||||
final fields = gateway.retries.single.fields;
|
||||
expect(fields.keys, containsAll(<String>['run_id', 'request_key']));
|
||||
expect(fields.containsKey('retry_mode'), isFalse);
|
||||
expect(fields['run_id'], 7);
|
||||
expect(fields['request_key'], startsWith('app-retry-7-'));
|
||||
expect(fields['request_key'].length, lessThanOrEqualTo(128));
|
||||
expect(changed.single, equals(accepted));
|
||||
expect(find.byType(AlertDialog), findsNothing);
|
||||
expect(find.byKey(retryActionKey), findsNothing);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'material restart has its own confirmation and sends retry_mode',
|
||||
(tester) async {
|
||||
final accepted = retriedRun();
|
||||
final gateway = FakeRetryGateway(
|
||||
(type, fields) async => {'run_detail': accepted},
|
||||
);
|
||||
final changed = <JsonMap>[];
|
||||
await pumpRetry(tester, gateway: gateway, changed: changed);
|
||||
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(retryRestartKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text(restartDialogTitle(7)), findsOneWidget);
|
||||
expect(find.text(restartDialogMessage), findsOneWidget);
|
||||
expect(find.text(retryDialogTitle(7)), findsNothing);
|
||||
expect(find.text(retryDialogMessage), findsNothing);
|
||||
expect(find.text(restartConfirmLabel), findsOneWidget);
|
||||
expect(find.byKey(retryRestartKey), findsNothing);
|
||||
expect(gateway.calls, isEmpty);
|
||||
|
||||
await tester.tap(find.byKey(retryConfirmKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.retries, hasLength(1));
|
||||
final fields = gateway.retries.single.fields;
|
||||
expect(fields['run_id'], 7);
|
||||
expect(fields['retry_mode'], 'restart');
|
||||
expect(fields['request_key'], startsWith('app-retry-7-'));
|
||||
expect(changed.single, equals(accepted));
|
||||
expect(find.byType(AlertDialog), findsNothing);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'cupertino retry uses a native prompt and sends only on confirm',
|
||||
(tester) async {
|
||||
final accepted = retriedRun();
|
||||
final gateway = FakeRetryGateway(
|
||||
(type, fields) async => {'run_detail': accepted},
|
||||
);
|
||||
final changed = <JsonMap>[];
|
||||
await pumpRetry(
|
||||
tester,
|
||||
gateway: gateway,
|
||||
changed: changed,
|
||||
cupertino: true,
|
||||
);
|
||||
|
||||
expect(find.byKey(retryActionKey), findsOneWidget);
|
||||
expect(find.byType(CupertinoButton), findsOneWidget);
|
||||
expect(find.byType(FilledButton), findsNothing);
|
||||
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(CupertinoAlertDialog), findsOneWidget);
|
||||
expect(find.byType(AlertDialog), findsNothing);
|
||||
expect(find.text(retryDialogTitle(7)), findsOneWidget);
|
||||
expect(find.text(retryDialogMessage), findsOneWidget);
|
||||
expect(gateway.calls, isEmpty);
|
||||
|
||||
await tester.tap(find.byKey(retryKeepKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.calls, isEmpty);
|
||||
expect(find.byType(CupertinoAlertDialog), findsNothing);
|
||||
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(retryConfirmKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.retries, hasLength(1));
|
||||
final fields = gateway.retries.single.fields;
|
||||
expect(fields['run_id'], 7);
|
||||
expect(fields.containsKey('retry_mode'), isFalse);
|
||||
expect(fields['request_key'], startsWith('app-retry-7-'));
|
||||
expect(changed.single, equals(accepted));
|
||||
expect(find.byType(CupertinoAlertDialog), findsNothing);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('cupertino restart switches to the restart confirmation', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = FakeRetryGateway(
|
||||
(type, fields) async => {'run_detail': retriedRun()},
|
||||
);
|
||||
await pumpRetry(
|
||||
tester,
|
||||
gateway: gateway,
|
||||
changed: <JsonMap>[],
|
||||
cupertino: true,
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(retryRestartKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(CupertinoAlertDialog), findsOneWidget);
|
||||
expect(find.text(restartDialogTitle(7)), findsOneWidget);
|
||||
expect(find.text(restartDialogMessage), findsOneWidget);
|
||||
expect(gateway.calls, isEmpty);
|
||||
|
||||
await tester.tap(find.byKey(retryConfirmKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.retries.single.fields['retry_mode'], 'restart');
|
||||
});
|
||||
|
||||
testWidgets('the action is absent for runs the web does not retry', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = FakeRetryGateway(
|
||||
(type, fields) async => {'run_detail': retriedRun()},
|
||||
);
|
||||
final changed = <JsonMap>[];
|
||||
final cases = <(String, JsonMap, bool)>[
|
||||
('failed', failedRun(), true),
|
||||
('executing', failedRun(executing: true), false),
|
||||
('running', failedRun(status: 'running'), false),
|
||||
('waiting', failedRun(status: 'waiting'), false),
|
||||
('succeeded', failedRun(status: 'succeeded'), false),
|
||||
('canceled', failedRun(status: 'canceled'), false),
|
||||
];
|
||||
for (final cupertino in [false, true]) {
|
||||
for (final (label, run, visible) in cases) {
|
||||
await tester.pumpWidget(
|
||||
retryApp(
|
||||
RetryHost(
|
||||
key: ValueKey('$label-$cupertino'),
|
||||
gateway: gateway,
|
||||
initial: run,
|
||||
changed: changed,
|
||||
),
|
||||
cupertino: cupertino,
|
||||
),
|
||||
);
|
||||
expect(
|
||||
find.byKey(retryActionKey),
|
||||
visible ? findsOneWidget : findsNothing,
|
||||
reason: '$label cupertino=$cupertino',
|
||||
);
|
||||
}
|
||||
}
|
||||
expect(gateway.calls, isEmpty);
|
||||
expect(changed, isEmpty);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/core/transport/connection_state.dart';
|
||||
import 'package:pipelines_app/features/runs/actions/retry_eligibility.dart';
|
||||
import 'package:pipelines_app/features/runs/actions/retry_wording.dart';
|
||||
|
||||
import 'retry_test_support.dart';
|
||||
|
||||
Future<void> _openAndConfirm(WidgetTester tester) async {
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(retryConfirmKey));
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('a refusal is shown at once and Keep does not wait for resync', (
|
||||
tester,
|
||||
) async {
|
||||
const refusal = 'run 7 is still executing; wait for it to stop completely';
|
||||
final resync = Completer<JsonMap>();
|
||||
final gateway = FakeRetryGateway((type, fields) {
|
||||
if (type == 'retry_run') throw const ProtocolError(refusal);
|
||||
return resync.future;
|
||||
});
|
||||
final changed = <JsonMap>[];
|
||||
await pumpRetry(tester, gateway: gateway, changed: changed);
|
||||
|
||||
await _openAndConfirm(tester);
|
||||
await tester.pump();
|
||||
|
||||
expect(gateway.calls.map((call) => call.type), ['retry_run', 'get_run']);
|
||||
expect(find.text(refusal), findsOneWidget);
|
||||
expect(find.byKey(retryErrorKey), findsOneWidget);
|
||||
expect(
|
||||
tester.widget<TextButton>(find.byKey(retryKeepKey)).onPressed,
|
||||
isNotNull,
|
||||
);
|
||||
expect(
|
||||
tester.widget<FilledButton>(find.byKey(retryConfirmKey)).onPressed,
|
||||
isNull,
|
||||
);
|
||||
expect(changed, isEmpty);
|
||||
|
||||
await tester.tap(find.byKey(retryKeepKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(AlertDialog), findsNothing);
|
||||
|
||||
resync.complete({'run_detail': failedRun(status: 'succeeded')});
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(changed.single['status'], 'succeeded');
|
||||
expect(find.byKey(retryActionKey), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('server truth that is ineligible blocks a repeat action', (
|
||||
tester,
|
||||
) async {
|
||||
const refusal = 'only failed runs can be retried';
|
||||
final finished = failedRun(status: 'succeeded');
|
||||
final gateway = FakeRetryGateway((type, fields) async {
|
||||
if (type == 'retry_run') throw const ProtocolError(refusal);
|
||||
return {'run_detail': finished};
|
||||
});
|
||||
final changed = <JsonMap>[];
|
||||
await pumpRetry(tester, gateway: gateway, changed: changed);
|
||||
|
||||
await _openAndConfirm(tester);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.calls.map((call) => call.type), ['retry_run', 'get_run']);
|
||||
expect(find.text(refusal), findsOneWidget);
|
||||
expect(
|
||||
tester.widget<FilledButton>(find.byKey(retryConfirmKey)).onPressed,
|
||||
isNull,
|
||||
);
|
||||
expect(
|
||||
tester.widget<TextButton>(find.byKey(retryKeepKey)).onPressed,
|
||||
isNotNull,
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(retryConfirmKey));
|
||||
await tester.pump();
|
||||
expect(gateway.calls.map((call) => call.type), ['retry_run', 'get_run']);
|
||||
|
||||
await tester.tap(find.byKey(retryKeepKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(AlertDialog), findsNothing);
|
||||
expect(find.byKey(retryActionKey), findsNothing);
|
||||
expect(changed.single, equals(finished));
|
||||
expect(canRetryRun(changed.single), isFalse);
|
||||
});
|
||||
|
||||
testWidgets('a failed recheck keeps the same key for the uncertain request', (
|
||||
tester,
|
||||
) async {
|
||||
const refusal = 'connection dropped while retrying';
|
||||
var attempts = 0;
|
||||
final gateway = FakeRetryGateway((type, fields) async {
|
||||
if (type == 'get_run') throw const NotConnectedError();
|
||||
attempts += 1;
|
||||
if (attempts == 1) throw const ProtocolError(refusal);
|
||||
return {'run_detail': retriedRun()};
|
||||
});
|
||||
final changed = <JsonMap>[];
|
||||
await pumpRetry(tester, gateway: gateway, changed: changed);
|
||||
|
||||
await _openAndConfirm(tester);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text(refusal), findsOneWidget);
|
||||
expect(
|
||||
tester.widget<FilledButton>(find.byKey(retryConfirmKey)).onPressed,
|
||||
isNotNull,
|
||||
);
|
||||
expect(gateway.retries, hasLength(1));
|
||||
|
||||
await tester.tap(find.byKey(retryConfirmKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.retries, hasLength(2));
|
||||
expect(
|
||||
gateway.retries.last.fields['request_key'],
|
||||
gateway.retries.first.fields['request_key'],
|
||||
);
|
||||
expect(
|
||||
gateway.retries.every((call) => !call.fields.containsKey('retry_mode')),
|
||||
isTrue,
|
||||
);
|
||||
expect(changed.single, equals(retriedRun()));
|
||||
expect(find.byType(AlertDialog), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a restart retry keeps the mode and key across uncertainty', (
|
||||
tester,
|
||||
) async {
|
||||
var attempts = 0;
|
||||
final gateway = FakeRetryGateway((type, fields) async {
|
||||
if (type == 'get_run') throw const NotConnectedError();
|
||||
attempts += 1;
|
||||
if (attempts == 1) throw const ProtocolError('network lost');
|
||||
return {'run_detail': retriedRun()};
|
||||
});
|
||||
await pumpRetry(tester, gateway: gateway, changed: <JsonMap>[]);
|
||||
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(retryRestartKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(retryConfirmKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(retryConfirmKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.retries, hasLength(2));
|
||||
expect(gateway.retries.first.fields['retry_mode'], 'restart');
|
||||
expect(gateway.retries.last.fields['retry_mode'], 'restart');
|
||||
expect(
|
||||
gateway.retries.last.fields['request_key'],
|
||||
gateway.retries.first.fields['request_key'],
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('a deliberate reopen sends a fresh request key', (tester) async {
|
||||
final gateway = FakeRetryGateway((type, fields) async {
|
||||
if (type == 'get_run') throw const NotConnectedError();
|
||||
throw const ProtocolError('server did not answer');
|
||||
});
|
||||
await pumpRetry(tester, gateway: gateway, changed: <JsonMap>[]);
|
||||
|
||||
await _openAndConfirm(tester);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(retryKeepKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await _openAndConfirm(tester);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.retries, hasLength(2));
|
||||
expect(
|
||||
gateway.retries.first.fields['request_key'],
|
||||
isNot(gateway.retries.last.fields['request_key']),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('a restart after a dismissed resume uses a fresh key', (
|
||||
tester,
|
||||
) async {
|
||||
var attempts = 0;
|
||||
final gateway = FakeRetryGateway((type, fields) async {
|
||||
if (type == 'get_run') throw const NotConnectedError();
|
||||
attempts += 1;
|
||||
if (attempts == 1) throw const ProtocolError('resume refused');
|
||||
return {'run_detail': retriedRun()};
|
||||
});
|
||||
await pumpRetry(tester, gateway: gateway, changed: <JsonMap>[]);
|
||||
|
||||
await _openAndConfirm(tester);
|
||||
await tester.pumpAndSettle();
|
||||
// A refusal leaves the prompt open; keep the mode frozen and dismiss.
|
||||
await tester.tap(find.byKey(retryKeepKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(retryRestartKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(retryConfirmKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.retries, hasLength(2));
|
||||
expect(gateway.retries.first.fields.containsKey('retry_mode'), isFalse);
|
||||
expect(gateway.retries.last.fields['retry_mode'], 'restart');
|
||||
expect(
|
||||
gateway.retries.first.fields['request_key'],
|
||||
isNot(gateway.retries.last.fields['request_key']),
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/core/transport/connection_state.dart';
|
||||
import 'package:pipelines_app/features/runs/actions/retry_wording.dart';
|
||||
|
||||
import 'retry_test_support.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('confirm cannot submit twice while the retry is in flight', (
|
||||
tester,
|
||||
) async {
|
||||
final reply = Completer<JsonMap>();
|
||||
final gateway = FakeRetryGateway((type, fields) => reply.future);
|
||||
final changed = <JsonMap>[];
|
||||
await pumpRetry(tester, gateway: gateway, changed: changed);
|
||||
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
final confirm = find.byKey(retryConfirmKey);
|
||||
await tester.tap(confirm);
|
||||
await tester.tap(confirm);
|
||||
await tester.pump();
|
||||
|
||||
expect(gateway.retries, hasLength(1));
|
||||
expect(
|
||||
tester.widget<FilledButton>(find.byKey(retryConfirmKey)).onPressed,
|
||||
isNull,
|
||||
);
|
||||
expect(
|
||||
tester.widget<TextButton>(find.byKey(retryKeepKey)).onPressed,
|
||||
isNull,
|
||||
);
|
||||
expect(find.byType(AlertDialog), findsOneWidget);
|
||||
|
||||
reply.complete({'run_detail': retriedRun()});
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(AlertDialog), findsNothing);
|
||||
expect(changed, hasLength(1));
|
||||
});
|
||||
|
||||
testWidgets('a late retry reply after disposal is ignored safely', (
|
||||
tester,
|
||||
) async {
|
||||
final reply = Completer<JsonMap>();
|
||||
final gateway = FakeRetryGateway((type, fields) => reply.future);
|
||||
final changed = <JsonMap>[];
|
||||
await pumpRetry(tester, gateway: gateway, changed: changed);
|
||||
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(retryConfirmKey));
|
||||
await tester.pump();
|
||||
expect(gateway.retries, hasLength(1));
|
||||
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
reply.complete({'run_detail': retriedRun()});
|
||||
await tester.pump();
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(changed, isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('a late resync after disposal is ignored safely', (tester) async {
|
||||
final resync = Completer<JsonMap>();
|
||||
final gateway = FakeRetryGateway((type, fields) {
|
||||
if (type == 'retry_run') throw const ProtocolError('refused');
|
||||
return resync.future;
|
||||
});
|
||||
final changed = <JsonMap>[];
|
||||
await pumpRetry(tester, gateway: gateway, changed: changed);
|
||||
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(retryConfirmKey));
|
||||
await tester.pump();
|
||||
expect(gateway.calls.map((call) => call.type), ['retry_run', 'get_run']);
|
||||
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
resync.complete({'run_detail': retriedRun()});
|
||||
await tester.pump();
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(changed, isEmpty);
|
||||
});
|
||||
|
||||
testWidgets('both confirmations fit 2x text at a narrow width', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(320, 480);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
final gateway = FakeRetryGateway(
|
||||
(type, fields) async => {'run_detail': retriedRun()},
|
||||
);
|
||||
await pumpRetry(
|
||||
tester,
|
||||
gateway: gateway,
|
||||
changed: <JsonMap>[],
|
||||
cupertino: cupertino,
|
||||
textScale: 2,
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull, reason: 'cupertino=$cupertino');
|
||||
expect(find.text(retryDialogTitle(7)), findsOneWidget);
|
||||
expect(find.text(retryDialogMessage), findsOneWidget);
|
||||
expect(
|
||||
cupertino
|
||||
? find.byType(CupertinoAlertDialog)
|
||||
: find.byType(AlertDialog),
|
||||
findsOneWidget,
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(retryRestartKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull, reason: 'restart=$cupertino');
|
||||
expect(find.text(restartDialogTitle(7)), findsOneWidget);
|
||||
expect(find.text(restartDialogMessage), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(retryKeepKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.calls, isEmpty);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
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_action.dart';
|
||||
|
||||
typedef RetryHandler = Future<JsonMap> Function(String type, JsonMap fields);
|
||||
|
||||
/// A fake gateway that records every request and never owns a socket.
|
||||
class FakeRetryGateway implements ApiGateway {
|
||||
FakeRetryGateway(this.handler);
|
||||
|
||||
final RetryHandler handler;
|
||||
final List<({String type, JsonMap fields})> calls = [];
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
||||
final copy = Map<String, dynamic>.from(fields);
|
||||
calls.add((type: type, fields: copy));
|
||||
return handler(type, copy);
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => const Stream.empty();
|
||||
|
||||
Iterable<({String type, JsonMap fields})> get retries =>
|
||||
calls.where((call) => call.type == 'retry_run');
|
||||
}
|
||||
|
||||
JsonMap failedRun({
|
||||
num id = 7,
|
||||
bool executing = false,
|
||||
String status = 'failed',
|
||||
String title = 'Nightly build',
|
||||
}) => {'id': id, 'title': title, 'status': status, 'executing': executing};
|
||||
|
||||
JsonMap retriedRun({num id = 8}) =>
|
||||
failedRun(id: id, status: 'running', executing: true, title: 'Retry of 7');
|
||||
|
||||
/// Owns the run like a run-detail screen would, so the callback's returned
|
||||
/// server detail is what the action renders next.
|
||||
class RetryHost extends StatefulWidget {
|
||||
const RetryHost({
|
||||
super.key,
|
||||
required this.gateway,
|
||||
required this.initial,
|
||||
required this.changed,
|
||||
});
|
||||
|
||||
final FakeRetryGateway gateway;
|
||||
final JsonMap initial;
|
||||
final List<JsonMap> changed;
|
||||
|
||||
@override
|
||||
State<RetryHost> createState() => _RetryHostState();
|
||||
}
|
||||
|
||||
class _RetryHostState extends State<RetryHost> {
|
||||
late JsonMap _run = widget.initial;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RetryRunAction(
|
||||
run: _run,
|
||||
gateway: widget.gateway,
|
||||
onRunChanged: (run) {
|
||||
widget.changed.add(run);
|
||||
setState(() => _run = run);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Widget retryApp(Widget child, {required bool cupertino, double textScale = 1}) {
|
||||
Widget media(BuildContext context, Widget? app) => MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: TextScaler.linear(textScale)),
|
||||
child: app!,
|
||||
);
|
||||
if (cupertino) {
|
||||
return CupertinoApp(
|
||||
builder: media,
|
||||
home: CupertinoPageScaffold(child: Center(child: child)),
|
||||
);
|
||||
}
|
||||
return MaterialApp(
|
||||
builder: media,
|
||||
home: Scaffold(body: Center(child: child)),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> pumpRetry(
|
||||
WidgetTester tester, {
|
||||
required FakeRetryGateway gateway,
|
||||
required List<JsonMap> changed,
|
||||
bool cupertino = false,
|
||||
double textScale = 1,
|
||||
JsonMap? run,
|
||||
}) async {
|
||||
await tester.pumpWidget(
|
||||
retryApp(
|
||||
RetryHost(
|
||||
gateway: gateway,
|
||||
initial: run ?? failedRun(),
|
||||
changed: changed,
|
||||
),
|
||||
cupertino: cupertino,
|
||||
textScale: textScale,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/schedules/domain/saved_schedule.dart';
|
||||
|
||||
import 'schedule_test_support.dart';
|
||||
|
||||
void main() {
|
||||
test('saved schedule exposes run-configuration provenance', () {
|
||||
final schedule = SavedSchedule(savedRecord());
|
||||
|
||||
expect(schedule.id, 8);
|
||||
expect(schedule.revision, 3);
|
||||
expect(schedule.pipelineId, 4);
|
||||
expect(schedule.version, 2);
|
||||
expect(schedule.name, 'Research batteries');
|
||||
expect(schedule.enabled, isTrue);
|
||||
expect(schedule.prompt, 'Research batteries');
|
||||
expect(schedule.input['custom'], {'nested': 'kept'});
|
||||
expect(schedule.workspace, '/srv/research');
|
||||
expect(schedule.writePaths, ['reports/research.md']);
|
||||
expect(schedule.allowTools, isTrue);
|
||||
expect(schedule.model, 'openai/gpt-5');
|
||||
expect(schedule.stageModels, {'one': 'openai/gpt-5'});
|
||||
expect(schedule.notifyMode, 'off');
|
||||
expect(schedule.title, 'Battery research');
|
||||
expect(schedule.outputFormat, 'markdown');
|
||||
expect(schedule.rule.every, '24h');
|
||||
expect(schedule.rule.days, ['mon', 'wed']);
|
||||
expect(schedule.rule.timezone, 'Europe/London');
|
||||
expect(schedule.rule.isClock, isFalse);
|
||||
expect(schedule.nextDue, '2026-10-22T09:00:00Z');
|
||||
expect(schedule.createdAt, '2026-10-20T09:00:00Z');
|
||||
expect(schedule.updatedAt, '2026-10-21T09:00:00Z');
|
||||
});
|
||||
|
||||
test('unknown fields survive the typed view and pause copy', () {
|
||||
final schedule = SavedSchedule(savedRecord());
|
||||
final paused = schedule.withEnabled(false);
|
||||
|
||||
expect(paused.enabled, isFalse);
|
||||
expect(paused.id, 8);
|
||||
expect(paused.revision, 3);
|
||||
expect(paused.toJson()['future_server_field'], {
|
||||
'nested': [
|
||||
1,
|
||||
2,
|
||||
{'deep': true},
|
||||
],
|
||||
});
|
||||
expect(paused.toJson()['input'], {
|
||||
'prompt': 'Research batteries',
|
||||
'custom': {'nested': 'kept'},
|
||||
});
|
||||
expect(paused.toJson()['rule'], savedRecord()['rule']);
|
||||
|
||||
// The original snapshot is untouched and still enabled.
|
||||
expect(schedule.enabled, isTrue);
|
||||
expect(schedule.revision, 3);
|
||||
});
|
||||
|
||||
test('toJson is a deep copy, not an alias of the server reply', () {
|
||||
final source = savedRecord();
|
||||
final schedule = SavedSchedule(source);
|
||||
|
||||
final first = schedule.toJson();
|
||||
((first['future_server_field'] as Map)['nested'] as List).add('changed');
|
||||
final second = schedule.toJson();
|
||||
expect((second['future_server_field'] as Map)['nested'], [
|
||||
1,
|
||||
2,
|
||||
{'deep': true},
|
||||
]);
|
||||
|
||||
final promptInput = schedule.input;
|
||||
promptInput['custom'] = 'changed';
|
||||
expect(schedule.input['custom'], {'nested': 'kept'});
|
||||
});
|
||||
|
||||
test('missing fields stay absent instead of being fabricated', () {
|
||||
final schedule = SavedSchedule(const {});
|
||||
|
||||
expect(schedule.id, isNull);
|
||||
expect(schedule.revision, isNull);
|
||||
expect(schedule.pipelineId, isNull);
|
||||
expect(schedule.version, isNull);
|
||||
expect(schedule.enabled, isFalse);
|
||||
expect(schedule.prompt, '');
|
||||
expect(schedule.workspace, '');
|
||||
expect(schedule.rule.every, '');
|
||||
expect(schedule.rule.times, isEmpty);
|
||||
expect(schedule.writePaths, isEmpty);
|
||||
expect(schedule.stageModels, isEmpty);
|
||||
expect(schedule.toJson(), isEmpty);
|
||||
});
|
||||
|
||||
test('a fractional revision is not truncated into a false token', () {
|
||||
final schedule = SavedSchedule(const {'id': 8, 'revision': 3.5});
|
||||
|
||||
expect(schedule.id, 8);
|
||||
expect(schedule.revision, isNull);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
|
||||
class RecordedCall {
|
||||
const RecordedCall(this.type, this.fields);
|
||||
final String type;
|
||||
final JsonMap fields;
|
||||
}
|
||||
|
||||
/// Records the exact request built by the repository and replays queued
|
||||
/// replies. Both are deep-copied, so a test can prove the repository neither
|
||||
/// mutated its input nor depended on alias mutation of a reply.
|
||||
class RecordingGateway implements ApiGateway {
|
||||
final calls = <RecordedCall>[];
|
||||
final replies = <JsonMap>[];
|
||||
Object? failure;
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
||||
calls.add(RecordedCall(type, deepCopy(fields)));
|
||||
if (failure case final error?) throw error;
|
||||
if (replies.isEmpty) throw StateError('No recorded reply for $type');
|
||||
return deepCopy(replies.removeAt(0));
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => const Stream.empty();
|
||||
}
|
||||
|
||||
JsonMap deepCopy(JsonMap value) => jsonDecode(jsonEncode(value)) as JsonMap;
|
||||
|
||||
/// A complete server record including fields this client does not interpret
|
||||
/// yet, an unknown nested rule field and unknown input.
|
||||
JsonMap savedRecord() => {
|
||||
'id': 8,
|
||||
'revision': 3,
|
||||
'name': 'Research batteries',
|
||||
'pipeline_id': 4,
|
||||
'version': 2,
|
||||
'enabled': true,
|
||||
'input': {
|
||||
'prompt': 'Research batteries',
|
||||
'custom': {'nested': 'kept'},
|
||||
},
|
||||
'workspace': '/srv/research',
|
||||
'write_paths': ['reports/research.md'],
|
||||
'allow_tools': true,
|
||||
'model': 'openai/gpt-5',
|
||||
'stage_models': {'one': 'openai/gpt-5'},
|
||||
'notify_mode': 'off',
|
||||
'title': 'Battery research',
|
||||
'output_format': 'markdown',
|
||||
'rule': {
|
||||
'every': '24h',
|
||||
'days': ['mon', 'wed'],
|
||||
'timezone': 'Europe/London',
|
||||
'future_rule_field': 'kept',
|
||||
},
|
||||
'next_due': '2026-10-22T09:00:00Z',
|
||||
'created_at': '2026-10-20T09:00:00Z',
|
||||
'updated_at': '2026-10-21T09:00:00Z',
|
||||
'future_server_field': {
|
||||
'nested': [
|
||||
1,
|
||||
2,
|
||||
{'deep': true},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
/// The create form of the record: id 0 is the server's create sentinel and no
|
||||
/// revision has been issued yet.
|
||||
JsonMap createRecord() => {
|
||||
'id': 0,
|
||||
'name': 'Research batteries',
|
||||
'pipeline_id': 4,
|
||||
'version': 2,
|
||||
'enabled': true,
|
||||
'input': {'prompt': 'Research batteries'},
|
||||
'workspace': '/srv/research',
|
||||
'rule': {'every': '24h', 'timezone': 'Europe/London'},
|
||||
};
|
||||
@@ -0,0 +1,131 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/transport/connection_state.dart';
|
||||
import 'package:pipelines_app/features/schedules/data/schedules_repository.dart';
|
||||
|
||||
import 'schedule_test_support.dart';
|
||||
|
||||
void main() {
|
||||
test('delete sends the exact ID and expected revision', () async {
|
||||
final gateway = RecordingGateway()
|
||||
..replies.add({'type': 'schedule_deleted', 'schedule_id': 8});
|
||||
final repository = SchedulesRepository(gateway);
|
||||
|
||||
await repository.deleteSchedule(8, 3);
|
||||
|
||||
expect(gateway.calls.single.type, 'delete_schedule');
|
||||
expect(gateway.calls.single.fields, {
|
||||
'schedule_id': 8,
|
||||
'expected_revision': 3,
|
||||
});
|
||||
});
|
||||
|
||||
test('delete refuses a confirmation for anything else', () async {
|
||||
final gateway = RecordingGateway();
|
||||
final repository = SchedulesRepository(gateway);
|
||||
for (final reply in [
|
||||
<String, dynamic>{},
|
||||
{'type': 'pong'},
|
||||
{'type': 'schedule_deleted'},
|
||||
{'type': 'schedule_deleted', 'schedule_id': 9},
|
||||
]) {
|
||||
gateway.replies.add(reply);
|
||||
await expectLater(
|
||||
repository.deleteSchedule(8, 3),
|
||||
throwsA(
|
||||
isA<SchedulesRepositoryException>().having(
|
||||
(error) => error.message,
|
||||
'message',
|
||||
'The server did not confirm deletion of this schedule.',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('server refusals and conflicts propagate verbatim', () async {
|
||||
final conflict = const ProtocolError(
|
||||
'schedule revision conflict; reload before editing',
|
||||
);
|
||||
final recording = RecordingGateway()..failure = conflict;
|
||||
final conflicting = SchedulesRepository(recording);
|
||||
await expectLater(
|
||||
conflicting.saveSchedule(createRecord()),
|
||||
throwsA(same(conflict)),
|
||||
);
|
||||
await expectLater(
|
||||
conflicting.deleteSchedule(8, 3),
|
||||
throwsA(same(conflict)),
|
||||
);
|
||||
|
||||
final unsupported = const ProtocolError(
|
||||
'unknown message type: list_schedules',
|
||||
);
|
||||
recording.failure = unsupported;
|
||||
await expectLater(
|
||||
conflicting.listSchedules(pipelineId: 4),
|
||||
throwsA(same(unsupported)),
|
||||
);
|
||||
});
|
||||
|
||||
test('missing and empty list replies are different facts', () async {
|
||||
final gateway = RecordingGateway();
|
||||
final repository = SchedulesRepository(gateway);
|
||||
|
||||
gateway.replies.add({'type': 'schedules'});
|
||||
expect(await repository.listSchedules(), isEmpty);
|
||||
|
||||
gateway.replies.add({'type': 'schedules', 'schedules': null});
|
||||
expect(await repository.listSchedules(), isEmpty);
|
||||
|
||||
for (final reply in [
|
||||
<String, dynamic>{},
|
||||
{'type': 'pong'},
|
||||
{'type': 'schedules', 'schedules': <String, dynamic>{}},
|
||||
{
|
||||
'type': 'schedules',
|
||||
'schedules': ['not a record'],
|
||||
},
|
||||
]) {
|
||||
gateway.replies.add(reply);
|
||||
await expectLater(
|
||||
repository.listSchedules(),
|
||||
throwsA(isA<SchedulesRepositoryException>()),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('save requires a saved schedule in the reply', () async {
|
||||
final gateway = RecordingGateway();
|
||||
final repository = SchedulesRepository(gateway);
|
||||
for (final reply in [
|
||||
<String, dynamic>{},
|
||||
{'type': 'schedule'},
|
||||
{'type': 'schedule', 'schedule': null},
|
||||
{'type': 'schedule', 'schedule': 'record'},
|
||||
]) {
|
||||
gateway.replies.add(reply);
|
||||
await expectLater(
|
||||
repository.saveSchedule(createRecord()),
|
||||
throwsA(
|
||||
isA<SchedulesRepositoryException>().having(
|
||||
(error) => error.message,
|
||||
'message',
|
||||
'The server returned no saved schedule.',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('an empty schedule object is not turned into a fake identity', () async {
|
||||
final gateway = RecordingGateway()
|
||||
..replies.add({'type': 'schedule', 'schedule': <String, dynamic>{}});
|
||||
final repository = SchedulesRepository(gateway);
|
||||
|
||||
final saved = await repository.saveSchedule(createRecord());
|
||||
|
||||
expect(saved.id, isNull);
|
||||
expect(saved.revision, isNull);
|
||||
expect(saved.toJson(), isEmpty);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/schedules/data/schedules_repository.dart';
|
||||
|
||||
import 'schedule_test_support.dart';
|
||||
|
||||
void main() {
|
||||
test(
|
||||
'list rejects non-positive and unsafe pipeline IDs before sending',
|
||||
() async {
|
||||
final gateway = RecordingGateway();
|
||||
final repository = SchedulesRepository(gateway);
|
||||
|
||||
for (final id in [0, -1, 9007199254740992]) {
|
||||
await expectLater(
|
||||
repository.listSchedules(pipelineId: id),
|
||||
throwsA(
|
||||
isA<SchedulesRepositoryException>().having(
|
||||
(error) => error.message,
|
||||
'message',
|
||||
'A positive pipeline ID is required.',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
expect(gateway.calls, isEmpty);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'delete rejects an inexact identity or revision before sending',
|
||||
() async {
|
||||
final gateway = RecordingGateway();
|
||||
final repository = SchedulesRepository(gateway);
|
||||
|
||||
for (final pair in [
|
||||
(0, 1),
|
||||
(-1, 1),
|
||||
(8, 0),
|
||||
(8, -1),
|
||||
(8, 9007199254740992),
|
||||
]) {
|
||||
await expectLater(
|
||||
repository.deleteSchedule(pair.$1, pair.$2),
|
||||
throwsA(
|
||||
isA<SchedulesRepositoryException>().having(
|
||||
(error) => error.message,
|
||||
'message',
|
||||
'An exact schedule ID and revision are required.',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
expect(gateway.calls, isEmpty);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'request keys are bounded at 128 characters like the web client',
|
||||
() async {
|
||||
final gateway = RecordingGateway();
|
||||
final repository = SchedulesRepository(gateway);
|
||||
|
||||
await expectLater(
|
||||
repository.saveSchedule(createRecord(), requestKey: 'x' * 129),
|
||||
throwsA(
|
||||
isA<SchedulesRepositoryException>().having(
|
||||
(error) => error.message,
|
||||
'message',
|
||||
'Schedule request keys must be strings of at most 128 characters.',
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(gateway.calls, isEmpty);
|
||||
|
||||
final key = 'x' * 128;
|
||||
gateway.replies.add({'type': 'schedule', 'schedule': savedRecord()});
|
||||
await repository.saveSchedule(createRecord(), requestKey: key);
|
||||
expect(gateway.calls.single.fields['request_key'], key);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/schedules/data/schedules_repository.dart';
|
||||
import 'package:pipelines_app/features/schedules/domain/saved_schedule.dart';
|
||||
|
||||
import 'schedule_test_support.dart';
|
||||
|
||||
void main() {
|
||||
test(
|
||||
'lists with the exact web envelope and retains every record field',
|
||||
() async {
|
||||
final record = savedRecord();
|
||||
final gateway = RecordingGateway()
|
||||
..replies.add({
|
||||
'type': 'schedules',
|
||||
'schedules': [record],
|
||||
});
|
||||
final repository = SchedulesRepository(gateway);
|
||||
|
||||
final listed = await repository.listSchedules(pipelineId: 4);
|
||||
|
||||
expect(gateway.calls.single.type, 'list_schedules');
|
||||
expect(gateway.calls.single.fields, {'pipeline_id': 4});
|
||||
expect(listed.single.toJson(), record);
|
||||
expect(listed.single.pipelineId, 4);
|
||||
expect(listed.single.version, 2);
|
||||
expect(listed.single.prompt, 'Research batteries');
|
||||
expect(listed.single.workspace, '/srv/research');
|
||||
expect(listed.single.enabled, isTrue);
|
||||
expect(listed.single.rule.every, '24h');
|
||||
expect(listed.single.rule.days, ['mon', 'wed']);
|
||||
expect(listed.single.rule.timezone, 'Europe/London');
|
||||
expect(listed.single.model, 'openai/gpt-5');
|
||||
expect(listed.single.notifyMode, 'off');
|
||||
expect(listed.single.toJson()['future_server_field'], {
|
||||
'nested': [
|
||||
1,
|
||||
2,
|
||||
{'deep': true},
|
||||
],
|
||||
});
|
||||
|
||||
gateway.replies.add({'type': 'schedules'});
|
||||
await repository.listSchedules();
|
||||
expect(gateway.calls.last.type, 'list_schedules');
|
||||
expect(gateway.calls.last.fields, isEmpty);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'create sends the web sentinel record without inventing a revision',
|
||||
() async {
|
||||
final create = createRecord();
|
||||
final original = deepCopy(create);
|
||||
final gateway = RecordingGateway()
|
||||
..replies.add({'type': 'schedule', 'schedule': savedRecord()});
|
||||
final repository = SchedulesRepository(gateway);
|
||||
|
||||
final saved = await repository.saveSchedule(create);
|
||||
|
||||
expect(gateway.calls.single.type, 'save_schedule');
|
||||
expect(gateway.calls.single.fields, {'schedule': create});
|
||||
expect(gateway.calls.single.fields.containsKey('request_key'), isFalse);
|
||||
expect(
|
||||
gateway.calls.single.fields.containsKey('expected_revision'),
|
||||
isFalse,
|
||||
);
|
||||
expect(create, original, reason: 'the caller record must be unchanged');
|
||||
expect(saved.id, 8);
|
||||
expect(saved.revision, 3);
|
||||
expect(saved.toJson(), savedRecord());
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'a stable create key is forwarded exactly and blanks are omitted',
|
||||
() async {
|
||||
final create = createRecord();
|
||||
final gateway = RecordingGateway();
|
||||
final repository = SchedulesRepository(gateway);
|
||||
|
||||
gateway.replies.add({'type': 'schedule', 'schedule': savedRecord()});
|
||||
await repository.saveSchedule(
|
||||
create,
|
||||
requestKey: 'schedule:stable-editor-key',
|
||||
);
|
||||
expect(gateway.calls.last.fields, {
|
||||
'schedule': create,
|
||||
'request_key': 'schedule:stable-editor-key',
|
||||
});
|
||||
|
||||
gateway.replies.add({'type': 'schedule', 'schedule': savedRecord()});
|
||||
await repository.saveSchedule(create, requestKey: '');
|
||||
expect(gateway.calls.last.fields, {'schedule': create});
|
||||
},
|
||||
);
|
||||
|
||||
test('update reuses the read revision as the CAS token', () async {
|
||||
final current = SavedSchedule(savedRecord());
|
||||
final paused = current.withEnabled(false);
|
||||
expect(paused.id, 8);
|
||||
expect(paused.revision, 3);
|
||||
expect(paused.toJson()['future_server_field'], isNotNull);
|
||||
|
||||
final gateway = RecordingGateway()
|
||||
..replies.add({
|
||||
'type': 'schedule',
|
||||
'schedule': {...savedRecord(), 'enabled': false, 'revision': 4},
|
||||
});
|
||||
final repository = SchedulesRepository(gateway);
|
||||
|
||||
final updated = await repository.saveSchedule(paused.toJson());
|
||||
|
||||
final body = gateway.calls.single.fields['schedule'] as Map;
|
||||
expect(gateway.calls.single.type, 'save_schedule');
|
||||
expect(gateway.calls.single.fields.containsKey('request_key'), isFalse);
|
||||
expect(
|
||||
gateway.calls.single.fields.containsKey('expected_revision'),
|
||||
isFalse,
|
||||
);
|
||||
expect(body['id'], 8);
|
||||
expect(body['revision'], 3);
|
||||
expect(body['enabled'], isFalse);
|
||||
expect(body['future_server_field'], isNotNull);
|
||||
expect(updated.revision, 4);
|
||||
expect(updated.enabled, isFalse);
|
||||
|
||||
// The stale draft keeps its token: a conflict must not be papered over by
|
||||
// silently adopting the reply revision.
|
||||
expect(current.revision, 3);
|
||||
expect(current.enabled, isTrue);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user