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

@@ -86,10 +86,20 @@ func findJSONLPath() string {
if err := os.MkdirAll(dbDir, 0750); err != nil {
// If we can't create the directory, return discovered path anyway
// (the subsequent write will fail with a clearer error)
return jsonlPath
return canonicalizeIfRelative(jsonlPath)
}
return jsonlPath
return canonicalizeIfRelative(jsonlPath)
}
// canonicalizeIfRelative ensures path is absolute for filepath.Rel() compatibility.
// Guards against any code path that might set dbPath to relative.
// See GH#959 for root cause analysis.
func canonicalizeIfRelative(path string) string {
if path != "" && !filepath.IsAbs(path) {
return utils.CanonicalizePath(path)
}
return path
}
// autoImportIfNewer checks if JSONL content changed (via hash) and imports if so