From ced3dfe220428b61e52bd9c29f83803b339edcee Mon Sep 17 00:00:00 2001 From: Jim Wordelman Date: Tue, 29 Sep 2026 13:26:35 -0700 Subject: [PATCH] fix: isolate 2 doctor role tests from global git beads.role (#6247) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: isolate 2 doctor role tests from global git beads.role (refs be-klbl6) TestCheckBeadsRole_NotConfigured and TestCheckBeadsRole_NotGitRepo fail when a global `git config --global beads.role` is set on the host, since `git config --get` reads global/system scope regardless of whether the target path is a git repo. Isolate via GIT_CONFIG_GLOBAL/GIT_CONFIG_SYSTEM pointed at os.DevNull. This commit originally also cleared the ambient BEADS_ACTOR in three cmd/bd tests (TestCollectViperEntriesWithEnvOverride and the two TestPrepareSelectedCommandContext_* tests). main has since fixed those itself (06b3320a6, and clearActorEnv in context_binding_test.go), so that half was dropped when rebasing onto main. Test-isolation only; no production code changed. * docs(release-gates): PASS 7/7 — be-1wwre (ambient BEADS_ACTOR / global git beads.role leak into 5 tests) * chore: remove leaked internal release-gate doc from PR branch release-gates/be-1wwre-gate.md Tracked our internal gc-management/beads-rig release-gate checklist and should never have been committed to this upstream branch -- it's process residue from our deploy tooling, not part of the change itself. Per maintainer bee-ghosttrack's request during review of PR #6571. The root cause (our deploy tooling auto-committing this file) is already fixed as of gm-qatxl1; this branch predates that fix, so this commit is cleanup only -- no other content on this branch is touched. Ref: be-lk7o3 * fix(doctor): isolate the 2 role tests via HOME/XDG, not GIT_CONFIG_* The role reads now scrub every GIT_CONFIG* entry from the subprocess environment (gitenv.ScrubRoutingAndSuppression, landed in #6454/#6461), so the GIT_CONFIG_GLOBAL/GIT_CONFIG_SYSTEM=/dev/null suppression this PR originally used never reaches git and the two tests still read the ambient global beads.role. Redirect the config search path instead, matching the idiom TestCheckBeadsRoleIgnoresInheritedRouting already uses in this file. Adopt-pr rebase repair (base cefcabb1e). Review iteration 1 (both nits, non-gating; scorecard 1000/1000 approve): - Extract the repeated 4-line preamble into isolateGlobalGitConfig(t), which returns the temp home, and call it from all three sites. The preamble went from 3 copies to 1; TestCheckBeadsRoleIgnoresInheritedRouting keeps its `home` for the .gitconfig/nondefault fixtures it writes. - Record the system-scope residual in the helper doc comment: HOME/XDG redirection cannot close /etc/gitconfig (or PROGRAMDATA), and ScrubRoutingAndSuppression takes GIT_CONFIG_NOSYSTEM with it, so no env-based way to close system scope exists from a test in this package. Two deviations from the reviewer's prescription, both measured: - The helper lives in role_test.go, not beside newGitRepo in git_repo_template_test.go as prescribed. All three identical sites are in role_test.go, and that file's own TestNewGitRepo_UsesRepoLocalHooksPathDespiteGlobalConfig (:105) has a deliberately different preamble - no USERPROFILE, and GIT_CONFIG_GLOBAL pointed at a writable fixture so it can write a global config - so it must not adopt the helper. Placing the helper there would leave a non-adopting neighbour in the helper's own file, manufacturing the drift the nit targets. - The doc comment scopes the NOSYSTEM claim to ScrubRoutingAndSuppression rather than "the scrub". ScrubRouting (keepSuppression=true) retains the suppression trio - routing.go:121 short-circuits the isConfigSuppression exemption only when keepSuppression is false - as bare_parent_fallback_test.go:175 documents. Measured both arms: ScrubRoutingAndSuppression drops NOSYSTEM/GLOBAL/SYSTEM and keeps HOME/USERPROFILE/XDG_CONFIG_HOME; ScrubRouting keeps all three. Behaviour-preserving and non-vacuous: cmd/bd/doctor is 885P/4F/15S, the same 4-name pre-existing FAIL set as the pre-refactor head; neutering the helper body reds exactly 5 cells (both targets plus absent/nonrepository/default_global) while repository/inline/invalid stay green. --------- Co-authored-by: Julian Knutsen Co-authored-by: Gas City Merge Queue --- cmd/bd/doctor/role_test.go | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/cmd/bd/doctor/role_test.go b/cmd/bd/doctor/role_test.go index b51a6ee0b..5ec4ca071 100644 --- a/cmd/bd/doctor/role_test.go +++ b/cmd/bd/doctor/role_test.go @@ -10,7 +10,32 @@ import ( "github.com/steveyegge/beads/internal/gitenv" ) +// isolateGlobalGitConfig redirects git's config search path to a fresh temp home +// so an ambient global `git config --global beads.role` cannot reach the role +// checks, and returns that home. +// +// The role reads run git with gitenv.ScrubRoutingAndSuppression, which strips +// every GIT_CONFIG* entry from the subprocess environment, so the usual +// GIT_CONFIG_GLOBAL=/dev/null suppression cannot work here — the search path +// itself has to move. System scope (/etc/gitconfig, or PROGRAMDATA on Windows) +// stays visible either way: that scrub takes GIT_CONFIG_NOSYSTEM with it, so no +// env-based way to close system scope exists from a test in this package. It is +// inert for beads.role today and the limitation is shared with every caller on +// this boundary; only a production-side config-scope override could close it. +func isolateGlobalGitConfig(t *testing.T) string { + t.Helper() + home := t.TempDir() + t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) + t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) + return home +} + func TestCheckBeadsRole_NotConfigured(t *testing.T) { + // Isolate from ambient global git config (e.g. a developer machine with + // `git config --global beads.role contributor` set). + isolateGlobalGitConfig(t) + // Create a temp directory with git init but no beads.role config tmpDir := newGitRepo(t) @@ -89,6 +114,11 @@ func TestCheckBeadsRole_InvalidValue(t *testing.T) { } func TestCheckBeadsRole_NotGitRepo(t *testing.T) { + // Isolate from ambient global git config: "git config --get" reads global + // scope even outside a git repo, so without this an ambient + // `git config --global beads.role` leaks into a check that should be N/A. + isolateGlobalGitConfig(t) + tmpDir, err := os.MkdirTemp("", "beads-role-test") if err != nil { t.Fatal(err) @@ -143,10 +173,7 @@ func TestCheckBeadsRoleIgnoresInheritedRouting(t *testing.T) { {"default_global", "", "contributor", StatusOK, "Configured as contributor"}, } { t.Run(tc.name, func(t *testing.T) { - home := t.TempDir() - t.Setenv("HOME", home) - t.Setenv("USERPROFILE", home) - t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) + home := isolateGlobalGitConfig(t) if tc.global != "" { if err := os.WriteFile(filepath.Join(home, ".gitconfig"), []byte("[beads]\nrole = "+tc.global+"\n"), 0600); err != nil { t.Fatal(err)