package main import ( "context" "errors" "reflect" "testing" "time" ) type frozenScheduleSpy struct { calls []string trackErr error } func (s *frozenScheduleSpy) EnqueueDue(context.Context) (bool, error) { s.calls = append(s.calls, "sync") return true, nil } func (s *frozenScheduleSpy) TrackQualityWeeks(context.Context, time.Time) error { s.calls = append(s.calls, "track") return s.trackErr } func (s *frozenScheduleSpy) FreezePreviousQualityWeek(context.Context, time.Time) (bool, error) { s.calls = append(s.calls, "freeze") return true, nil } func TestRecordsSchedulerActuallyCapturesFrozenWeeklyMetrics(t *testing.T) { s := &frozenScheduleSpy{} if e := runRecordsSyncCycle(context.Background(), s, time.Now()); e != nil || !reflect.DeepEqual(s.calls, []string{"sync", "track", "freeze"}) { t.Fatal("weekly capture is not on the real scheduler invocation path", e, s.calls) } broken := &frozenScheduleSpy{trackErr: errors.New("isolated tracking unavailable")} if e := runRecordsSyncCycle(context.Background(), broken, time.Now()); e == nil || !reflect.DeepEqual(broken.calls, []string{"sync", "track"}) { t.Fatal("snapshot failure must not suppress source sync or freeze untracked history") } }