fix: Sync database before beads integration test to prevent flaky failures

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 <noreply@anthropic.com>
This commit is contained in:
wretched
2026-01-04 23:40:11 -08:00
committed by Steve Yegge
parent 18578b3030
commit 2141be7672

View File

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