diff --git a/docs/decisions/records/process/hook-resolves-inputs-from-repo-root.md b/docs/decisions/records/process/hook-resolves-inputs-from-repo-root.md index 30419bb5e..3cb2b8951 100644 --- a/docs/decisions/records/process/hook-resolves-inputs-from-repo-root.md +++ b/docs/decisions/records/process/hook-resolves-inputs-from-repo-root.md @@ -7,7 +7,7 @@ supersedes: none superseded-by: none rule: 'A hook resolves every path whose CONTENT it sources, executes, or consults to decide, from `$repo_root` — derived from the hook''s own `${BASH_SOURCE[0]}` — and never from `$CLAUDE_PROJECT_DIR` or any other environment variable. There is NO telemetry exemption, and the attempt to write one is instructive: the first draft of this record exempted `ETV_HOOK_FIRE_LIB` on the grounds that "a wrong log destination is not a wrong verdict", and cold review refuted it by execution — that path is `. `-SOURCED, so whatever it names runs as CODE inside the hook before stdin is read and before `decide` exists; a file there that prints an `allow` decision and exits 0 grants the merge having bypassed every check in the file. A path''s PURPOSE does not bound its authority; how the hook consumes it does. THE SAME TEST DRAWS THE OTHER BOUNDARY, and it is not optional: a path the hook consumes as its SUBJECT — the tree it is asked to JUDGE — is caller-supplied by design, and binding it to `$repo_root` would break the guard, since the hook lives in one tree and must judge whichever worktree is being acted in. Two live cases, both deliberate: `pretooluse-bom-guard.sh` takes the committed tree from the command''s `cd`, then the payload `cwd`, then `${CLAUDE_PROJECT_DIR:-$PWD}` as a last-resort default; and `decisions-guard.sh` `cd`s to `git rev-parse --show-toplevel` and EXECUTES that tree''s `scripts/decisions_validate.py`, whose exit code is the hook''s decision — the stronger case, since it is code and not data, and it is admissible for the same reason: a pre-commit validator must validate the tree being committed, and under husky, its only launcher, git sets the cwd to that tree so the two roots agree anyway. The distinction is not first-two-sources-versus-third and not data-versus-code: it is WHOSE QUESTION the path answers. Ban the variable in the assignment naming the AUTHORITY — the code that decides — never every mention of it in a hook. The failure that matters is not an attacker — the same variable already names the hook binary in `.claude/settings.json`, so a hostile value has chosen which hook runs and the gate is moot before any inner path is read — it is LAUNCHER DIVERGENCE, and it is reachable: husky invokes the prepush hooks as `./.claude/hooks/…`, a relative path wholly independent of `$CLAUDE_PROJECT_DIR`, so the two roots genuinely disagree there. A wrong path holding a plausible file returns a confident answer about another tree; a missing path only asks, so the silent direction is the dangerous one. Two halves of one comparison must never come from two roots.' signals: 'env var as a security input · `$CLAUDE_PROJECT_DIR` vs `$repo_root` · `${BASH_SOURCE[0]}` self-location · sourced file is code not configuration · which checkout''s code decided this · launcher divergence · husky relative path vs harness env · a wrong path returns a confident answer, a missing one asks · both halves of a comparison from one root · paths: `.claude/hooks/pretooluse-merge-consent.sh`, `scripts/hook-fire-log.sh`, `scripts/check-review-verdict.sh`, `scripts/check-required-contexts.sh` · issues: #858, #891, #787, #629' -mechanics: 'No linter can spot "this path should have come from `$repo_root`". Enforcement is review plus a behavioural test per site: point `$CLAUDE_PROJECT_DIR` at a decoy tree whose copy of the resolved file returns the OPPOSITE decision, and assert the outcome is unchanged. That test needs a NEGATIVE CONTROL or it proves nothing — the passing outcome is also what an inert decoy produces — so run the same decoy again with the hook COPIED INTO it, making the decoy genuinely `$repo_root`, and assert the decision DOES flip. Since #891 that test is PARAMETRIZED OVER THE DERIVED HOOK POPULATION in `test_hook_fire_log.py` — `test_CLAUDE_PROJECT_DIR_cannot_choose_the_SOURCED_sink` beside `test_the_sink_decoy_IS_sourced_when_it_genuinely_is_the_repo_root` — so a hook added tomorrow arrives covered rather than needing someone to remember it, and the static arm of `instrumentation_faults` refuses the env-var form at review time, with `test_an_ENV_VAR_resolved_sink_path_is_DETECTED` as its mutation proof. Two worked single-site pairs live in `test_merge_consent_required_check.py`: `test_CLAUDE_PROJECT_DIR_cannot_choose_which_verdict_classifier_runs` and `test_the_SOURCED_fire_log_library_cannot_be_chosen_by_CLAUDE_PROJECT_DIR`, each beside its `..._IS_honoured/sourced_when_it_genuinely_is_the_repo_root` control.' +mechanics: 'No linter can spot "this path should have come from `$repo_root`". Enforcement is review plus a behavioural test per site: point `$CLAUDE_PROJECT_DIR` at a decoy tree whose copy of the resolved file returns the OPPOSITE decision, and assert the outcome is unchanged. That test needs a NEGATIVE CONTROL or it proves nothing — the passing outcome is also what an inert decoy produces — so run the same decoy again with the hook COPIED INTO it, making the decoy genuinely `$repo_root`, and assert the decision DOES flip. Since #891 that test is PARAMETRIZED OVER THE DERIVED HOOK POPULATION in `test_hook_fire_log.py` — `test_CLAUDE_PROJECT_DIR_cannot_choose_the_SOURCED_sink` beside `test_the_sink_decoy_IS_sourced_when_it_genuinely_is_the_repo_root`, and the husky RELATIVE launch as its own pair, since that construct resolves through the CWD — so a hook added tomorrow arrives covered rather than needing someone to remember it. The STATIC half is not a pattern over the line but BYTE-IDENTITY of the preamble''s two lines (a lexical rule was tried and withdrawn; see the body), proved by `test_a_LATER_reassignment_the_regex_cannot_see_is_DETECTED` for the shape only it catches, with `test_an_ENV_VAR_resolved_sink_path_is_DETECTED` and `test_the_NEXT_env_var_to_be_invented_is_DETECTED` pinning the diagnostic arms, each asserting its OWN arm''s phrase because the byte-identity message echoes the offending line and would otherwise satisfy them by itself. The sink''s own root resolution additionally requires the root to OWN it, proved by `test_the_report_REFUSES_a_root_that_does_not_OWN_this_sink`. Two worked single-site pairs live in `test_merge_consent_required_check.py`: `test_CLAUDE_PROJECT_DIR_cannot_choose_which_verdict_classifier_runs` and `test_the_SOURCED_fire_log_library_cannot_be_chosen_by_CLAUDE_PROJECT_DIR`, each beside its `..._IS_honoured/sourced_when_it_genuinely_is_the_repo_root` control.' --- `.claude/hooks/pretooluse-merge-consent.sh` resolved three decision-bearing paths from two different diff --git a/docs/decisions/records/testing/mutation-claims-are-executed.md b/docs/decisions/records/testing/mutation-claims-are-executed.md index 67e6eba52..9dd38e566 100644 --- a/docs/decisions/records/testing/mutation-claims-are-executed.md +++ b/docs/decisions/records/testing/mutation-claims-are-executed.md @@ -45,7 +45,7 @@ finer mutations settled which guards actually admit clause-level proof: all but including `pin_population_faults`, where disarming the against-the-registry comparison alone reddens the proof because a job that loses its `container:` block leaves the two derived sets equal. One does not. -`instrumentation_faults` accumulates from independent arms and a stripped hook trips three of +`instrumentation_faults` accumulates from independent arms and a stripped hook trips several of them at once, so disarming any single arm leaves the proof test green — measured, by running `if not _SOURCES_SINK.search(text):` → `if False:` and watching it pass. That surviving mutation is carried as data and re-run on every suite: if it ever starts reddening, the guard has become diff --git a/docs/guard-inventory.md b/docs/guard-inventory.md index c348a2397..37b95011c 100644 --- a/docs/guard-inventory.md +++ b/docs/guard-inventory.md @@ -373,8 +373,8 @@ Two things that column still does not say. It does not say the declared clause i guard hangs on — for three rows (measured 2026-08-22) the redness arrives through the proof test's own "this clause has moved, RETARGET it" assertion rather than through changed behaviour, which catches the recorded proof going stale but not much else. And one row is graded `DETECTOR` rather than `CLAUSE` in the -manifest: `instrumentation_faults` accumulates from independent arms and a stripped hook trips three -at once, so no single-arm disarm reddens its proof. That finer mutation is carried as data and +manifest: `instrumentation_faults` accumulates from independent arms and a stripped hook trips +several at once, so no single-arm disarm reddens its proof. That finer mutation is carried as data and re-run every suite, and must keep surviving — if it starts reddening, the guard has become clause-provable and the entry is regraded. diff --git a/scripts/hook-fire-log.sh b/scripts/hook-fire-log.sh index cc51e8e25..7b23a366e 100755 --- a/scripts/hook-fire-log.sh +++ b/scripts/hook-fire-log.sh @@ -454,9 +454,16 @@ etv_hook_fire_end() { # Read side: the report # --------------------------------------------------------------------------------------------- -# The hook population, DERIVED from the filesystem, never listed -# (`testing.guard-derives-population-from-source`). A hook added tomorrow appears in the report as +# The hook population, DERIVED rather than listed. A hook added tomorrow appears in the report as # NEVER-FIRED the moment it exists, rather than being invisible because nobody updated an array. +# +# A FILESYSTEM WALK, and that is the carve-out rather than the rule. +# `testing.guard-derives-population-from-source` requires the GIT INDEX for a guard's file +# population and allows a walk only with its reason written down, so: this is the REPORT, not a +# gate — it describes what is on disk in the tree it was run from, and an untracked scratch hook +# that really does fire is a row a reader wants to see. The guard over these same hooks +# (`test_hook_fire_log.py`) uses `git ls-files`, and the two populations are deliberately not the +# same one. etv_hook_fire_population() { local root="${1:-}" f [ -d "$root/.claude/hooks" ] || return 0 @@ -486,11 +493,13 @@ etv_hook_fire_repo_root() { self="${BASH_SOURCE[0]}" root="$( cd -- "$(dirname -- "$self")/.." >/dev/null 2>&1 && pwd )" || return 0 # AND THE ROOT MUST OWN THIS FILE. Self-location alone answers "two directories up from wherever - # I am", which is this repo only when this file sits in it. A copy or symlink somewhere whose - # grandparent happens to hold a `.claude/hooks` — `~/bin/hook-fire-log.sh` beside `~/.claude/hooks` - # exists on a real machine here — otherwise roots at `$HOME` and prints a confident table about - # another tree's hooks. Requiring the root's own sink to BE this file makes that case return - # nothing, which `etv_hook_fire_report` already refuses with exit 2 rather than an empty table. + # I am", which is this repo only when this file sits in it. A copy or symlink whose grandparent + # happens to hold a `.claude/hooks` otherwise roots there and prints a confident table about + # another tree's hooks. The shape is ordinary — `$HOME` holds a `.claude/hooks` on any machine + # running Claude Code, so anything dropped in a `$HOME/