Skip to content

Probe the Interpreter the Way the Host Contract Declares It - #647

Merged
ptr727 merged 2 commits into
developfrom
fix/hook-interpreter-probe
Aug 9, 2026
Merged

Probe the Interpreter the Way the Host Contract Declares It#647
ptr727 merged 2 commits into
developfrom
fix/hook-interpreter-probe

Conversation

@ptr727

@ptr727 ptr727 commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Answers the suppressed finding on the promotion pull request #643, which cannot take a fix of its own since its head is develop.

The hook invokes python3 directly, but docs/host-setup.md notes that on native Windows the python.org install registers py (and python) but not python3, so this hook will fail for Windows contributors running Git hooks via Git Bash.

Accepted. This is the repository contradicting itself: docs/host-setup.md states the hazard in its own paragraph, and spec/host-tools.json already encodes the answer as its probe order, [["python3", "--version"], ["py", "-3", "--version"]]. The hook restated a name the contract says is wrong on one supported platform. It now follows the same order rather than naming an interpreter.

Checked on a PATH that has py and no python3

Rather than reasoning about Windows from Linux, the shape was reproduced: a PATH carrying git, sh and a stand-in for the Windows launcher, and no python3 at all.

$ PATH=$D command -v python3 || echo NO
NO
$ PATH="$D" sh .husky/pre-commit
[ok  ] eol          0 issue(s)
exit=0

The previous version on that same PATH:

$ PATH="$D" sh "$D/old-pre-commit"
old-pre-commit: 32: python3: not found
exit=127

So this fixes a real break rather than hardening against a hypothetical one. Worth being precise about the failure it was: exit 127 is non-zero, so the old hook blocked the commit rather than passing it falsely. The defect is that it was unusable on such a host, not that it was silently wrong.

With neither interpreter present

pre-commit: no python3 and no py -3 on PATH, so the doc gates did not run.
pre-commit: see docs/host-setup.md 'What a Host Must Provide'.
exit=1

It names what did not run and points at the contract, and exits non-zero. A hook that cannot run its gates must not report a clean commit, which is the same rule prose_lint.py follows when it announces a dropped rule rather than going quiet.

Verification

552 tests pass, prose_lint.py with the CI check list exits 0, and repo_gate.py reports eol, eol-coverage and sha-pin clean. The hook ran on this commit.

🤖 Generated with Claude Code

The hook named python3. docs/host-setup.md states that a native Windows install
registers py and python but not python3, that the name resolves to a Microsoft
Store alias stub, and that Git Bash inherits the Windows PATH, so the hook could
not run for a Windows contributor. spec/host-tools.json already encodes the answer
as its probe order, and the hook now follows the same order rather than restating
a name the contract says is wrong.

Checked on a PATH carrying py and no python3, with a stand-in for the Windows
launcher. The hook passes there, and the previous version on the same PATH exits
127 with "python3: not found", so this fixes a real break rather than hardening
against a hypothetical one. With neither interpreter present it prints what did not
run and points at the contract, and exits 1, since a hook that cannot run its gates
must not report a clean commit.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

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.

Pull request overview

Updates the repo’s local pre-commit hook to select a Python interpreter in the platform-aware order declared by the host contract, so the hook remains usable on native Windows setups where python3 may be absent.

Changes:

  • Adds interpreter selection logic to prefer python3 and fall back to py -3 when needed.
  • Routes the prose and EOL checks through the selected interpreter.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread .husky/pre-commit Outdated
The previous commit tested `command -v python3` and did not fix the case it was
written for. The Microsoft Store alias stub is on PATH and fails only when run,
which docs/host-setup.md states in the same paragraph the fix cited, so a presence
test selects the stub on exactly the host the change was meant to serve.

The hook now runs the probes spec/host-tools.json declares, python3 --version then
py -3 --version, which is what tells a working interpreter from a name. The chosen
one is wrapped in run_py() rather than held in a variable, so nothing depends on
intentional word splitting of "py -3".

Checked against a stand-in for the stub, present on PATH and exiting non-zero:

  presence version (0a26cd2)  selects the stub and fails
  probe version               skips it, uses py -3, exits 0

And against the other half of the finding, a py that exists and rejects -3: both
probes fail, the hook names what did not run, points at the contract and exits 1
rather than falling through to a name that does not work.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings August 9, 2026 19:47

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.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@ptr727
ptr727 merged commit bfef86a into develop Aug 9, 2026
7 checks passed
@ptr727
ptr727 deleted the fix/hook-interpreter-probe branch August 9, 2026 19:53
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