Skip to content

Let Git hooks allow an exact path past the local preflight - #143

Open
ammartahamohamedy wants to merge 2 commits into
prooflinedev:mainfrom
ammar-taha-dev:fix/hook-allow-path
Open

ammartahamohamedy wants to merge 2 commits into
prooflinedev:mainfrom
ammar-taha-dev:fix/hook-allow-path

Conversation

@ammartahamohamedy

Copy link
Copy Markdown

Fixes #142

Problem

A pre-commit patch starts at the upstream merge-base, so it carries every unpushed commit. Once one of them holds a file the preflight refuses (a committed .env.example is enough), each later commit gets the same refusal until the push. The refusal says to pass --allow-path, but that's a review flag: hooks::ready passes no allowed paths, and there's no hook setting. Under onIncomplete=block, every later commit is blocked, and --no-verify is the only way through.

Fix

  • proofline.hook.<hook>.allowPath, multi-valued (git config --add), read with the other hook settings (git::config_all, --get-all -z) and passed to preflight::check. Same exact-path rules as --allow-path (preflight::exact_path, shared). A bad value is refused by its key before anything is read or sent, like failOn and timeout. That includes a value that isn't UTF-8: it is refused rather than read lossily, since two different non-UTF-8 paths can read the same lossy way.
  • Each refusal names the remedy its caller can use. preflight::Allowed carries the paths and an Allowance: Flag keeps review's text byte for byte; Hook(name) names the setting.
  • The module doc no longer says the hook "reviews exactly what the commit adds".
  • The merge-base scope is unchanged.

The pre-commit hook, at a later commit:

- Proofline could not review the staged changes: local patch includes the sensitive .env path ".env.example"; remove it before upload, or pass --allow-path for that exact path
+ Proofline could not review the staged changes: local patch includes the sensitive .env path ".env.example"; remove it before upload, or allow that exact path with git config --add proofline.hook.pre-commit.allowPath

Overlap with #132: it also edits hooks::ready (it adds check_refused). The two changes are independent; I'll rebase on whichever lands first.

Overlap with #140: it turns \ into / in --allow-path inside lib.rs, so hook values wouldn't get that rule; the preflight::check call it sits next to changes shape here. Either order is a small rebase.

Tests (written first; the new test failed on main with the --allow-path refusal above)

Test What it checks
allow_path_lets_later_commits_past_a_refusal_in_unpushed_history (new, tests/hooks.rs) Two unpushed commits (.env.example, then a GitHub token in config.rs) and a staged orders.rs, with onIncomplete=block. Each refusal names proofline.hook.pre-commit.allowPath, not --allow-path, and never prints the token. Nothing is uploaded until both paths are allowed. Then the commit is reviewed (exit 0) and the patch holds both the history and the staged change. /config.rs, ./config.rs, src//config.rs, an empty value, and a value with a 0xFF byte written straight into .git/config are each refused by key, with no upload

Mutation checks, each of which makes the test fail: ready ignoring the setting (passing &[]), skipping the value check in settings, and config_all decoding values lossily again.

End to end with the built binary (Git Bash, a bare local remote): the issue's steps name the setting at each commit; after git config --add proofline.hook.pre-commit.allowPath .env.example the hook moves past the preflight to the next step. review --staged still prints --allow-path, unchanged.

Checks

  • cargo fmt --check: ✅
  • cargo clippy --locked -- -D warnings: clean on the lib, the bins and every integration test. --all-targets stops at the 2 errors main already has on Windows (src/agent/tests.rs).
  • cargo test --locked: the new test passes. On Windows, 12 tests outside this change fail, the same as on main (mcp, agent install, update, a file name Windows forbids, a Windows push URL).
  • cargo deny check: no dependency changes.
  • Fork CI: check and windows green on ammar-taha-dev/proofline-cli#3 (commit 88c929b).

Proofline review log

Fork review PR: ammar-taha-dev/proofline-cli#3. Rounds capped at 2.

Round Finding What I made of it Outcome
1 Warning, doc drift: config_all in src/git.rs promises arbitrary-byte values but decodes Git output lossily as UTF-8. Recommended: document that values keep whitespace and newlines, replace invalid UTF-8 and are split on NUL Right, but a comment alone leaves the risk in place. A lossy value can match a path it doesn't name, and once #132 lands, refused patch paths are read lossily too, so two different non-UTF-8 paths could match one allowPath Fixed, going past the recommendation: a value that isn't UTF-8 is refused by its key (as an inexact path already is), the comment now states what config_all keeps, and the test covers it (written first, failed before the change)
2 No findings Clean, so the review stopped here

The prompts below are the ones that drove this implementation; the investigation, reproduction and fix scope were done before them and aren't included.

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.

A file the pre-commit preflight refuses is refused again at every later commit, and the hook can't allow it

1 participant