diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 17c8ac560..57a246683 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -155,7 +155,7 @@ jobs: mkdir -p "$staging" cp "bd-darwin-${arch}" "$staging/bd" cp LICENSE README.md CHANGELOG.md "$staging/" - tar -czf "${staging}.tar.gz" "$staging" + tar -czf "${staging}.tar.gz" -C "$staging" . shasum -a 256 "${staging}.tar.gz" >> darwin-checksums.txt done @@ -323,4 +323,3 @@ jobs: npm publish --access public # Uses OIDC trusted publishing - no token needed # Provenance attestations are automatic with trusted publishing - diff --git a/Makefile b/Makefile index 800a6dff2..4bb492694 100644 --- a/Makefile +++ b/Makefile @@ -148,7 +148,7 @@ endif install install-force: build @mkdir -p $(INSTALL_DIR) ifeq ($(OS),Windows_NT) - @rm -f $(INSTALL_DIR)/bd.exe + @rm -f $(INSTALL_DIR)/bd $(INSTALL_DIR)/bd.exe @cp $(BUILD_DIR)/bd.exe $(INSTALL_DIR)/bd.exe @echo "Installed bd.exe to $(INSTALL_DIR)/bd.exe" else diff --git a/cmd/bd/hooks.go b/cmd/bd/hooks.go index c6089ff7a..c7befa0ab 100644 --- a/cmd/bd/hooks.go +++ b/cmd/bd/hooks.go @@ -1175,12 +1175,11 @@ func exportJSONLForCommit() { // gitAddFile as the parent, which relies on the inherited GIT_DIR to // identify the hook's worktree and apply the cross-worktree staging // guard (GH#3311 part 2). Scrubbing here would disable that guard. - // The theoretical downside is sync.Once-cached git.GetRepoRoot() in - // the subprocess being computed against cwd=.beads/; no current - // caller reads it on this path, so it is a latent hazard rather than - // a live bug. + // Run from the project root, not .beads/. Embedded Dolt discovery starts + // from cwd, so cwd=.beads/ can make the export subprocess look for a + // nested .beads/.beads workspace and warn on every commit (GH#3454). cmd := exec.Command("bd", "export", "-o", fullPath) - cmd.Dir = beadsDir + cmd.Dir = exportSubprocessDir(beadsDir) cmd.Env = filterEnv(os.Environ(), "BD_GIT_HOOK") cmd.Stderr = os.Stderr if err := cmd.Run(); err != nil { @@ -1200,6 +1199,10 @@ func exportJSONLForCommit() { } } +func exportSubprocessDir(beadsDir string) string { + return filepath.Dir(beadsDir) +} + // filterEnv returns a copy of env with entries matching the given key removed. func filterEnv(env []string, key string) []string { prefix := key + "=" diff --git a/cmd/bd/hooks_husky_test.go b/cmd/bd/hooks_husky_test.go index 39b78c46d..8c45c5c0a 100644 --- a/cmd/bd/hooks_husky_test.go +++ b/cmd/bd/hooks_husky_test.go @@ -7,6 +7,16 @@ import ( "testing" ) +func TestExportSubprocessDirUsesProjectRoot(t *testing.T) { + repo := t.TempDir() + beadsDir := filepath.Join(repo, ".beads") + + got := exportSubprocessDir(beadsDir) + if got != repo { + t.Fatalf("exportSubprocessDir(%q) = %q, want project root %q", beadsDir, got, repo) + } +} + // TestSanitizeHuskyHook_V8 verifies that husky v8's `_/husky.sh` source line // is stripped and replaced with a PATH export, so the hook runs standalone // without needing `.beads/hooks/_/husky.sh` to exist. (GH#3132) diff --git a/cmd/bd/setup/mux_test.go b/cmd/bd/setup/mux_test.go index b2e512496..a6b5b6ebf 100644 --- a/cmd/bd/setup/mux_test.go +++ b/cmd/bd/setup/mux_test.go @@ -2,6 +2,7 @@ package setup import ( "os" + "path/filepath" "strings" "testing" ) @@ -40,24 +41,25 @@ func TestCheckMuxMissingFile(t *testing.T) { } func TestMuxProjectAgentsPath(t *testing.T) { - if got := muxProjectAgentsPath("AGENTS.md"); got != ".mux/AGENTS.md" { - t.Fatalf("got %q, want .mux/AGENTS.md", got) + if got, want := muxProjectAgentsPath("AGENTS.md"), filepath.Join(".mux", "AGENTS.md"); got != want { + t.Fatalf("got %q, want %q", got, want) } - if got := muxProjectAgentsPath("/tmp/work/AGENTS.md"); got != "/tmp/work/.mux/AGENTS.md" { - t.Fatalf("got %q, want /tmp/work/.mux/AGENTS.md", got) + agentsPath := filepath.Join(t.TempDir(), "AGENTS.md") + if got, want := muxProjectAgentsPath(agentsPath), filepath.Join(filepath.Dir(agentsPath), ".mux", "AGENTS.md"); got != want { + t.Fatalf("got %q, want %q", got, want) } } func TestMuxProjectHookPaths(t *testing.T) { initPath, toolPostPath, toolEnvPath := muxProjectHookPaths("AGENTS.md") - if initPath != ".mux/init" { - t.Fatalf("init path = %q, want .mux/init", initPath) + if want := filepath.Join(".mux", "init"); initPath != want { + t.Fatalf("init path = %q, want %q", initPath, want) } - if toolPostPath != ".mux/tool_post" { - t.Fatalf("tool_post path = %q, want .mux/tool_post", toolPostPath) + if want := filepath.Join(".mux", "tool_post"); toolPostPath != want { + t.Fatalf("tool_post path = %q, want %q", toolPostPath, want) } - if toolEnvPath != ".mux/tool_env" { - t.Fatalf("tool_env path = %q, want .mux/tool_env", toolEnvPath) + if want := filepath.Join(".mux", "tool_env"); toolEnvPath != want { + t.Fatalf("tool_env path = %q, want %q", toolEnvPath, want) } } @@ -114,16 +116,17 @@ func TestMuxGlobalAgentsPath(t *testing.T) { t.Cleanup(func() { muxUserHomeDir = os.UserHomeDir }) + home := t.TempDir() muxUserHomeDir = func() (string, error) { - return "/tmp/test-home", nil + return home, nil } got, err := muxGlobalAgentsPath() if err != nil { t.Fatalf("muxGlobalAgentsPath returned error: %v", err) } - if got != "/tmp/test-home/.mux/AGENTS.md" { - t.Fatalf("got %q, want /tmp/test-home/.mux/AGENTS.md", got) + if want := filepath.Join(home, ".mux", "AGENTS.md"); got != want { + t.Fatalf("got %q, want %q", got, want) } } diff --git a/internal/storage/dolt/circuit_test.go b/internal/storage/dolt/circuit_test.go index 11dc09795..d47365810 100644 --- a/internal/storage/dolt/circuit_test.go +++ b/internal/storage/dolt/circuit_test.go @@ -417,7 +417,7 @@ func TestCircuitBreakerDir_UsesSubdirectory(t *testing.T) { cb := newCircuitBreaker("127.0.0.1", 44444, "") t.Cleanup(func() { os.Remove(cb.filePath) }) - if filepath.Dir(cb.filePath) != circuitBreakerDir { + if filepath.Dir(cb.filePath) != filepath.Clean(circuitBreakerDir) { t.Errorf("circuit breaker file should be in %s, got dir %s", circuitBreakerDir, filepath.Dir(cb.filePath)) } diff --git a/internal/storage/dolt/credentials_test.go b/internal/storage/dolt/credentials_test.go index 4c9eea805..4283f5ee5 100644 --- a/internal/storage/dolt/credentials_test.go +++ b/internal/storage/dolt/credentials_test.go @@ -6,6 +6,7 @@ import ( "os" "os/exec" "path/filepath" + "runtime" "strings" "testing" @@ -170,7 +171,9 @@ func TestCredentialKeyFileGeneration(t *testing.T) { if err != nil { t.Fatalf("key file should exist after initCredentialKey: %v", err) } - if perm := info.Mode().Perm(); perm != 0600 { + if runtime.GOOS == "windows" { + t.Log("skipping POSIX mode-bit check on Windows") + } else if perm := info.Mode().Perm(); perm != 0600 { t.Errorf("key file permissions = %o, want 0600", perm) } diff --git a/internal/utils/path_test.go b/internal/utils/path_test.go index 5f08f622b..b52d90a56 100644 --- a/internal/utils/path_test.go +++ b/internal/utils/path_test.go @@ -254,6 +254,7 @@ func TestCanonicalizePathCase(t *testing.T) { } func TestCanonicalizeIfRelative(t *testing.T) { + absInput := filepath.Join(t.TempDir(), "test", "path") tests := []struct { name string input string @@ -270,10 +271,10 @@ func TestCanonicalizeIfRelative(t *testing.T) { }, { name: "absolute path returns unchanged", - input: "/tmp/test/path", + input: absInput, validate: func(t *testing.T, result string) { - if result != "/tmp/test/path" { - t.Errorf("expected /tmp/test/path, got %q", result) + if result != absInput { + t.Errorf("expected %q, got %q", absInput, result) } }, },