364fd5b538
Keep the Material-only run action behavior while preserving public Cupertino parameters for callers that will be cleaned up separately. Narrow the related tests to the supported Material path.
184 lines
6.6 KiB
Dart
184 lines
6.6 KiB
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',
|
|
);
|
|
});
|
|
|
|
test('the full entropy width still forms a bounded request key', () {
|
|
// The web build once rejected every retry because `1 << 32` is 0 there;
|
|
// the generator now uses a literal 2^32 bound. This pins the largest
|
|
// entropy value it may consume.
|
|
final key = newRetryRequestKey(
|
|
7,
|
|
now: DateTime.utc(2026, 1, 1),
|
|
random: 0xFFFFFFFF,
|
|
);
|
|
expect(
|
|
key,
|
|
'app-retry-7-${DateTime.utc(2026, 1, 1).microsecondsSinceEpoch}-1z141z3',
|
|
);
|
|
expect(key.length, lessThanOrEqualTo(128));
|
|
});
|
|
|
|
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);
|
|
// One native run-action style: outlined on Material.
|
|
expect(find.byType(OutlinedButton), 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('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 (label, run, visible) in cases) {
|
|
await tester.pumpWidget(
|
|
retryApp(
|
|
RetryHost(
|
|
key: ValueKey(label),
|
|
gateway: gateway,
|
|
initial: run,
|
|
changed: changed,
|
|
),
|
|
),
|
|
);
|
|
expect(
|
|
find.byKey(retryActionKey),
|
|
visible ? findsOneWidget : findsNothing,
|
|
reason: label,
|
|
);
|
|
}
|
|
expect(gateway.calls, isEmpty);
|
|
expect(changed, isEmpty);
|
|
});
|
|
}
|