Skip to content

Run the Write Guard Self-Test Without an Ambient GIT_DIR - #3323

Merged
ptr727 merged 4 commits into
developfrom
feature/promo-3316-fix-1
Oct 22, 2026
Merged

ptr727 merged 4 commits into
developfrom
feature/promo-3316-fix-1

Conversation

@ptr727

@ptr727 ptr727 commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

Summary

Answers a CodeRabbit finding on the promotion pull request #3321: the write guard's --selftest builds its temporary repositories with git -C, which an ambient GIT_DIR overrides. 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.

  • _selftest now 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_VARS holds that list, moved unchanged from _is_primary_checkout_selftest, which no longer clears on its own since the wrapper covers it.
  • TestSelftestIgnoresAmbientGitDir runs a case through _selftest under an ambient GIT_DIR and checks that the case's repository holds its own config and that the ambient repository is unchanged.

Verification

  • Full guard self-test under an ambient GIT_DIR pointing 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.
  • Differential of the guard self-test, develop versus this branch, with no ambient variables: 1595 decision rows each, identical, 0 deny-to-allow and 0 allow-to-deny flips.
  • Revert proof: with the wrapper's clearing removed, the new test fails on the ambient repository's state. With it, the test passes.
  • test_install full suite: 163 tests OK. tests.test_tooling_encoding OK 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_VARS repeats located_by_environment in .github/actions/prose-gate/prose_lint.py. Declined: install.py installs gh-write-guard.py as 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-existing finding: 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

ptr727 and others added 3 commits October 21, 2026 16:25
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]>
Copilot AI lite review requested due to automatic review settings October 21, 2026 23:51
@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: Repository: ptr727/ProjectTemplate/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1e621c87-4a7c-4282-8da1-bad1eb6e64ed

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: ptr727/ProjectTemplate/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5f5a6f9b-3a68-4b69-a72a-12e4129687f2
📥 Commits

Reviewing files that changed from the base of the PR and between c945040 and 510ae4d.

📒 Files selected for processing: 2
  • host-setup/agent-safety/claude/gh-write-guard.py
  • host-setup/agent-safety/claude/test_install.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.

📝 Walkthrough

The self-test now clears Git repository-location variables for its full run and restores them afterward. A regression test checks that an ambient GIT_DIR does not redirect the test or remain altered in the caller environment.

Changes: Self-test Git environment

Layer / File(s) Summary
Clear and restore Git variables
host-setup/agent-safety/claude/gh-write-guard.py, host-setup/agent-safety/claude/test_install.py
The self-test runs inside a context that clears and then restores Git repository-location variables. The primary-checkout test relies on this wrapper. A regression test verifies the requested repository receives its configuration, the ambient repository remains unchanged, and the caller’s GIT_DIR is restored.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 510ae

The self-test appears to preserve the caller’s Git environment while using its own repository. No actionable merge-blocking issue remains.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 1 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: running the write guard self-test without an ambient GIT_DIR.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 1 files. (1 skipped: 1 too large.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

✨ Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ptr727

ptr727 commented Oct 21, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 510ae4d5b753894fc4ed9dfbfa3353c8c4c11463, the content this pull request carries at that commit against develop, and it recorded 1 finding.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

@ptr727

ptr727 commented Oct 21, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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]>
@ptr727

ptr727 commented Oct 22, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head e8db26d3e611860cbfe45e7147ecb3a4a1f5d09e, the content this pull request carries at that commit against develop, and it recorded 1 finding.

@codecov

codecov Bot commented Oct 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.47%. Comparing base (c945040) to head (e8db26d).

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     
Flag Coverage Δ
python-3.13 65.47% <ø> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ptr727

ptr727 commented Oct 22, 2026

Copy link
Copy Markdown
Owner Author

Answering the one introduced finding this pull request's body lists (1 listed), raised by the third local strict-review pass:

host-setup/agent-safety/claude/gh-write-guard.py:15556 _GIT_LOCATION_VARS repeats located_by_environment in .github/actions/prose-gate/prose_lint.py.

No change needed. install.py copies gh-write-guard.py into the hooks directory as a single file (GUARD_NAME = "gh-write-guard.py") and runs --selftest on that copy, so the guard cannot import a list that lives in the prose gate's action. The tuple is the guard's existing inline list moved unchanged into a named constant, not a new copy. The wider class of temporary-repository sites outside the guard is filed as #3324.

@ptr727
ptr727 merged commit 37b3cf1 into develop Oct 22, 2026
13 checks passed
@ptr727
ptr727 deleted the feature/promo-3316-fix-1 branch October 22, 2026 01:02
ptr727 added a commit that referenced this pull request Oct 22, 2026
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants