Repository navigation
Share One Git Location Variable List Across Self-Tests - #3335
Conversation
A self-test or test that builds a temporary repository with git -C or cwd= inherits any GIT_DIR, GIT_INDEX_FILE, and similar variable a git hook sets, so it writes into the hook's repository. spec/audit.py --selftest cleared nothing and ran init, config, add, and commit that way. - spec/git_env.py holds the full list (git rev-parse --local-env-vars plus three discovery controls), a without_git_location() copy helper, and a git_location_cleared() context manager. - spec/audit.py wraps its self-test in the context manager. - scripts/local_review.py, tests/test_pr_review.py, and tests/test_pre_commit_hook.py use the shared list in place of their own variants. - tests/test_git_env.py runs the audit self-test under a GIT_DIR naming a scratch repository and asserts its config and history are unchanged. Refs #3324 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Drop the three discovery names from the shared list, keep the pre-commit hook test on its stricter GIT_ prefix strip, and make the new test restore the environment and assert the self-test passed. Refs #3324 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
A recorded local strict-review pass covers head |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🟡 Changes recommended
The Git environment context manager must restore variables created inside the context before approval.
1 open issue
What changed in this PR
This pull request centralizes Git repository-location environment handling so self-tests and temporary-repository tests are isolated from inherited hook variables.
Changes:
- Adds shared Git environment-variable definitions and cleanup helpers in
spec/git_env.py. - Applies the helpers to the audit self-test, local review script, and PR-review fixtures.
- Adds regression coverage for Git variable completeness and audit self-test isolation.
| File | Summary |
|---|---|
tests/test_pr_review.py |
Uses the shared Git environment filtering helper for repository fixtures. |
tests/test_git_env.py |
Tests environment filtering, restoration behavior, variable-list coverage, and audit self-test isolation. |
spec/git_env.py |
Defines shared Git environment handling; has an unresolved restoration issue where variables created inside the context can persist, plus an unnecessary future-annotations import. |
spec/audit.py |
Runs the audit self-test with Git repository-location variables cleared. |
scripts/local_review.py |
Reuses the shared Git variable list for subprocess isolation. |
Review effort: Lite
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #3335 +/- ##
==========================================
Coverage ? 65.53%
==========================================
Files ? 18
Lines ? 10036
Branches ? 0
==========================================
Hits ? 6577
Misses ? 3459
Partials ? 0
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:
|
Answers a review finding: the context manager restored only the names that existed on entry, so a variable set inside it outlived it. Refs #3324 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
A recorded local strict-review pass covers head |
|
A recorded local strict-review pass covers head |
… Narrowing to Main (#3346) ## Summary Promotes these pull requests from develop. - [#3329](#3329): restores the prerelease filter on the GitHub Pre-Release shield and has the audit require it. - [#3333](#3333): narrows the prose gate's comment-added promotion stand-down by workflow model. - [#3335](#3335): shares one git location variable list across the self-tests. - [#3342](#3342): the write guard reads every launcher and exported git directory. - [#3345](#3345): the write guard reads tokenizer, directory-value, and launched-string gaps. Refs #3307 Refs #2943 Closes #3320 Closes #1663 Closes #3324 Closes #3050 Closes #3083 Closes #3085 Closes #3304 Closes #2991 Closes #2995 Closes #3090 Closes #3074 Closes #3075 🤖 Generated with [Claude Code](https://claude.com/claude-code)

Summary
A self-test or test that builds a temporary repository with
git -Corcwd=inherits theGIT_DIR,GIT_INDEX_FILE, and similar variables a git hook sets, and writes into the hook's own repository.spec/audit.py --selftestcleared nothing and ran init, config, add, and commit that way.spec/git_env.pyholds the list (whatgit rev-parse --local-env-varsprints),without_git_location(), andgit_location_cleared().spec/audit.pyruns its self-test insidegit_location_cleared().scripts/local_review.py(INHERITED_REDIRECTS) andtests/test_pr_review.py(_clean_env) use the shared list.tests/test_git_env.pyruns the audit self-test under aGIT_DIRnaming a scratch repository, asserts it exits 0 withSELFTEST PASS, and asserts the scratch repository's config, history, and status are unchanged. It also checks the list covers every name the installed git prints.Refs #3324. The
host-setup/agent-safety/item (test_install.py missingGIT_INDEX_FILE) lands in the guard lane, so this does not close the issue.Not moved
tests/test_pre_commit_hook.pyalready strips everyGIT_-prefixed variable, a superset of the list, so moving it would weaken it. Left unchanged.scripts/pr_review.pyorigin_owner()keeps its own four-name strip, and the.github/actions/prose-gate/prose_lint.pycopy cannot import fromspec/because it is carried downstream.Verification
test_git_env,test_local_review,test_pr_review,test_canonical_review,test_pre_commit_hook,test_audit,audit.py --selftest,validate.py, ruff, mypy, prose gate, and the EOL gate pass.Local review
Two passes. The first raised seven findings: the pre-commit test fixture got weaker (fixed by leaving that file unchanged), the discovery names in the list (fixed by dropping them), a docstring inaccuracy (fixed), a stale docstring claim in
_clean_env(fixed), two test-quality issues (fixed). Declined:local_reviewnow also clearsGIT_DIRandGIT_CONFIG_PARAMETERS, which are on git's own list of per-repository variables, and every call there names its working directory. The second pass found nothing.🤖 Generated with Claude Code