import 'package:crdt_sync/crdt_sync.dart'; /// An in-memory `LogPersistence`. class MemPersistence implements LogPersistence { /// The persisted text, or null before the first write. String? text; @override Future read() async => text; @override Future write(String value) async => text = value; } /// An in-memory `RemoteStore`: a flat path -> text map. class MemRemote implements RemoteStore { /// Every file, by full path. final Map files = {}; @override Future> listDirectory(String path) async { final prefix = '$path/'; return files.keys .where((k) => k.startsWith(prefix)) .map((k) => k.substring(prefix.length).split('/').first) .toSet() .toList(); } @override Future getFileText(String path) async => files[path]; @override Future putFileText( String path, String text, { required String message, }) async => files[path] = text; @override Future deleteFile(String path, {String? message}) async => files.remove(path); @override Future canAccessRemote() async => true; @override void close() {} } /// A remote that is offline for every read and write. class BrokenRemote implements RemoteStore { @override Future> listDirectory(String path) async => throw RemoteSyncError('offline'); @override Future getFileText(String path) async => throw RemoteSyncError('offline'); @override Future putFileText( String path, String text, { required String message, }) async => throw RemoteSyncError('offline'); @override Future deleteFile(String path, {String? message}) async {} @override Future canAccessRemote() async => false; @override void close() {} } /// A log exactly as `sickdays` 0.1.0 (Python) writes it: 2026-10-20 sick, /// 2026-10-21 marked and then cleared. Generated by `add_sick_day` / /// `remove_sick_day` on 2026-10-16, not hand-written. const pythonSickLog = '{"2026-10-20": {"id": "2026-10-20", "fields": {"state": ["sick", ' '"2026-10-16T11:13:53.005Z-0000-ad78e209-49cd-4989-9235-da5ec179f183"], ' '"actor": ["ad78e209-49cd-4989-9235-da5ec179f183", ' '"2026-10-16T11:13:53.005Z-0000-ad78e209-49cd-4989-9235-da5ec179f183"]}, ' '"deleted": false, "deleted_hlc": null}, "2026-10-21": {"id": ' '"2026-10-21", "fields": {"state": ["cleared", ' '"2026-10-16T11:13:53.007Z-0000-ad78e209-49cd-4989-9235-da5ec179f183"], ' '"actor": ["ad78e209-49cd-4989-9235-da5ec179f183", ' '"2026-10-16T11:13:53.007Z-0000-ad78e209-49cd-4989-9235-da5ec179f183"]}, ' '"deleted": false, "deleted_hlc": null}}'; /// The PC's device directory in [pythonSickLog]. const pythonDeviceId = 'ad78e209-49cd-4989-9235-da5ec179f183'; /// A log exactly as `sickdays` 0.2.0 (Python) writes it, generated by /// `add_sick_day` / `set_kept_lockers` on 2026-10-16, not hand-written: /// 2026-10-20 sick keeping leetcode + workout; 2026-10-22 sick, then a /// keep-only edit to keep the alarm (state keeps its older tick); /// 2026-10-23 sick keeping nothing. const pythonKeepLog = '{"2026-10-20": {"id": "2026-10-20", "fields": {"state": ["sick", ' '"2026-10-16T13:16:33.057Z-0000-$_py"], "actor": ["$_py", ' '"2026-10-16T13:16:33.057Z-0000-$_py"], "keep": [["leetcode", ' '"workout"], "2026-10-16T13:16:33.057Z-0000-$_py"]}, "deleted": false, ' '"deleted_hlc": null}, "2026-10-22": {"id": "2026-10-22", "fields": ' '{"state": ["sick", "2026-10-16T13:16:33.058Z-0000-$_py"], "actor": ' '["$_py", "2026-10-16T13:16:33.058Z-0001-$_py"], "keep": [["alarm"], ' '"2026-10-16T13:16:33.058Z-0001-$_py"]}, "deleted": false, ' '"deleted_hlc": null}, "2026-10-23": {"id": "2026-10-23", "fields": ' '{"state": ["sick", "2026-10-16T13:16:33.059Z-0000-$_py"], "actor": ' '["$_py", "2026-10-16T13:16:33.059Z-0000-$_py"], "keep": [[], ' '"2026-10-16T13:16:33.059Z-0000-$_py"]}, "deleted": false, ' '"deleted_hlc": null}}'; const _py = '578c399d-4b1d-4558-ab86-b8a9c5aa123a';