Skip to content

Guard the hook line hooks install prints when proofline is not on PATH - #129

Open
ammartahamohamedy wants to merge 1 commit into
prooflinedev:mainfrom
ammar-taha-dev:fix/hook-line-path-guard
Open

ammartahamohamedy wants to merge 1 commit into
prooflinedev:mainfrom
ammar-taha-dev:fix/hook-line-path-guard

Conversation

@ammartahamohamedy

Copy link
Copy Markdown

Fixes #128

Problem

With core.hooksPath set (Husky, lefthook), or when another tool's hook already exists, hooks install prints a bare proofline hook run <hook> "$@" to paste. In a clone without proofline on PATH, that line fails with status 127 and onIncomplete never applies:

  • under sh -e (Husky) or as the last line, Git refuses the commit even under warn;
  • ahead of other commands, the failure is ignored and block doesn't block.

The script hooks install writes itself (Hook::script()) already guards this case.

Fix

  • New Hook::snippet(). It wraps the unchanged Hook::line() in the same command -v check and onIncomplete policy that script() uses. hooks install prints it in both advice spots.
  • Safe to paste among other commands. No exec and no exit 0, so the commands after it still run:
    • Proofline's own non-zero status stops the hook (|| exit $?);
    • when skipped under warn, it leaves status 0, also as the last line under sh -e;
    • under block, it exits 1.
  • line() is unchanged. It's still a substring of the snippet, so contains(&hook.line()) (feat(hooks): add proofline hooks status subcommand #77 hooks status, feat(cli): add proofline doctor diagnostics command (--json, --offline) #99 doctor) still recognizes a pasted snippet.
  • Not changed: script() is byte-identical, so uninstall still recognizes installed hooks, and hook run is untouched.

The advice now reads:

core.hooksPath is .husky, so nothing was written. Add this to its pre-commit hook:
if command -v proofline >/dev/null 2>&1; then
  proofline hook run pre-commit "$@" || exit $?
else
  echo 'proofline is not on PATH, so Proofline did not review this commit.' >&2
  if [ "$(git config --get proofline.hook.pre-commit.onIncomplete)" = block ]; then exit 1; fi
fi

Tests (written first, both failed before the fix)

Test What it checks
install_writes_only_its_own_scripts_and_uninstall_removes_only_them (extended) Both advice spots still contain line() and now also the guard
the_advice_for_a_hooks_path_applies_the_policy_when_proofline_is_not_on_path (new) Pastes the printed advice into .husky/pre-commit twice: ahead of another command, then as the last line under set -e. It then commits with and without proofline on PATH, under warn and block (8 commits). A commit lands only under warn, the later command runs only then, and the note appears only when proofline is missing

Mutation checks: each of these makes the new test fail:

  • dropping || exit $?;
  • adding exit 0 after the note;
  • exec on the line;
  • [ … ] && exit 1 as the snippet's last command.

End to end, with the built binary: I pasted the printed advice into a Husky-style hook with set -e and a later echo, then committed without proofline on PATH:

  • under warn, the commit is created, with the note, and the later command runs;
  • under block, Git exits 1.

Checks

  • cargo fmt --check: ✅
  • cargo clippy --locked -- -D warnings: clean on the lib, the bins and tests/hooks.rs. --all-targets stops at the 2 errors main already has on Windows (src/agent/tests.rs).
  • cargo test --locked: the changed and new tests pass. On Windows, 9 tests fail outside the code this PR changes (mcp, agent install, update, local patch). One is a_push_reviews_the_branches_it_updates_and_skips_tags_and_deletions, which rejects a Windows path push URL through the unchanged script().
  • cargo deny check: no dependency changes.
  • Fork CI: check and windows pass.

Proofline review log

Fork review PR: ammar-taha-dev#1. Rounds capped at 2.

Round Finding What I made of it Outcome
1 None ("no new findings") n/a Nothing to change

The prompts below are from the session that implemented this change; the investigation and reproduction happened in earlier sessions.

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.

The hook line hooks install prints has no PATH guard

1 participant