Skip to content

fix(hooks): stop test.sh from passing git's hook environment to the tests - #1626

Open
yaokaiy wants to merge 1 commit into
openenv:mainfrom
yaokaiy:fix/test-sh-clear-git-env
Open

yaokaiy wants to merge 1 commit into
openenv:mainfrom
yaokaiy:fix/test-sh-clear-git-env

Conversation

@yaokaiy

@yaokaiy yaokaiy commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to the #1576 review: finding 1 and the optional assertion in 2.

Git exports GIT_DIR to hooks that run from a linked worktree, and pre-push runs test.sh. Tests that run git in a throwaway repo, such as the repo fixture in tests/scripts/test_lint_hook.py, then commit to and configure the developer's repository instead. test.sh now unsets GIT_DIR, GIT_WORK_TREE and GIT_INDEX_FILE before it runs pytest.

The hook test also asserts that pre-commit and pre-push still fail on unformatted code. The repo fixture stubs timeout, which stock macOS lacks, so on macOS the pre-push assertion holds for the same reason as on Linux.

lint.sh already clears GIT_DIR and GIT_WORK_TREE for its own git init (#1573).

Type of Change

  • Bug fix

Alignment Checklist

  • I have read .claude/docs/PRINCIPLES.md and this PR aligns with our principles
  • I have checked .claude/docs/INVARIANTS.md and no invariants are violated
  • I have run /pre-submit-pr (or bash .claude/hooks/lint.sh and tests) and addressed all issues. lint.sh passes, and tests/scripts/ passes.

RFC Status

  • Not required (bug fix, docs, minor refactoring)

Test Plan

  • test_test_hook_clears_git_hook_environment runs test.sh with the three variables set and a stub uv that prints its environment. It fails on main, where all three reach pytest, and passes here.
  • The new exit assertion in test_git_hooks_leave_uncommitted_work_alone fails for both hooks when their lint.sh call is removed.
  • End to end: a real git push from a linked worktree, with the hooks that install.sh writes and a stub uv that does what the repo fixture does.
    • With main's test.sh, the repository's config gets core.bare=true, core.hooksPath=/dev/null and user.email=t@example.com, a fixture-init commit is created, and the worktree's index is replaced. The push itself succeeds.
    • With this branch, nothing changes.
  • The full test.sh with GIT_DIR set also passes all 14 tests in test_lint_hook.py. That run ignored tests/envs/test_sql_optim_environment.py, which CI also ignores and which fails to collect without duckdb.

Claude Code Review

/alignment-review checks (lint.sh, check-debug.sh, PRINCIPLES, INVARIANTS, RFCs): no Tier 1 issues, no alignment flags.


Note

Low Risk
Isolated change to the pre-push test hook plus hook regression tests; no production auth or data paths.

Overview
Pre-push test.sh now unsets GIT_DIR, GIT_WORK_TREE, and GIT_INDEX_FILE before invoking pytest so hook-injected git paths from linked worktrees do not leak into tests that create throwaway repos.

Hook tests add a timeout stub for macOS, assert pre-commit/pre-push still exit non-zero when code needs formatting, and add test_test_hook_clears_git_hook_environment to verify those variables are not passed through to the test run.

Reviewed by Cursor Bugbot for commit 94ea577. Bugbot is set up for automated code reviews on this repo. Configure here.

…ests

Git exports GIT_DIR to hooks that run from a linked worktree, and
pre-push runs test.sh. Tests that run git in a throwaway repo then
commit to and configure the developer's repository instead. Unset
GIT_DIR, GIT_WORK_TREE and GIT_INDEX_FILE before running pytest.

Also assert that pre-commit and pre-push still fail on unformatted
code. The repo fixture stubs `timeout`, which stock macOS lacks, so the
pre-push assertion holds there for the same reason as on Linux.

Follow-up to openenv#1576

This branch has not been deployed

No deployments
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.

1 participant