fix(887): a selector where a pin was available — the blocker round 5 measured

Round 5 found a BLOCKER, and it is the sharpest kind: I made the exact mistake I had
described one screen earlier. `test_only_the_PINNED_npm_SCRIPTS_run_vitest` SELECTED the
scripts to pin by asking whether their body contained the literal `vitest` — a selector,
the category this file calls the worst-behaved because going short is silent — and then
its docstring claimed "going short is caught by the equality below", which is false: a
script the substring misses is absent from the compared map, so the equality still holds.

Four one-line `web/package.json` edits, none of which spells `vitest`, each put the suite
back into the gitless stage with the whole guard green: `"build": "npm run test -- --run
&& …"`, the same via `npm t`, and the `prebuild` / `preinstall` LIFECYCLE HOOKS, which
npm runs for `npm run build` and `npm ci` without anything naming them. That is #883
verbatim, through the route round 4 identified and the previous commit reported closed.

The fix is the one the file's own vocabulary prescribes: pin the WHOLE script map. A
script that does not exist cannot be a lifecycle hook, and one that changes is not equal.
The category disappears rather than being widened by two entries.

ALSO CLOSED, all measured:
  * `web/vite.config.ts`'s `test:` block is now pinned. `npm test -- --run` collects what
    that file says, so `test.exclude` is where a filter would now naturally be written —
    it is the only place left after this change removed the Dockerfile's. Three mutants
    narrowed the gating suite through it with the step's own command unchanged.
  * A step-level `shell:` and a job-level `defaults:` each override the pinned workflow
    default. Both forbidden.
  * `test_no_run_BODY_builds_or_pushes_an_image` is RESTORED — I dropped it in the parser
    withdrawal, and a job publishing via `run: docker build … && docker push …` was then
    outside the action-derived population with anti-vacuity none the wiser.
  * A leading-slash context copy (`COPY /web/. ./web/`) was not recognised.
  * The sweep gains `yarn test`, `pnpm test`, `bun test`.

The residual naming the uncovered COPY shapes was wrong for the SECOND consecutive round —
it named `COPY --from=X /source/web /elsewhere`, which is covered (only the destination is
renamed). The real gaps are an ANCESTOR source (`/source` brings `/source/web` along) and
`/source/.`. Both measured.

Route count: five, then six, now seven. It has been wrong at every count, so it is now
stated as a running total with that history attached rather than as an enumeration.

Battery 51 -> 60, 0 missed.

