merge(app): land retry and restart actions in the native run detail
This commit is contained in:
@@ -40,6 +40,22 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
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 {
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
@TestOn('browser')
|
||||
library;
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/runs/actions/retry_intent.dart';
|
||||
|
||||
void main() {
|
||||
test('a fresh key uses the full entropy bound under dart2js', () {
|
||||
// `1 << 32` compiles to 0 on the web, so Random.nextInt threw a RangeError
|
||||
// and no retry request was ever sent. Generating without an injected
|
||||
// random value exercises the real bound; a VM test cannot catch this
|
||||
// class of bug, so this file runs only in a browser:
|
||||
//
|
||||
// flutter test --platform chrome \
|
||||
// test/features/runs/actions/retry_intent_web_test.dart
|
||||
final keys = <String>{};
|
||||
for (var index = 0; index < 32; index++) {
|
||||
final key = newRetryRequestKey(7);
|
||||
expect(key, startsWith('app-retry-7-'));
|
||||
expect(key.length, lessThanOrEqualTo(128));
|
||||
keys.add(key);
|
||||
}
|
||||
expect(keys, hasLength(32));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/transport/connection_state.dart';
|
||||
import 'package:pipelines_app/features/runs/actions/retry_wording.dart';
|
||||
import 'package:pipelines_app/features/runs/actions/title_wording.dart';
|
||||
|
||||
import 'run_retry_wiring_support.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('a reply without an id never opens a guessed run', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = RetryWiringGateway();
|
||||
addTearDown(gateway.framesController.close);
|
||||
final opened = <int>[];
|
||||
await mountRetryScreen(
|
||||
tester,
|
||||
gateway,
|
||||
cupertino: false,
|
||||
onRunSelected: opened.add,
|
||||
);
|
||||
|
||||
await confirmRetry(tester);
|
||||
gateway.retries.last.complete({
|
||||
'run_detail': {'title': 'Unknown run', 'status': 'running'},
|
||||
});
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(opened, isEmpty);
|
||||
expect(find.text(retryFailedTitle), findsOneWidget);
|
||||
expect(find.text('Unknown run'), findsNothing);
|
||||
expect(gateway.calls.where((call) => call.type == 'get_run'), hasLength(1));
|
||||
});
|
||||
|
||||
testWidgets('a refused retry stays on the failed run', (tester) async {
|
||||
final gateway = RetryWiringGateway();
|
||||
addTearDown(gateway.framesController.close);
|
||||
final opened = <int>[];
|
||||
await mountRetryScreen(
|
||||
tester,
|
||||
gateway,
|
||||
cupertino: false,
|
||||
onRunSelected: opened.add,
|
||||
);
|
||||
|
||||
await confirmRetry(tester);
|
||||
gateway.refuseRetry(const ProtocolError('the run is still executing'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('the run is still executing'), findsOneWidget);
|
||||
expect(opened, isEmpty);
|
||||
expect(find.text(retryFailedTitle), findsOneWidget);
|
||||
await tester.tap(find.byKey(retryKeepKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(retryActionKey), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a retry reply that lands after leaving is ignored', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = RetryWiringGateway();
|
||||
addTearDown(gateway.framesController.close);
|
||||
final opened = <int>[];
|
||||
await mountRetryScreen(
|
||||
tester,
|
||||
gateway,
|
||||
cupertino: false,
|
||||
onRunSelected: opened.add,
|
||||
);
|
||||
|
||||
await confirmRetry(tester);
|
||||
expect(gateway.retryCalls, hasLength(1));
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
gateway.acceptRetry(retryCreatedDetail());
|
||||
await tester.pump();
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(opened, isEmpty);
|
||||
expect(gateway.calls.where((call) => call.type == 'get_run'), hasLength(1));
|
||||
});
|
||||
|
||||
testWidgets('a reply naming the source run opens nothing', (tester) async {
|
||||
final gateway = RetryWiringGateway();
|
||||
addTearDown(gateway.framesController.close);
|
||||
final opened = <int>[];
|
||||
await mountRetryScreen(
|
||||
tester,
|
||||
gateway,
|
||||
cupertino: false,
|
||||
onRunSelected: opened.add,
|
||||
);
|
||||
|
||||
await confirmRetry(tester);
|
||||
gateway.acceptRetry(retryCreatedDetail(id: 7));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// The accepted detail still folds, but its id is the source run, so there
|
||||
// is no new run to open and no second read.
|
||||
expect(opened, isEmpty);
|
||||
expect(find.text(retryCreatedTitle), findsOneWidget);
|
||||
expect(gateway.calls.where((call) => call.type == 'get_run'), hasLength(1));
|
||||
});
|
||||
|
||||
testWidgets('a failed run that is still executing exposes no retry', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = RetryWiringGateway(executing: true);
|
||||
addTearDown(gateway.framesController.close);
|
||||
await mountRetryScreen(tester, gateway, cupertino: false);
|
||||
|
||||
expect(find.byKey(runTitleActionKey), findsOneWidget);
|
||||
expect(find.byKey(retryActionKey), findsNothing);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/runs/actions/cancel_wording.dart';
|
||||
import 'package:pipelines_app/features/runs/actions/retry_wording.dart';
|
||||
import 'package:pipelines_app/features/runs/actions/title_wording.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_detail_actions.dart';
|
||||
|
||||
import 'run_retry_wiring_support.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('a hidden retry adds no extra gap for Rename and Cancel', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = RetryWiringGateway();
|
||||
addTearDown(gateway.framesController.close);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: RunDetailActions(
|
||||
run: retryCreatedDetail(id: 7),
|
||||
gateway: gateway,
|
||||
onRunChanged: (_) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Retry is not eligible on the running run and must not consume spacing.
|
||||
expect(find.byKey(retryActionKey), findsNothing);
|
||||
final rename = tester.getRect(find.byKey(runTitleActionKey));
|
||||
final cancel = tester.getRect(find.byKey(cancelActionKey));
|
||||
expect(cancel.left - rename.right, closeTo(8, 0.5));
|
||||
});
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets('adjacent actions keep native spacing at 320 px ($cupertino)', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(320, 480);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
final gateway = RetryWiringGateway();
|
||||
addTearDown(gateway.framesController.close);
|
||||
final row = Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: RunDetailActions(
|
||||
run: retryFailedDetail(),
|
||||
gateway: gateway,
|
||||
onRunChanged: (_) {},
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(
|
||||
home: CupertinoPageScaffold(child: SafeArea(child: row)),
|
||||
)
|
||||
: MaterialApp(home: Scaffold(body: row)),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expectNativeActionSpacing(tester);
|
||||
});
|
||||
}
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets('320 px at 2x keeps Rename and Retry reachable ($cupertino)', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(320, 480);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
final gateway = RetryWiringGateway();
|
||||
addTearDown(gateway.framesController.close);
|
||||
Widget scale(BuildContext context, Widget? app) => MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: const TextScaler.linear(2)),
|
||||
child: app!,
|
||||
);
|
||||
// The action row itself, in the detail's 16 px inset, so the narrow
|
||||
// accessibility state is measured without unrelated header controls.
|
||||
final row = Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: RunDetailActions(
|
||||
run: retryFailedDetail(),
|
||||
gateway: gateway,
|
||||
onRunChanged: (_) {},
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(
|
||||
builder: scale,
|
||||
home: CupertinoPageScaffold(child: SafeArea(child: row)),
|
||||
)
|
||||
: MaterialApp(
|
||||
builder: scale,
|
||||
home: Scaffold(body: row),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byKey(runTitleActionKey).hitTestable(), findsOneWidget);
|
||||
expect(find.byKey(retryActionKey).hitTestable(), findsOneWidget);
|
||||
final rect = tester.getRect(find.byKey(retryActionKey));
|
||||
expect(rect.left, greaterThanOrEqualTo(0));
|
||||
expect(rect.right, lessThanOrEqualTo(320));
|
||||
expectNativeActionSpacing(tester);
|
||||
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text(retryDialogTitle(7)), findsOneWidget);
|
||||
await tester.tap(find.byKey(retryKeepKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.retryCalls, isEmpty);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Asserts the action row uses the detail's native 8 dp / 4 dp spacing.
|
||||
///
|
||||
/// The row previously had no `spacing`, leaving the outlined Rename border
|
||||
/// touching the filled Retry button; browser measurement at 320 px reported a
|
||||
/// 0.008 px gap. A hidden action must not consume spacing either.
|
||||
void expectNativeActionSpacing(WidgetTester tester) {
|
||||
final rename = tester.getRect(find.byKey(runTitleActionKey));
|
||||
final retry = tester.getRect(find.byKey(retryActionKey));
|
||||
final sameRow = retry.top < rename.bottom && rename.top < retry.bottom;
|
||||
if (sameRow) {
|
||||
expect(
|
||||
retry.left - rename.right,
|
||||
greaterThanOrEqualTo(8 - 0.01),
|
||||
reason: 'side-by-side actions need the 8 dp Wrap spacing',
|
||||
);
|
||||
} else {
|
||||
expect(
|
||||
retry.top - rename.bottom,
|
||||
greaterThanOrEqualTo(4 - 0.01),
|
||||
reason: 'wrapped actions need the 4 dp Wrap run spacing',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
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/features/runs/actions/retry_wording.dart';
|
||||
import 'package:pipelines_app/features/runs/screen.dart';
|
||||
|
||||
const retryFailedTitle = 'Fixture failed run';
|
||||
const retryCreatedTitle = 'Retry of fixture';
|
||||
|
||||
JsonMap retryFailedDetail({bool executing = false}) => {
|
||||
'id': 7,
|
||||
'title': retryFailedTitle,
|
||||
'name': 'fixture',
|
||||
'status': 'failed',
|
||||
'executing': executing,
|
||||
'input': {'prompt': 'the stored prompt'},
|
||||
'steps': const <JsonMap>[],
|
||||
};
|
||||
|
||||
JsonMap retryCreatedDetail({num id = 8}) => {
|
||||
'id': id,
|
||||
'title': retryCreatedTitle,
|
||||
'name': 'fixture',
|
||||
'status': 'running',
|
||||
'executing': true,
|
||||
'retry_of': 7,
|
||||
'input': {'prompt': 'the stored prompt'},
|
||||
'steps': const <JsonMap>[],
|
||||
};
|
||||
|
||||
JsonMap _summary(JsonMap run) => {
|
||||
'id': run['id'],
|
||||
'title': run['title'],
|
||||
'name': run['name'],
|
||||
'status': run['status'],
|
||||
'executing': run['executing'] ?? false,
|
||||
};
|
||||
|
||||
/// Serves the same envelopes as the app server and holds each retry reply until
|
||||
/// the test releases it, so nothing can be applied optimistically.
|
||||
class RetryWiringGateway implements ApiGateway {
|
||||
RetryWiringGateway({bool executing = false}) {
|
||||
details[7] = retryFailedDetail(executing: executing);
|
||||
}
|
||||
|
||||
final framesController = StreamController<JsonMap>.broadcast();
|
||||
final calls = <({String type, JsonMap fields})>[];
|
||||
final retries = <Completer<JsonMap>>[];
|
||||
final details = <num, JsonMap>{};
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => framesController.stream;
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
||||
calls.add((type: type, fields: Map<String, dynamic>.from(fields)));
|
||||
switch (type) {
|
||||
case 'list_runs':
|
||||
return Future.value({
|
||||
'runs': [for (final run in details.values) _summary(run)],
|
||||
});
|
||||
case 'get_run':
|
||||
final id = fields['run_id'] as num;
|
||||
return Future.value({'run_detail': details[id] ?? retryFailedDetail()});
|
||||
case 'retry_run':
|
||||
final reply = Completer<JsonMap>();
|
||||
retries.add(reply);
|
||||
return reply.future;
|
||||
}
|
||||
return Future.error(UnsupportedError(type));
|
||||
}
|
||||
|
||||
Iterable<({String type, JsonMap fields})> get retryCalls =>
|
||||
calls.where((call) => call.type == 'retry_run');
|
||||
|
||||
void acceptRetry(JsonMap detail) {
|
||||
details[detail['id'] as num] = detail;
|
||||
retries.last.complete({'run_detail': detail});
|
||||
}
|
||||
|
||||
void refuseRetry(Object error) => retries.last.completeError(error);
|
||||
}
|
||||
|
||||
Future<void> mountRetryScreen(
|
||||
WidgetTester tester,
|
||||
RetryWiringGateway gateway, {
|
||||
required bool cupertino,
|
||||
ValueChanged<int>? onRunSelected,
|
||||
}) async {
|
||||
final screen = RunsScreen(
|
||||
gateway: gateway,
|
||||
initialRunId: 7,
|
||||
onRunSelected: onRunSelected,
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(
|
||||
home: CupertinoPageScaffold(child: SafeArea(child: screen)),
|
||||
)
|
||||
: MaterialApp(home: Scaffold(body: screen)),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Future<void> confirmRetry(WidgetTester tester) async {
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(retryConfirmKey));
|
||||
await tester.pump();
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/runs/actions/cancel_wording.dart';
|
||||
import 'package:pipelines_app/features/runs/actions/retry_wording.dart';
|
||||
import 'package:pipelines_app/features/runs/actions/title_wording.dart';
|
||||
|
||||
import 'run_retry_wiring_support.dart';
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets(
|
||||
'accepted retry reply opens the server-identified run ($cupertino)',
|
||||
(tester) async {
|
||||
final gateway = RetryWiringGateway();
|
||||
addTearDown(gateway.framesController.close);
|
||||
final opened = <int>[];
|
||||
await mountRetryScreen(
|
||||
tester,
|
||||
gateway,
|
||||
cupertino: cupertino,
|
||||
onRunSelected: opened.add,
|
||||
);
|
||||
|
||||
expect(find.text(retryFailedTitle), findsOneWidget);
|
||||
expect(find.byKey(runTitleActionKey), findsOneWidget);
|
||||
expect(find.byKey(retryActionKey), findsOneWidget);
|
||||
expect(find.byKey(cancelActionKey), findsNothing);
|
||||
expect(gateway.retryCalls, isEmpty);
|
||||
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text(retryDialogTitle(7)), findsOneWidget);
|
||||
expect(find.text(retryDialogMessage), findsOneWidget);
|
||||
expect(gateway.retryCalls, isEmpty);
|
||||
|
||||
await tester.tap(find.byKey(retryKeepKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.retryCalls, isEmpty);
|
||||
expect(opened, isEmpty);
|
||||
expect(find.byKey(retryActionKey), findsOneWidget);
|
||||
|
||||
await confirmRetry(tester);
|
||||
expect(gateway.retryCalls, hasLength(1));
|
||||
final fields = gateway.retryCalls.single.fields;
|
||||
expect(fields.keys.toSet(), {'run_id', 'request_key'});
|
||||
expect(fields['run_id'], 7);
|
||||
expect(fields['request_key'], startsWith('app-retry-7-'));
|
||||
expect(
|
||||
(fields['request_key'] as String).length,
|
||||
lessThanOrEqualTo(128),
|
||||
);
|
||||
// The prompt closes only from server truth; no navigation is guessed.
|
||||
expect(opened, isEmpty);
|
||||
expect(find.text(retryFailedTitle), findsOneWidget);
|
||||
|
||||
gateway.acceptRetry(retryCreatedDetail());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(opened, [8]);
|
||||
expect(find.text(retryCreatedTitle), findsOneWidget);
|
||||
expect(find.text(retryFailedTitle), findsNothing);
|
||||
expect(find.byKey(retryActionKey), findsNothing);
|
||||
expect(
|
||||
gateway.calls.where((call) => call.type == 'get_run').last.fields,
|
||||
{'run_id': 8},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('restart sends its explicit mode through the real detail row', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = RetryWiringGateway();
|
||||
addTearDown(gateway.framesController.close);
|
||||
final opened = <int>[];
|
||||
await mountRetryScreen(
|
||||
tester,
|
||||
gateway,
|
||||
cupertino: false,
|
||||
onRunSelected: opened.add,
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(retryActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(retryRestartKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text(restartDialogTitle(7)), findsOneWidget);
|
||||
await tester.tap(find.byKey(retryConfirmKey));
|
||||
await tester.pump();
|
||||
|
||||
final fields = gateway.retryCalls.single.fields;
|
||||
expect(fields.keys.toSet(), {'run_id', 'request_key', 'retry_mode'});
|
||||
expect(fields['run_id'], 7);
|
||||
expect(fields['retry_mode'], 'restart');
|
||||
expect(fields['request_key'], startsWith('app-retry-7-'));
|
||||
|
||||
gateway.acceptRetry(retryCreatedDetail());
|
||||
await tester.pumpAndSettle();
|
||||
expect(opened, [8]);
|
||||
expect(find.text(retryCreatedTitle), findsOneWidget);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user