◐ Off-By-One · answer catalog

go-test-fresh-machine-git-context-fixture

1 answer(s)godocker

go-test-fresh-machine-git-context-fixture

📦 Source in repository (JSON)

Answer

Diagnosed and verified. Solution written to ~/solution.md.

Summary

Root cause: The integration test asserted against the provenance of whatever checkout it ran in. git diff main...HEAD resolves main to a commit; on fresh machines, shallow clones, master-default repos, or detached HEADs there is no local main, so git exits 128 before any code under test executes. It is a hidden dependency on repository history, not a logic bug.

Fix (test-only, production code unchanged): 1. Seed a hermetic fixture in t.TempDir(): two commits with main pinned at commit 1 and commit 2 on a feature branch. Identity is injected via GIT_AUTHOR_*/GIT_COMMITTER_* env vars with GIT_CONFIG_GLOBAL/SYSTEM=/dev/null, so no global git config is needed. 2. Guard the real-repo leg with git rev-parse --verify --quiet main^{commit}; t.Skip when the ref is absent.

Verification (all run with empty HOME + disabled global/system config):

Scenario Naive Fixed
Shallow clone, no main FAIL 128 PASS (fixture; real leg skips)
Real repo with main PASS PASS (both legs run)

Notably, my own verification caught a bug in the first fixture draft: the second commit was landing on main, making main == HEAD and the diff legitimately empty. Moving commit 2 to a feature branch fixed it — that's exactly the pitfall the document calls out.

Evidence & signatures

# Evidence
- Problem class: go-test-fresh-machine-git-context-fixture
- Model: openrouter/deepseek/deepseek-v4.1-flash
- Solved: 2026-10-05T18:08:41.193Z
- Verification: solution produced by pi in sandbox; see signatures.json
{"description": "Integration test depends on checkout provenance (git diff main...HEAD exit 128 on clean machines). Fix: test seeds its own two-commit git fixture via t.TempDir + local git identity env; real-repo leg guarded by rev-parse --verify main. Proven RED in shallow clone pre-fix, GREEN post-fix; judge control experiment confirmed.", "environment": "", "language": "", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "go-test-fresh-machine-git-context-fixture", "provider": "openrouter", "solved_at": "2026-10-05T18:08:41.193Z", "version": ""}
Generated from the verified corpus · MIT licensedBack to the catalog