Refs: #887
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019T79beF1Ufid3dXju4yqkF
This commit is contained in:
2026-08-30 13:37:59 +02:00
co-authored by Claude Opus 5
parent 3a88f5dc3d
commit 9b99a23835
4 changed files with 160 additions and 35 deletions
@@ -45,17 +45,21 @@ pin and reddens.
WHAT A PIN IS AND IS NOT IMMUNE TO, stated precisely because an earlier version of this paragraph
claimed the absolute "a pin cannot have a false green" and cold review refuted it by execution. A
pin is immune to the class that defeated the parser: a DIFFERENT SPELLING of the command. It is not
immune to the same text MEANING something else, and there are six such routes. Four are closed
here — `working-directory`, `defaults.run.shell`, a stage `SHELL`, and `web/package.json`'s scripts,
since `RUN npm run build` executes whatever that file says (an INDIRECT chain, `"test": "npm run
inner"` with `inner` running vitest, is caught by the same equality rather than needing its own
clause). A fifth, the `container:` image the gating job runs in, decides which `npm` exists at all
and is pinned by `test_ci_image_pin_population.py` — cited rather than re-asserted, because two
guards on one condition mask each other (ersatztv#685). The sixth, an `ENV` rewriting `PATH` so a
pinned `RUN` resolves a different `npm`, is not modelled and is stated as a residual rather than
implied away. So: the pin removes the spelling problem entirely
and shrinks the meaning problem to an enumerated list, which is a much better place to be than a
predicate that was wrong nine times — but it is not "cannot be wrong".
immune to the same text MEANING something else. SEVEN such routes have been IDENTIFIED, and that
number is a running total, not a proof: it was written as five, then six, and both were wrong when
checked. Six are handled — `working-directory` and the gating step's own `shell:`; the workflow
`defaults.run.shell` and the job-level `defaults` that would override it; a stage `SHELL`, refused
outright; `web/package.json`'s script map, pinned WHOLE after selecting on the literal `vitest`
missed `npm run test`, `npm t`, and the `prebuild`/`preinstall` LIFECYCLE HOOKS npm runs for
`npm run build` and `npm ci`; `web/vite.config.ts`'s `test:` block, which decides what the suite
COLLECTS and is where a filter would now naturally be written; and the gating job's `container:`
image, pinned by `test_ci_image_pin_population.py` and CITED rather than re-asserted, because two
guards on one condition mask each other (ersatztv#685). The seventh, an `ENV` rewriting `PATH` so a
pinned `RUN` resolves a different `npm`, is not modelled and is stated as a residual.
So: the pin removes the SPELLING problem outright and reduces the MEANING problem to a list that can
be worked through — a much better place than a predicate that was wrong nine times. It is not
"cannot be wrong", and the list's own history says so.
The cost is stated rather than hidden: a legitimate edit to those command lines reddens this guard
and its author must update the pin. That is the same deliberate review trigger `KNOWN_GATE_*` uses,
@@ -84,8 +88,12 @@ WHAT IS NOT COVERED, stated rather than implied:
copy whose source names `web` — and NOT the wider "has the suite available to run", which is
what an earlier version of this sentence claimed. A stage copy that RENAMES the tree on the way
in (`COPY --from=web-build /source/web /elsewhere`) has no `web` segment in its source and is
not recognised. The false-NEGATIVE direction is the one that drops a stage out of the check, so
it is pinned in both directions by its own test.
not recognised — nor is a source that is an ANCESTOR of it (`COPY --from=web-build /source /src`
brings `/source/web` along without naming it). Both were MEASURED; the previous two attempts at
this sentence each named a shape that was in fact covered while omitting these. The
false-NEGATIVE direction is what drops a stage out of the check, so the predicate is pinned in
both directions by its own test, and the substring sweep below is the backstop for whatever it
still misses.
* A step or stage OTHER than a pinned one could run the suite, and the substring sweep is what
reports it. `SUITE_MENTIONS` is a hand-written SELECTOR — a third category the population/pin
split does not name, and the one that behaves worst: a population going short is caught by an
@@ -171,11 +179,42 @@ PUBLISH_STEP_IF = "steps.detect.outputs.docs_only != 'true'"
# back into the gitless stage, and `"prepare"` is run by `npm ci`. So the SCRIPTS THAT MENTION VITEST
# are pinned too — exactly one, and its body.
PACKAGE_JSON = "web/package.json"
PINNED_VITEST_SCRIPTS: dict[str, str] = {"test": "vitest"}
# THE WHOLE MAP, not the scripts that mention vitest. Selecting on the literal `vitest` was a
# SELECTOR where a PIN was available, and cold review re-armed ersatztv#887 through four spellings
# none of which contain it: `"build": "npm run test -- --run && …"`, `"build": "npm t -- …"`, and the
# lifecycle hooks `prebuild` (npm runs it before `npm run build`) and `preinstall` (before `npm ci`).
# Both pinned RUN lines in the gitless stage execute whatever this map says, so the map is pinned.
PINNED_PACKAGE_SCRIPTS: dict[str, str] = {
"dev": "vite --host 0.0.0.0",
"build": "tsc -b && vite build",
"generate:api": "node scripts/generate-openapi-types.mjs",
"check:api": "npm run generate:api && git diff --exit-code -- src/api/generated/v1.d.ts",
"lint": "eslint .",
"test": "vitest",
"test:ui-e2e": "playwright test",
"typecheck": "tsc -b --pretty false",
"prepare": "cd .. && husky",
}
# `npm test -- --run` collects whatever this config says it does, so `test.exclude`/`include` is the
# remaining place a filter can be written — and, since this change removes the Dockerfile
# `--exclude`s, the FIRST place anyone reaching for one would now look. The `test:` block is pinned
# for the same reason the script map is.
VITE_CONFIG = "web/vite.config.ts"
PINNED_VITE_TEST_BLOCK = """test: {
environment: 'jsdom',
environmentOptions: {
jsdom: {
url: 'http://localhost/app/'
}
},
exclude: [...configDefaults.exclude, 'e2e/**'],
setupFiles: './src/setupTests.ts'
}"""
# Substrings that mean "a human should look at this step". NOT a semantic predicate — the pinned step
# is allowed to contain them and every other step is not.
SUITE_MENTIONS = ("npm t", "npm run test", "vitest")
SUITE_MENTIONS = ("npm t", "npm run test", "yarn test", "pnpm test", "bun test", "vitest")
# `npm t` rather than `npm test`: it is npm's own documented alias, it SUBSUMES `npm test` as a
# substring, and this file enumerates it among the spellings that defeated the parser. Leaving it out
# meant an unpinned stage running `npm t -- --run` passed the sweep — measured by cold review.
@@ -186,6 +225,31 @@ def _normalise(text: str) -> str:
return " ".join(text.split())
def _vite_test_block() -> list[str]:
"""The `test: {` … matching `}` block of `web/vite.config.ts`, normalised per line.
Brace matching from a single marker — the same class of syntax handling as splitting a Dockerfile
on `FROM`: unambiguous, and it interprets nothing. Comment lines are dropped so the block can be
explained without the explanation being pinned.
"""
text = _read(VITE_CONFIG)
start = text.index("test: {")
depth = 0
for index in range(start, len(text)):
if text[index] == "{":
depth += 1
elif text[index] == "}":
depth -= 1
if depth == 0:
block = text[start : index + 1]
return [
_normalise(line)
for line in block.splitlines()
if line.strip() and not line.strip().startswith(("//", "*", "/*"))
]
raise AssertionError(f"{VITE_CONFIG}: the `test: {{` block is not brace-balanced")
def _normalise_lines(text: str) -> list[str]:
"""Per-line normalisation, so indentation is free but the LINE BOUNDARIES are not.
@@ -321,7 +385,7 @@ def _source_reaches_web(source: str) -> bool:
which left the receiving stage unpinned. `fnmatch` against the literal segment `web` is what
separates the two without hand-listing patterns.
"""
normalised = source.removeprefix("./").rstrip("/")
normalised = source.removeprefix("./").lstrip("/").rstrip("/")
if normalised in {"", ".", "web"} or normalised.startswith("web/"):
return True
head = normalised.split("/")[0]
@@ -579,6 +643,18 @@ def test_the_GATING_STEP_is_exactly_what_was_reviewed() -> None:
f"nothing. Only absent, `false` or `False` is acceptable here."
)
if "shell" in step:
faults.append(
f"the gating step carries its own `shell: {step['shell']!r}`, which overrides the pinned "
f"workflow default. The default is pinned because `bash` means `bash -e`; a step-level "
f"override moves that decision somewhere nothing checks."
)
if "defaults" in job:
faults.append(
f"the job `{GATING_JOB}` carries `defaults: {job['defaults']!r}`, which overrides the "
f"pinned workflow default for every step in it, including the gating one."
)
if "if" in job:
faults.append(
f"the job `{GATING_JOB}` carries a job-level `if:` ({job['if']!r}). None did when "
@@ -589,23 +665,42 @@ def test_the_GATING_STEP_is_exactly_what_was_reviewed() -> None:
assert not faults, "\n".join(faults)
def test_only_the_PINNED_npm_SCRIPTS_run_vitest() -> None:
"""A pinned `RUN` executes whatever `web/package.json` says; pin that too.
def test_the_npm_SCRIPT_MAP_is_exactly_what_was_reviewed() -> None:
"""The whole map, because a pinned `RUN npm …` executes whatever it says.
The Dockerfile stage runs `npm ci` and `npm run build`. Neither line changes when a script body
does, so `"build": "vitest run && …"` or a `"prepare"` that runs vitest re-arms ersatztv#887 with
every pin still matching — measured by cold review, twice. A substring test on `vitest`, not a
predicate: it decides which scripts must be pinned, and going short is caught by the equality
below rather than by the substring.
An earlier version pinned only the scripts whose body contained `vitest`, which is a SELECTOR —
the category this file elsewhere calls the worst-behaved, because going short is silent. It went
short four ways, each re-arming ersatztv#887 in the gitless stage with every other pin matching:
`npm run test`, `npm t`, and the `prebuild`/`preinstall` LIFECYCLE HOOKS, which npm runs for
`npm run build` and `npm ci` without anything naming them. Pinning the map removes the category:
a script that does not exist cannot be a hook, and one that changes is not equal.
"""
scripts = json.loads(_read(PACKAGE_JSON)).get("scripts", {})
mentioning = {name: body for name, body in scripts.items() if isinstance(body, str) and "vitest" in body}
assert mentioning == PINNED_VITEST_SCRIPTS, (
f"the `{PACKAGE_JSON}` scripts mentioning vitest are {mentioning}, not the pinned "
f"{PINNED_VITEST_SCRIPTS}. Every `RUN npm …` in a pinned Dockerfile stage executes whatever "
f"these say, so a suite run added here reaches the gitless stage with no pinned line "
f"changed — which is ersatztv#887 re-armed through a file nobody would think to check "
f"against this guard. If the change is deliberate, update the pin and say why."
assert scripts == PINNED_PACKAGE_SCRIPTS, (
f"`{PACKAGE_JSON}`'s scripts are not the pinned map.\n pinned: {PINNED_PACKAGE_SCRIPTS}\n"
f" actual: {scripts}\n Both pinned `RUN npm …` lines in the gitless `web-build` stage "
f"execute whatever this says, INCLUDING npm's `pre*`/`post*` lifecycle hooks, which nothing "
f"in the Dockerfile names. A suite run added here reaches that stage with no Dockerfile or "
f"workflow line changed — ersatztv#887 through a file nobody would think to check against "
f"this guard. Update the pin deliberately, in the same commit, with a reason."
)
def test_the_VITE_TEST_BLOCK_is_exactly_what_was_reviewed() -> None:
"""`npm test -- --run` collects what this config says; "unfiltered" is otherwise unverified.
`test.exclude` is where the Dockerfile's `--exclude`s would naturally be re-created now that they
are gone, and a filter there leaves every other pin matching while the gating run reports green
over a narrowed suite. Cold review measured three: adding the three git-dependent specs to
`exclude`, narrowing `include` to `src/**`, and `include: ['nope/**']` with `passWithNoTests`.
"""
block = _vite_test_block()
assert block == _normalise_lines(PINNED_VITE_TEST_BLOCK), (
f"`{VITE_CONFIG}`'s `test:` block is not the pinned one.\n"
f" pinned: {_normalise_lines(PINNED_VITE_TEST_BLOCK)}\n actual: {block}\n"
f" This block decides WHICH specs `npm test -- --run` collects, so a filter here narrows "
f"the gating suite with the step's own command unchanged — the same defect ersatztv#887 "
f"removed from the Dockerfile, relocated. Update the pin deliberately."
)
@@ -682,6 +777,34 @@ def test_no_DOCKERFILE_outside_a_pinned_stage_mentions_the_suite() -> None:
# ------------------------------------------------------------------------------------------------
def test_no_run_BODY_builds_or_pushes_an_image() -> None:
"""`publishing_jobs()` keys on the ACTION, which is a selector; assert nothing publishes around it.
A job doing `docker build -f ./docker/Dockerfile … && docker push …` in a shell body is not in
that population, so the positive invariant is silently not applied to it — and anti-vacuity does
not notice, because the real `build` job is still there. Measured MISSED by cold review after
this assertion was dropped in the rewrite; it is restored rather than reasoned away.
"""
stray: list[str] = []
for path in workflow_files():
rel = path.relative_to(REPO_ROOT).as_posix()
for job_id, job in workflow_jobs(rel).items():
for step in _steps(job):
body = step.get("run")
if not isinstance(body, str):
continue
for line in body.splitlines():
if line.lstrip().startswith("#"):
continue
if re.search(r"\bdocker\s+(?:push|build|buildx\s+build)\b", line):
stray.append(f"{rel} :: job `{job_id}`: {line.strip()!r}")
assert not stray, (
f"image build/push outside `{PUBLISH_ACTION}`:\n " + "\n ".join(stray) + "\n\n"
"`publishing_jobs()` derives from that action, so these jobs are NOT checked for the suite "
"gate — extend it before adding one."
)
def test_the_populations_are_NOT_empty() -> None:
"""Every assertion above passes over an empty set, which is how a completeness guard dies."""
assert dockerfiles(), "`git ls-files` reported no Dockerfile — the derivation is broken, not the repo."