Repository navigation
Run the Write Guard Self-Test Without an Ambient GIT_DIR - #3323
Conversation
The guard's self-test builds its temporary repositories with `git -C`, which an ambient `GIT_DIR` overrides, so a self-test run from a git hook wrote its remotes, branches, and config into the hook's own repository. The builder now runs each command without the variables that name a repository, the same list the primary-checkout self-test already cleared, now shared as one constant. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Scrubbing only the builder's spawns stopped the writes, but every case still read its answers back through git under the ambient `GIT_DIR`, so it measured the caller's repository rather than the one it built. The self-test now clears those variables once around every case, through one context manager the primary-checkout case also uses, and the builder no longer carries its own. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The whole self-test run now clears the repository variables, and this case is reached only through it, so its own clearing found nothing to remove. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
|
A recorded local strict-review pass covers head |
There was a problem hiding this comment.
🟢 Approval recommended
No unresolved review findings remain, and all reviewed changes are covered by regression tests.
No open issues 🎉
What changed in this PR
This pull request makes the write-guard self-test independent of ambient Git repository environment variables, preventing hook-invoked tests from reading or modifying the caller’s repository.
Changes:
- Clears and restores Git repository-location variables around the complete self-test.
- Separates the self-test cases from the environment-isolating wrapper.
- Adds regression coverage for isolation under an ambient
GIT_DIR.
| File | Description |
|---|---|
host-setup/agent-safety/claude/test_install.py |
Verifies self-test isolation and environment restoration under an ambient GIT_DIR. |
host-setup/agent-safety/claude/gh-write-guard.py |
Isolates all self-test repository operations from ambient Git environment state and removes redundant local clearing. |
Review effort: Lite
|
@coderabbitai review |
✅ Action performedReview finished.
|
The repository's tooling test refuses a text-mode spawn that leaves its encoding to the locale, and the new test's git helper did. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
A recorded local strict-review pass covers head |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #3323 +/- ##
===========================================
- Coverage 65.49% 65.47% -0.02%
===========================================
Files 17 17
Lines 10011 10011
===========================================
- Hits 6557 6555 -2
- Misses 3454 3456 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Answering the one
No change needed. |
…moke Stub Pin Bump to Main (#3321) ## Summary Promotes these pull requests from develop. - [#3316](#3316): the write guard judges a push against the repository and branches it actually writes, covering a push to another remote and a bare push under `push.default=matching`. - [#3313](#3313): pins the catalog caller snippets and their documented copies to release 2.0.1122, a release whose task workflows declare every input the snippets pass, `enable_release_asset` included. - [#3323](#3323): runs the write guard's self-test with the repository-location variables cleared, so a run from a git hook no longer writes into or reads from the hook's own repository. Closes #3048 Closes #3053 Closes #3302 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Summary
Answers a CodeRabbit finding on the promotion pull request #3321: the write guard's
--selftestbuilds its temporary repositories withgit -C, which an ambientGIT_DIRoverrides. Run from a git hook, the self-test wrote its remotes, branches, and config into the hook's own repository, and every case read its answers back from there._selftestnow runs every case (the old body, renamed_selftest_cases) inside_git_location_cleared(), which removes the variables that name a repository from the environment and restores them afterwards._GIT_LOCATION_VARSholds that list, moved unchanged from_is_primary_checkout_selftest, which no longer clears on its own since the wrapper covers it.TestSelftestIgnoresAmbientGitDirruns a case through_selftestunder an ambientGIT_DIRand checks that the case's repository holds its own config and that the ambient repository is unchanged.Verification
GIT_DIRpointing at a scratch repository: develop reports 19 FAIL lines and leaves 7 refs plus new config in the scratch repository. This branch reports 0 FAIL lines and leaves it unchanged.test_installfull suite: 163 tests OK.tests.test_tooling_encodingOK after the new test's git reads name UTF-8, which the first CI run refused. ruff format and check, mypy, prose gate, and the EOL gate pass in the pre-commit hook.Local review findings
Four local passes ran. The first raised that scrubbing only the builder left reads measuring the caller's repository, fixed by the whole-run wrapper. The second raised that the primary-checkout case's own clearing became redundant, fixed by removing it. The third raised one finding, still open here, with its outcome:
introduced,_GIT_LOCATION_VARSrepeatslocated_by_environmentin.github/actions/prose-gate/prose_lint.py. Declined:install.pyinstallsgh-write-guard.pyas one standalone hook file and runs its self-test on that copy, so the guard cannot import from the prose gate's action. The list itself moved unchanged from inside the guard rather than being added.The fourth pass, over the encoding fix, raised one
pre-existingfinding: the same class sits unprotected or with a narrower list in files outside the guard,spec/audit.py's self-test clearing nothing at all. Filed as #3324, naming each site.🤖 Generated with Claude Code