wip: 891 review round 5 fixes
This commit is contained in:
@@ -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`, 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 — repair for the first, whose assertion the byte-identity message''s echo of the offending line did satisfy by itself, and prudence for the rest. 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.'
|
||||
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 — repair for `test_an_ENV_VAR_resolved_sink_path_is_DETECTED`, whose assertion the byte-identity message''s echo of the offending line did satisfy by itself, and prudence for the others. 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
|
||||
@@ -68,7 +68,8 @@ INDENTED or `export`ed reassignment further down that a column-anchored regex ca
|
||||
this repo's recorded signal to stop rather than patch again — a guard was WITHDRAWN from that same
|
||||
test file after four iterations of pattern-matching shell source. A shell assignment is not
|
||||
recognisable by regex, so the guard stopped trying: every non-comment line mentioning the variable
|
||||
must be one of the two canonical lines, byte for byte. The lexical arms over that assignment survive only to say WHY a line is wrong; the arms
|
||||
checking other things — a self-disabled hook, the begin call''s name, mode and ordering — are not
|
||||
subsumed by byte-identity and still decide. The cost is that a future rewrite of the line must edit one constant and all the hooks
|
||||
must be one of the two canonical lines, byte for byte. The lexical arms over the preamble survive only to say WHY a line is wrong — that includes the
|
||||
pattern matching the sourcing line, which byte-identity necessarily matches and which therefore
|
||||
decides nothing on its own. The arms judging other things — a self-disabled hook, the begin call's
|
||||
name, mode and ordering — are not subsumed and still decide. The cost is that a future rewrite of the line must edit one constant and all the hooks
|
||||
together, which is the property #891 exists to hold.
|
||||
|
||||
+10
-5
@@ -252,7 +252,7 @@ recorded as unexamined rather than as cleared.
|
||||
| `scripts/tests/test_docs_only_detector_clone_depth.py` | the `script-tests` job | PROOF | NONE | — |
|
||||
| `scripts/tests/test_guard_inventory.py` | the `script-tests` job, on an unclassified guard or a stale proof ref | GUARD | MUTATION | `test_guard_inventory.py::test_the_inventory_covers_exactly_the_guards_that_exist` |
|
||||
| `scripts/tests/test_guard_populations_derive_from_git.py` | the `script-tests` job, on a guard whose file population admits a file git does not track | GUARD | MUTATION | `test_guard_populations_derive_from_git.py::test_no_derivation_admits_an_untracked_file` |
|
||||
| `scripts/tests/test_hook_fire_log.py` | the `script-tests` job, on a hook that stops reporting that it fired, whose reporting changes what the harness sees, or that resolves the SOURCED sink from `$CLAUDE_PROJECT_DIR` instead of its own location | GUARD | MUTATION | `test_hook_fire_log.py::test_a_hook_that_LOSES_its_instrumentation_is_DETECTED` |
|
||||
| `scripts/tests/test_hook_fire_log.py` | the `script-tests` job, on a hook that stops reporting that it fired, whose reporting changes what the harness sees, or that resolves the SOURCED sink from `$CLAUDE_PROJECT_DIR` instead of its own location | GUARD | MUTATION | `test_hook_fire_log.py::test_a_LATER_reassignment_the_regex_cannot_see_is_DETECTED` |
|
||||
| `scripts/tests/test_image_build_delegates_the_spa_suite.py` | the `script-tests` job, on ANY change to the commands an SPA-carrying Dockerfile stage runs, on ANY change to the gating `Test SPA` step (its `run:` body, its `if:`, or a `continue-on-error` in any spelling), on the publish step losing its `docs_only` gate, on an image-publishing job that stops being gated on the job holding that step, or on any other step mentioning the suite | GUARD | MUTATION | `test_image_build_delegates_the_spa_suite.py::test_every_SPA_CARRYING_STAGE_runs_exactly_its_pinned_commands` |
|
||||
| `scripts/tests/test_jq_preflight.py` | the `script-tests` job | PROOF | NONE | — |
|
||||
| `scripts/tests/test_mcp_smoke.py` | the `script-tests` job, when the MCP smoke checker accepts a server it should refuse — an impostor identity, a reply carrying only an id, a missing expected tool, or an `initialize` pre-answered before the request (the `tools/list` twin is held by two mechanisms jointly and is covered behaviourally, not by the declared clause) | GUARD | MUTATION | `test_mcp_smoke.py::test_MUTATION_a_PRE_ANSWERED_id_is_refused_because_the_request_ids_are_UNGUESSABLE` |
|
||||
@@ -435,7 +435,7 @@ lines flagged wrongly — and cold review then constructed more of both (`[[ "$x
|
||||
a backslash continuation, a `>` inside a quoted string). Deleted rather than patched a fifth time,
|
||||
on the same reasoning as the vocabulary-parity withdrawal above.
|
||||
|
||||
**`test_hook_fire_log.py` proves FIVE clauses, and its row claims three of them.** Coverage (every
|
||||
**`test_hook_fire_log.py` proves SIX clauses, and its row claims three of them.** Coverage (every
|
||||
hook reports that it fired) via `test_a_hook_that_LOSES_its_instrumentation_is_DETECTED`;
|
||||
transparency (the wrapper changes nothing the harness can see) via
|
||||
`test_instrumentation_changes_NOTHING_the_harness_can_see` with its mutation proof
|
||||
@@ -448,9 +448,14 @@ preamble's two lines byte-for-byte and carries three mutation proofs — `…_EN
|
||||
for the pre-#891 form, `…_the_NEXT_env_var_to_be_invented…` for its lexical successor, and
|
||||
`…_a_LATER_reassignment_the_regex_cannot_see…` for the indented/exported shape that only byte-identity
|
||||
sees; and suite
|
||||
isolation, added in ersatztv#809/#822 and described in the section below. The row's `Blocks` column
|
||||
covers the first two and the fourth, and the `Proof ref` column holds one ref because the column
|
||||
holds one, not because the others are unproven. Placement is proved and unclaimed.
|
||||
isolation, added in ersatztv#809/#822 and described in the section below; and, since ersatztv#891,
|
||||
the report's own root — `etv_hook_fire_repo_root` ignores `$CLAUDE_PROJECT_DIR` and refuses a root
|
||||
that does not own this sink — via `test_CLAUDE_PROJECT_DIR_cannot_choose_which_trees_hooks_the_REPORT_describes`
|
||||
with its control, and `test_the_report_REFUSES_a_root_that_does_not_OWN_this_sink`. The row's
|
||||
`Blocks` column covers coverage, transparency and ROOT, and the `Proof ref` column holds one ref
|
||||
because the column holds one. PLACEMENT, SUITE ISOLATION and the REPORT'S ROOT are proved and
|
||||
unclaimed — named individually rather than left as the remainder of a subtraction, which is how the
|
||||
last two revisions of this paragraph mis-sorted.
|
||||
|
||||
ROOT carries a NEGATIVE CONTROL because its assertion is an ABSENCE — the decoy's marker must not
|
||||
appear — which is also exactly what an inert fixture produces. (That is the distinguishing property,
|
||||
|
||||
@@ -495,11 +495,13 @@ etv_hook_fire_repo_root() {
|
||||
# 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 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/<dir>/` roots at `$HOME` — and it is the
|
||||
# another tree's hooks. The shape is ordinary — `$HOME` commonly holds a `.claude/hooks` (it does
|
||||
# on this machine), so anything dropped in a `$HOME/<dir>/` roots at `$HOME` — and it is the
|
||||
# SILENT direction, since the wrong answer is a plausible one. Requiring the root's own sink to BE
|
||||
# this file makes that case return nothing, which `etv_hook_fire_report` refuses with exit 2.
|
||||
# Proven by `test_the_report_REFUSES_a_root_that_does_not_OWN_this_sink`, for a copy and a symlink.
|
||||
# `-ef` and not `-e`: presence is the weaker test and accepts precisely the case that matters, a
|
||||
# root holding a DIFFERENT sink. Proven by `test_the_report_REFUSES_a_root_that_does_not_OWN_this_sink`,
|
||||
# whose `other-sink` arm is the load-bearing one — the copy and symlink arms pass a weaker `-e`.
|
||||
[ "$root/scripts/hook-fire-log.sh" -ef "$self" ] || return 0
|
||||
printf '%s' "$root"
|
||||
}
|
||||
|
||||
@@ -264,21 +264,23 @@ MUTATIONS: tuple[Mutation, ...] = (
|
||||
Mutation(
|
||||
guard="scripts/tests/test_hook_fire_log.py",
|
||||
target="scripts/tests/test_hook_fire_log.py",
|
||||
clause=" return faults\n\n\ndef strip_instrumentation",
|
||||
replacement=" return []\n\n\ndef strip_instrumentation",
|
||||
proof="test_hook_fire_log.py::test_a_hook_that_LOSES_its_instrumentation_is_DETECTED",
|
||||
granularity=DETECTOR,
|
||||
expect="left the check GREEN. The check is not load-bearing",
|
||||
why="NO CLAUSE-LEVEL MUTATION REDDENS THIS ONE, and that is a finding rather than a shortcut. "
|
||||
"`instrumentation_faults` accumulates from independent arms and a stripped hook trips SEVERAL "
|
||||
"of them at once (no sink source, a preamble that is not the canonical two lines, no "
|
||||
"ETV_HOOK_FIRE_LIB assignment, no begin call), so disarming any single arm leaves the rest "
|
||||
"answering and the proof test stays green. No count is pinned here: it moved once already "
|
||||
"when an arm was added, and the argument needs `more than one`, not a number. The "
|
||||
"whole detector is therefore the smallest mutation this proof can witness — and the surviving "
|
||||
"single-arm mutation below is re-run every time so that claim is checked, not recited.",
|
||||
survived_clause=" if not _SOURCES_SINK.search(text):",
|
||||
survived_replacement=" if False:",
|
||||
clause=" if mentions != [CANONICAL_SINK_ASSIGNMENT, CANONICAL_SINK_SOURCE]:",
|
||||
replacement=" if False:",
|
||||
proof="test_hook_fire_log.py::test_a_LATER_reassignment_the_regex_cannot_see_is_DETECTED",
|
||||
granularity=CLAUSE,
|
||||
expect="reassignment of the SOURCED sink passed clean",
|
||||
why="REGRADED FROM `DETECTOR` BY ersatztv#891, because the guard acquired a clause that IS "
|
||||
"load-bearing on its own. `instrumentation_faults` used to accumulate only from arms a "
|
||||
"stripped hook trips several of at once, so disarming any one left the rest answering and no "
|
||||
"clause-level mutation could redden the proof; the entry carried the finest surviving "
|
||||
"mutation (`if not _SOURCES_SINK.search(text):` -> `if False:`) as its honesty check. #891 "
|
||||
"replaced the lexical rule over the sink assignment with BYTE-IDENTITY of the preamble's two "
|
||||
"lines, and that comparison decides alone: disarming it reddens this proof on every hook, "
|
||||
"while nothing else catches an indented or `export`ed reassignment. The old canary had to go "
|
||||
"with it rather than be carried on: byte-identity necessarily matches the sourcing line, so "
|
||||
"`_SOURCES_SINK` can no longer decide anything (measured: 0 cases in 13 hooks x 8 "
|
||||
"perturbations) and a mutation required to KEEP surviving would have been guaranteed to, "
|
||||
"which is a tautology wearing a canary's clothes.",
|
||||
),
|
||||
Mutation(
|
||||
guard="scripts/tests/test_remote_state_inventory.py",
|
||||
|
||||
@@ -68,9 +68,12 @@ SINK = REPO_ROOT / "scripts" / "hook-fire-log.sh"
|
||||
# the cross-suite claim that test has always made in its docstring and never checked in its body.
|
||||
_IMPORT_TIME_ENV = {**os.environ}
|
||||
|
||||
# The three lines a hook must carry. Matched structurally rather than as one frozen blob so that a
|
||||
# comment reflow does not redden the suite, but the two things that matter — sourcing the single
|
||||
# shared sink, and calling begin with this hook's own name — are both pinned.
|
||||
# The lines a hook must carry. `_BEGINS` is matched structurally, so a comment reflow around the
|
||||
# begin call does not redden the suite. The SINK PREAMBLE is matched as a frozen blob instead —
|
||||
# byte-identity against the two constants below — because every lexical rule tried over it was
|
||||
# defeated by a shape it did not anticipate (ersatztv#891). `_SOURCES_SINK` predates that and is now
|
||||
# subsumed: byte-identity necessarily matches the sourcing line, so that pattern can no longer decide
|
||||
# anything alone. It is kept for the diagnostic it produces, not for a verdict.
|
||||
_SOURCES_SINK = re.compile(r'^\[ -r "\$ETV_HOOK_FIRE_LIB" \] && \. "\$ETV_HOOK_FIRE_LIB" \|\| true$', re.M)
|
||||
|
||||
# THE TWO LINES, byte for byte. Named once so the checker, the mutation proofs and the hooks all mean
|
||||
@@ -162,16 +165,16 @@ def instrumentation_faults(text: str, name: str) -> list[str]:
|
||||
f"trailing comment, a rewritten expansion — is a divergence, not a variant. got={mentions}"
|
||||
)
|
||||
|
||||
# THE `libs` ARMS BELOW — and only those — no longer decide anything: byte-identity above
|
||||
# already refuses every line they catch. (No count: the last two attempts at this sentence both
|
||||
# pinned one and both were wrong within a round.) They survive to say WHY a line is wrong, because "not
|
||||
# byte-identical" is a true but useless message for the failure that actually recurs.
|
||||
# THE ARMS OVER THE SINK PREAMBLE no longer decide anything — the `libs` arms below AND
|
||||
# `_SOURCES_SINK` above — because byte-identity already refuses every line they catch. They
|
||||
# survive to say WHY a line is wrong, since "not byte-identical" is true but useless for the
|
||||
# failure that recurs.
|
||||
#
|
||||
# Scoped deliberately. The sentence used to read over everything below it, which is a
|
||||
# coverage-boundary claim that MIS-SORTS: the `ETV_HOOK_FIRE_DISABLE` arm and the begin
|
||||
# name/mode/stdin-order arms are NOT subsumed — a hook carrying both canonical lines plus
|
||||
# `ETV_HOOK_FIRE_DISABLE=1` trips exactly one fault, and it is not byte-identity's. A reader
|
||||
# trusting the unscoped sentence would delete a live detector.
|
||||
# ENUMERATED, not counted: a count here has been wrong twice. The arms judging OTHER THINGS are
|
||||
# NOT subsumed — `ETV_HOOK_FIRE_DISABLE`, and the begin call's name, mode and stdin ordering. A
|
||||
# hook carrying both canonical lines plus `ETV_HOOK_FIRE_DISABLE=1` trips exactly one fault, and
|
||||
# it is not byte-identity's, so a reader who sorts those into "already covered" deletes a live
|
||||
# detector.
|
||||
libs = re.findall(r"^ETV_HOOK_FIRE_LIB=(.*)$", text, re.M)
|
||||
if not libs:
|
||||
faults.append(f"{name}: no ETV_HOOK_FIRE_LIB assignment")
|
||||
@@ -618,8 +621,8 @@ def test_an_ENV_VAR_resolved_sink_path_is_DETECTED():
|
||||
faults = instrumentation_faults(mutated, hook.stem)
|
||||
# THE ARM'S OWN PHRASE, never the variable name. The byte-identity fault echoes the
|
||||
# offending line verbatim, so a substring assertion on `CLAUDE_PROJECT_DIR` is satisfied by
|
||||
# the ECHO — measured by cold review: deleting the dedicated arm entirely left this test
|
||||
# green. Asserting that a MESSAGE mentions the defect is not asserting the DETECTOR ran.
|
||||
# the ECHO alone — measured: with the dedicated arm deleted, this test still passed.
|
||||
# Asserting that a MESSAGE mentions the defect is not asserting the DETECTOR ran.
|
||||
assert any("resolves the SOURCED sink from" in f for f in faults), (
|
||||
f"restoring the env-var-first sink path in {hook.name} did not trip the arm that names "
|
||||
f"it, so nothing stops it being reintroduced one hook at a time. faults={faults}"
|
||||
@@ -680,10 +683,9 @@ def test_the_NEXT_env_var_to_be_invented_is_DETECTED(hook):
|
||||
text = hook.read_text()
|
||||
assert current in text, f"{hook.name} no longer carries the line this mutation replaces"
|
||||
faults = instrumentation_faults(text.replace(current, successor), hook.stem)
|
||||
# Its own phrase too — though for THIS proof it is prudence rather than repair: `besides` never
|
||||
# appears in the byte-identity fault, so the old assertion was already non-vacuous. Pinned anyway
|
||||
# so the next arm added beside it cannot silently de-pin it, which is exactly what happened to
|
||||
# the sibling.
|
||||
# Its own phrase too — prudence here rather than repair: `besides` never appears in the
|
||||
# byte-identity fault, so this assertion was already non-vacuous. Pinned anyway, because an arm
|
||||
# added later can de-pin a shared substring silently.
|
||||
assert any("expands" in f and "besides" in f for f in faults), (
|
||||
f"a sink path steered by a NEW environment variable passed clean on {hook.name}. The arm is "
|
||||
f"a containment test, not a resolution test, and the ban is worth only the one name in it. "
|
||||
@@ -1329,6 +1331,73 @@ def test_the_report_names_hooks_that_NEVER_fired(sandbox):
|
||||
assert zero_rows, "no never-fired rows shown despite only one hook appearing in the log"
|
||||
|
||||
|
||||
def _report_decoy_tree(tmp_path: Path) -> Path:
|
||||
"""A tree that looks like a checkout and holds a hook found NOWHERE in the real repo."""
|
||||
project = tmp_path / "report-decoy"
|
||||
(project / ".claude" / "hooks").mkdir(parents=True)
|
||||
(project / ".claude" / "hooks" / "someone-elses-hook.sh").write_text("#!/bin/sh\nexit 0\n")
|
||||
return project
|
||||
|
||||
|
||||
def test_CLAUDE_PROJECT_DIR_cannot_choose_which_trees_hooks_the_REPORT_describes(tmp_path, sandbox):
|
||||
"""THE READ SIDE'S half of ersatztv#891, which is the change this file makes to the sink itself.
|
||||
|
||||
`etv_hook_fire_repo_root` used to prefer `$CLAUDE_PROJECT_DIR` whenever it named a tree with a
|
||||
`.claude/hooks`. That reads as harmless — a report decides nothing — but the report's two halves
|
||||
ARE the population and the log, so resolving them from two roots produces a confident table about
|
||||
another checkout: NEVER-FIRED rows for hooks that fired, and rows for hooks this tree does not
|
||||
have. `process.hook-resolves-inputs-from-repo-root` requires a behavioural test PER SITE, and
|
||||
this is that test for this site — cold review measured its absence by restoring the preference
|
||||
verbatim and watching the whole file stay green.
|
||||
"""
|
||||
project = _report_decoy_tree(tmp_path)
|
||||
_root, env = sandbox
|
||||
runenv = dict(env)
|
||||
runenv["CLAUDE_PROJECT_DIR"] = str(project)
|
||||
p = subprocess.run(
|
||||
["bash", str(SINK), "report", "--all", "--dir", str(tmp_path / "nolog")],
|
||||
capture_output=True,
|
||||
cwd=str(tmp_path),
|
||||
env=runenv,
|
||||
timeout=60,
|
||||
)
|
||||
out = p.stdout.decode()
|
||||
assert b"someone-elses-hook" not in p.stdout, (
|
||||
f"$CLAUDE_PROJECT_DIR chose which tree the report describes — it listed a hook that exists "
|
||||
f"only in the decoy: {out[:400]!r}"
|
||||
)
|
||||
# ...and it must still have described THIS tree, or the absence above is just an empty report.
|
||||
for hook in hook_scripts():
|
||||
assert hook.stem in out, (
|
||||
f"the report did not describe this checkout either ({hook.stem} missing), so the "
|
||||
f"assertion above is vacuous: {out[:400]!r}"
|
||||
)
|
||||
|
||||
|
||||
def test_the_report_decoy_IS_described_when_it_genuinely_is_the_repo_root(tmp_path, sandbox):
|
||||
"""NEGATIVE CONTROL for the test above; its assertion is an ABSENCE, which an inert fixture also
|
||||
produces. Copy the sink into the decoy so the decoy genuinely IS its `$repo_root`, and the
|
||||
decoy's hook must now be the one described."""
|
||||
project = _report_decoy_tree(tmp_path)
|
||||
(project / "scripts").mkdir()
|
||||
copied = project / "scripts" / "hook-fire-log.sh"
|
||||
shutil.copy2(SINK, copied)
|
||||
_root, env = sandbox
|
||||
runenv = dict(env)
|
||||
runenv["CLAUDE_PROJECT_DIR"] = str(project)
|
||||
p = subprocess.run(
|
||||
["bash", str(copied), "report", "--all", "--dir", str(tmp_path / "nolog")],
|
||||
capture_output=True,
|
||||
cwd=str(tmp_path),
|
||||
env=runenv,
|
||||
timeout=60,
|
||||
)
|
||||
assert b"someone-elses-hook" in p.stdout, (
|
||||
f"the decoy tree was never described even as its own $repo_root, so its sibling's absence "
|
||||
f"proves nothing: {p.stdout.decode()[:400]!r} / {p.stderr.decode()[:200]!r}"
|
||||
)
|
||||
|
||||
|
||||
def test_the_report_REFUSES_a_root_that_does_not_OWN_this_sink(tmp_path, sandbox):
|
||||
"""THE PROOF for the ownership clause in `etv_hook_fire_repo_root` (ersatztv#891).
|
||||
|
||||
@@ -1347,7 +1416,7 @@ def test_the_report_REFUSES_a_root_that_does_not_OWN_this_sink(tmp_path, sandbox
|
||||
and prints a confident table about the other tree, `-ef` refuses.
|
||||
|
||||
The copy and symlink arms are kept because they are the shapes that actually occur, not because
|
||||
they exercise different branches — they do not, and saying so was the previous claim here.
|
||||
they exercise different branches — measured, they do not: both pass a weaker `[ -e … ]`.
|
||||
"""
|
||||
_root, env = sandbox
|
||||
for label in ("copy", "symlink", "other-sink"):
|
||||
@@ -1421,9 +1490,8 @@ def test_the_report_REFUSES_an_empty_population(tmp_path, sandbox):
|
||||
f"clean table of nothing. stdout={p.stdout.decode()!r}"
|
||||
)
|
||||
# ITS OWN PHRASE. Both refusals say "refusing to report", so asserting on that shared text
|
||||
# stopped distinguishing which arm fired the moment the ownership refusal was added beside it —
|
||||
# measured: forcing the ownership arm to always fire left this test green. Same shape as the
|
||||
# `got={mentions}` echo, on the shell side, introduced by the commit that fixed the first one.
|
||||
# cannot distinguish which arm fired — measured: forcing the ownership arm to always fire left
|
||||
# this test green. A refusal message shared by two arms pins neither.
|
||||
assert b"empty population" in p.stderr
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user