From 2141be7672a613ceec307c7a5fba0ebf98eb7ea7 Mon Sep 17 00:00:00 2001 From: wretched Date: Sun, 4 Jan 2026 23:40:11 -0800 Subject: [PATCH] fix: Sync database before beads integration test to prevent flaky failures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The TestIntegration test was flaky because it uses the real .beads directory and the SQLite database could be out of sync with the JSONL file (e.g., after git pull updates the JSONL but before the database is re-imported). The fix runs `bd sync --import-only` at the start of the test to ensure the database is synchronized before running the actual test operations. Fixes gt-5ww96 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- internal/beads/beads_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/internal/beads/beads_test.go b/internal/beads/beads_test.go index 9ab444e1..58a42b8a 100644 --- a/internal/beads/beads_test.go +++ b/internal/beads/beads_test.go @@ -3,6 +3,7 @@ package beads import ( "encoding/json" "os" + "os/exec" "path/filepath" "strings" "testing" @@ -141,6 +142,17 @@ func TestIntegration(t *testing.T) { b := New(dir) + // Sync database with JSONL before testing to avoid "Database out of sync" errors. + // This can happen when JSONL is updated (e.g., by git pull) but the SQLite database + // hasn't been imported yet. Running sync --import-only ensures we test against + // consistent data and prevents flaky test failures. + syncCmd := exec.Command("bd", "--no-daemon", "sync", "--import-only") + syncCmd.Dir = dir + if err := syncCmd.Run(); err != nil { + // If sync fails (e.g., no database exists), just log and continue + t.Logf("bd sync --import-only failed (may not have db): %v", err) + } + // Test List t.Run("List", func(t *testing.T) { issues, err := b.List(ListOptions{Status: "open"})