Skip to content

Share One Git Location Variable List Across Self-Tests - #3335

Merged
ptr727 merged 4 commits into
developfrom
feature/git-location-env-helper
Oct 22, 2026
Merged

ptr727 merged 4 commits into
developfrom
feature/git-location-env-helper

Conversation

@ptr727

@ptr727 ptr727 commented Oct 22, 2026

Copy link
Copy Markdown
Owner

Summary

A self-test or test that builds a temporary repository with git -C or cwd= inherits the GIT_DIR, GIT_INDEX_FILE, and similar variables a git hook sets, and writes into the hook's own repository. spec/audit.py --selftest cleared nothing and ran init, config, add, and commit that way.

  • spec/git_env.py holds the list (what git rev-parse --local-env-vars prints), without_git_location(), and git_location_cleared().
  • spec/audit.py runs its self-test inside git_location_cleared().
  • scripts/local_review.py (INHERITED_REDIRECTS) and tests/test_pr_review.py (_clean_env) use the shared list.
  • tests/test_git_env.py runs the audit self-test under a GIT_DIR naming a scratch repository, asserts it exits 0 with SELFTEST 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 missing GIT_INDEX_FILE) lands in the guard lane, so this does not close the issue.

Not moved

  • tests/test_pre_commit_hook.py already strips every GIT_-prefixed variable, a superset of the list, so moving it would weaken it. Left unchanged.
  • scripts/pr_review.py origin_owner() keeps its own four-name strip, and the .github/actions/prose-gate/prose_lint.py copy cannot import from spec/ because it is carried downstream.

Verification

  • Revert proof: with the wrapper replaced by a bare call, the new test fails on the scratch repository's changed config. With it, it passes.
  • 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_review now also clears GIT_DIR and GIT_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

ptr727 and others added 2 commits October 21, 2026 20:14
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>
Copilot AI lite review requested due to automatic review settings October 22, 2026 03:29
@ptr727

ptr727 commented Oct 22, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 12886f79c44940bcac1e13eecd48786e99f0204b, the content this pull request carries at that commit against develop, and it recorded 0 findings.

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

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: a7935ad8-ed3f-4d72-b4b6-e271cdec0210
  • 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.

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.

🟡 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

Comment thread spec/git_env.py Resolved
@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.30435% with 2 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@366d8e5). Learn more about missing BASE report.

Files with missing lines Patch % Lines
spec/audit.py 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #3335   +/-   ##
==========================================
  Coverage           ?   65.53%           
==========================================
  Files              ?       18           
  Lines              ?    10036           
  Branches           ?        0           
==========================================
  Hits               ?     6577           
  Misses             ?     3459           
  Partials           ?        0           
Flag Coverage Δ
python-3.13 65.53% <91.30%> (?)

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.

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

ptr727 commented Oct 22, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 7dde5f0de6b88232a5be277995aaefdcedc19f05, the content this pull request carries at that commit against develop, and it recorded 0 findings.

The self-test aborts there at a probe unrelated to this change, filed as #3338.

Refs #3324

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@ptr727

ptr727 commented Oct 22, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 435c250884e3ed86756051c91c6f9879ef37f26c, the content this pull request carries at that commit against develop, and it recorded 0 findings.

@ptr727
ptr727 merged commit 455f9f5 into develop Oct 22, 2026
13 checks passed
ptr727 added a commit that referenced this pull request Oct 22, 2026
… 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)
@ptr727
ptr727 deleted the feature/git-location-env-helper branch October 22, 2026 13:06
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