fix(resolve): map embeddeddolt data dir back to its beads dir (GH#4574) (#4575)
resolveBeadsDirForDBPath matched a candidate beads dir only when cfg.DatabasePath(beadsDir) == dbPath. DatabasePath returns <beadsDir>/dolt, but embedded stores keep data at <beadsDir>/embeddeddolt, so the compare never matched for embedded stores whose dir is not named ".beads". resolveCommandBeadsDir then walked ancestors and grabbed the auto-created empty ~/.beads, silently returning zero issues. Match on the parent relationship (dbPath lives directly inside beadsDir) so resolution works for embedded stores of any directory name, without changing DatabasePath's broad contract. Co-authored-by: enieuwy <enieuwy@users.noreply.github.com>
This commit is contained in:
parent
616706094d
commit
a813f9a2f2
2 changed files with 50 additions and 0 deletions
|
|
@ -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
|
||||
// (<beadsDir>/embeddeddolt for embedded, <beadsDir>/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
|
||||
}
|
||||
|
|
|
|||
42
cmd/bd/store_reopen_embedded_resolution_test.go
Normal file
42
cmd/bd/store_reopen_embedded_resolution_test.go
Normal file
|
|
@ -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 <beadsDir>/embeddeddolt/, but Config.DatabasePath
|
||||
// returns <beadsDir>/dolt. When the beads dir is not literally named ".beads"
|
||||
// the early-return in resolveBeadsDirForDBPath does not fire, so resolution
|
||||
// must still map <beadsDir>/embeddeddolt back to <beadsDir> 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/<app>/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)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue