fix(sync): canonicalize dbPath to fix filepath.Rel error (GH#959) (#960)

Problem:
- When dbPath is set to relative fallback (".beads/beads.db"),
  findJSONLPath() returns a relative path
- daemon_sync_branch.go calls filepath.Rel(absolutePath, relativePath)
  which fails with: "Rel: can't make .beads/issues.jsonl relative to ..."

Solution:
- Canonicalize dbPath at assignment in main.go:471 (source fix)
- Add defensive guard in findJSONLPath() (defense-in-depth)
- Use utils.CanonicalizePath() for OS-agnostic handling
  (symlinks, case normalization on macOS)

Testing:
- Add TestFindJSONLPath_RelativeDbPath (tracer bullet for bug)
- Add edge case tests for BEADS_JSONL and empty dbPath
- All sync mode tests pass including daemon E2E
This commit is contained in:
Peter Chanthamynavong
2026-01-08 14:36:50 -08:00
committed by GitHub
parent 4486e0e7bd
commit 28ff9fe991
3 changed files with 170 additions and 3 deletions

View File

@@ -468,7 +468,10 @@ var rootCmd = &cobra.Command{
os.Exit(1)
}
// For import/setup commands, set default database path
dbPath = filepath.Join(".beads", beads.CanonicalDatabaseName)
// Invariant: dbPath must always be absolute for filepath.Rel() compatibility
// in daemon sync-branch code path. Use CanonicalizePath for OS-agnostic
// handling (symlinks, case normalization on macOS).
dbPath = utils.CanonicalizePath(filepath.Join(".beads", beads.CanonicalDatabaseName))
}
}