fix: dolt config tests corrupt rig metadata.json in worktree environments

Tests in dolt_test.go call setDoltConfig() which uses FindBeadsDir() to
locate the .beads directory. In worktree environments (polecats),
FindBeadsDir() follows the worktree to the main repo root and returns
the rig's .beads — not the test's temp directory. This causes every
polecat test run to overwrite the production metadata.json with test
values (host=10.0.0.1, port=3309, database=mydb), making the Dolt
server unreachable.

Fix: set BEADS_DIR env var in each test to point at the temp .beads
directory, ensuring FindBeadsDir() returns the correct path regardless
of worktree state. Uses t.Setenv for automatic cleanup.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Executed-By: beads/crew/emma
Rig: beads
Role: crew
This commit is contained in:
emma 2026-02-16 01:09:44 -08:00 • committed by Steve Yegge
commit 63544a5e5c

View file

@ -55,6 +55,10 @@ func TestDoltShowConfigEmbeddedMode(t *testing.T) {
t.Fatalf("failed to save config: %v", err)
}
// Override BEADS_DIR so FindBeadsDir() returns our temp .beads,
// not the rig's .beads (which happens in worktree environments).
t.Setenv("BEADS_DIR", beadsDir)
oldCwd, _ := os.Getwd()
if err := os.Chdir(tmpDir); err != nil {
t.Fatalf("failed to chdir: %v", err)
@ -127,6 +131,10 @@ func TestDoltShowConfigServerMode(t *testing.T) {
t.Fatalf("failed to save config: %v", err)
}
// Override BEADS_DIR so FindBeadsDir() returns our temp .beads,
// not the rig's .beads (which happens in worktree environments).
t.Setenv("BEADS_DIR", beadsDir)
oldCwd, _ := os.Getwd()
if err := os.Chdir(tmpDir); err != nil {
t.Fatalf("failed to chdir: %v", err)
@ -205,6 +213,12 @@ func TestDoltSetConfigValidation(t *testing.T) {
t.Fatalf("failed to save config: %v", err)
}
// Override BEADS_DIR so FindBeadsDir() returns our temp .beads,
// not the rig's .beads (which happens in worktree environments).
// Without this, setDoltConfig writes test values to the production
// metadata.json, corrupting the Dolt server connection config.
t.Setenv("BEADS_DIR", beadsDir)
oldCwd, _ := os.Getwd()
if err := os.Chdir(tmpDir); err != nil {
t.Fatalf("failed to chdir: %v", err)
@ -303,6 +317,10 @@ func TestDoltSetConfigJSONOutput(t *testing.T) {
t.Fatalf("failed to save config: %v", err)
}
// Override BEADS_DIR so FindBeadsDir() returns our temp .beads,
// not the rig's .beads (which happens in worktree environments).
t.Setenv("BEADS_DIR", beadsDir)
oldCwd, _ := os.Getwd()
if err := os.Chdir(tmpDir); err != nil {
t.Fatalf("failed to chdir: %v", err)
@ -354,6 +372,10 @@ func TestDoltSetConfigWithUpdateConfig(t *testing.T) {
t.Fatalf("failed to create config.yaml: %v", err)
}
// Override BEADS_DIR so FindBeadsDir() returns our temp .beads,
// not the rig's .beads (which happens in worktree environments).
t.Setenv("BEADS_DIR", beadsDir)
oldCwd, _ := os.Getwd()
if err := os.Chdir(tmpDir); err != nil {
t.Fatalf("failed to chdir: %v", err)