fix(806): guard populations over FILES derive from the git index, not a filesystem walk (#818)
Build ErsatzTV Image / Delimiter ban (release path) (push) Successful in 27s
Build ErsatzTV Image / Build & test (.NET) (push) Successful in 8m53s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (push) Successful in 5m57s
Build ErsatzTV Image / Functional E2E (curl + UI contracts) (push) Successful in 5m56s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (push) Skipped
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (push) Skipped
Build ErsatzTV Image / Build & push image (amd64) (push) Successful in 4m20s

`testing.guard-derives-population-from-source` (#774) was silent on the commonest
population in our own guards — files in a directory — and every one answered with a
filesystem walk. A walk is not authoritative: it reports build output, generated
shims and editor droppings, and differs per machine. #778 measured the cost by
getting the same population wrong three times in one PR.

CONVERTED (a completeness claim over tracked files): `test_guard_inventory.py`,
`test_hook_fire_log.py`, `test_ci_image_pin_population.py` (which also gained
`*.yaml`), `test_remote_state_inventory.py` (folded onto the shared derivation), and
`test_pr_changed_files.py` (not on the issue's list — found by sweeping the whole
repo).

ASSESSED AND RECORDED, not silently skipped: `_repo_copy` takes its file list from
the index for hermeticity though it makes no completeness claim;
`test_ci_dropped_step_guard.py` has no filesystem population at all; the decisions
corpus is recorded as unexamined rather than cleared; and the SPA page-size guard is
deferred to #819 with its obstacle documented. This is not "replace every glob".

`scripts/tests/tracked_files.py` is the single derivation.
`test_guard_populations_derive_from_git.py` proves it in two measured complements:
exhaustive removal catches a hardcoded `.exists()` admit and memoisation; the call
log catches an append-only source that yields nothing on this machine — #778's
shape — which removal cannot see because it has nothing to remove.

Twelve rounds of independent cold review, alternating model families in isolated
worktrees. The production derivations were confirmed sound every round; every
blocking finding after the first was in the proofs or in prose claims about them.
Counts over growing populations were removed rather than corrected, after three
drifted.

fixes #806

Co-authored-by: Timothy <timothy@noreply.gitea.tblindustries.be>
This commit was merged in pull request #818.
This commit is contained in:
2026-08-22 16:07:58 +00:00
committed by timothy
parent 3a53c50c45
commit 29d7a06e65
15 changed files with 1131 additions and 83 deletions
+25 -8
View File
@@ -2,9 +2,12 @@
Two separable claims, and conflating them is how instrumentation ships as a regression:
1. COVERAGE — every hook script records its own execution. The population is DERIVED from
`.claude/hooks/*.sh`, never listed, per `testing.guard-derives-population-from-source`, so a
hook added tomorrow is uninstrumented-and-red rather than silently unobserved.
1. COVERAGE — every hook script records its own execution. The population is DERIVED from the
tracked `.claude/hooks/*.sh`, never listed, per `testing.guard-derives-population-from-source`,
so a hook staged tomorrow is uninstrumented-and-red rather than silently unobserved. From
the git index rather than a filesystem walk since ersatztv#806 — an untracked file on one
machine is not part of the repo, and a guard whose population differs per checkout is one
nobody trusts.
2. TRANSPARENCY — the wrapper is invisible to the harness. It slurps stdin and replays it, and it
diverts stdout and replays it, which puts it directly in the path of the most load-bearing
@@ -34,7 +37,13 @@ from pathlib import Path
import pytest
from scripts.tests.tracked_files import tracked_paths
REPO_ROOT = Path(__file__).resolve().parents[2]
# Directory + patterns resolved against the GIT INDEX, not `Path.glob` (ersatztv#806) — see
# `scripts/tests/tracked_files.py`. `HOOKS_DIR` survives only for error messages.
HOOKS = (".claude/hooks", ("*.sh",))
HUSKY = (".husky", ("*",))
HOOKS_DIR = REPO_ROOT / ".claude" / "hooks"
SINK = REPO_ROOT / "scripts" / "hook-fire-log.sh"
@@ -46,8 +55,15 @@ _BEGINS = re.compile(r"^etv_hook_fire_begin (\S+) .*\|\| true$", re.M)
def hook_scripts() -> list[Path]:
"""THE POPULATION, from the filesystem. Never a list."""
return sorted(HOOKS_DIR.glob("*.sh"))
"""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
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.
"""
return tracked_paths(*HOOKS)
def expected_mode(name: str) -> str:
@@ -64,8 +80,8 @@ def expected_mode(name: str) -> str:
"""
if name in (REPO_ROOT / ".claude" / "settings.json").read_text():
return "capture"
for husky in (REPO_ROOT / ".husky").iterdir():
if husky.is_file() and name in husky.read_text():
for husky in tracked_paths(*HUSKY):
if name in husky.read_text():
return "stream"
return "capture"
@@ -150,7 +166,8 @@ def strip_instrumentation(text: str) -> str:
def test_the_population_is_not_empty():
hooks = hook_scripts()
assert len(hooks) >= 10, (
f"only found {len(hooks)} hook scripts under {HOOKS_DIR} — the glob has stopped matching, "
f"only found {len(hooks)} hook scripts tracked under {HOOKS_DIR} — the derivation has "
"stopped matching, "
"so every coverage assertion in this file is vacuous."
)
assert SINK.exists(), "the shared sink is missing; the instrumentation cannot work"