fix(774,775): close the cold-review findings — including three the change inflicted on itself

Two independent cold reviews (Codex GPT-5.6 cross-family; Fable 5 on the patch) both
returned BLOCKED. They agreed on the counts error and the extractor hole; each found
things the other did not. Fixes, with what each was:

THE INVENTORY DID NOT COVER ITS OWN NEW GUARDS. `_SCRIPT_REF` matched `scripts/name.py`
but not `scripts/tests/*.py`, so the three guard files this change introduced had no rows
and the completeness check stayed green. A completeness guard blind to its author's new
guards is precisely the defect being legislated against. The population now globs
`scripts/tests/test_*.py` — which is how they actually run, since pr-checks.yml invokes
the directory. 32 rows -> 48.

That forced a third Kind. Once test files are in the population, every mutation proof
becomes a row wanting a proof of its own, forever. `PROOF` marks a file whose job is to
prove another guard; a scripts/tests file enforcing a repo invariant with no separate
guard behind it stays GUARD and may cite a mutation case in its own file.

HOOK EXISTENCE WAS STANDING IN FOR HOOK WIRING. Deleting a hook's registration from
.claude/settings.json left the population and the table unchanged, so the row went on
describing a guard that no longer ran — #631's shape one level down. Now derived from
settings.json plus the husky hooks.

THE SUMMARY COUNTS WERE A HAND-KEPT MIRROR AND WERE WRONG ON ARRIVAL: "28 guards, 4
tooling ... 19 have none" against a table holding 27/5/6/3/18. Both reviewers found it
independently. The prose is now parsed and asserted against the table.

TWO FALSE MUTATION GRADES, each with a concrete disarm:
  - test_full_first_page_alone_does_not_end_enumeration sends 50 docs paths then one more
    docs path; disarm pagination to treat a full page as final and it is still all-docs,
    still exempt, still green. Re-pointed at test_protected_path_on_a_LATER_page_is_still_seen,
    which does go red under that mutation.
  - test_the_scan_job_runs_the_out_of_pytest_positive_control asserts only that the script
    exists, is executable, is referenced and is marked; replace its logic with `exit 0` and
    all four pass. ci-prove-ban-detects.sh regraded NONE.

The MUTATION column was also being applied as a curve: three rows graded MUTATION fed the
real script an input only that clause rejects, which is what the rows eight lines away are
graded BEHAVIOUR-ONLY for. Definition sharpened to *witnessed* rather than plausible, and
those regraded. 5 MUTATION / 6 BEHAVIOUR-ONLY / 21 NONE across 32 guards.

THE VOCABULARY EXTRACTOR COULD RETURN A PARTIAL SET. `[A-Z|-]` cannot match `SHIP*)`, so
adding that arm leaves the extracted set non-empty AND equal to the read side — parity
green while the gate desyncs. Emptiness checks cannot see partial degradation. A loose
counterpart now asserts the strict pattern consumed every arm; proven red on exactly that
attack and green on a clean tree. Also: each verdict pattern must be assigned once, since
the extractor unions assignments while the classifier runs the last.

Also: docker-build.yml was itself an unchecked scope mirror (now asserted to be the only
workflow with toolchain container jobs, by parsing container.image rather than grepping —
ci-image.yml names the image because it builds it); the mutant floor is an equality;
e2e-functional.sh reclassified GUARD (it exits 1 on a failed contract assertion);
design-sync-reminder.sh does block the first Stop. The doc now states all six excluded
classes instead of one.

Not done here, filed instead: workflow-owned execution-class metadata to replace
TOOLCHAIN_JOBS, a single shared verdict vocabulary, and an executable clause-level
mutation harness. Each touches a CI-gating or merge-gate path and wants its own review.

580 script-tests pass.

