From babc9a8096a2fa13be3dbda3c873db605035dadb Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Thu, 20 Aug 2026 16:42:08 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20Reproduce=20failing=20sync=20fro?= =?UTF-8?q?m=20zero?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/store/sync_store_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/internal/store/sync_store_test.go b/internal/store/sync_store_test.go index b6da3b4..5da33ef 100644 --- a/internal/store/sync_store_test.go +++ b/internal/store/sync_store_test.go @@ -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) { s := mustSyncStore(t) ctx := context.Background()