Skip to content

Commit 69eefc2

Browse files
committed
[red] cover multi-delete lifecycle regressions
Signed-off-by: Viwat Vchirawongkwin <viwat.v@chula.ac.th>
1 parent 5f07311 commit 69eefc2

2 files changed

Lines changed: 215 additions & 11 deletions

File tree

‎app/test/unit/file_explorer_controller_test.dart‎

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ final class _HeldGetConnection extends RecordingConnection {
5959
/// shared test support deliberately need no bulk-delete-specific hooks.
6060
final class _BatchDeleteConnection extends RecordingConnection
6161
implements ConnectionSessionStampSource {
62-
_BatchDeleteConnection({DeviceInfo? deviceInfo})
63-
: super(initial: ConnState.ready, deviceInfo: deviceInfo);
62+
_BatchDeleteConnection({super.deviceInfo}) : super(initial: ConnState.ready);
6463

6564
Object _sessionStamp = Object();
6665
int _deleteOrdinal = 0;
@@ -490,7 +489,7 @@ void main() {
490489

491490
group('ADR-0043 FileExplorerController.deleteMany', () {
492491
test(
493-
'dedupes in display order, reports item progress, and reconciles once',
492+
'deletes in display order, reports item progress, and reconciles once',
494493
() async {
495494
final h = await batchReady(
496495
files: <String>['z.py', 'Alpha.py', 'middle.txt'],
@@ -499,7 +498,7 @@ void main() {
499498
<FileDeleteBatchProgress>[];
500499

501500
final FileDeleteBatchResult result = await ctrl(h.container).deleteMany(
502-
<String>['z.py', 'middle.txt', 'z.py', 'Alpha.py'],
501+
<String>['z.py', 'middle.txt', 'Alpha.py'],
503502
expectedCwd: '/',
504503
expectedSessionStamp: h.connection.connectionSessionStamp,
505504
onProgress: progress.add,
@@ -548,6 +547,22 @@ void main() {
548547
},
549548
);
550549

550+
test('rejects a duplicate selection before board I/O', () async {
551+
final h = await batchReady(files: <String>['alpha.py', 'beta.py']);
552+
553+
final FileDeleteBatchResult result = await ctrl(
554+
h.container,
555+
).deleteMany(<String>['beta.py', 'alpha.py', 'beta.py']);
556+
557+
expect(result.outcome, FileDeleteBatchOutcome.failed);
558+
expect(result.failure, FileErrorKind.badRequest);
559+
expect(result.succeededPaths, isEmpty);
560+
expect(result.failedPath, isNull);
561+
expect(result.unattemptedPaths, isEmpty);
562+
expect(h.connection.attemptedDeletePaths, isEmpty);
563+
expect(h.connection.listedPaths, isEmpty);
564+
});
565+
551566
test('awaits each delete before starting the next', () async {
552567
final h = await batchReady(files: <String>['alpha.py', 'beta.py']);
553568
h.connection.holdDeleteAt = 1;
@@ -767,14 +782,19 @@ void main() {
767782
final FileDeleteBatchResult concurrent = await ctrl(
768783
h.container,
769784
).deleteMany(<String>['beta.py']);
785+
final List<String> listedBeforeRelease = List<String>.of(
786+
h.connection.listedPaths,
787+
);
788+
h.connection.releaseDelete.complete();
789+
final FileDeleteBatchResult firstResult = await first;
790+
770791
expect(concurrent.outcome, FileDeleteBatchOutcome.failed);
771792
expect(concurrent.failure, FileErrorKind.busy);
772793
expect(concurrent.succeededPaths, isEmpty);
773-
expect(h.connection.attemptedDeletePaths, <String>['/alpha.py']);
774-
expect(h.connection.listedPaths, isEmpty);
775-
776-
h.connection.releaseDelete.complete();
777-
expect((await first).outcome, FileDeleteBatchOutcome.complete);
794+
expect(concurrent.failedPath, isNull);
795+
expect(concurrent.unattemptedPaths, <String>['/beta.py']);
796+
expect(listedBeforeRelease, isEmpty);
797+
expect(firstResult.outcome, FileDeleteBatchOutcome.complete);
778798
expect(h.connection.attemptedDeletePaths, <String>['/alpha.py']);
779799
expect(h.connection.listedPaths, <String>['/']);
780800
});

‎app/test/widget/files_view_test.dart‎

Lines changed: 186 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@
2020
// CURRENTLY RED: lib/files exports no FilesView. HAND-OFF:
2121
// lib/files/files_view.dart -> app-files-engineer.
2222

23+
import 'dart:async';
2324
import 'dart:convert';
24-
import 'dart:typed_data';
2525

2626
import 'package:flutter/material.dart';
2727
import 'package:flutter/services.dart';
2828
import 'package:flutter_test/flutter_test.dart';
2929

30+
import 'package:pyble/app/providers.dart';
3031
import 'package:pyble/editor/editor.dart';
3132
import 'package:pyble/files/files.dart';
3233
import 'package:pyble/localization/localization.dart';
33-
import 'package:pyble/app/providers.dart';
3434
import 'package:pyble/pble/pble.dart';
3535

3636
import '../support/feature_harness.dart';
@@ -55,6 +55,34 @@ class _FailingDeleteConnection extends RecordingConnection {
5555
}
5656
}
5757

58+
/// Holds one delete so the shell navigation provider can change while the
59+
/// non-cancellable PBLE/1 mutation remains in flight.
60+
class _HeldDeleteConnection extends RecordingConnection {
61+
_HeldDeleteConnection() : super(initial: ConnState.ready);
62+
63+
final Completer<void> started = Completer<void>();
64+
final Completer<void> release = Completer<void>();
65+
66+
@override
67+
Future<void> delete(String path) async {
68+
if (!started.isCompleted) started.complete();
69+
await release.future;
70+
await super.delete(path);
71+
}
72+
}
73+
74+
/// Simulates a file disappearing before the board reports ENOENT. Reconciliation
75+
/// must not leave that absent row counted as a selected, retryable ghost.
76+
class _DisappearingDeleteConnection extends RecordingConnection {
77+
_DisappearingDeleteConnection() : super(initial: ConnState.ready);
78+
79+
@override
80+
Future<void> delete(String path) async {
81+
await super.delete(path);
82+
throw const ENoEnt('scripted file disappeared before delete');
83+
}
84+
}
85+
5886
void main() {
5987
Uint8List b(String s) => Uint8List.fromList(utf8.encode(s));
6088
Key entryKey(String n) => ValueKey<String>('fileEntry_$n');
@@ -885,6 +913,162 @@ void main() {
885913
},
886914
);
887915

916+
testWidgets(
917+
'editing selection clears the prior partial-result accounting',
918+
(WidgetTester tester) async {
919+
final _FailingDeleteConnection rec = _FailingDeleteConnection(
920+
failPath: '/beta.py',
921+
);
922+
addTearDown(rec.dispose);
923+
for (final String name in <String>['alpha.py', 'beta.py', 'gamma.py']) {
924+
await rec.putFile('/$name', b('$name\n'));
925+
}
926+
await pumpSurface(tester, const FilesView(), connection: rec);
927+
await tester.pumpAndSettle();
928+
final AppLocalizations l10n = l10nOf(tester);
929+
930+
await enterSelection(tester);
931+
await selectAllShown(tester);
932+
await tester.tap(find.byKey(kFilesBulkDeleteActionKey));
933+
await tester.pumpAndSettle();
934+
await tester.tap(
935+
find.descendant(
936+
of: find.byType(AlertDialog),
937+
matching: find.widgetWithText(FilledButton, l10n.commonDelete),
938+
),
939+
);
940+
await tester.pumpAndSettle();
941+
942+
final String stopped = l10n.filesDeleteSelectedStopped(1, 2);
943+
expect(find.text(stopped), findsOneWidget);
944+
await tester.tap(find.byKey(entryKey('gamma.py')));
945+
await tester.pump();
946+
947+
expect(
948+
find.text(stopped),
949+
findsNothing,
950+
reason:
951+
'a terminal result cannot be rewritten by later selection edits',
952+
);
953+
expect(
954+
find.text(l10n.filesDeleteSelectedStopped(1, 1)),
955+
findsNothing,
956+
reason:
957+
'a later selection edit dismisses rather than mutates the result',
958+
);
959+
expect(find.text(l10n.filesSelectionSelectedCount(1)), findsOneWidget);
960+
},
961+
);
962+
963+
testWidgets(
964+
'reconciliation removes an absent failed row from retry selection',
965+
(WidgetTester tester) async {
966+
final _DisappearingDeleteConnection rec =
967+
_DisappearingDeleteConnection();
968+
addTearDown(rec.dispose);
969+
await rec.putFile('/alpha.py', b('alpha\n'));
970+
await rec.putFile('/beta.py', b('beta\n'));
971+
await pumpSurface(tester, const FilesView(), connection: rec);
972+
await tester.pumpAndSettle();
973+
final AppLocalizations l10n = l10nOf(tester);
974+
975+
await enterSelection(tester);
976+
await selectAllShown(tester);
977+
await tester.tap(find.byKey(kFilesBulkDeleteActionKey));
978+
await tester.pumpAndSettle();
979+
await tester.tap(
980+
find.descendant(
981+
of: find.byType(AlertDialog),
982+
matching: find.widgetWithText(FilledButton, l10n.commonDelete),
983+
),
984+
);
985+
await tester.pumpAndSettle();
986+
987+
expect(find.byKey(entryKey('alpha.py')), findsNothing);
988+
expect(find.byKey(selectKey('alpha.py')), findsNothing);
989+
expect(find.byKey(selectKey('beta.py')), findsOneWidget);
990+
expect(
991+
tester.widget<Checkbox>(find.byKey(selectKey('beta.py'))).value,
992+
isTrue,
993+
);
994+
expect(find.text(l10n.filesSelectionSelectedCount(1)), findsOneWidget);
995+
expect(
996+
find.text(l10n.filesDeleteSelectedStopped(0, 1)),
997+
findsOneWidget,
998+
);
999+
},
1000+
);
1001+
1002+
testWidgets(
1003+
'navigation during a running delete clears selection without hidden focus',
1004+
(WidgetTester tester) async {
1005+
final _HeldDeleteConnection rec = _HeldDeleteConnection();
1006+
addTearDown(rec.dispose);
1007+
await rec.putFile('/alpha.py', b('alpha\n'));
1008+
await pumpSurface(tester, const FilesView(), connection: rec);
1009+
await tester.pumpAndSettle();
1010+
final AppLocalizations l10n = l10nOf(tester);
1011+
1012+
await enterSelection(tester);
1013+
await tester.tap(find.byKey(entryKey('alpha.py')));
1014+
await tester.pump();
1015+
await tester.tap(find.byKey(kFilesBulkDeleteActionKey));
1016+
await tester.pumpAndSettle();
1017+
await tester.tap(
1018+
find.descendant(
1019+
of: find.byType(AlertDialog),
1020+
matching: find.widgetWithText(FilledButton, l10n.commonDelete),
1021+
),
1022+
);
1023+
await tester.pump();
1024+
expect(rec.started.isCompleted, isTrue);
1025+
1026+
containerOf(tester).read(selectedSurfaceProvider.notifier).state =
1027+
AppSurface.editor;
1028+
await tester.pump();
1029+
rec.release.complete();
1030+
await tester.pumpAndSettle();
1031+
1032+
expect(find.byKey(kFilesSelectionBarKey), findsNothing);
1033+
final Finder selectAction = find.byKey(kFilesSelectActionKey);
1034+
expect(selectAction, findsOneWidget);
1035+
expect(
1036+
primaryFocusIsWithin(tester, selectAction),
1037+
isFalse,
1038+
reason: 'completion must not move focus into an offstage Files tree',
1039+
);
1040+
expect(find.text(l10n.filesDeleteSelectedComplete(1)), findsOneWidget);
1041+
},
1042+
);
1043+
1044+
testWidgets('a replaced listing dismisses a stale confirmation safely', (
1045+
WidgetTester tester,
1046+
) async {
1047+
final RecordingConnection rec = RecordingConnection(
1048+
initial: ConnState.ready,
1049+
);
1050+
addTearDown(rec.dispose);
1051+
await rec.putFile('/alpha.py', b('alpha\n'));
1052+
await pumpSurface(tester, const FilesView(), connection: rec);
1053+
await tester.pumpAndSettle();
1054+
1055+
await enterSelection(tester);
1056+
await tester.tap(find.byKey(entryKey('alpha.py')));
1057+
await tester.pump();
1058+
await tester.tap(find.byKey(kFilesBulkDeleteActionKey));
1059+
await tester.pumpAndSettle();
1060+
expect(find.byType(AlertDialog), findsOneWidget);
1061+
1062+
await containerOf(tester).read(fileExplorerProvider.notifier).refresh();
1063+
await tester.pumpAndSettle();
1064+
1065+
expect(find.byType(AlertDialog), findsNothing);
1066+
expect(find.byKey(kFilesSelectionBarKey), findsNothing);
1067+
expect(rec.deleteCalls, isEmpty);
1068+
final Finder selectAction = find.byKey(kFilesSelectActionKey);
1069+
expect(primaryFocusIsWithin(tester, selectAction), isTrue);
1070+
});
1071+
8881072
testWidgets(
8891073
'selection and exact confirmation do not overflow narrow 2x UI',
8901074
(WidgetTester tester) async {

0 commit comments

Comments
 (0)