From 165efcc7479461df35c832aa904a22e37ef6fde2 Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Thu, 27 Aug 2026 07:40:33 -0700 Subject: [PATCH 1/2] test(check-pr-size): pin initTestRepo's initial branch so go test passes under init.defaultBranch=main initTestRepo ran `git init -q` with no `-b`, so the fixture repo's first branch was whatever the developer's `init.defaultBranch` happened to be. TestResolveMergeBaseWithAdvancedBaseBranch then runs `git checkout -q -b main `, which fails with `fatal: a branch named 'main' already exists` on any machine configured with `init.defaultBranch = main`. CI is green only because the ubuntu-latest runner's git still defaults to `master`. Pin the fixture's initial branch to a sentinel name so it can never collide with a branch the tests create themselves. `-b` needs git >= 2.28, the same release that introduced `init.defaultBranch`, so no supported git regresses. --- scripts/check-pr-size/main_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/check-pr-size/main_test.go b/scripts/check-pr-size/main_test.go index 6878574e..c191daeb 100644 --- a/scripts/check-pr-size/main_test.go +++ b/scripts/check-pr-size/main_test.go @@ -31,7 +31,9 @@ func gitRun(t *testing.T, dir string, args ...string) string { func initTestRepo(t *testing.T) string { t.Helper() dir := t.TempDir() - gitRun(t, dir, "init", "-q") + // Pin the initial branch so the fixture never collides with a developer's + // init.defaultBranch (tests below create their own "main" branch). + gitRun(t, dir, "init", "-q", "-b", "groom-test-base") gitRun(t, dir, "config", "user.email", "test@example.com") gitRun(t, dir, "config", "user.name", "Test") gitRun(t, dir, "config", "commit.gpgsign", "false") From 934415d293d4cdcd82b1e5a983655b95e4999885 Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Thu, 27 Aug 2026 08:19:10 -0700 Subject: [PATCH 2/2] test(check-pr-size): isolate initTestRepo from global git config, drop `init -b` (BE-9614) Addresses the cursor-review panel findings on #240: - `init -b` needs git >= 2.28, and gitRun escalates any non-zero exit to t.Fatalf, so on older git every repo-backed test died inside initTestRepo before reaching its "git too old for check-attr --source" skip. Pin the branch with `git -c init.defaultBranch=...` instead, which pre-2.28 git ignores harmlessly (it does not honor the key, so it cannot collide). - Pinning the branch closed one collision with the developer's global config but left the class open. Neutralize it wholesale with GIT_CONFIG_GLOBAL / GIT_CONFIG_SYSTEM = os.DevNull, the idiom already used by .github/groom/tests/test_scope.py and groom.yml. Set via t.Setenv, not gitRun's cmd.Env, because the production helpers under test (diffFiles, checkAttrSourceSupported) spawn their own git from the test process. Verified: under a global `diff.renames=false`, TestClassifyRenameIntoAttrGeneratedTreeStillCounts and TestAnnotateDiscountsPairsRenamesSoTheEditStillCounts failed with "rename detection did not fire" before this change and pass after. - Rename the fixture branch groom-test-base -> pr-size-test-base; `groom` is an unrelated subsystem under .github/groom/. --- scripts/check-pr-size/main_test.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/scripts/check-pr-size/main_test.go b/scripts/check-pr-size/main_test.go index c191daeb..05b93b64 100644 --- a/scripts/check-pr-size/main_test.go +++ b/scripts/check-pr-size/main_test.go @@ -30,10 +30,28 @@ func gitRun(t *testing.T, dir string, args ...string) string { // initTestRepo creates an empty git repo with a committer identity configured. func initTestRepo(t *testing.T) string { t.Helper() + // Neutralize the developer's global/system git config for the whole test: + // a global diff.renames=false (or a low diff.renameLimit) would empty the + // OldPath values the rename tests assert on, and a global core.hooksPath / + // core.excludesFile would change what commitAll stages. This is t.Setenv + // rather than gitRun's cmd.Env because the production helpers under test + // (diffFiles, checkAttrSourceSupported, ...) spawn their own git from this + // process. Safe here: these tests are already non-parallel (see above). + // Same idiom as .github/groom/tests/test_scope.py and groom.yml. Both vars + // need git >= 2.32; older git simply ignores them, which is no worse than + // today. + t.Setenv("GIT_CONFIG_GLOBAL", os.DevNull) + t.Setenv("GIT_CONFIG_SYSTEM", os.DevNull) dir := t.TempDir() // Pin the initial branch so the fixture never collides with a developer's - // init.defaultBranch (tests below create their own "main" branch). - gitRun(t, dir, "init", "-q", "-b", "groom-test-base") + // init.defaultBranch (tests below create their own "main" branch). Set via + // `-c` rather than `init -b`: -b needs git >= 2.28, and gitRun turns any + // non-zero exit into t.Fatalf, so on older git every repo-backed test here + // would die in initTestRepo instead of reaching its + // "git too old for check-attr --source" skip. Pre-2.28 git ignores the + // unknown key harmlessly -- it does not honor init.defaultBranch, so it + // cannot collide in the first place. + gitRun(t, dir, "-c", "init.defaultBranch=pr-size-test-base", "init", "-q") gitRun(t, dir, "config", "user.email", "test@example.com") gitRun(t, dir, "config", "user.name", "Test") gitRun(t, dir, "config", "commit.gpgsign", "false")