Fix doctor DB-JSONL sync check to exclude ephemeral wisps (#1144)

The DB-JSONL Sync check was showing a false positive warning when wisps
(ephemeral issues) existed in the database. Wisps are intentionally
excluded from JSONL exports, so they shouldn't be counted when comparing
database and JSONL issue counts.

Changes:
- Updated CheckDatabaseJSONLSync to exclude ephemeral issues from count
  using 'WHERE ephemeral = 0 OR ephemeral IS NULL'
- Added 'ephemeral' column to test database schema
- Added test case to verify ephemeral issues are excluded from count
- Updated TestCheckDatabaseJSONLSync_MoleculePrefix to include ephemeral column

This prevents false warnings like 'database has 92 issues, JSONL has 30'
when the difference is entirely due to wisps that should not be exported.

Co-authored-by: Roland Tritsch <roland@ailtir.com>
This commit is contained in:
Roland Tritsch
2026-01-19 18:11:23 +00:00
committed by GitHub
parent aa3b318939
commit 34b741d2e0
2 changed files with 33 additions and 4 deletions

View File

@@ -412,9 +412,9 @@ func CheckDatabaseJSONLSync(path string) DoctorCheck {
}
defer db.Close()
// Get database count
// Get database count (exclude ephemeral/wisp issues - they're never exported to JSONL)
var dbCount int
err = db.QueryRow("SELECT COUNT(*) FROM issues").Scan(&dbCount)
err = db.QueryRow("SELECT COUNT(*) FROM issues WHERE ephemeral = 0 OR ephemeral IS NULL").Scan(&dbCount)
if err != nil {
// Database opened but can't query. If JSONL has issues, suggest recovery.
if jsonlErr == nil && jsonlCount > 0 {

View File

@@ -28,7 +28,8 @@ func setupTestDatabase(t *testing.T, dir string) string {
_, err = db.Exec(`CREATE TABLE IF NOT EXISTS issues (
id TEXT PRIMARY KEY,
title TEXT,
status TEXT
status TEXT,
ephemeral INTEGER DEFAULT 0
)`)
if err != nil {
t.Fatalf("failed to create table: %v", err)
@@ -161,6 +162,34 @@ func TestCheckDatabaseJSONLSync(t *testing.T) {
},
expectedStatus: "warning",
},
{
name: "ephemeral wisps excluded from count",
setup: func(t *testing.T, dir string) {
// Create database with 3 issues: 2 regular + 1 ephemeral wisp
dbPath := setupTestDatabase(t, dir)
db, _ := sql.Open("sqlite3", dbPath)
defer db.Close()
// Add config table for prefix check
_, _ = db.Exec(`CREATE TABLE IF NOT EXISTS config (key TEXT PRIMARY KEY, value TEXT)`)
_, _ = db.Exec(`INSERT INTO config (key, value) VALUES ('issue_prefix', 'test')`)
// Insert 2 regular issues
_, _ = db.Exec(`INSERT INTO issues (id, title, status, ephemeral) VALUES ('test-1', 'Regular Issue 1', 'open', 0)`)
_, _ = db.Exec(`INSERT INTO issues (id, title, status, ephemeral) VALUES ('test-2', 'Regular Issue 2', 'open', 0)`)
// Insert 1 ephemeral wisp (should be ignored in count)
_, _ = db.Exec(`INSERT INTO issues (id, title, status, ephemeral) VALUES ('test-wisp-1', 'Wisp Issue', 'open', 1)`)
// Create JSONL with only 2 issues (wisps are never exported)
jsonlPath := filepath.Join(dir, ".beads", "issues.jsonl")
content := `{"id":"test-1","title":"Regular Issue 1","status":"open"}
{"id":"test-2","title":"Regular Issue 2","status":"open"}
`
if err := os.WriteFile(jsonlPath, []byte(content), 0600); err != nil {
t.Fatalf("failed to create JSONL: %v", err)
}
},
expectedStatus: "ok",
expectMessage: "Database and JSONL are in sync",
},
{
// GH#885: Status mismatch detection
name: "status mismatch - same count different status",
@@ -975,7 +1004,7 @@ func TestCheckDatabaseJSONLSync_MoleculePrefix(t *testing.T) {
}
// Create issues table
_, err = db.Exec(`CREATE TABLE issues (id TEXT PRIMARY KEY, title TEXT, status TEXT)`)
_, err = db.Exec(`CREATE TABLE issues (id TEXT PRIMARY KEY, title TEXT, status TEXT, ephemeral INTEGER DEFAULT 0)`)
if err != nil {
db.Close()
t.Fatalf("failed to create issues table: %v", err)