You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(hooks): keep test fixtures from rewriting a worktree's shared git config - #252
Urgent hook-safety fix, split out of #247. In a linked worktree, git commit exports GIT_DIR=<main>/.git/worktrees/<name> and GIT_INDEX_FILE to the pre-commit hooks. Test fixtures that run git init <tmp> with those variables re-initialize that git dir. Its path doesn't end in .git, so git guesses it's bare and writes core.bare = true to the main checkout's shared .git/config. The fixture commits (base, drop the companion) also land on the worktree's branch. That's what broke the main checkout. I reproduced it in a throwaway main repo with a worktree and a one-line hook.
tests/test_hook_scripts.py: same fix for FeatureBranchPushTest's fixture repo and for the push-hook runs. CI runs these today; no hook does.
New tests/test_hook_git_env.py, run by the hook-git-env pre-commit hook and by Markdown Validation. It builds a throwaway main repo with a linked worktree and runs every git-fixture suite with exactly the environment that worktree's hooks get: WorkTreeTests, RepositoryScriptTests, and FeatureBranchPushTest on non-Windows systems with jq. It fails if the main config, refs, HEADs or the worktree index change. It points at a decoy, not the real repo, so a regression can't damage your checkout.
CONTRIBUTING: lists hook-git-env and the apm-external-skills hook.
This PR doesn't touch .python-version or mise. #247 (the Python and mise change) is stacked on top of it.
Validation (native Windows ARM64)
These checks ran in a fresh testing context, separate from implementation, using an existing user-local Python 3.14.8. The main checkout's .git/config hash was the same before and after.
Check
Result
test_hook_git_env.py, test_apm_external_skills.py
✅
Mutation: drop WorkTreeTests' GIT_* scrub → test_hook_git_env fails, decoy config shows bare = true
No actionable comments were generated in the recent review.
Walkthrough
The test fixtures now exclude inherited GIT_ variables. A new regression test runs selected suites with linked-worktree hook variables and checks that the main repository’s config, refs, and index remain unchanged. The test runs in pre-commit hooks and CI.
The test fixtures remove inherited GIT_ variables from their environments when setting up repositories and running Git commands.
Test and run hook-environment regression tests/test_hook_git_env.py, .lefthook.toml, .github/workflows/markdown-validation.yml, CONTRIBUTING.md
A regression test runs selected suites with linked-worktree hook variables and checks the main repository’s config, refs, and index. Pre-commit hooks and CI run the test, and the pre-commit documentation lists it.
Issue 238 asks to route the external-skills pre-commit hook through scripts/py.sh; this pull request makes that change. The issue’s separate request to vendor Humanizer is not covered.
Possibly related PRs
DevSecNinja/ai-toolkit#249: This PR also routes the external-skills hook through scripts/py.sh and isolates its Git fixtures from inherited GIT_ variables.
Merge Risk: Minimal · up to 92b9d
This change stops test fixtures from modifying a linked worktree's shared git config, and adds a regression test that checks for it. No actionable merge risk remains.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: test fixtures were inheriting GIT_* variables from hooks in a linked worktree and could rewrite the shared git config. The changeset removes GIT_* variables from the a…
Linked Issues check
Stack scope: the objectives of #251 are fully addressed by PR #252 at head 92b9dd7. No contribution from PR #256 or PR #247 is needed for these objectives.
Objective 1 [#251]: Drop GIT_* variables in…
Out of Scope Changes check
Changes at head, limited to the current PR: - tests/test_apm_external_skills.py and tests/test_hook_scripts.py: GIT_* filtering in fixtures. Directly implements #251. - tests/test_hook_git_env.py: new…
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check
Explanation
The title names the main change: test fixtures were inheriting GIT_* variables from hooks in a linked worktree and could rewrite the shared git config. The changeset removes GIT_* variables from the affected fixture suites and adds a regression test for this. The title is specific, uses a conventional commit prefix, and is a single sentence. It does not mention the new regression test or the hook routing changes, which is acceptable because it covers the primary change.
Full details: Linked Issues check
Explanation
Stack scope: the objectives of #251 are fully addressed by PR #252 at head 92b9dd7. No contribution from PR #256 or PR #247 is needed for these objectives.
Objective 1 [#251]: Drop GIT_* variables in every fixture suite that runs git. Addressed by #252. Verified at head: tests/test_apm_external_skills.py defines without_git_env() and WorkTreeTests.setUp applies it through mock.patch.dict(os.environ, ..., clear=True), so the fixture git init and git commit calls inherit no GIT_* variables. The summary also reports the same filter in tests/test_hook_scripts.py (FeatureBranchPushTest and hook runs). I did not read that file's diff, because the PR diff was unavailable, so that part rests on the attested summary only. The summary says tests/test_renovate_prs.py already filters GIT_* variables; I did not verify it.
Objective 2 [#251]: Add a regression test, run by a pre-commit hook and in CI, that runs git-fixture suites in a linked-worktree hook environment against a throwaway repo and fails if its config, refs, or index change. Addressed by #252. Verified at head: tests/test_hook_git_env.py builds a temporary main repo and linked worktree, sets GIT_DIR and GIT_INDEX_FILE as hooks receive them, runs the fixture suites with unittest, and asserts that .git/config bytes, for-each-ref output, and the HEAD and index of both the main repo and the worktree are unchanged. The summary reports wiring through the hook-git-env hook in .lefthook.toml and through the Markdown Validation workflow. Those wiring files were not read directly. The author reports a mutation check that failed as expected; I did not reproduce it.
Limits: FeatureBranchPushTest runs only on non-Windows systems with jq. The PR states that Linux CI covers it.
Full details: Out of Scope Changes check
Explanation
Changes at head, limited to the current PR:
tests/test_apm_external_skills.py and tests/test_hook_scripts.py: GIT_* filtering in fixtures. Directly implements #251.
tests/test_hook_git_env.py: new regression test. Directly implements #251.
.github/workflows/markdown-validation.yml and .lefthook.toml: run the regression test and the hook-git-env hook. These implement the #251 requirement that a pre-commit hook and CI run the regression test.
.lefthook.toml: apm-external-skills hook routed through scripts/py.sh. The PR states the hook failed on Windows because bare python3 resolves to the Microsoft Store stub. This is a hook-execution fix that the PR describes. It is adjacent to #251, not strictly required by its text, but it does not change any behavior unrelated to the hook that runs the #251 fixtures.
CONTRIBUTING.md: documents the two hooks. Documentation that supports the new hooks.
No change was found that is unrelated to #251 or to the hook and test infrastructure it depends on. The PR diff was unavailable, so this assessment relies on the attested summaries for the workflow, lefthook, CONTRIBUTING, and test_hook_scripts.py changes.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: defaults
Review profile: CHILL
Plan: Advanced
Run ID: 45226703-d96a-43ce-bd78-6046f6c58357
Commits
Reviewing files that changed from the base of the PR and between b4b3ed1 and 92b9dd7.
Files selected for processing: 6
.github/workflows/markdown-validation.yml
.lefthook.toml
CONTRIBUTING.md
tests/test_apm_external_skills.py
tests/test_hook_git_env.py
tests/test_hook_scripts.py
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The Git path lookup uses locale-dependent decoding, which can corrupt non-ASCII paths on Windows and cause the mandatory pre-commit check to block commits.
This PR addresses #251 by isolating Git test fixtures from inherited hook environment variables, preventing linked-worktree commits from modifying the real repository’s shared configuration, refs, or index.
Changes:
Remove inherited GIT_* variables from fixture and hook subprocess environments.
Add a throwaway-worktree regression check to pre-commit and CI.
Use the Python launcher for the external-skills hook and document both checks.
File
Description
tests/test_hook_scripts.py
Scrubs Git environment variables for fixture repositories and hook runs.
tests/test_hook_git_env.py
Adds regression coverage for repository isolation under a worktree hook environment.
tests/test_apm_external_skills.py
Clears inherited Git variables during worktree fixture tests.
CONTRIBUTING.md
Documents the external-skills and Git-environment checks.
.lefthook.toml
Registers the regression check and uses the Python launcher for external-skills tests.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The test fixture preserves an exported SKIP_PUSH_APPROVAL=true, causing the push hook to bypass approval checks, fail risky-push assertions, and block commits through the mandatory pre-commit check on POSIX systems with jq.
…nfig alone
In a linked worktree, git commit exports GIT_DIR=<main>/.git/worktrees/<name>
and GIT_INDEX_FILE to the hooks. A fixture git init that inherits them
re-initialises that git dir as bare and writes core.bare = true to the
main checkout's shared config, and fixture commits land on the branch.
test_hook_scripts.py's FeatureBranchPushTest now drops GIT_* variables
too. The new test_hook_git_env.py runs every git-fixture suite under a
linked worktree's hook environment against a throwaway repo and fails if
its config, refs or index change; it runs as a pre-commit hook and in CI.
Closes#251
Refs #246
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
With a non-UTF-8 Windows locale, text=True decoded git's UTF-8 paths
with the wrong codec, so a temp path with a non-ASCII user name broke the
snapshot and blocked commits through this pre-commit check.
Refs #251
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
cls.env is forwarded to run_hook(), so building it from the whole
environment let an exported SKIP_PUSH_APPROVAL override the helper's
empty skip flag and fail the risky-push assertions. Keep cls.env to the
git config variables and give the fixture git calls their own
environment without GIT_* variables.
Refs #251
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Urgent hook-safety fix, split out of #247. In a linked worktree,
git commitexportsGIT_DIR=<main>/.git/worktrees/<name>andGIT_INDEX_FILEto the pre-commit hooks. Test fixtures that rungit init <tmp>with those variables re-initialize that git dir. Its path doesn't end in.git, so git guesses it's bare and writescore.bare = trueto the main checkout's shared.git/config. The fixture commits (base,drop the companion) also land on the worktree's branch. That's what broke the main checkout. I reproduced it in a throwaway main repo with a worktree and a one-line hook.tests/test_apm_external_skills.py:WorkTreeTests'git init/git commitfixtures caused the incident through theapm-external-skillshook (fix: keep committed external skills through APM Materialize #240). feat(skills): vendor SHA-pinned Humanizer #249 has since landed the sameGIT_*scrub there, and routed that hook throughscripts/py.sh, so this PR no longer changes that file or that hook.tests/test_hook_scripts.py: same fix forFeatureBranchPushTest's fixture repo and for the push-hook runs. CI runs these today; no hook does.tests/test_hook_git_env.py, run by thehook-git-envpre-commit hook and by Markdown Validation. It builds a throwaway main repo with a linked worktree and runs every git-fixture suite with exactly the environment that worktree's hooks get:WorkTreeTests,RepositoryScriptTests, andFeatureBranchPushTeston non-Windows systems withjq. It fails if the main config, refs, HEADs or the worktree index change. It points at a decoy, not the real repo, so a regression can't damage your checkout.hook-git-envand theapm-external-skillshook.This PR doesn't touch
.python-versionor mise. #247 (the Python and mise change) is stacked on top of it.Validation (native Windows ARM64)
These checks ran in a fresh testing context, separate from implementation, using an existing user-local Python 3.14.8. The main checkout's
.git/confighash was the same before and after.test_hook_git_env.py,test_apm_external_skills.pyWorkTreeTests'GIT_*scrub →test_hook_git_envfails, decoy config showsbare = truelefthook run pre-commit --all-files(incl.apm-external-skills,hook-git-env), re-run after rebasing on #249 / #259validate-prompts.shFeatureBranchPushTestdoesn't run on Windows. The Linux CI run covers it.The commit is signed (1Password SSH) and passed every pre-commit hook.
Closes #251
Refs #246