Repository navigation
Conversation
…te config decide_hook_action resolves verdicts through check_command_for, which reads .claude/settings.json from both the home directory and the project, locating the latter by walking up the process-global CWD. Any local deny/ask/allow Bash rule therefore decided the outcome of the Claude and Copilot CLI hook unit tests: a deny rule matching `cargo test` or `git status` turns an expected rewrite into a skip, and six tests fail on that machine alone. The CWD walk also races the tests in init.rs that call set_current_dir. get_rewritten had the same problem one layer down, loading hooks.exclude_commands from config.toml, where a local exclude_commands = ["grep"] already broke test_claude_pipeline_rewrites_only_safe_final_stage. Both inputs now reach the decision logic as parameters, matching evaluate_with_verdict in rewrite_cmd.rs, which already takes this exact (excluded, transparent_prefixes) pair: decide_from_verdict gains the two settings alongside the verdict it already accepted, and decide_hook_action becomes the thin wrapper that reads both off the machine. A seam can no longer inherit ambient state by omission — it has to name what it wants. process_claude_payload splits into a wrapper plus claude_action_from_decision so run_claude_inner_with_rules can supply the verdict, mirroring the existing run_cursor_inner_with_rules and run_droid_inner_with_rules; the Copilot CLI tests go through copilot_cli_response_with_rules, and run_vibe_inner takes its settings from run_vibe. Separately, end_to_end passed the unextracted "Bash(git:*)" as an allow rule. Rules reach check_command_with_rules already unwrapped by extract_bash_pattern, so that pattern matched nothing and every verdict below it degraded to Default. test_copilot_cli_cve_newline_bypass_never_auto_allows and its background-& sibling rely on that rule to exercise the per-segment allow invariant — bare \n and & are not unattestable constructs, so nothing else stood between those payloads and an Allow. Reverting the invariant to its pre-fix "any matching segment allows the chain" form left both tests green; with the literal corrected they fail, as their names promise. Their asserts are unconditional now too, so a None response cannot skip the check. New coverage: the Allow and Deny directions through the Claude seam, the deny-versus-defer audit reason (indistinguishable from the JSON output alone), a non-string command payload, exclude_commands suppressing a rewrite, and the Config to (excluded, transparent_prefixes) field mapping, which no test reached before. Verified by running the test binary with HOME and CWD pointed at settings files holding deny, allow and mixed-scope rules alongside a config.toml excluding grep, git and cargo, with and without RTK_HOOK_AUDIT=1: all 430 hooks:: tests pass in every combination.
2f8da46 to
26027bb
Compare
|
Keeping this one as the fix for hook tests reading the machine's real config — #3461 covered the same two functions and is closed pointing here. Two things before it can land: The branch is in conflict and needs a rebase on More importantly: you have #3645 open against the same file, also touching the hook entry points, and also conflicting. Rather than guess at the intended order, which of the two supersedes the other? Happy to take them as a stack if they're meant to be sequential, or as one consolidated PR if #3645 grew out of this one — whichever matches what you had in mind. Just not both landing independently against For context on why this matters beyond test hygiene: #3324 hit exactly this problem from the other side — three unrelated tests failing on the contributor's machine because |
|
Thanks for chasing this one down. Develop now does what this PR set out to do: #3955 (merged 2026-09-11) extracted src/hooks/decision.rs with decide_with_params, which takes exclude_commands and transparent_prefixes as arguments so a decision under test no longer picks up the developer's own config.toml, and #3206 (merged 2026-09-02) split process_claude_payload into process_claude_payload_from_decision so the Allow/Ask/Deny/Defer matrix is testable without real permission files. The verdict itself was already passed in rather than looked up, so that part of the seam was in place before. Two things you found are still true on develop and would be welcome as an issue or a narrow PR against the new decision module: end_to_end in src/hooks/hook_cmd.rs still passes the unextracted "Bash(git:*)" as an allow rule, which leaves the newline and background-& bypass tests unfalsifiable, and run_vibe_inner still resolves its verdict and rewrite settings off the machine with no rules seam of its own. If I have missed a part of this that develop still lacks, please say so or reopen. |
Hook unit tests resolved permission verdicts through
decide_hook_action, which reads.claude/settings.jsonfrom the home directory and from the project — the latter located by walking up the process-global CWD. A localBash(cargo test)orBash(git status)deny rule turns an expected rewrite into a skip, so six Claude-path tests fail on that machine and pass everywhere else. The CWD walk also races theinit.rstests that callset_current_dir.get_rewrittenhad the same problem one layer down, loadinghooks.exclude_commandsfromconfig.toml, where a localexclude_commands = ["grep"]already broketest_claude_pipeline_rewrites_only_safe_final_stage.Changes
decide_from_verdictas parameters, matchingevaluate_with_verdictinrewrite_cmd.rs, which already takes this exact(excluded, transparent_prefixes)pair.decide_hook_actionbecomes the thin wrapper that reads them off the machine, so a seam can no longer inherit ambient state by omission.process_claude_payloadsplits into a wrapper plusclaude_action_from_decision, lettingrun_claude_inner_with_rulesinject the verdict — the seamrun_cursor_inner_with_rulesandrun_droid_inner_with_rulesalready have. Copilot CLI tests go throughcopilot_cli_response_with_rules;run_vibe_innertakes its settings fromrun_vibe.end_to_endpassed the unextracted"Bash(git:*)"as an allow rule, but rules arrive atcheck_command_with_rulesalready unwrapped byextract_bash_pattern, so it matched nothing.test_copilot_cli_cve_newline_bypass_never_auto_allowsand its background-&sibling rely on that rule to exercise the per-segment allow invariant, and bare\n/&are not unattestable constructs — so both were unfalsifiable. Reverting the invariant to its pre-fix "any matching segment allows the chain" form leaves both green with the old literal and fails both with the corrected one. Their asserts are unconditional now too.exclude_commandssuppressing a rewrite, and theConfigto(excluded, transparent_prefixes)field mapping.Test plan
cargo fmt --all && cargo clippy --all-targets && cargo test --all— clean, 2632 pass.HOMEand CWD pointed at settings files holding deny, allow and mixed-scope rules alongside aconfig.tomlexcluding grep/git/cargo, with and withoutRTK_HOOK_AUDIT=1: all 430hooks::tests pass in every combination, against 27 failures before the fix.