test(watch): deterministically seed updated_at in TestWatchIssueDetectsFieldUpdate (#4683)

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 <test@test.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Julian Knutsen 2026-07-09 08:08:15 -07:00 • committed by GitHub
commit 65b0d7ea53
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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)
}