Skip to content

fix(hooks): keep installed hooks portable - #3009

Open
hopstreax wants to merge 1 commit into
Graphify-Labs:v8from
hopstreax:fix/2989-hook-install-portability
Open

hopstreax wants to merge 1 commit into
Graphify-Labs:v8from
hopstreax:fix/2989-hook-install-portability

Conversation

@hopstreax

@hopstreax hopstreax commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #2989.

graphify hook install was embedding the absolute path of the Python
interpreter used to run the command directly into the tracked
.githooks/post-commit and .githooks/post-checkout files.

For example, installing Graphify on two different machines could produce:

-_PINNED='/Users/alice/.local/pipx/venvs/graphify/bin/python'
+_PINNED='C:\Users\Bob\AppData\Roaming\uv\tools\graphify\Scripts\python.exe'

Because these hook files are tracked, running hook install on different
machines could continuously rewrite the same tracked files and introduce
unnecessary churn or conflicts.

This change moves the machine-specific interpreter path into the existing
gitignored graphify-out/.graphify_python sidecar while keeping the tracked
hook templates portable.

What changed

1. Keep interpreter paths out of tracked hooks

The hook templates no longer receive the installing machine's
sys.executable as _PINNED.

Instead, graphify hook install records the sanitized interpreter path in:

graphify-out/.graphify_python

The existing runtime interpreter detection then uses this local sidecar before
falling back to launcher/PATH discovery.

_pinned_python() itself is retained because it is also used when configuring
the local graphify merge driver.

2. Respect GRAPHIFY_OUT

The sidecar location now follows the configured GRAPHIFY_OUT directory.

For example:

GRAPHIFY_OUT=my-graphify-out

results in:

my-graphify-out/.graphify_python

Runtime hook detection uses the same configured location and retains a fallback
to the default:

graphify-out/.graphify_python

This keeps existing repositories compatible while allowing custom output
directories.

3. Fix corrupted post-checkout template text

The post-checkout template contained:

ΓÇö

instead of the intended Unicode em dash:

—

Investigation showed that this was already present in the committed
graphify/hooks.py source and was introduced by commit 5c88af7. The existing
hook writer already uses explicit UTF-8 encoding, so no encoding changes were
needed in _install_hook().

The source/template text has been corrected and regression coverage added.

Why this approach

The original _PINNED mechanism was introduced to support installations such
as uv/pipx where Graphify may live inside an isolated environment and the
Graphify launcher may not be available on the PATH used by GUI Git clients or
CI.

Removing the mechanism entirely could therefore regress those environments.

Instead, the interpreter path remains available at runtime through the
gitignored per-checkout sidecar, while the tracked hook remains
machine-independent.

The resulting flow is:

graphify hook install
        |
        +--> graphify-out/.graphify_python
        |        (machine-local, gitignored)
        |
        +--> tracked .githooks/*
                 (machine-independent)
                         |
                         v
                  runtime detection
                         |
              sidecar -> launcher -> PATH

Regression coverage

Added/updated tests cover:

  • machine-specific interpreter paths are not written into generated hooks
  • installations using different interpreter paths produce identical tracked
    hook contents
  • graphify-out/.graphify_python is populated during hook installation
  • interpreter paths containing spaces are handled correctly
  • custom GRAPHIFY_OUT directories work
  • runtime detection reads the custom sidecar
  • runtime detection falls back to the default graphify-out sidecar
  • the post-checkout template contains U+2014 rather than ΓÇö

Validation

uv run pytest tests/test_hooks.py -v
98 passed

uv run pytest tests/ -k "not test_benchmarks and not test_live" --maxfail=5
2288 passed, 30 skipped, 4 warnings

git diff --check
clean

Scope

The changes are limited to:

  • graphify/hooks.py
  • tests/test_hooks.py

No changes were made to the existing UTF-8 file-writing behavior of
_install_hook().

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Graphify reviewed this change.

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 5 advisory finding(s) below merit a look before merge.

Formal verification. 1 change(s) tested, no difference found (not proven).


Graphify review — findings

Moves the pinned interpreter out of the tracked hook scripts and into a gitignored graphify-out/.graphify_python sidecar, so install() writes sys.executable there and emits _PINNED='' in the hook bodies. Teaches the _PYTHON_DETECT probe to honor GRAPHIFY_OUT (with a graphify-out fallback) when reading the sidecar, and switches _merge_attr_line to read GRAPHIFY_OUT from the environment. Updates the hooks tests to assert machine-specific paths never leak into tracked scripts and that scripts stay byte-identical across machines.

Worth a look

  • Installed hooks lose support for Python interpreter paths containing spaces — graphify/hooks.py:35 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
  • GRAPHIFY_OUT env var reaches shell interpreter-path sink without validation — graphify/hooks.py:44 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
  • GRAPHIFY_OUT newline injects extra .gitattributes entries — graphify/hooks.py:591 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
  • GRAPHIFY_OUT can escape the repo when writing .graphify_python — graphify/hooks.py:744 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
  • GRAPHIFY_OUT allows parent-directory traversal for sidecar write — graphify/hooks.py:747 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 341 functions depend on the 187 functions this change touches.

Health — this change adds coupling hotspots:

  • new: install() — 37 callers, 8 callees
  • new: dispatch_command() — 2 callers, 119 callees
  • new: dispatch_install_cli() — 2 callers, 31 callees
  • new: status() — 8 callers, 6 callees
  • new: uninstall() — 9 callers, 5 callees
  • new: uninstall_all() — 2 callers, 13 callees
  • new: test_poisoned_manifest_is_healed() — 0 callers, 6 callees

Verification — 341 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 194 function(s) in the blast radius were not formally verified this run

Formal verification

Could not verify: Could not verify install.

The verifier did not have enough to check install, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: parameter `path` is annotated `Path` — outside the synthesizable primitive/collection set

No difference found (not proven): No behavior difference found in \_merge\_attr\_line (not a proof).

The verifier ran both versions of \_merge\_attr\_line on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

· 7 more finding(s) on lines outside this diff (see the check run).

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.

hook install writes a machine-specific interpreter path into tracked .githooks files, and mangles non-ASCII in its templates on Windows

1 participant