forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocal_wal_sync_test.dart
More file actions
588 lines (477 loc) · 22 KB
/
Copy pathlocal_wal_sync_test.dart
File metadata and controls
588 lines (477 loc) · 22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
import 'dart:io';
import 'dart:typed_data';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:omi/backend/preferences.dart';
import 'package:omi/backend/schema/bt_device/bt_device.dart';
import 'package:omi/backend/schema/conversation.dart';
import 'package:omi/backend/schema/geolocation.dart';
import 'package:omi/services/audio_sources/audio_source.dart';
import 'package:omi/services/wals/flash_page_wal_sync.dart';
import 'package:omi/services/wals/local_wal_sync.dart';
import 'package:omi/services/wals/wal.dart';
import 'package:omi/services/wals/wal_interfaces.dart';
/// Minimal listener for testing — records calls without side effects.
class _MockListener implements IWalSyncListener {
int walUpdatedCount = 0;
final List<Wal> syncedWals = [];
@override
void onWalUpdated() {
walUpdatedCount++;
}
@override
void onWalSynced(Wal wal, {ServerConversation? conversation}) {
syncedWals.add(wal);
}
}
void main() {
late LocalWalSyncImpl sync;
late _MockListener listener;
setUp(() async {
TestWidgetsFlutterBinding.ensureInitialized();
SharedPreferences.setMockInitialValues({});
await SharedPreferencesUtil.init();
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
const MethodChannel('plugins.flutter.io/path_provider'),
(MethodCall call) async {
if (call.method == 'getApplicationDocumentsDirectory') return Directory.systemTemp.path;
return null;
},
);
listener = _MockListener();
sync = LocalWalSyncImpl(listener);
});
group('onFrameCaptured', () {
test('adds frame with synced=false', () {
final frame = WalFrame(payload: [0xAA, 0xBB], syncKey: FrameSyncKey([1]));
sync.onFrameCaptured(frame);
expect(sync.testFrames.length, 1);
expect(sync.testFrames[0].payload, [0xAA, 0xBB]);
expect(sync.testFrameSynced.length, 1);
expect(sync.testFrameSynced[0], false);
});
test('preserves insertion order for multiple frames', () {
for (int i = 0; i < 5; i++) {
sync.onFrameCaptured(WalFrame(payload: [i], syncKey: FrameSyncKey([i])));
}
expect(sync.testFrames.length, 5);
expect(sync.testFrameSynced.length, 5);
for (int i = 0; i < 5; i++) {
expect(sync.testFrames[i].payload, [i]);
expect(sync.testFrameSynced[i], false);
}
});
});
group('markFrameSynced', () {
test('marks matching frame as synced', () {
final key = FrameSyncKey([0x10, 0x20, 0x30]);
sync.onFrameCaptured(WalFrame(payload: [1], syncKey: key));
sync.markFrameSynced(key);
expect(sync.testFrameSynced[0], true);
});
test('marks only the last matching frame when duplicate keys exist', () {
final key = FrameSyncKey([0x10]);
// Add 3 frames with the same key
sync.onFrameCaptured(WalFrame(payload: [1], syncKey: key));
sync.onFrameCaptured(WalFrame(payload: [2], syncKey: key));
sync.onFrameCaptured(WalFrame(payload: [3], syncKey: key));
sync.markFrameSynced(key);
// Only the last (index 2) should be marked
expect(sync.testFrameSynced[0], false);
expect(sync.testFrameSynced[1], false);
expect(sync.testFrameSynced[2], true);
});
test('calling twice with same key marks two frames (reverse scan)', () {
final key = FrameSyncKey([0x10]);
sync.onFrameCaptured(WalFrame(payload: [1], syncKey: key));
sync.onFrameCaptured(WalFrame(payload: [2], syncKey: key));
sync.onFrameCaptured(WalFrame(payload: [3], syncKey: key));
sync.markFrameSynced(key); // marks index 2
sync.markFrameSynced(
key,
); // marks index 1 (2 is already true, but reverse scan finds 2 first and breaks — so second call marks 2 again? No — it checks syncKey equality, not synced status)
// Actually: markFrameSynced scans backward and breaks on FIRST syncKey match,
// regardless of synced status. So second call marks index 2 again (already true).
// Index 1 remains false.
expect(sync.testFrameSynced[0], false);
expect(sync.testFrameSynced[1], false);
expect(sync.testFrameSynced[2], true);
});
test('no-op when key does not match any frame', () {
final key1 = FrameSyncKey([0x10]);
final key2 = FrameSyncKey([0x99]);
sync.onFrameCaptured(WalFrame(payload: [1], syncKey: key1));
// Mark with non-matching key — should not crash or change anything
sync.markFrameSynced(key2);
expect(sync.testFrameSynced[0], false);
});
test('no-op when frames list is empty', () {
// Should not crash
sync.markFrameSynced(FrameSyncKey([0x10]));
expect(sync.testFrames, isEmpty);
});
test('correctly matches BLE-style 3-byte keys', () {
final bleKey = FrameSyncKey.fromBleHeader([0x05, 0x00, 0x02, 0xFF, 0xFF]);
sync.onFrameCaptured(WalFrame(payload: [1], syncKey: FrameSyncKey([0x05, 0x00, 0x01])));
sync.onFrameCaptured(WalFrame(payload: [2], syncKey: bleKey));
sync.onFrameCaptured(WalFrame(payload: [3], syncKey: FrameSyncKey([0x05, 0x00, 0x03])));
sync.markFrameSynced(FrameSyncKey([0x05, 0x00, 0x02]));
expect(sync.testFrameSynced[0], false);
expect(sync.testFrameSynced[1], true);
expect(sync.testFrameSynced[2], false);
});
test('correctly matches phone-mic-style 1-byte index keys', () {
for (int i = 0; i < 5; i++) {
sync.onFrameCaptured(WalFrame(payload: List.filled(320, i), syncKey: FrameSyncKey.fromIndex(i)));
}
sync.markFrameSynced(FrameSyncKey.fromIndex(3));
for (int i = 0; i < 5; i++) {
expect(sync.testFrameSynced[i], i == 3);
}
});
});
group('WAL binary serialization format', () {
test('length-prefixed format with headerless payloads', () {
// Simulate what _flush does: write [4-byte length][payload bytes]
// Verify the format is correct when payloads have no firmware header
final payloads = [
[0xAA, 0xBB, 0xCC], // 3 bytes — pure audio, no header
[0xDD, 0xEE], // 2 bytes
];
// Reproduce the _flush serialization logic
List<int> data = [];
for (int i = 0; i < payloads.length; i++) {
var frame = payloads[i];
final byteFrame = ByteData(frame.length);
for (int j = 0; j < frame.length; j++) {
byteFrame.setUint8(j, frame[j]);
}
data.addAll(Uint32List.fromList([frame.length]).buffer.asUint8List());
data.addAll(byteFrame.buffer.asUint8List());
}
// First frame: 4-byte length (3) + 3 payload bytes = 7 bytes
expect(data.length, 4 + 3 + 4 + 2); // 13 bytes total
// Verify first frame length prefix
final len1 = ByteData.sublistView(Uint8List.fromList(data.sublist(0, 4))).getUint32(0, Endian.little);
expect(len1, 3);
expect(data.sublist(4, 7), [0xAA, 0xBB, 0xCC]);
// Verify second frame length prefix
final len2 = ByteData.sublistView(Uint8List.fromList(data.sublist(7, 11))).getUint32(0, Endian.little);
expect(len2, 2);
expect(data.sublist(11, 13), [0xDD, 0xEE]);
});
test('BLE payload stored without firmware header matches old sublist(3) behavior', () {
// Old behavior: raw BLE packet stored in wal.data, then sublist(3) during flush
final blePacket = [0x05, 0x00, 0x02, ...List.filled(80, 0xAA)];
final oldFlushPayload = blePacket.sublist(3);
// New behavior: BleDeviceSource strips header, payload stored directly
// _flush writes wal.data[i] (already headerless) — no sublist(3)
final newStorePayload = blePacket.sublist(3); // what BleDeviceSource.processBytes returns
// Serialization of both should be identical
List<int> serialize(List<int> payload) {
List<int> data = [];
final byteFrame = ByteData(payload.length);
for (int j = 0; j < payload.length; j++) {
byteFrame.setUint8(j, payload[j]);
}
data.addAll(Uint32List.fromList([payload.length]).buffer.asUint8List());
data.addAll(byteFrame.buffer.asUint8List());
return data;
}
expect(serialize(newStorePayload), equals(serialize(oldFlushPayload)));
expect(newStorePayload.length, 80);
});
test('phone mic frames stored at correct size in WAL format', () {
// Phone mic produces 320-byte PCM frames — stored directly
final micPayload = List.filled(320, 0x42);
List<int> data = [];
final byteFrame = ByteData(micPayload.length);
for (int j = 0; j < micPayload.length; j++) {
byteFrame.setUint8(j, micPayload[j]);
}
data.addAll(Uint32List.fromList([micPayload.length]).buffer.asUint8List());
data.addAll(byteFrame.buffer.asUint8List());
// 4-byte length + 320 payload bytes
expect(data.length, 324);
final storedLen = ByteData.sublistView(Uint8List.fromList(data.sublist(0, 4))).getUint32(0, Endian.little);
expect(storedLen, 320);
expect(data.sublist(4), micPayload);
});
});
group('upload batching', () {
test('newest first, one conversation per batch', () {
const now = 2000000000;
final oldNewest = Wal(timerStart: now - 7 * 60 * 60, codec: BleAudioCodec.opus, seconds: 60);
final liveOlder = Wal(
timerStart: now - 120,
codec: BleAudioCodec.opus,
seconds: 60,
conversationId: 'server-conversation',
);
final oldOldest = Wal(timerStart: now - 8 * 24 * 60 * 60, codec: BleAudioCodec.opus, seconds: 60);
final liveNewest = Wal(
timerStart: now - 30,
codec: BleAudioCodec.opus,
seconds: 60,
conversationId: 'server-conversation',
);
final batch = nextSyncUploadBatch([oldNewest, liveOlder, oldOldest, liveNewest], now);
expect(batch.map((wal) => wal.timerStart), [liveNewest.timerStart, liveOlder.timerStart]);
});
test('only a conversation-bound recent WAL counts as live capture', () {
const now = 2000000000;
Wal at(int ageSeconds, {String? conversationId}) =>
Wal(timerStart: now - ageSeconds, codec: BleAudioCodec.opus, seconds: 60, conversationId: conversationId);
expect(isLiveCaptureWal(at(60), now), isFalse);
expect(isLiveCaptureWal(at(60, conversationId: 'c'), now), isTrue);
expect(isLiveCaptureWal(at(7 * 60 * 60, conversationId: 'c'), now), isFalse);
});
test('a backlog smaller than the limit drains in one batch', () {
const now = 2000000000;
final historical = List.generate(
3,
(index) => Wal(timerStart: now - 7 * 60 * 60 - index, codec: BleAudioCodec.opus, seconds: 60),
);
final batch = nextSyncUploadBatch(historical.reversed.toList(), now);
expect(batch.length, 3);
});
test('a batch never exceeds the limit that keeps a job inside the backend stale guard', () {
const now = 2000000000;
final historical = List.generate(
25,
(index) => Wal(timerStart: now - 7 * 60 * 60 - index, codec: BleAudioCodec.opus, seconds: 60),
);
final batch = nextSyncUploadBatch(historical.reversed.toList(), now);
expect(batch.length, 5);
expect(batch.map((wal) => wal.timerStart), historical.take(5).map((wal) => wal.timerStart));
});
test('historical WALs with different recording locations are never uploaded as one conversation batch', () {
const now = 2000000000;
final firstCapture = Geolocation(
latitude: 40.7128,
longitude: -74.0060,
time: DateTime.utc(2033, 5, 18, 3, 30),
captureSource: 'current_position',
);
final secondCapture = Geolocation(
latitude: 34.0522,
longitude: -118.2437,
time: DateTime.utc(2033, 5, 18, 4, 30),
captureSource: 'current_position',
);
final wals = [
Wal(timerStart: now - 7 * 60 * 60, codec: BleAudioCodec.opus, seconds: 60, geolocation: firstCapture),
Wal(timerStart: now - 7 * 60 * 60 - 60, codec: BleAudioCodec.opus, seconds: 60, geolocation: firstCapture),
Wal(timerStart: now - 8 * 60 * 60, codec: BleAudioCodec.opus, seconds: 60, geolocation: secondCapture),
];
final batch = nextSyncUploadBatch(wals, now);
expect(batch, hasLength(2));
expect(batch.every((wal) => identical(wal.geolocation, firstCapture)), isTrue);
});
test('a conversation too large for one batch does not claim a manifest', () {
const now = 2000000000;
final oversized = List.generate(
6,
(index) => Wal(
timerStart: now - index,
codec: BleAudioCodec.opus,
seconds: 60,
conversationId: 'oversized-conversation',
),
);
final batch = nextSyncUploadBatch(oversized, now);
expect(batch.length, 5);
expect(canClaimLiveCapture(batch, oversized, now), isFalse);
expect(canClaimLiveCapture(batch, oversized.take(5).toList(), now), isTrue);
});
});
group('audio_player_utils temp file serialization (no double-strip)', () {
test('headerless payloads are serialized without extra sublist(3)', () {
// Simulate a Wal with headerless payloads (as now stored by _chunk)
final headerlessPayloads = [
[0xAA, 0xBB, 0xCC, 0xDD], // 4 bytes of pure audio
[0x11, 0x22, 0x33], // 3 bytes of pure audio
];
// This is the FIXED audio_player_utils._createTempFileFromMemoryData logic:
// var frame = wal.data[i]; (no sublist(3))
List<int> fixedData = [];
for (int i = 0; i < headerlessPayloads.length; i++) {
var frame = headerlessPayloads[i]; // FIXED: direct access
final byteFrame = ByteData(frame.length);
for (int j = 0; j < frame.length; j++) {
byteFrame.setUint8(j, frame[j]);
}
fixedData.addAll(Uint32List.fromList([frame.length]).buffer.asUint8List());
fixedData.addAll(byteFrame.buffer.asUint8List());
}
// Verify first frame is fully preserved
final len1 = ByteData.sublistView(Uint8List.fromList(fixedData.sublist(0, 4))).getUint32(0, Endian.little);
expect(len1, 4); // Full 4-byte payload
expect(fixedData.sublist(4, 8), [0xAA, 0xBB, 0xCC, 0xDD]);
// Verify second frame is fully preserved
final len2 = ByteData.sublistView(Uint8List.fromList(fixedData.sublist(8, 12))).getUint32(0, Endian.little);
expect(len2, 3); // Full 3-byte payload
expect(fixedData.sublist(12, 15), [0x11, 0x22, 0x33]);
});
test('old buggy sublist(3) would corrupt headerless payloads', () {
// Demonstrate the bug that was fixed: applying sublist(3) to
// already-headerless payloads truncates audio data
final headerlessPayload = [0xAA, 0xBB, 0xCC, 0xDD]; // 4 bytes
// OLD buggy code: wal.data[i].sublist(3) on headerless payload
final buggyResult = headerlessPayload.sublist(3);
expect(buggyResult, [0xDD]); // Lost 3 bytes of audio!
// FIXED code: wal.data[i] directly
final fixedResult = headerlessPayload;
expect(fixedResult, [0xAA, 0xBB, 0xCC, 0xDD]); // All audio preserved
expect(fixedResult.length, buggyResult.length + 3); // 3 bytes recovered
});
});
group('session lifecycle (production)', () {
test('setDeviceInfo updates metadata without error', () {
sync.setDeviceInfo('phone-mic', 'Phone Microphone');
// Just verify no crash — metadata used during WAL creation
});
test('frames and synced arrays stay in sync after mixed operations', () {
// Add 3 frames
sync.onFrameCaptured(WalFrame(payload: [1], syncKey: FrameSyncKey([0])));
sync.onFrameCaptured(WalFrame(payload: [2], syncKey: FrameSyncKey([1])));
sync.onFrameCaptured(WalFrame(payload: [3], syncKey: FrameSyncKey([2])));
// Mark middle frame synced
sync.markFrameSynced(FrameSyncKey([1]));
// Verify parallel arrays stay consistent
expect(sync.testFrames.length, 3);
expect(sync.testFrameSynced.length, 3);
expect(sync.testFrameSynced[0], false);
expect(sync.testFrameSynced[1], true);
expect(sync.testFrameSynced[2], false);
});
test('phone mic frames with wrapping index keys', () {
// Simulate phone mic producing 256+ frames (index wraps at 255)
for (int i = 0; i < 260; i++) {
sync.onFrameCaptured(WalFrame(payload: List.filled(320, i & 0xFF), syncKey: FrameSyncKey.fromIndex(i)));
}
expect(sync.testFrames.length, 260);
// Mark frame index 3 (appears at position 3 and 259 due to wrapping)
// Reverse scan finds position 259 first
sync.markFrameSynced(FrameSyncKey.fromIndex(3));
expect(sync.testFrameSynced[3], false); // Not this one
expect(sync.testFrameSynced[259], true); // This one (last match)
});
test('each finalized WAL owns an independent location snapshot', () async {
SharedPreferencesUtil().unlimitedLocalStorageEnabled = true;
final location = Geolocation(
latitude: 40.7128,
longitude: -74.006,
time: DateTime.utc(2026, 8, 1, 12),
captureSource: 'current_position',
);
sync.setSessionGeolocation(location);
location.latitude = 41.0;
sync.onFrameCaptured(WalFrame(payload: [1], syncKey: FrameSyncKey([1])));
await sync.finalizeCurrentSession();
sync.onFrameCaptured(WalFrame(payload: [2], syncKey: FrameSyncKey([2])));
await sync.finalizeCurrentSession();
expect(sync.testWals, hasLength(2));
expect(sync.testWals[0].geolocation?.latitude, 40.7128);
expect(sync.testWals[1].geolocation?.latitude, 40.7128);
sync.testWals[0].geolocation!.latitude = 42.0;
expect(sync.testWals[1].geolocation?.latitude, 40.7128);
});
test('cleared session location is not inherited by external WALs', () async {
sync.setSessionGeolocation(
Geolocation(latitude: 40.7128, longitude: -74.006, time: DateTime.utc(2026, 8, 1, 12)),
);
sync.setSessionGeolocation(null);
final wal = Wal(timerStart: DateTime.now().millisecondsSinceEpoch ~/ 1000, codec: BleAudioCodec.opus, seconds: 1);
await sync.addExternalWal(wal);
expect(wal.geolocation, isNull);
});
});
group('_chunk payload extraction', () {
test('WalFrame.payload is used for Wal.data (not raw bytes)', () {
// Simulate what _chunk does: extract payloads from WalFrames
final frames = [
WalFrame(payload: [0xAA, 0xBB], syncKey: FrameSyncKey([1])),
WalFrame(payload: [0xCC, 0xDD], syncKey: FrameSyncKey([2])),
WalFrame(payload: [0xEE, 0xFF], syncKey: FrameSyncKey([3])),
];
// This is the exact expression from _chunk:
final chunk = frames.map((f) => f.payload).toList();
expect(chunk.length, 3);
expect(chunk[0], [0xAA, 0xBB]);
expect(chunk[1], [0xCC, 0xDD]);
expect(chunk[2], [0xEE, 0xFF]);
// Sync keys are NOT included in the chunk data
for (final payload in chunk) {
expect(payload.length, 2);
}
});
test('BLE frames have header stripped before chunk storage', () {
// Raw BLE packet: 3-byte header + audio
final blePacket = [0x05, 0x00, 0x02, 0xAA, 0xBB, 0xCC];
// BleDeviceSource strips header
final payload = blePacket.sublist(3); // [0xAA, 0xBB, 0xCC]
final frame = WalFrame(payload: payload, syncKey: FrameSyncKey.fromBleHeader(blePacket));
// _chunk stores payload only
final chunk = [frame].map((f) => f.payload).toList();
expect(chunk[0], [0xAA, 0xBB, 0xCC]);
// No firmware header in stored data
expect(chunk[0].length, 3);
expect(chunk[0][0], 0xAA); // First byte is audio, not header
});
});
group('WAL lists are growable (regression: Cannot add to an unmodifiable list)', () {
// Crash: LocalWalSyncImpl._chunk called wal.data.addAll(chunk) on a WAL
// loaded from disk. Wal.fromJson never passed `data`, so the constructor
// default `const []` left an unmodifiable list that threw on addAll.
test('Wal.fromJson produces a growable data list that _chunk can append to', () {
final wal = Wal.fromJson({
'timer_start': 1700000000,
'codec': 'opus',
'seconds': 60,
'status': 'miss',
'storage': 'disk',
});
// The exact operation from _chunk that crashed in production:
wal.data.addAll([
[0xAA, 0xBB],
[0xCC, 0xDD],
]);
expect(wal.data.length, 2);
});
test('Wal constructed without data has a growable data list', () {
final wal = Wal(timerStart: 1700000000, codec: BleAudioCodec.opus, seconds: 60);
wal.data.add([0x01]);
expect(wal.data, [
[0x01],
]);
});
test('addExternalWal before _initializeWals completes does not throw on _wals', () async {
// Same failure class: `_wals = const []` was unmodifiable until
// _initializeWals replaced it, so an early addExternalWal crashed.
final freshListener = _MockListener();
final freshSync = LocalWalSyncImpl(freshListener);
// Old timerStart → backfill lane, so no fresh-upload network call runs.
final wal = Wal(timerStart: 1000, codec: BleAudioCodec.opus, seconds: 60);
await freshSync.addExternalWal(wal);
expect(freshSync.testWals.map((w) => w.id), contains(wal.id));
});
});
group('syncWal — orphan WAL guard', () {
// A WAL the user taps "sync" on may already be gone from `_wals` (a
// concurrent delete/reload). Previously `.first` on the empty match list
// threw an uncaught StateError; the guard now bails out to null instead.
test('LocalWalSyncImpl.syncWal returns null when the WAL is not tracked', () async {
final orphan = Wal(timerStart: 123, codec: BleAudioCodec.opus, seconds: 10);
final result = await sync.syncWal(wal: orphan);
expect(result, isNull);
});
test('FlashPageWalSyncImpl.syncWal returns null when the WAL is not tracked', () async {
final flashSync = FlashPageWalSyncImpl(listener);
final orphan = Wal(timerStart: 456, codec: BleAudioCodec.opus, seconds: 10);
final result = await flashSync.syncWal(wal: orphan);
expect(result, isNull);
});
});
}