🧪 Reproduce failing sync from zero

This commit is contained in:
2026-08-20 16:42:08 +02:00
parent 4fa598e5ce
commit babc9a8096
+27
View File
@@ -83,6 +83,33 @@ func TestSyncPruneStaleClient(t *testing.T) {
} }
} }
func TestSyncBootstrapAfterPruneReturnsLatestData(t *testing.T) {
s := mustSyncStore(t)
ctx := context.Background()
old := &domain.Entry{ID: "old", DayKey: "2026-01-01", UpdatedAt: time.Now().Add(-31 * 24 * time.Hour).UnixMilli()}
latest := &domain.Entry{ID: "latest", DayKey: "2026-02-01", UpdatedAt: time.Now().UnixMilli()}
if err := s.LogEntry(ctx, old); err != nil {
t.Fatal(err)
}
if err := s.Prune(ctx, -time.Millisecond); err != nil {
t.Fatal(err)
}
if err := s.LogEntry(ctx, latest); err != nil {
t.Fatal(err)
}
// A zero-version client has no history to reconcile. It should receive
// current data rather than being rejected because older history was pruned.
changes, _, err := s.Pull(ctx, 0)
if err != nil {
t.Fatalf("bootstrap should return latest data after pruning, got %v", err)
}
if len(changes) != 1 || changes[0].EntityID != "latest" {
t.Fatalf("expected only latest data, got %+v", changes)
}
}
func TestSyncPruneNoRows(t *testing.T) { func TestSyncPruneNoRows(t *testing.T) {
s := mustSyncStore(t) s := mustSyncStore(t)
ctx := context.Background() ctx := context.Background()