fix(localdb): applier review fixes — null-row_json guard, clock recovery via last_seen_hlc, fidelity + guard tests

Claude-Session: https://claude.ai/code/session_01BL2Vu1ESDQ9SCN4gVKkdts
This commit is contained in:
Joseph Doherty
2026-07-17 22:15:51 -04:00
parent d7cbdce65c
commit b223507070
5 changed files with 179 additions and 19 deletions
@@ -191,6 +191,27 @@ public sealed class OplogStoreTests : IDisposable
Assert.Equal(0, count[0]);
}
[Fact]
public async Task CapExceeded_ByAge_MixedFixture_FreshRowSurvives()
{
using var db = await NewOrdersDb();
await db.ExecuteAsync("INSERT INTO orders (id, sku, qty) VALUES (1,'A',1),(2,'B',2)");
// Backdate only the first entry's HLC past the 7d MaxOplogAge; the second stays fresh.
var expiredHlc = DateTimeOffset.UtcNow.AddDays(-30).ToUnixTimeMilliseconds() << 16;
await db.ExecuteAsync(
"UPDATE __localdb_oplog SET hlc = @h WHERE seq = (SELECT MIN(seq) FROM __localdb_oplog)",
new { h = expiredHlc });
var store = new OplogStore(db, new ReplicationOptions());
var flagged = await store.EnforceCapsAsync(default);
Assert.True(flagged);
Assert.True((await store.GetPeerStateAsync(default)).NeedsSnapshot);
var remaining = await store.ReadBatchAboveAsync(0, 100, default);
Assert.Single(remaining);
Assert.Equal("{\"id\":2}", remaining[0].PkJson);
}
[Fact]
public async Task PeerState_RoundTrips()
{