♻️ Bootstrap when syncmarker is zero
This commit is contained in:
@@ -83,33 +83,26 @@ func TestSyncPruneStaleClient(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSyncBootstrapAfterPruneReturnsLatestData(t *testing.T) {
|
||||
s := mustSyncStore(t)
|
||||
|
||||
func TestSyncBootstrapIncludesPrunedEntityData(t *testing.T) {
|
||||
db, err := store.Open(":memory:")
|
||||
if err != nil { t.Fatal(err) }
|
||||
defer db.Close()
|
||||
|
||||
ctx := context.Background()
|
||||
entries := store.NewEntryStore(db)
|
||||
entry := &domain.Entry{ID: "retained", StartTime: 1, DayKey: "2026-01-01", Note: "old"}
|
||||
if err := entries.Create(ctx, entry); err != nil { t.Fatal(err) }
|
||||
syncStore := store.NewSyncStore(db)
|
||||
if err := syncStore.Prune(ctx, -time.Millisecond); err != nil { t.Fatal(err) }
|
||||
|
||||
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)
|
||||
changes, version, err := syncStore.Bootstrap(ctx)
|
||||
if err != nil { t.Fatal(err) }
|
||||
if version != 0 { t.Fatalf("expected sync version 0, got %d", version) }
|
||||
if len(changes) == 0 || changes[0].Entity != "entries" || changes[0].EntityID != entry.ID {
|
||||
t.Fatalf("expected current entry in bootstrap, got %+v", changes)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSyncPruneNoRows(t *testing.T) {
|
||||
s := mustSyncStore(t)
|
||||
ctx := context.Background()
|
||||
|
||||
Reference in New Issue
Block a user