fix(876): sweep session narrative out of hooks, workflows, scripts, tests and code comments; grow the detector to the process corpus
Build ErsatzTV Image / CI toolchain image resolves (pull_request) Successful in 35s
Build ErsatzTV Image / Delimiter ban (release path) (pull_request) Successful in 57s
PR Gates / CI image pin matches docker/ci (pull_request) Successful in 37s
PR Gates / Docs update reminder (pull_request) Successful in 1m0s
PR Gates / decisions lifecycle (pull_request) Successful in 20s
PR Gates / Fix proofs (Proves trailers) (pull_request) Successful in 17s
review-verdict/h10 Review-verdict: MERGEABLE @ a7d91bf (base: main)
Review verdict / Set review-verdict status (pull_request_target) Successful in 45s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 9m25s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 6m17s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Skipped
PR Gates / Script lint and tests (ruff + pytest) (pull_request) Successful in 19m27s
Build ErsatzTV Image / Functional E2E (curl + UI contracts) (pull_request) Successful in 6m4s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 8s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 7s

`docs.no-session-narrative` reaches every durable artifact, but its detector scanned only
`docs/**/*.md` and root markdown, and nothing had ever swept the rest. The issue named four sites
from one grep and called them a floor. Deriving the population instead — a whitespace-joined sweep
over every tracked file outside the detector, for the detector's own phrasings plus the attribution
and review-round class #812 found — gave 453 sites in 108 files at `fb5592971`, and a second pass
for phrasings the first list missed (hyphenated `round-N`, "an earlier version", "the reviewer
proved") added residuals in the same files. Every site was classified with #812's three
dispositions (CUT / SEVER / KEEP with its sub-kind) under the who-benefits test; the per-site
manifests are on the PR. The rejected designs, tested-and-rejected fixtures, measurements and
traps stay; the attribution of who found them and the round in which they were found go.

The detector's population grows to `.claude/`, `.gitea/`, `.husky/` and `scripts/` regardless
of extension, minus the detector and its own test (whose fixtures ARE the phrasings) and minus
`scripts/tests/fixtures/` (test data, including decision-record copies — the same reasoning as
the records' own exemption, and what keeps the record's depth measurement true), and `--all`
lists tracked REGULAR files only — a symlink's content is its target and a gitlink has none. The #812
argument for leaving `docs/superpowers/**` in the population runs the other way here: `--diff`
sees only ADDED lines, and 287 of the 453 sites were under 30 days old — this corpus is where
narrative is being added, so the advisory nudge has reach. Density agrees: 56 line-mode hits over
the 113 regular files the predicate admits, against 9 over 66 docs files before #812. `web/` and C# stay out on the same
measurement (3 of 74 PATTERNS-matching sites, ~4,600 files). The predicate did not grow: PATTERNS
matched 74 of 453 sites, and widening the word list to the attribution class is the treadmill
the withdrawn parity test ran on. The population oracle is restated over segments with the new
arms, the synthetic cross product gains the process heads and non-markdown extensions, a fixture
witnesses that a tracked symlink is neither scanned nor counted, a `.py.bak` axis separates a
by-name exemption from a `startswith` over the same tuple, and eight mutants (drop the process
arm, drop the by-name exemption, exempt by `startswith`, drop or add a prefix, drop the fixtures
exemption, list only markdown, drop the symlink filter, test the mode per row instead of per
path) each
redden it. A pre-existing silent drop in `--diff` goes with it: git tab-terminates a `+++`
filename that contains a space, and the kept tab made `is_scanned_path` refuse the file with no
notice — fixed, with a positive control and its own mutant.

Code is unchanged by construction, measured per file type against `origin/main`: Python modules
are AST-equal with docstrings stripped, except `#` lines inside the embedded fixture programs
(string literals) of three test modules; workflows differ only in `#` lines inside `run:` block
scalars; shell, C#, TypeScript and jq are equal with comment lines stripped. The stated
exceptions: the detector and its test, 26 vitest titles that carried review-round or severity
labels or a reviewer attribution (call sites whose title changed — every changed title line
walked back to its `it(` / `it.each(...)(` anchor, so a `' + '` concatenation counts once), two
registry note strings and the mutation manifest's prose fields. scripts/tests: 1565 passed.
Web: lint, typecheck, 1319 tests green. Closes #876.

Decisions-Edit: yes
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PEcBoFw7ctrf3Nb7R7x7wk
This commit is contained in:
2026-09-03 20:51:39 +02:00
co-authored by Claude Fable 5.1
parent fb55929711
commit a7d91bf15a
95 changed files with 1275 additions and 1103 deletions
+44 -44
View File
@@ -60,9 +60,10 @@ SINK = REPO_ROOT / "scripts" / "hook-fire-log.sh"
#
# `{**os.environ}` at module level is the shape #785 shipped: a suite that snapshots the environment
# once, at collection, and hands that stale mapping to every subprocess it launches. Because the
# autouse isolation fixture runs at test SETUP, such a snapshot used to predate it and every hook
# driven from it wrote to `$HOME/.cache/ersatztv/hook-fire/` — 58 records per run, with every
# assertion green, since the fire-log library is fail-open by design.
# autouse isolation fixture runs at test SETUP, such a snapshot PREDATES it. Before isolation was
# installed at `pytest_configure` (pre-collection), every hook driven from that snapshot wrote to
# `$HOME/.cache/ersatztv/hook-fire/` — 58 records per run, measured, with every assertion green,
# since the fire-log library is fail-open by design.
#
# `test_the_suite_does_not_write_to_the_PRODUCTION_log` asserts this specimen is now SAFE, which is
# the cross-suite claim that test has always made in its docstring and never checked in its body.
@@ -92,7 +93,7 @@ def hook_scripts() -> list[Path]:
"""THE POPULATION, from the GIT INDEX. Never a list, and never the filesystem (ersatztv#806).
The filesystem is not an authoritative source: an untracked `.sh` dropped in `.claude/hooks/` —
a scratch copy, a half-written hook — used to enter this population and be demanded to carry
a scratch copy, a half-written hook — would enter this population and be demanded to carry
instrumentation, reddening the suite on that checkout while CI, which never sees the file, stayed
green. That is #778's third shape, and a guard that fails everywhere except where it runs trains
its readers to ignore it.
@@ -130,14 +131,14 @@ def instrumentation_faults(text: str, name: str) -> list[str]:
# the `[ -r ] && .` line untouched and disables all reporting silently — a mutation the first
# version of this checker passed clean.
#
# EVERY assignment, and EXACTLY ONE of them. Reading only the first is a hole cold review found
# and measured: a hook carrying the canonical self-located line and then a SECOND
# EVERY assignment, and EXACTLY ONE of them. Reading only the first is a hole, and it is
# MEASURED: a hook carrying the canonical self-located line and then a SECOND
# `ETV_HOOK_FIRE_LIB=${SOME_OTHER_VAR:-…}/scripts/hook-fire-log.sh` passed this checker clean on
# all 13 hooks, and the shell would source the LAST value. The sourcing line reads the variable's
# final value, so the checker must judge every writer of it — checking the first is checking the
# one the defect does not use.
# THE AUTHORITY IS BYTE-IDENTITY, not a pattern — and that is a withdrawal, recorded rather than
# quietly performed. Three review rounds attacked a lexical rule over this line: `${VAR:-<self>}`
# quietly performed. Three successive lexical rules over this line each fell: `${VAR:-<self>}`
# satisfied a containment test; then backticks and `$((…))`; then `$(printenv VAR)`, `$1`, `$?`,
# an INDENTED or `export`ed reassignment further down, and `$'…'` quoting that makes the required
# token literal rather than expanded. Every fix admitted the next shape, which is this repo's own
@@ -180,7 +181,7 @@ def instrumentation_faults(text: str, name: str) -> list[str]:
# answering). Disarm an arm here with `pass`. `if False:` is safe on an arm with no `elif` after
# it — `mutation_manifest.py` disarms byte-identity that way every run — but on the two begin-call
# arms below it falls through to a `.group(1)` on None and reds with an AttributeError: a red for
# the wrong reason that reads like a proof, and cost this branch two review rounds. A
# the wrong reason that reads like a proof. 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.
@@ -221,8 +222,8 @@ def instrumentation_faults(text: str, name: str) -> list[str]:
if "${BASH_SOURCE[0]}" not in value:
faults.append(f"{name}: the sink path is not self-located from ${{BASH_SOURCE[0]}}: {value}")
# ...and MENTIONING `${BASH_SOURCE[0]}` is not the same as being DECIDED by it. Cold review
# measured the gap: `${ETV_HOOKS_ROOT:-$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../..")}`
# ...and MENTIONING `${BASH_SOURCE[0]}` is not the same as being DECIDED by it. The gap is
# MEASURED: `${ETV_HOOKS_ROOT:-$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../..")}`
# — literally "the next `${SOME_OTHER_DIR:-…}`" the comment above says it stops — passed on
# all 13 hooks, because the self-location sitting in the `:-` FALLBACK satisfied a
# containment test while the environment still won whenever the variable was set. A
@@ -231,8 +232,8 @@ def instrumentation_faults(text: str, name: str) -> list[str]:
# So the value must contain NO expansion at all beyond `${BASH_SOURCE[0]}` itself and the
# `$(…)` command substitution the canonical line is MADE of. Four spellings can let something
# outside this file choose the tree, and all four fail: `${…}`, a bare `$NAME`, an arithmetic
# `$((…))`, and a BACKTICK substitution — the last two found by self-audit rather than by a
# reviewer, and both slip past a `${…}`/`$NAME` test when `${BASH_SOURCE[0]}` also appears
# `$((…))`, and a BACKTICK substitution — the last two
# slip past a `${…}`/`$NAME` test when `${BASH_SOURCE[0]}` also appears
# (`` `cat /tmp/root` `` names a tree while containing no `$` at all). Neither has any use in
# this line, so refusing them costs nothing and "could not tell where this resolves from"
# fails rather than passing quietly.
@@ -322,9 +323,9 @@ def test_the_population_is_not_empty():
def test_the_stripper_removes_EXACTLY_the_preamble_and_nothing_else():
"""The A/B control must be the hook minus the instrumentation — no more, no less.
This compared `strip_instrumentation(hook)` against the hook at the merge base, which asserted
two unrelated things at once: that the stripper is exact, AND that no hook was edited in this PR
for any other reason. The second is not a property worth pinning — it went red the moment
Comparing `strip_instrumentation(hook)` against the hook at the merge base asserts
two unrelated things at once: that the stripper is exact, AND that no hook was edited on the
branch for any other reason. The second is not a property worth pinning — it went red the moment
`pretooluse-bom-guard.sh` had a real defect fixed (`xxd`, absent on the CI runner, made it
fail open) — and coupling them means a legitimate change reads as a broken control.
@@ -619,8 +620,8 @@ def test_the_husky_launched_population_is_not_empty():
def _pushed_tree(tmp_path: Path, hook: Path, sink_body: str) -> Path:
"""A repo-SHAPED scratch tree holding this hook and a `scripts/hook-fire-log.sh` of `sink_body`.
The pair below used to make its relative launch from REPO_ROOT itself, which was wrong twice
over and cold review measured both: `prepush-rebase-check.sh` reaches `git fetch origin main` on
A relative launch from REPO_ROOT itself is wrong twice
over, and both were measured: `prepush-rebase-check.sh` reaches `git fetch origin main` on
an empty ref list, so every suite run made a NETWORK CALL and rewrote `FETCH_HEAD` in the very
checkout under test — the one ref this repo's process treats as the baseline — and
`decisions-guard.sh` ran the full decisions validator over the live tree. A unit test must not
@@ -741,7 +742,7 @@ def test_a_LATER_reassignment_the_regex_cannot_see_is_DETECTED(hook):
The diagnostic arms below it read `^ETV_HOOK_FIRE_LIB=(.*)$`, anchored at column zero, so an
INDENTED reassignment inside an `if`, or an `export`ed one, is invisible to them while bash
executes it and the `. `-source line takes the LAST value. Cold review measured both passing a
executes it and the `. `-source line takes the LAST value. Both were MEASURED passing a
checker that had just been "fixed" to read every assignment — which is what retired the pattern
approach in favour of pinning the two canonical lines.
@@ -768,7 +769,7 @@ def test_the_NEXT_env_var_to_be_invented_is_DETECTED(hook):
"""THE MUTATION PROOF for the no-other-expansion arm, and the reason that arm exists.
Banning `CLAUDE_PROJECT_DIR` by name only moves the defect to the next name. This is that shape,
and cold review measured it passing on all 13 hooks against the arm that merely required
and it was MEASURED passing on all 13 hooks against the arm that merely required
`${BASH_SOURCE[0]}` to APPEAR: the self-location sits in the `:-` fallback, so the containment
test is satisfied while the environment still decides whenever `$ETV_HOOKS_ROOT` is set.
@@ -807,7 +808,7 @@ def test_the_NEXT_env_var_to_be_invented_is_DETECTED(hook):
# reach with a bare payload get a constructed positive case in `positive_cases()` below, and
# `test_the_AB_is_not_VACUOUS_for_any_hook` refuses to let any hook rely on this matrix alone.
#
# Stated because the first version of this file claimed the opposite in three places: this matrix
# MEASURED, not assumed: this matrix
# alone produced empty-vs-empty comparisons for 8 of 13 hooks and a zero exit status for all 13, so
# deleting the entire stdout replay left the differential test green for four hooks — two of which
# issue `deny`. An A/B over silent allows proves transparency on the one path where there is nothing
@@ -1121,7 +1122,7 @@ def _normalise_stderr(err: bytes) -> bytes:
"""
# The two fields are normalised TOGETHER, as one anchored prefix, not independently. A global
# `line \d+:` substitution also rewrites application text that happens to contain that phrase,
# and cold review demonstrated it collapsing two genuinely different diagnostics ("highest
# and was DEMONSTRATED collapsing two genuinely different diagnostics ("highest
# private fd line 0" vs "line 4") into one — hiding exactly the kind of fd-state difference this
# comparison exists to catch.
return re.sub(rb"(?m)^[^\s:]*/[^\s:]*\.sh: line \d+:", b"<script>: line <n>:", err)
@@ -1150,7 +1151,7 @@ def test_instrumentation_changes_NOTHING_the_harness_can_see(hook, sandbox, posi
@pytest.mark.parametrize("hook", hook_scripts(), ids=lambda h: h.stem)
def test_the_AB_is_not_VACUOUS_for_any_hook(hook, sandbox, positives):
"""ANTI-VACUITY FOR CLAIM 2 — the assertion the first version of this file was missing.
"""ANTI-VACUITY FOR CLAIM 2.
`test_instrumentation_changes_NOTHING_the_harness_can_see` compares the two halves against each
other. If a hook emits nothing and exits 0 on every case, that comparison is `("", 0) == ("", 0)`
@@ -1448,12 +1449,12 @@ def _report_decoy_tree(tmp_path: Path) -> Path:
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
Preferring `$CLAUDE_PROJECT_DIR` whenever it names a tree with a
`.claude/hooks` 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
this is that test for this site — its absence was MEASURED by restoring the preference
verbatim and watching the whole file stay green.
"""
project = _report_decoy_tree(tmp_path)
@@ -1510,14 +1511,14 @@ def test_the_report_REFUSES_a_root_that_does_not_OWN_this_sink(tmp_path, sandbox
Self-location answers "two directories above 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 — the wrong-root case the sink's own
comment claims is enforced rather than hoped for. It was shipped unexecuted: cold review measured
that replacing the clause with `:` left this whole file green, because the sibling test below
comment claims is enforced rather than hoped for. It was shipped unexecuted — MEASURED: replacing
the clause with `:` left this whole file green, because the sibling test below
copies the sink into `<tmp>/scripts/`, where the root DOES own it.
THREE arms, and the third is the one that tests OWNERSHIP rather than mere presence. The first
two roots hold no `scripts/hook-fire-log.sh` at all, so `-ef` never evaluates against an existing
left-hand side and a strictly weaker `[ -e … ]` would pass them both — measured by cold review,
which left the whole file green on that mutant. The `other-sink` arm gives the fake root a
left-hand side and a strictly weaker `[ -e … ]` would pass them both — MEASURED: that mutant
left the whole file green. The `other-sink` arm gives the fake root a
DIFFERENT `scripts/hook-fire-log.sh`, where presence and identity finally disagree: `-e` accepts
and prints a confident table about the other tree, `-ef` refuses.
@@ -1602,8 +1603,8 @@ def test_the_report_REFUSES_an_empty_population(tmp_path, sandbox):
# ------------------------------------------------------------------------------------------------
# PROOFS FOR THE ROUND-2 FIXES. Each of these went red before its fix and green after; each names
# the failure it pins, because "this test exists for a reason" is not a reason.
# PROOFS FOR THE DEFECTS THIS INSTRUMENTATION SHIPPED. Each went red before its fix and green
# after; each names the failure it pins, because "this test exists for a reason" is not a reason.
# ------------------------------------------------------------------------------------------------
@@ -1636,7 +1637,7 @@ def test_stderr_is_NOT_silenced(sandbox):
def test_output_SURVIVES_a_vanished_stdout_tempfile(sandbox):
"""The swallowed-`deny` path, found by cold review by stubbing `mktemp`.
"""The swallowed-`deny` path, also reachable by stubbing `mktemp`.
Two coupled mistakes: the fd restore lived inside the same conditional as the replay, so a
missing file left stdout still pointing at the temp target; and the replay read the PATH, so an
@@ -1773,8 +1774,8 @@ def test_the_suite_does_not_write_to_the_PRODUCTION_log(sandbox):
oracle was global mutable state: an unrelated session firing a hook inside the window failed
this test with `a test run modified the production hook-fire log` — an accusation about the
suite when the writer was another process. Observed on three separate branches, green on an
immediate re-run each time, and corroborated by an independent reviewer who found a file in that
directory written 13 seconds earlier by someone else (ersatztv#822). The misattribution was the
immediate re-run each time, and corroborated by a file in that
directory written 13 seconds earlier by another process (ersatztv#822). The misattribution was the
expensive part: it points the next reader at the suite, and the honest diagnosis costs a re-run
plus a directory listing.
@@ -2489,8 +2490,8 @@ def test_a_launch_NOT_CARRYING_the_isolated_log_dir_FAILS_THE_LAUNCH():
with pytest.raises(AssertionError, match="inside a shared hook-fire log"):
launch({**scratch, ENV_VAR: str(SHARED_LOG_DIRS[0] / "sub")})
# (5) the variable set RELATIVE, with a `cwd` that makes it land on a shared log. Found by
# cross-family review as a live bypass: a relative value resolves against the CHILD's directory,
# (5) the variable set RELATIVE, with a `cwd` that makes it land on a shared log. A LIVE
# BYPASS: a relative value resolves against the CHILD's directory,
# so a guard anchoring it at the parent's sees an unrelated path under the repo and clears it.
# The guard raises before `Popen` runs anything, so this launch never enters that directory.
shared = SHARED_LOG_DIRS[0]
@@ -2529,20 +2530,20 @@ def test_specimen_drives_a_hook():
def test_the_guard_JUDGES_every_env_and_cwd_SHAPE_that_Popen_ACCEPTS(tmp_path):
"""`env` and `cwd` each have several legal shapes; the guard must judge, not crash, on all.
`Popen` accepts `cwd` as str, bytes or `PathLike`. The first version of the relative-path
anchoring called `os.fspath(cwd)` and then `os.path.join`, which raises `TypeError` on mixing
`Popen` accepts `cwd` as str, bytes or `PathLike`. Relative-path
anchoring that calls `os.fspath(cwd)` and then `os.path.join` raises `TypeError` on mixing
str with bytes — a guard that raises `TypeError` on a legitimate launch is not a stricter guard,
it is a broken one, and the failure names the wrong thing entirely.
THE PREMISE IS PINNED, not assumed. A file descriptor is NOT a fourth shape: `Popen` calls
`os.fsencode(cwd)`, which rejects an int. A previous version of the guard added a branch for
that case; the branch was dead — `os.fspath` already raises on an int — and deleting it left its
`os.fsencode(cwd)`, which rejects an int. A branch for
that case is dead code — `os.fspath` already raises on an int — and deleting it left its
own test green, so it was removed rather than proved. The assertion below is what makes that
removal safe: if a future CPython starts accepting a descriptor, this goes red and says so.
"""
# A RELATIVE value, so the anchoring is actually REACHED. An absolute one short-circuits before
# `cwd` is consulted at all — an earlier draft of this test used one and passed identically for
# every shape, including shapes that crashed the guard the moment anything relative arrived.
# `cwd` is consulted at all — using one here passes identically for every shape, including
# shapes that crash the guard the moment anything relative arrives.
relative = {ENV_VAR: "isolated/log"}
for cwd in (str(tmp_path), tmp_path, os.fsencode(str(tmp_path))):
assert isolation_violation(relative, cwd) is None, (
@@ -2555,8 +2556,7 @@ def test_the_guard_JUDGES_every_env_and_cwd_SHAPE_that_Popen_ACCEPTS(tmp_path):
# AND THE ANCHOR MUST BIND TO THE LAUNCH'S cwd, for every shape — not merely fail to crash.
# The same relative value judged against two different `cwd`s must give two different verdicts;
# otherwise `cwd` is being ignored, which is the round-3 defect, and the shape loop above would
# pass while it was.
# otherwise `cwd` is being ignored, and the shape loop above would pass while it was.
shared_parent = SHARED_LOG_DIRS[0].parent.parent.parent
for shape in (str, Path, os.fsencode):
onto_shared = shape(str(shared_parent))