fix hook install silent no-op for uv tool and pipx installs (#1127)

graphify hook install generated scripts that resolved the Python interpreter
purely at git-trigger time via 'command -v graphify'. GUI git clients (VS Code,
GitKraken), CI runners, and non-login shells often run with a minimal PATH that
omits ~/.local/bin -- the uv-tool / pipx launcher location. command -v graphify
returned empty, the python3/python fallbacks could not import graphify (it lives
only in the isolated venv), and the hook silently exited 0 with no output.

Fix: embed sys.executable of the currently-running install process as a pinned
first probe. Since 'graphify hook install' itself runs under the correct isolated
interpreter, sys.executable is always the right path. It is validated at
hook-runtime via 'import graphify' before use, so a stale pinned path safely
falls through to the existing dynamic detection rather than breaking the hook.

Also make the final fallback loud: print a diagnostic to stderr before exiting 0
so the failure is visible rather than invisible.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Safi
2026-06-03 15:40:06 +01:00
co-authored by Claude Opus 4.8
parent 1b21368250
commit 88bb1864aa
2 changed files with 85 additions and 21 deletions
+36
View File
@@ -161,6 +161,42 @@ def test_hook_skips_head_on_exe():
assert "*.exe) _SHEBANG=" in _PYTHON_DETECT or '*.exe)' in _PYTHON_DETECT
def test_install_embeds_pinned_interpreter(tmp_path):
"""Hook scripts must embed sys.executable so the hook works without the
graphify launcher on PATH (uv tool / pipx isolation, #1127).
When graphify is installed via `uv tool install graphifyy` or `pipx install
graphifyy`, the interpreter lives in an isolated venv and the launcher is in
~/.local/bin. GUI git clients and CI runners often run with a minimal PATH
that omits that directory, so `command -v graphify` fails, the python3/python
fallbacks cannot import graphify (wrong venv), and the hook silently exits 0.
Pinning sys.executable at install time makes the hook work regardless of PATH.
"""
import sys
repo = _make_git_repo(tmp_path)
install(repo)
commit_hook = (repo / ".git" / "hooks" / "post-commit").read_text()
checkout_hook = (repo / ".git" / "hooks" / "post-checkout").read_text()
# The pinned interpreter path must appear in both generated scripts.
assert sys.executable in commit_hook, "pinned sys.executable missing from post-commit"
assert sys.executable in checkout_hook, "pinned sys.executable missing from post-checkout"
# The placeholder must be fully substituted -- no __PINNED_PYTHON__ left.
assert "__PINNED_PYTHON__" not in commit_hook, "placeholder not substituted in post-commit"
assert "__PINNED_PYTHON__" not in checkout_hook, "placeholder not substituted in post-checkout"
def test_install_fallback_is_loud_not_silent(tmp_path):
"""The detection fallback must emit a message to stderr rather than bare exit 0.
A silent no-op (the pre-fix behaviour) leaves the user with no indication
that the hook ran but found nothing, making the bug extremely hard to diagnose.
"""
from graphify.hooks import _PYTHON_DETECT
assert "could not locate" in _PYTHON_DETECT, (
"fallback branch must print a diagnostic message; bare 'exit 0' is silent and unhelpful"
)
def test_hook_check_no_additionalContext(tmp_path):
"""graphify hook-check must not emit additionalContext — Codex Desktop rejects it."""
import sys