Refs #774
Refs #775

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-13 22:20:51 +02:00
co-authored by Claude Opus 5
parent 0bd59b0b6e
commit 3473a6c889
5 changed files with 322 additions and 31 deletions
+43 -2
View File
@@ -39,7 +39,8 @@ import pytest
import yaml
REPO_ROOT = Path(__file__).resolve().parents[2]
WORKFLOW = REPO_ROOT / ".gitea" / "workflows" / "docker-build.yml"
WORKFLOWS_DIR = REPO_ROOT / ".gitea" / "workflows"
WORKFLOW = WORKFLOWS_DIR / "docker-build.yml"
# The image repository, without the tag. Matched as a whole path rather than by the bare
# `ersatztv-ci` token so a job pointing at a LOOK-ALIKE registry (a personal fork, a typo'd host)
@@ -254,7 +255,47 @@ def test_the_mutation_set_is_not_empty():
nothing. That is the vacuous-by-sampling shape this whole issue is about, and it is reachable
here through a single broken helper.
"""
assert len(_MUTANTS) >= 12, f"expected 4 mutations per container job, got {len(_MUTANTS)}"
expected = 4 * len(TOOLCHAIN_JOBS)
assert len(_MUTANTS) == expected, (
f"expected 4 mutations per registered job ({expected}), got {len(_MUTANTS)}. A floor rather "
"than an equality here would let a `container_jobs()` that degraded to 3 of 5 jobs pass "
"while silently testing less — the message would still claim 4 per job."
)
def test_docker_build_is_the_ONLY_workflow_pinning_the_toolchain_image():
"""This file reads ONE workflow, which is itself a scope mirror needing its own check.
`WORKFLOW` hardcodes `docker-build.yml`, and the implicit claim — that no other workflow uses
the toolchain image — mirrors a machine-readable source (the glob of `.gitea/workflows/*.yml`)
that nothing consulted. `renovate.yml` already declares a `container:` with a different image,
so the shape is live. A future workflow adopting `ersatztv-ci:` would acquire no pin-population
guard, no single-tag check and no partition, silently, while `pin_population_faults`'s own error
text claims "All container jobs must run the same toolchain image".
Found by cold review, which correctly noted this file criticises `MARKED_JOBS` for exactly this
and then shipped the same shape without even the dated comment `MARKED_JOBS` carries.
Checked by PARSING each workflow's `container.image`, not by grepping the file. A text search
reports `ci-image.yml`, which names the image because it BUILDS and PUSHES it — a producer, not
a consumer. Grepping would have made this test permanently red on a correct tree, which is the
fastest route to a correct guard being deleted.
"""
others = []
for p in sorted(WORKFLOWS_DIR.glob("*.yml")):
if p.name == WORKFLOW.name:
continue
doc = yaml.safe_load(p.read_text()) or {}
for name, job in (doc.get("jobs") or {}).items():
if not isinstance(job, dict):
continue
if _PIN.match(str((job.get("container") or {}).get("image", ""))):
others.append(f"{p.name}:{name}")
assert not others, (
f"{sorted(others)} run container jobs on the CI toolchain image, but this file only checks "
f"{WORKFLOW.name}, so they have no pin-population guard at all. Extend the check to cover "
"them rather than leaving the coverage implied."
)
def test_the_shell_guards_grep_sees_the_same_tags_the_jobs_run():
+120 -2
View File
@@ -32,6 +32,7 @@ stays with review, and the table is the thing review reads.
from __future__ import annotations
import re
from collections import Counter
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parents[2]
@@ -40,12 +41,27 @@ HOOKS_DIR = REPO_ROOT / ".claude" / "hooks"
HUSKY_DIR = REPO_ROOT / ".husky"
WORKFLOWS_DIR = REPO_ROOT / ".gitea" / "workflows"
KINDS = {"GUARD", "TOOLING"}
KINDS = {"GUARD", "TOOLING", "PROOF"}
PROOFS = {"MUTATION", "BEHAVIOUR-ONLY", "NONE"}
_SCRIPT_REF = re.compile(r"scripts/[a-z0-9_.-]+\.(?:sh|py)")
# `scripts/x.sh` AND `scripts/tests/x.py`. The first version omitted the `/`, and the consequence was
# not theoretical: the three guard files this inventory shipped with were themselves outside the
# population it checked for completeness, so they acquired no rows and the guard stayed green. Cold
# review found it. A completeness guard blind to its own author's new guards is the defect this
# whole change is about, so the miss is recorded here rather than quietly corrected.
_SCRIPT_REF = re.compile(r"scripts/(?:[a-z0-9_.-]+/)?[a-z0-9_.-]+\.(?:sh|py)")
_ROW = re.compile(r"^\|\s*`([^`]+)`\s*\|([^|]*)\|\s*([A-Z-]+)\s*\|\s*([A-Z-]+)\s*\|([^|]*)\|\s*$", re.M)
# The prose summary, parsed so it cannot drift from the table it summarises. It already had:
# shipped as "28 guards, 4 tooling … 6 … 3 … 19" against a table holding 27/5/6/3/18, because it was
# a hand-maintained mirror with no equality check — #773's Family C inside the deliverable arguing
# against it. Both reviewers caught it independently.
_SUMMARY = re.compile(
r"(\d+)\s+guards?,\s+(\d+)\s+tooling\s+scripts?,\s+(\d+)\s+proof\s+files?\.\s+"
r"\*\*(\d+)\s+guards?\s+carry\s+a\s+mutation\s+proof;\s+(\d+)\s+(?:are|is)\s+behaviour-only;\s+"
r"(\d+)\s+have\s+none\.\*\*"
)
def derived_guard_files() -> set[str]:
"""THE AUTHORITATIVE POPULATION, from the filesystem and the call sites — never a list.
@@ -60,6 +76,11 @@ def derived_guard_files() -> set[str]:
str(p.relative_to(REPO_ROOT)) for p in HOOKS_DIR.glob("*.sh")
} | {
str(p.relative_to(REPO_ROOT)) for p in HUSKY_DIR.iterdir() if p.is_file()
} | {
# `pr-checks.yml` runs `pytest scripts/tests` as a directory, so every file in it is
# invoked and none is individually named anywhere. Globbing is the only derivation that
# matches how they actually run.
str(p.relative_to(REPO_ROOT)) for p in (REPO_ROOT / "scripts" / "tests").glob("test_*.py")
}
callers = list(WORKFLOWS_DIR.glob("*.yml")) + list(HOOKS_DIR.glob("*.sh"))
@@ -71,6 +92,23 @@ def derived_guard_files() -> set[str]:
return found
def wired_hook_files() -> set[str]:
"""Hooks reachable from `.claude/settings.json` or a husky hook — WIRING, not existence.
Directory membership is not execution. A hook whose settings.json registration is deleted keeps
its file, keeps its inventory row, and stops running — and the table would go on describing a
working guard. That is #631 and #719's shape ("wired is not running") one level down, and it was
the derivation's blind spot until cold review named it.
"""
text = (REPO_ROOT / ".claude" / "settings.json").read_text()
for husky in HUSKY_DIR.iterdir():
if husky.is_file():
text += husky.read_text()
return {
str(p.relative_to(REPO_ROOT)) for p in HOOKS_DIR.glob("*.sh") if p.name in text
}
def inventory_rows() -> list[tuple[str, str, str, str]]:
"""(guard, kind, proof, proof_ref) for each table row."""
rows = []
@@ -161,6 +199,86 @@ def test_every_claimed_proof_names_a_test_that_exists():
)
def test_every_hook_file_is_actually_WIRED():
"""A hook file nothing registers is dead code holding an inventory row that reads as coverage."""
on_disk = {str(p.relative_to(REPO_ROOT)) for p in HOOKS_DIR.glob("*.sh")}
unwired = sorted(on_disk - wired_hook_files())
assert not unwired, (
f"these hook files exist and have inventory rows but are referenced by neither "
f".claude/settings.json nor any .husky/ hook: {unwired}. They do not run. Either wire them "
"or delete them — a row for a hook that never fires is the coverage claim #631 paid for."
)
def test_proof_rows_do_not_themselves_claim_a_proof():
"""`PROOF` exists to stop an infinite regress, and the regress is not hypothetical.
Once `scripts/tests/*.py` entered the population, every mutation proof became a row needing a
proof of its own, and so on. `PROOF` marks a file whose job IS to prove another guard; grading
it would ask what proves the prover, forever. Files under `scripts/tests/` that enforce a repo
invariant with no separate guard file behind them are `GUARD`, not `PROOF`, and are graded
normally — that is the honest place to draw the line.
"""
for guard, kind, proof, ref in inventory_rows():
if kind == "PROOF":
assert proof == "NONE", f"{guard} is PROOF but claims Proof {proof}"
assert guard.startswith("scripts/tests/"), (
f"{guard} is marked PROOF but does not live in scripts/tests/"
)
assert ref in ("—", "-", ""), f"{guard}: PROOF rows carry no proof ref"
def test_every_proof_ref_points_at_a_row_marked_PROOF():
"""Ties the two halves of the table together. A guard citing a test that the table does not
classify as a PROOF means the population and the refs disagree about what that file is."""
rows = inventory_rows()
proof_files = {g for g, k, _, _ in rows if k == "PROOF"}
for guard, _kind, proof, ref in rows:
if proof == "NONE":
continue
filename = ref.strip("`").split("::", 1)[0]
path = f"scripts/tests/{filename}"
# A test-file GUARD may cite ITSELF: its mutation cases live in the same file, because the
# thing it guards is a repo invariant rather than another script. Splitting those into a
# separate file to satisfy the table would be bookkeeping driving the code.
if path == guard:
continue
assert path in proof_files, (
f"{guard} cites {filename} as its proof, but that file is not a PROOF row in this "
"table. The citation and the classification must agree."
)
def test_the_summary_counts_match_the_table():
"""The prose is DERIVED-checked, not hand-maintained.
It shipped wrong the first time — "28 guards, 4 tooling … 19 have none" against a table holding
27/5/…/18 — because it was a mirror with no equality check. Both cold reviewers found it
independently, which is the clearest possible evidence that a summary nobody checks is a summary
nobody can trust.
"""
rows = inventory_rows()
kinds = Counter(k for _, k, _, _ in rows)
grades = Counter(p for _, k, p, _ in rows if k == "GUARD")
m = _SUMMARY.search(INVENTORY.read_text())
assert m, (
"could not find the summary sentence in the expected shape. It must read exactly like: "
"`N guards, N tooling scripts, N proof files. **N guards carry a mutation proof; N are "
"behaviour-only; N have none.**` — if you reword it, update `_SUMMARY` in the same commit, "
"because an unparsed summary is an unchecked one."
)
claimed = tuple(int(g) for g in m.groups())
actual = (
kinds["GUARD"], kinds["TOOLING"], kinds["PROOF"],
grades["MUTATION"], grades["BEHAVIOUR-ONLY"], grades["NONE"],
)
assert claimed == actual, (
f"the summary claims (guards, tooling, proofs, mutation, behaviour-only, none) = {claimed} "
f"but the table holds {actual}."
)
def test_tooling_rows_never_claim_a_proof():
"""A TOOLING row asserting nothing cannot have a proof that it can go red, and letting one
carry a ref would quietly inflate the coverage count at the bottom of the inventory."""
@@ -35,8 +35,20 @@ READ_SIDE = REPO_ROOT / "scripts" / "check-review-verdict.sh"
# `MERGEABLE|APPROVED|LGTM) state="success" ;;` — the case arm and the state it selects.
_CASE_ARM = re.compile(r'^\s*([A-Z|-]+)\)\s*state="(success|failure)"', re.M)
# THE LOOSE COUNTERPART, and the reason it exists. `_CASE_ARM`'s `[A-Z|-]` class cannot match an arm
# containing anything else — a glob (`SHIP*)`), a digit, an underscore. Such an arm is not a parse
# ERROR, it is INVISIBLE: the extractor returns the remaining arms, which are non-empty and, in the
# realistic case where the new arm was ADDED beside the old one, identical to the read side. Every
# assertion in this file then passes while the shell accepts a word the classifier does not.
#
# An emptiness check cannot see that, because the degradation is PARTIAL rather than total. So the
# strict pattern is held to consuming EVERY arm the loose one finds — the same completeness idea as
# the rest of this change, applied to the extractor rather than to the guard.
_ANY_CASE_ARM = re.compile(r'^\s*(\S+)\)\s*state="(?:success|failure)"', re.M)
# `POS_RE='^review-verdict:[[:space:]]*(mergeable|approved|lgtm)([[:space:]@]|$)'`
_VERDICT_RE = re.compile(r"^(POS_RE|NEG_RE)='[^']*?\(([a-z|-]+)\)", re.M)
_ANY_VERDICT_ASSIGN = re.compile(r"^(POS_RE|NEG_RE)=", re.M)
def write_side_vocabulary() -> dict[str, set[str]]:
@@ -66,6 +78,49 @@ def read_side_vocabulary() -> dict[str, set[str]]:
# ------------------------------------------------------------------------------------------------
def test_the_strict_extractor_consumed_EVERY_case_arm():
"""PARTIAL extraction, which emptiness cannot catch. Cold review demonstrated this rather than
hypothesising it: adding `SHIP*) state="success" ;;` beside the existing arm leaves
`write_side_vocabulary()` returning the unchanged baseline set — non-empty, and equal to the
read side — so anti-vacuity, the positive control and the parity assertion all stayed green
while `post-review-verdict.sh` had started accepting a word `check-review-verdict.sh` rejects.
"""
text = WRITE_SIDE.read_text()
# `findall` with ONE group yields plain strings; with two it yields tuples. Getting that wrong
# here made the first version of this test report arms `['B', 'M', 'S']` — the first character
# of each string — and fail on a clean tree.
loose = set(_ANY_CASE_ARM.findall(text))
strict = {arm for arm, _state in _CASE_ARM.findall(text)}
unparsed = loose - strict
assert not unparsed, (
f"{WRITE_SIDE.name} has case arm(s) {sorted(unparsed)} that the strict extractor cannot "
"read, so their words are absent from the parity comparison entirely — the gate could "
"accept them on the write side while the read side rejects them, and every other test here "
"would stay green. Either the arm uses characters the extractor does not model (a glob, a "
"digit, an underscore) or the case block was reformatted. Widen `_CASE_ARM` deliberately."
)
def test_each_verdict_pattern_is_assigned_exactly_once():
"""A SECOND assignment would narrow the pattern at runtime while the extractor unions both.
`read_side_vocabulary()` accumulates over every `POS_RE=` line, so a conditional re-assignment
inserted between definition and use — a strict mode narrowing the positives to `(mergeable)` —
leaves the extracted set equal to the write side while the running classifier rejects `approved`
and `lgtm`. Cold review confirmed the extracted set is unchanged in that case.
"""
counts = {"POS_RE": 0, "NEG_RE": 0}
for name in _ANY_VERDICT_ASSIGN.findall(READ_SIDE.read_text()):
counts[name] += 1
for name, n in counts.items():
assert n == 1, (
f"{READ_SIDE.name} assigns {name} {n} times. This file unions every assignment, so a "
"later narrowing one is invisible here while it is the one the classifier actually "
"runs. Keep it to a single assignment, or teach both this test and the extractor which "
"one wins."
)
def test_both_extractors_actually_found_words():
write, read = write_side_vocabulary(), read_side_vocabulary()
for label, vocab, path in (("write", write, WRITE_SIDE), ("read", read, READ_SIDE)):