diff --git a/cmd/bd/store_reopen.go b/cmd/bd/store_reopen.go index 9af4cc51b..a72bbd96b 100644 --- a/cmd/bd/store_reopen.go +++ b/cmd/bd/store_reopen.go @@ -96,6 +96,14 @@ func resolveBeadsDirForDBPath(dbPath string) string { if utils.PathsEqual(beadsDir, dbPath) || utils.PathsEqual(beadsDir, actualDBPath) { return beadsDir } + // dbPath is the data directory living directly inside beadsDir + // (/embeddeddolt for embedded, /dolt for server). + // Match on that parent relationship so resolution works for embedded + // stores regardless of the beads dir name; Config.DatabasePath alone + // returns the "dolt" name and misses embeddeddolt/ (GH#4574). + if utils.PathsEqual(filepath.Dir(dbPath), beadsDir) || utils.PathsEqual(filepath.Dir(actualDBPath), beadsDir) { + return beadsDir + } if utils.PathsEqual(cfg.DatabasePath(beadsDir), dbPath) || utils.PathsEqual(cfg.DatabasePath(beadsDir), actualDBPath) { return beadsDir } diff --git a/cmd/bd/store_reopen_embedded_resolution_test.go b/cmd/bd/store_reopen_embedded_resolution_test.go new file mode 100644 index 000000000..7106a1df9 --- /dev/null +++ b/cmd/bd/store_reopen_embedded_resolution_test.go @@ -0,0 +1,42 @@ +package main + +import ( + "os" + "path/filepath" + "testing" + + "github.com/steveyegge/beads/internal/configfile" + "github.com/steveyegge/beads/internal/utils" +) + +// TestResolveBeadsDirForDBPath_EmbeddedNonDotBeads guards GH#4574: an embedded +// store stores its data under /embeddeddolt/, but Config.DatabasePath +// returns /dolt. When the beads dir is not literally named ".beads" +// the early-return in resolveBeadsDirForDBPath does not fire, so resolution +// must still map /embeddeddolt back to via the parent +// relationship — otherwise commands silently fall back to an ancestor ~/.beads +// and report zero issues. +func TestResolveBeadsDirForDBPath_EmbeddedNonDotBeads(t *testing.T) { + root := t.TempDir() + // leaf is intentionally NOT ".beads" (mirrors an embedding tool that keeps + // its store at e.g. ~/.local/state//beads). + beadsDir := filepath.Join(root, "beads") + dbPath := filepath.Join(beadsDir, "embeddeddolt") + if err := os.MkdirAll(dbPath, 0o755); err != nil { + t.Fatalf("mkdir embeddeddolt dir: %v", err) + } + + cfg := &configfile.Config{ + Database: "dolt", + Backend: configfile.BackendDolt, + DoltMode: "embedded", + DoltDatabase: "mystore", + } + if err := cfg.Save(beadsDir); err != nil { + t.Fatalf("save metadata: %v", err) + } + + if got := resolveBeadsDirForDBPath(dbPath); !utils.PathsEqual(got, beadsDir) { + t.Fatalf("resolveBeadsDirForDBPath(%q) = %q, want %q", dbPath, got, beadsDir) + } +}