From 2e54d80a7817b3ee5cd7edd22cc1eb50c2f2a95c Mon Sep 17 00:00:00 2001 From: Mathias Date: Sat, 3 Oct 2026 21:31:14 +0200 Subject: [PATCH] test(uploads): jobSink forwards the tracker's timestamp to the store (#51) The worker fake ignored the heartbeat time, so the store-boundary half of the app-clock fix had no assertion. Found by the PR #58 review. Co-Authored-By: Claude Sonnet 5.5 --- internal/uploads/jobsink_test.go | 48 ++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 internal/uploads/jobsink_test.go diff --git a/internal/uploads/jobsink_test.go b/internal/uploads/jobsink_test.go new file mode 100644 index 0000000..79da468 --- /dev/null +++ b/internal/uploads/jobsink_test.go @@ -0,0 +1,48 @@ +package uploads + +// Observes what jobSink hands the store: the heartbeat's timestamp is the one the tracker +// stamped (its application clock), not a second reading taken here (#51). + +import ( + "context" + "testing" + "time" + + "git.d-ma.be/mathias/tapir/internal/domain" +) + +type atStore struct{ beatAt, saveAt time.Time } + +func (*atStore) StartTranscribing(context.Context, string, string) error { return nil } +func (*atStore) CompleteUpload(context.Context, string, string, domain.Transcription) error { + return nil +} +func (*atStore) FailUpload(context.Context, string, string, domain.UploadErrorKind) error { return nil } +func (s *atStore) SaveProgress(_ context.Context, _, _ string, _ []domain.ProgressStep, at time.Time) error { + s.saveAt = at + return nil +} +func (s *atStore) Heartbeat(_ context.Context, _, _ string, at time.Time) error { + s.beatAt = at + return nil +} + +func TestJobSink_ForwardsTheTrackersTimestampToTheStoreUnchanged(t *testing.T) { + st := &atStore{} + sink := jobSink{st: st, userID: "u", id: "i"} + stamp := time.Date(2020, 1, 2, 3, 4, 5, 0, time.UTC) + + if err := sink.Beat(context.Background(), stamp); err != nil { + t.Fatal(err) + } + if err := sink.SaveProgress(context.Background(), nil, stamp); err != nil { + t.Fatal(err) + } + + if !st.beatAt.Equal(stamp) { + t.Errorf("heartbeat reached the store stamped %v, want the tracker's %v", st.beatAt, stamp) + } + if !st.saveAt.Equal(stamp) { + t.Errorf("progress save reached the store stamped %v, want the tracker's %v", st.saveAt, stamp) + } +}