refactor(sync): remove dead Backfill/IncrementalSync exported wrappers

Both were only reachable via the periodic background sync loop removed
in 4d2cbe4 -- nothing in production calls them anymore, only tests did.
FullSync already calls backfillCore/incrementalSyncCore directly.
Rewrite the affected tests to call the *Core functions (still exported
within the package) instead, dropping the now-redundant standalone
SyncRun-recording assertion covered by TestFullSync_RecordsOneCombinedSyncRun.
This commit is contained in:
2026-07-27 06:44:39 +02:00
parent 9d65c50068
commit 7204a48c1c
5 changed files with 57 additions and 99 deletions

View File

@@ -52,7 +52,7 @@ func setBackfillHorizon(t *testing.T, db *store.DB, userID int64, days int) {
}
}
func TestBackfill_StoresActivitiesAndRecordsSyncRun(t *testing.T) {
func TestBackfillCore_StoresActivities(t *testing.T) {
db := openTestDB(t)
ctx := context.Background()
userID := provisionTestUser(t, db)
@@ -63,8 +63,12 @@ func TestBackfill_StoresActivitiesAndRecordsSyncRun(t *testing.T) {
}}
svc := NewService(m, db, userID, Config{}, fixedNow(time.Date(2026, 7, 11, 0, 0, 0, 0, time.UTC)))
if err := svc.Backfill(ctx); err != nil {
t.Fatalf("Backfill: %v", err)
total, err := svc.backfillCore(ctx)
if err != nil {
t.Fatalf("backfillCore: %v", err)
}
if total != 1 {
t.Errorf("backfillCore returned total = %d, want 1", total)
}
activities, err := db.ListActivities(ctx, userID, store.ActivityFilter{})
@@ -77,14 +81,6 @@ func TestBackfill_StoresActivitiesAndRecordsSyncRun(t *testing.T) {
if activities[0].GarminActivityID != 1 {
t.Errorf("GarminActivityID = %d, want 1", activities[0].GarminActivityID)
}
runs, err := db.ListSyncRuns(ctx, userID, 10)
if err != nil {
t.Fatalf("ListSyncRuns: %v", err)
}
if len(runs) != 1 || runs[0].Status != store.SyncStatusSuccess {
t.Fatalf("expected 1 successful sync run, got %+v", runs)
}
}
func TestAlignWorkoutTargets_MatchesLapsToFlattenedSteps(t *testing.T) {
@@ -195,7 +191,7 @@ func TestTargetHRRange_CustomRangeAndZoneNumberViaKarvonen(t *testing.T) {
}
}
func TestBackfill_SkipsNonRunningActivities(t *testing.T) {
func TestBackfillCore_SkipsNonRunningActivities(t *testing.T) {
db := openTestDB(t)
ctx := context.Background()
userID := provisionTestUser(t, db)
@@ -212,8 +208,8 @@ func TestBackfill_SkipsNonRunningActivities(t *testing.T) {
}}
svc := NewService(m, db, userID, Config{}, fixedNow(time.Date(2026, 7, 11, 0, 0, 0, 0, time.UTC)))
if err := svc.Backfill(ctx); err != nil {
t.Fatalf("Backfill: %v", err)
if _, err := svc.backfillCore(ctx); err != nil {
t.Fatalf("backfillCore: %v", err)
}
activities, err := db.ListActivities(ctx, userID, store.ActivityFilter{})
@@ -258,8 +254,8 @@ func TestFillPendingDetailsAndClassify_EndToEnd(t *testing.T) {
}
svc := NewService(m, db, userID, Config{MinConfidence: 0.5}, fixedNow(time.Date(2026, 7, 11, 0, 0, 0, 0, time.UTC)))
if err := svc.Backfill(ctx); err != nil {
t.Fatalf("Backfill: %v", err)
if _, err := svc.backfillCore(ctx); err != nil {
t.Fatalf("backfillCore: %v", err)
}
// A workout kind that should cleanly match the seeded activity's pace.
@@ -328,8 +324,8 @@ func TestFillPendingDetails_ResolvesWorkoutTargetsOntoLaps(t *testing.T) {
}
svc := NewService(m, db, userID, Config{}, fixedNow(time.Date(2026, 7, 11, 0, 0, 0, 0, time.UTC)))
if err := svc.Backfill(ctx); err != nil {
t.Fatalf("Backfill: %v", err)
if _, err := svc.backfillCore(ctx); err != nil {
t.Fatalf("backfillCore: %v", err)
}
if err := svc.FillPendingDetails(ctx, 10); err != nil {
t.Fatalf("FillPendingDetails: %v", err)
@@ -385,8 +381,8 @@ func TestFillPendingDetails_OneExtraTrailingLapKeepsOtherLapsTargets(t *testing.
}
svc := NewService(m, db, userID, Config{}, fixedNow(time.Date(2026, 7, 11, 0, 0, 0, 0, time.UTC)))
if err := svc.Backfill(ctx); err != nil {
t.Fatalf("Backfill: %v", err)
if _, err := svc.backfillCore(ctx); err != nil {
t.Fatalf("backfillCore: %v", err)
}
if err := svc.FillPendingDetails(ctx, 10); err != nil {
t.Fatalf("FillPendingDetails: %v", err)
@@ -454,7 +450,7 @@ func TestBuildMetricContext_DerivesIsRace(t *testing.T) {
}
}
func TestBackfill_SecondRunIsANoOpOnceHorizonFullyCovered(t *testing.T) {
func TestBackfillCore_SecondRunIsANoOpOnceHorizonFullyCovered(t *testing.T) {
db := openTestDB(t)
ctx := context.Background()
userID := provisionTestUser(t, db)
@@ -466,8 +462,8 @@ func TestBackfill_SecondRunIsANoOpOnceHorizonFullyCovered(t *testing.T) {
fixedNow(time.Date(2026, 7, 11, 0, 0, 0, 0, time.UTC)))
setBackfillHorizon(t, db, userID, 10)
if err := svc.Backfill(ctx); err != nil {
t.Fatalf("first Backfill: %v", err)
if _, err := svc.backfillCore(ctx); err != nil {
t.Fatalf("first backfillCore: %v", err)
}
firstCallCount := m.GetActivitiesCalls
if firstCallCount == 0 {
@@ -482,11 +478,11 @@ func TestBackfill_SecondRunIsANoOpOnceHorizonFullyCovered(t *testing.T) {
t.Fatalf("expected backfill_complete=true after covering the full horizon, got %+v", state)
}
if err := svc.Backfill(ctx); err != nil {
t.Fatalf("second Backfill: %v", err)
if _, err := svc.backfillCore(ctx); err != nil {
t.Fatalf("second backfillCore: %v", err)
}
if m.GetActivitiesCalls != firstCallCount {
t.Errorf("second Backfill made %d more GetActivities call(s); want 0 (should be a no-op once horizon is covered)",
t.Errorf("second backfillCore made %d more GetActivities call(s); want 0 (should be a no-op once horizon is covered)",
m.GetActivitiesCalls-firstCallCount)
}
}
@@ -503,8 +499,8 @@ func TestResetAll_AllowsFreshBackfillAfterwards(t *testing.T) {
fixedNow(time.Date(2026, 7, 11, 0, 0, 0, 0, time.UTC)))
setBackfillHorizon(t, db, userID, 10)
if err := svc.Backfill(ctx); err != nil {
t.Fatalf("first Backfill: %v", err)
if _, err := svc.backfillCore(ctx); err != nil {
t.Fatalf("first backfillCore: %v", err)
}
firstCallCount := m.GetActivitiesCalls
@@ -519,8 +515,8 @@ func TestResetAll_AllowsFreshBackfillAfterwards(t *testing.T) {
t.Fatalf("expected 0 activities after ResetAll, got %d", len(activities))
}
if err := svc.Backfill(ctx); err != nil {
t.Fatalf("Backfill after reset: %v", err)
if _, err := svc.backfillCore(ctx); err != nil {
t.Fatalf("backfillCore after reset: %v", err)
}
if m.GetActivitiesCalls <= firstCallCount {
t.Errorf("expected Backfill after ResetAll to call GetActivities again (fresh pull), call count stayed at %d", m.GetActivitiesCalls)
@@ -534,7 +530,7 @@ func TestResetAll_AllowsFreshBackfillAfterwards(t *testing.T) {
}
}
func TestBackfill_ResumesFromWatermarkWhenHorizonGrows(t *testing.T) {
func TestBackfillCore_ResumesFromWatermarkWhenHorizonGrows(t *testing.T) {
db := openTestDB(t)
ctx := context.Background()
userID := provisionTestUser(t, db)
@@ -546,8 +542,8 @@ func TestBackfill_ResumesFromWatermarkWhenHorizonGrows(t *testing.T) {
svc := NewService(m, db, userID, Config{BackfillWindowDays: 10}, now)
setBackfillHorizon(t, db, userID, 10)
if err := svc.Backfill(ctx); err != nil {
t.Fatalf("first Backfill: %v", err)
if _, err := svc.backfillCore(ctx); err != nil {
t.Fatalf("first backfillCore: %v", err)
}
firstCallCount := m.GetActivitiesCalls
@@ -556,8 +552,8 @@ func TestBackfill_ResumesFromWatermarkWhenHorizonGrows(t *testing.T) {
// make progress toward the new, deeper horizon.
setBackfillHorizon(t, db, userID, 30)
svc2 := NewService(m, db, userID, Config{BackfillWindowDays: 10}, now)
if err := svc2.Backfill(ctx); err != nil {
t.Fatalf("second Backfill: %v", err)
if _, err := svc2.backfillCore(ctx); err != nil {
t.Fatalf("second backfillCore: %v", err)
}
if m.GetActivitiesCalls <= firstCallCount {
t.Errorf("expected additional GetActivities calls when horizon grows, got %d total (was %d)", m.GetActivitiesCalls, firstCallCount)
@@ -655,8 +651,8 @@ func TestFillPendingDetails_ReportsLiveProgress(t *testing.T) {
svc := NewService(m, db, userID, Config{InterCallDelay: 150 * time.Millisecond},
fixedNow(time.Date(2026, 7, 11, 0, 0, 0, 0, time.UTC)))
if err := svc.Backfill(ctx); err != nil {
t.Fatalf("Backfill: %v", err)
if _, err := svc.backfillCore(ctx); err != nil {
t.Fatalf("backfillCore: %v", err)
}
if p := svc.Progress(); p.Total != 0 {
@@ -704,11 +700,11 @@ func TestService_TwoUsersSyncIndependently(t *testing.T) {
svcA := NewService(mA, db, userA, Config{}, fixedNow(time.Date(2026, 7, 11, 0, 0, 0, 0, time.UTC)))
svcB := NewService(mB, db, userB, Config{}, fixedNow(time.Date(2026, 7, 11, 0, 0, 0, 0, time.UTC)))
if err := svcA.Backfill(ctx); err != nil {
t.Fatalf("Backfill(a): %v", err)
if _, err := svcA.backfillCore(ctx); err != nil {
t.Fatalf("backfillCore(a): %v", err)
}
if err := svcB.Backfill(ctx); err != nil {
t.Fatalf("Backfill(b): %v", err)
if _, err := svcB.backfillCore(ctx); err != nil {
t.Fatalf("backfillCore(b): %v", err)
}
activitiesA, err := db.ListActivities(ctx, userA, store.ActivityFilter{})