From 65b0d7ea53899301b0bc4039e00dab45e86ec224 Mon Sep 17 00:00:00 2001 From: Julian Knutsen Date: Thu, 9 Jul 2026 08:08:15 -0700 Subject: [PATCH] test(watch): deterministically seed updated_at in TestWatchIssueDetectsFieldUpdate (#4683) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit singleIssueSnapshot compares updated_at at 1-second granularity, and a title change is not otherwise reflected in the snapshot. The test created and updated the issue back-to-back, so on a fast machine both landed in the same wall-clock second, updated_at tied, and the snapshot compared equal — a spurious failure. Seed the created issue's updated_at an hour in the past (CreateIssue honors a non-zero UpdatedAt) so the title update's fresh timestamp is unambiguously newer. No production change; the watch snapshot behavior is unchanged. Co-authored-by: Test User Co-authored-by: Claude Opus 4.8 (1M context) --- cmd/bd/show_watch_test.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cmd/bd/show_watch_test.go b/cmd/bd/show_watch_test.go index cac36f17e..197f0698d 100644 --- a/cmd/bd/show_watch_test.go +++ b/cmd/bd/show_watch_test.go @@ -124,13 +124,20 @@ func TestWatchIssueDetectsFieldUpdate(t *testing.T) { dbPath := filepath.Join(tmpDir, ".beads", "test.db") s := newTestStore(t, dbPath) + // Seed updated_at an hour in the past so the title update's fresh (now) + // timestamp is unambiguously newer. A title change is not itself reflected in + // singleIssueSnapshot, which compares updated_at at 1-second granularity — so a + // same-second create+update (the common case on a fast machine) would tie and + // spuriously fail. CreateIssue honors a non-zero UpdatedAt (see issueops + // create.go), making the gap deterministic. + seeded := time.Now().Add(-time.Hour) issue := &types.Issue{ ID: generateUniqueTestID(t, "test", 0), Title: "original title", Status: types.StatusOpen, IssueType: types.TypeTask, - CreatedAt: time.Now(), - UpdatedAt: time.Now(), + CreatedAt: seeded, + UpdatedAt: seeded, } if err := s.CreateIssue(ctx, issue, "test-actor"); err != nil { t.Fatalf("CreateIssue: %v", err) @@ -142,7 +149,7 @@ func TestWatchIssueDetectsFieldUpdate(t *testing.T) { } snapBefore := singleIssueSnapshot(got) - // Update title (which bumps UpdatedAt) + // Update title (which bumps UpdatedAt to now, an hour after the seed) if err := s.UpdateIssue(ctx, issue.ID, map[string]interface{}{"title": "updated title"}, "test-actor"); err != nil { t.Fatalf("UpdateIssue: %v", err) }