mirror of
https://github.com/Comfy-Org/github-workflows.git
synced 2026-11-05 00:17:37 +00:00
[PR #240] [MERGED] test(check-pr-size): pin initTestRepo's initial branch so go test passes under init.defaultBranch=main #246
Labels
No labels
cursor-review-catalog-drift
groom
groom
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Comfy-Org/github-workflows#246
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Comfy-Org/github-workflows/pull/240
Author: @mattmillerai
Created: 8/27/2026
Status: ✅ Merged
Merged: 8/27/2026
Merged by: @mattmillerai
Base:
main← Head:matt/be-9614-pin-inittestrepo-branch📝 Commits (2)
165efcctest(check-pr-size): pin initTestRepo's initial branch so go test passes under init.defaultBranch=main934415dtest(check-pr-size): isolate initTestRepo from global git config, dropinit -b(BE-9614)📊 Changes
1 file changed (+21 additions, -1 deletions)
View changed files
📝
scripts/check-pr-size/main_test.go(+21 -1)📄 Description
ELI-5
The Go tests for the PR-size checker build a throwaway git repo to test against. They never told git what to call that repo's first branch, so git used whatever the developer's
init.defaultBranchsetting says. One test then tries to create its own branch calledmain— and on any machine whereinit.defaultBranch = main(a very common setting), that blows up withfatal: a branch named 'main' already exists. This PR gives the throwaway repo an explicit, deliberately-boring starting branch name so nothing the tests create can ever collide with it — and, after review, seals off the rest of that same class by ignoring the developer's global git config for the duration of these tests.What changed
initTestRepoinscripts/check-pr-size/main_test.go, in two ways. No production code, no CI config, and no other test was touched.1. The initial branch is pinned —
git -c init.defaultBranch=pr-size-test-base init -qinstead of a baregit init -q.The first revision of this PR used
git init -q -b groom-test-base; review (thread) caught that-bneeds git >= 2.28 whilegitRunescalates any non-zero exit tot.Fatalf— so on older git every repo-backed test in the file would die insideinitTestReporather than reach itst.Skip("git too old for check-attr --source")guard. Those guards exist, so pre-2.28 git is explicitly anticipated here. The-cform (already used by.github/bump-callers/tests/test_preflight.sh) pins the branch identically and is ignored harmlessly by pre-2.28 git, which does not honorinit.defaultBranchand therefore cannot collide in the first place. The name also movedgroom-test-base->pr-size-test-base, sincegroomis an unrelated subsystem under.github/groom/.2. The developer's global/system git config is neutralized for these tests —
t.Setenv("GIT_CONFIG_GLOBAL", os.DevNull)+ the same forGIT_CONFIG_SYSTEM, the idiom already used by.github/groom/tests/test_scope.pyandgroom.yml.Pinning the branch fixed one setting; review (thread) pointed out it left the whole class open, and that turned out to be live rather than theoretical — see Verification. It is
t.Setenvrather thangitRun'scmd.Envbecause the failing assertions come fromdiffFiles, production code the test runs in-process aftert.Chdir, spawning its own git from the test process; acmd.Envon the fixture helper would not have covered them. Safe because everyinitTestRepocall site is serial — the same constraintt.Chdiralready imposes.Why CI never caught it
test-pr-size.ymlruns onubuntu-latest, whose git still defaults tomaster, socheckout -b mainfinds no existing branch and the suite is green. The bug only surfaces locally, and only for developers whose git is configured tomain— which is precisely the audience for the local Go gate command documented inAGENTS.md(line 33:(cd scripts/check-pr-size && [ -z "$(gofmt -l .)" ] && go vet ./... && go test ./...)), added by the docs-only #227.Verification
Reproduced the failure on
origin/main(75685ed) before changing anything:Then ran the full matrix on the fix (
-count=1throughout — Go's test cache does not key on env that only the git subprocess reads, so a plain rerun can return a stale cached result). Local git 2.54.0, Go 1.26.5:init.defaultBranchmain(GIT_CONFIG_COUNT=1 …)ok— 258 tests/subtests passed, 0 failedmaster(GIT_CONFIG_COUNT=1 …)okGIT_CONFIG_COUNT=0)okgofmt -l .clean,go vet ./...clean. All three env variants usedGIT_CONFIG_*rather than writing global git config.Review round 2 — the global-config class was not theoretical. Under a global
diff.renames=false, the pre-fix branch (165efcc) fails:Both pass after the
GIT_CONFIG_GLOBAL/GIT_CONFIG_SYSTEMchange, and the suite isokwith no hostile config as well. Separately confirmedgit -c init.defaultBranch=pr-size-test-base init -qstill yieldspr-size-test-baseon git 2.54.0, and re-checked that noinitTestRepocaller sits under at.Parallel()(which would maket.Setenvpanic) — all 15 are serial.The repo gate itself is green on this PR:
test-pr-size.yml(go test) passed in 25s — run 33083662393. As expected it proves nothing about the bug (its runner's git still defaults tomaster); it confirms only that the rename broke nothing. See Residual.Blast-radius check on the rest of the suite
initTestRepohas 16 call sites inmain_test.goand 0 insize_test.go. Grepping the wholecheck-pr-sizepackage for branch-name literals (master,"main",refs/heads,symbolic-ref,branch --show-current,rev-parse --abbrev-ref) returns exactly one hit — line 70, thecheckout -b mainthe tests create explicitly. Nothing reads the initial branch by name, so renaming it is behaviour-neutral for the other 15 call sites, which is what the green full-suite runs above confirm.The half this PR does not fix
Swept the whole repo for the same unpinned pattern: 13
git initsites across 9 files. This PR pins 1. The other 12 —.github/workflows/{pr-risk,pr-derisk,pr-area-label,linear-ticket}.yml(7, all the ancestry-check scratch repos),.github/public-repo-hygiene/tests/test_check_public_repo_hygiene.py(2),scripts/pr-risk/tests/test_pin_contract.sh,.github/groom/tests/test_scope.py,.github/groom/tests/sandbox-tests.sh— were each checked for a follow-oncheckout -b/switch -c/branch -mand for hardcodedmain/masterliterals near the init. None of them creates a named branch aftergit init, so none can collide the way this one does, and none is fixed here.Judgment calls
pr-size-test-base. The first revision kept the work item's literalgroom-test-baseon the reasoning that deviating for cosmetics would be unrequested drift; a reviewer did prefer the rename, so it moved. Either string is an arbitrary sentinel whose only job is to be nothing a developer would set asinit.defaultBranch.Residual
Not fixed here, and worth its own follow-up:
test-pr-size.ymlruns onego test ./...onubuntu-latest, where git defaults tomaster; if a future edit drops the-bagain, the job stays green and the breakage reappears only on developers' machines. The durable fix is a secondgo teststep (or matrix leg) run underGIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=init.defaultBranch GIT_CONFIG_VALUE_0=main, which costs ~2s. It is deliberately not in this PR because the work item scoped this to one file and said not to touchtest-pr-size.yml.git initsites remain unpinned. They are safe today only because none of them happens to create a named branch afterwards (swept and enumerated above) — that is an incidental property, not an enforced one, and the next test added to any of those suites can reintroduce the same collision. A blanket-bpin across all 13 sites, or a lint that requires it, would make the property enforced.mainand verified this fix under all threeinit.defaultBranchsettings. That tracker is not reachable from where this PR was produced, so its transcript was never read; the reproduction and the three-way verification above were re-done from scratch here rather than taken on trust, but the investigation's own artifacts remain unexercised.Provenance
test-pr-size.yml(go test) green on this PR (21s, run 33087171862); all 4 PR checks pass. Reproduced the original failure on origin/main@75685ed; on this branchgofmt -l .clean,go vet ./...clean,go test -count=1 ./...okunderinit.defaultBranch= main / master / unset (258 tests+subtests each). For the review-round change, reproduced thediff.renames=falsefailure on165efccand confirmed it green on934415d.git -c init.defaultBranch=instead ofinit -b(old-git compatibility), the sentinel branch was renamedgroom-test-base->pr-size-test-base, andGIT_CONFIG_GLOBAL/GIT_CONFIG_SYSTEMisolation was added. All three are inside the sameinitTestRepohelper in the same file; still no CI step added and no other test touched.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.