fix: preserve queued settings and recover interrupted or corrupt state

This commit is contained in:
Codex
2026-10-13 09:32:50 +08:00
parent 5ceab20b67
commit da5b8076a0
16 changed files with 373 additions and 50 deletions
+31
View File
@@ -15,6 +15,37 @@ void main() {
tearDown(() async {
await directory.delete(recursive: true);
});
for (final badBackup in [false, true]) {
test(
'fresh recovery archives corrupt primary and ${badBackup ? 'corrupt' : 'missing'} backup before saving',
() async {
await File('${directory.path}/hepan_snapshot.json')
.writeAsString('damaged primary');
if (badBackup) {
await File('${directory.path}/hepan_snapshot.bak')
.writeAsString('damaged backup');
}
final store = FileSnapshotStore(directory);
await expectLater(store.load(), throwsFormatException);
await store.startFresh();
final archives = await directory
.list()
.where((e) => e.path.contains('.damaged-'))
.toList();
expect(archives, hasLength(badBackup ? 2 : 1));
final contents = await Future.wait(
archives.map((e) => File(e.path).readAsString()),
);
expect(contents, contains('damaged primary'));
if (badBackup) {
expect(contents, contains('damaged backup'));
}
expect((await store.load())!.courses, isEmpty);
await store.save(AppSnapshot(courses: [course()]));
expect((await store.load())!.courses.single.id, 'math');
},
);
}
test(
'reopening restores courses, settings and calendar identifiers',
() async {