fix(751): a stray expression delimiter in a COMMENT killed the verdict gate

`review-verdict.yml`'s classify step stopped executing on 2026-08-03 and the job
reported `success` anyway, so `review-verdict/h10` — the branch-protection-required
status — was posted by nothing but a human hand for three days, and both exemption
classes (Renovate-manifest, docs-only) silently stopped working.

The cause is one token in prose. The #706 note explaining why a concurrency group
does not work here quoted a `concurrency:` snippet containing a PR-number expression
as an ILLUSTRATION, inside a shell comment. A shell comment is not inert there: the
runner scans the whole `run:` scalar for the expression opener before bash sees it,
and one occurrence makes it rewrite the ENTIRE body into a single `format(...)` call.
That rewrite is all-or-nothing, so a payload that does not parse — `pr number` does
not — fails the interpolation of the whole scalar, and the runner then DROPS THE STEP
AND CONCLUDES THE JOB GREEN. The prose documenting a fix disabled the fix.

`git blame`/`git log -S` put the line in 8f6d4f443 (2026-08-03), which dates the
outage precisely rather than "present in run 1832, not bisected further back".

Three changes, deliberately different in kind:

* The prose no longer writes the delimiters. It names the expression instead.
* The classifier writes a start marker and a new `if: always()` step FAILS THE JOB
  when it is missing. This is the half that generalises: the delimiter was one bug in
  one comment, but a dropped step concluding `success` is what made it cost three
  days behind a green tick. It asserts execution STARTED, never completed — the
  classifier has several legitimate `exit 0` abstention paths.
* Two static guards in scripts/tests/test_pr_changed_files.py: no expression
  delimiter in ANY `run:` body of the gate file (absolute, because a dropped step
  here is a dead merge gate and its bodies are ~700 lines of prose), and repo-wide,
  every expression payload must name a real context or function (permissive, because
  other workflows interpolate into `run:` legitimately). The second catches the class
  — a payload that cannot evaluate, wherever it appears.

Note every pre-existing workflow-shape test reads `_code_lines()`, which strips
comments. That is correct for what it was for, but it encodes the assumption this bug
falsifies: inside a `run:` scalar a comment CAN change behaviour. The new strict test
reads the raw scalar for that reason and must never adopt `_code_lines`.

Blast radius, audited: PR #739 (docs-only) merged 2026-08-05 with ZERO commit
statuses on its head, and got in only because admin force-merge was still enabled.
#743 disabled that on 2026-08-06, so the workaround that absorbed this bug is gone —
the next docs-only or Renovate-manifest PR would be permanently stuck. The two
Renovate PRs in the window escaped by timing, merging minutes before the bad commit.
Non-exempt PRs were unaffected throughout: humans posted their verdicts by hand.

Verification: all six mutations red, restored tree green — reintroducing the exact
defect (strict + general tests), deleting the guard step, deleting only the marker
write, weakening `if: always()`, turning the guard's `exit 1` into `exit 0`, and
putting a delimiter in the guard's own body. 129 passed on the fixed tree.

Still to establish, and NOT claimed here: that the runner executes a LATER step after
dropping an earlier one. The #751 evidence cannot say — the classifier was the job's
last step, so there was never a subsequent step to observe. A scratch-base probe with
a negative control answers it next; if the runner drops the rest of the steps too,
this guard is inert and the body has to move into `scripts/`.

Refs #751

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-10 19:22:50 +02:00
co-authored by Claude Opus 5
parent 9881d1ff81
commit 2bdb6c44e4
2 changed files with 275 additions and 2 deletions
+201
View File
@@ -2117,3 +2117,204 @@ def test_a_SENTINEL_landing_above_the_mark_also_triggers_the_repair(tmp_path):
assert seq[1]["state"] == "pending"
assert seq[1]["description"] == "Human verdict raced this exemption write — re-post the verdict", (
f"repaired, but not to the sentinel, so the fixed point is broken: {seq[1]}")
# --- The expression-delimiter class (ersatztv#751) ----------------------------------------------
#
# WHAT HAPPENED, because the shape of it is what these tests are written against. A `run:` body is
# not shell yet when the runner reads it. The runner scans the whole scalar for the expression
# opener, and a single occurrence makes it rewrite the ENTIRE body into one `format(...)` call so
# the evaluated result can be spliced back in. That rewrite is all-or-nothing, so a payload that
# does not parse takes the whole step with it — and the runner then DROPS THE STEP AND CONCLUDES THE
# JOB `success`.
#
# The occurrence that did it was in a SHELL COMMENT: the #706 note explaining why a concurrency
# group does not work quoted a `concurrency:` snippet containing a PR-number expression as an
# illustration. `pr number` is not an expression. The step stopped running on 2026-08-03 and nothing
# went red until 2026-08-06.
#
# WHY EVERY EXISTING GUARD IN THIS FILE WAS BLIND TO IT, which is the part worth keeping: they all
# read `_code_lines()`, which strips comment lines. That choice is correct for what it was for — its
# own docstring explains that prose legitimately discusses `pulls/N/files`, and a raw scan would
# redden the repo over a piece of writing. But it encodes an assumption this bug falsifies: that a
# comment in a workflow cannot change behaviour. Inside a `run:` scalar it can. So the test below
# reads the RAW text, deliberately, and is the one test here that must never adopt `_code_lines`.
_EXPR = re.compile(r"\$\{\{(.*?)\}\}", re.S)
# Roots of a dotted context path, and the callable functions. Both lists are what the runner
# actually accepts; anything outside them cannot evaluate, and an expression that cannot evaluate
# does not fail loudly — it silently removes the step it appears in.
_EXPR_CONTEXTS = frozenset({
"github", "env", "vars", "secrets", "inputs", "runner", "steps", "needs", "matrix", "job",
"jobs", "strategy",
})
_EXPR_FUNCTIONS = frozenset({
"always", "success", "failure", "cancelled", "hashFiles", "format", "toJSON", "toJson",
"fromJSON", "fromJson", "contains", "startsWith", "endsWith", "join",
})
_EXPR_LITERALS = frozenset({"true", "false", "null"})
def _workflow_files():
# `*.y*ml` for the reason test_no_OTHER_workflow_writes_the_review_verdict_status gives: a
# workflow added as `.yaml` is just as executable and would otherwise go unscanned.
return sorted((REPO_ROOT / ".gitea" / "workflows").glob("*.y*ml"))
def test_the_verdict_workflow_has_NO_expression_delimiter_in_any_run_body():
"""The absolute rule, and it is scoped to this one file on purpose.
Other workflows legitimately interpolate into a `run:` body (7 occurrences across
docker-build/ci-image/pr-checks today), so a repo-wide ban would be false and would be deleted
the first time it got in someone's way. This file is different in two ways that justify the
strict rule: it writes the branch-protection-required status, so a dropped step here is a dead
merge gate rather than a failed build; and its `run:` bodies are ~700 lines of dense prose,
which is the only place the delimiter has ever appeared by accident.
The rule is also what keeps the dropped-step guard trustworthy. A guard that the guarded
mechanism can silently delete is worse than no guard, because its absence is silent too.
RAW TEXT, never `_code_lines` — see the block comment above. A comment is not inert here.
"""
raw = WORKFLOW.read_text()
offenders = []
for job_name, step in _iter_workflow_steps(WORKFLOW):
for m in _EXPR.finditer(step.get("run") or ""):
offenders.append(f"{job_name}/{step.get('name', '?')}: {m.group(1).strip()!r}")
assert not offenders, (
f"review-verdict.yml has an expression delimiter inside a run: body — {offenders}. Even in "
"a comment this is unsafe: the runner rewrites the WHOLE body into a format(...) call, and "
"if the payload does not parse it drops the step and reports the job GREEN, leaving the "
"required review-verdict/h10 unposted (ersatztv#751). To describe an expression in prose, "
"name it (`a github.event.pull_request.number expression`) instead of quoting the "
"delimiters. Pass values in through the step's `env:` block, which is interpolated per "
"value, so a bad payload there cannot take the body with it."
)
# Belt-and-braces on the parse above: a `run:` body the YAML walk failed to reach would make
# this test vacuously green, which is the failure mode `eight ways a test passes for the wrong
# reason` warns about. The gate file's expressions all live in `with:`/`env:` blocks, so the raw
# count and the per-field count must agree exactly.
in_fields = sum(1 for _ in _EXPR.finditer(_workflow_expression_fields_text(WORKFLOW)))
assert len(list(_EXPR.finditer(raw))) == in_fields, (
"review-verdict.yml contains expression delimiters that are not in a `with:`/`env:` value. "
"The per-step scan above may not have reached them, so it cannot be trusted — locate them "
"before relying on a green here")
def _iter_workflow_steps(path: Path):
import yaml
doc = yaml.safe_load(path.read_text()) or {}
for job_name, job in (doc.get("jobs") or {}).items():
for step in (job.get("steps") or []):
yield job_name, step
def _workflow_expression_fields_text(path: Path) -> str:
"""Every `with:`/`env:` VALUE in the file, concatenated — the places an expression belongs."""
chunks = []
import yaml
doc = yaml.safe_load(path.read_text()) or {}
for job in (doc.get("jobs") or {}).values():
for holder in (job, *(job.get("steps") or [])):
for key in ("env", "with"):
for v in (holder.get(key) or {}).values():
chunks.append(str(v))
return "\n".join(chunks)
def test_every_workflow_expression_names_a_REAL_context_or_function():
"""The general form of #751, across every workflow and every field.
The strict test above hardens the gate file. It cannot see the class, which is not "prose in a
run body" but "a payload that does not evaluate" — a typo in an `if:`, a renamed output, a
context that does not exist. All of them fail the same silent way, and in an `if:` the
consequence is the same shape as #751: the step does not run and nothing is red.
A full expression parser is not needed to catch it. Every payload the runner accepts begins its
dotted paths at a known context and calls only known functions, so checking the head token of
each path is enough. `pr number` — the real defect — fails here on `pr`. Verified against all
31 distinct payloads in this repo today, which pass.
"""
offenders = []
for wf in _workflow_files():
for m in _EXPR.finditer(wf.read_text()):
payload = m.group(1).strip()
# Strip string literals first: a path inside `hashFiles('web/package-lock.json')` is
# data, not an identifier, and would otherwise read as an unknown context.
bare = re.sub(r"'[^']*'", "''", payload)
for ident in re.finditer(r"(?<![.\w'])([A-Za-z_][A-Za-z0-9_-]*)", bare):
name = ident.group(1)
if name in _EXPR_CONTEXTS or name in _EXPR_FUNCTIONS or name in _EXPR_LITERALS:
continue
offenders.append(f"{wf.name}: {payload!r} -> unknown '{name}'")
assert not offenders, (
"these workflow expressions name something the runner cannot resolve, so they will fail to "
f"interpolate — which DROPS THE STEP and still reports the job green (ersatztv#751): "
f"{offenders}. If this is prose describing an expression, do not write the delimiters; if "
"it is a real new context or function, add it to _EXPR_CONTEXTS / _EXPR_FUNCTIONS here."
)
def test_a_dropped_classify_step_FAILS_the_job_instead_of_going_green():
"""The silent-green half of #751 — the actual defect, and the only part that generalises.
The stray delimiter was one bug in one comment. What made it cost three days of a dead merge
gate was the REPORTING: a dropped step concludes `success`, the workflow's own status context
goes green, and the required `review-verdict/h10` is merely ABSENT — which on a normal PR is
indistinguishable from the correct "not reviewed yet" state. Nothing surfaced it. So the
classifier writes a start marker and a later `if: always()` step fails the job when it is
missing.
Asserted structurally, and the marker PATH is compared across the two steps rather than
hardcoded here twice: the failure mode of a divergent path is a job that reddens on every run
(fail-closed, but it would look like this guard is broken rather than like a real drop), and a
test carrying its own third copy of the literal could not see the divergence at all.
What this test does NOT establish, said plainly: that the runner still executes a LATER step
after dropping an earlier one. Nothing in the #751 evidence answers that — the classifier was
the last step in the job, so there was never a subsequent step to observe. Only the scratch-base
probe can answer it, with a negative control that reintroduces a bad payload and must produce a
RED job. If the runner drops the remaining steps too, this guard is inert and the body has to
move into `scripts/`, where a one-line `run:` makes the class unreachable.
"""
# ONE parse, and both steps located inside it. Using `_classify_step()` here instead was wrong
# in a way worth recording, because it went green-adjacent rather than loud: that helper does its
# own `yaml.safe_load`, so the dict it returns is never the same OBJECT as the equivalent step in
# this list. An `is not` filter against it therefore excluded nothing, the classify step matched
# as its own guard, and the assertions below ran against the wrong step.
steps = [s for _, s in _iter_workflow_steps(WORKFLOW)]
classifiers = [i for i, s in enumerate(steps) if "review-verdict/h10" in (s.get("run") or "")]
assert classifiers, "no step in review-verdict.yml posts review-verdict/h10"
classify = steps[classifiers[0]]
marker_writes = re.findall(r'(\w+)="\$\{RUNNER_TEMP[^"]*/([\w.-]+)"', classify["run"])
assert marker_writes, (
"the classify step no longer assigns a start-marker path under RUNNER_TEMP, so a step the "
"runner drops goes green again (ersatztv#751)")
var, marker_name = marker_writes[0]
assert re.search(rf':\s*>\s*"\${var}"', classify["run"]), (
f"the classify step defines {var} but never creates the marker, so the guard below will "
"fail on every run and read as broken rather than as a real dropped step")
guard_idx = [i for i, s in enumerate(steps)
if i != classifiers[0] and marker_name in (s.get("run") or "")]
assert guard_idx, (
f"no step checks for the {marker_name!r} start marker. Without it a dropped classify step "
"concludes success and the merge gate is silently dead (ersatztv#751)")
# AFTER the classifier, not merely present. A guard placed before it would read a marker that
# has not been written yet and fail on every run — fail-closed, but it would deadlock `main` and
# read as this guard being broken, which is how a correct-looking guard gets deleted.
assert guard_idx[0] > classifiers[0], (
f"the dropped-step guard is step {guard_idx[0]} but the classifier is step "
f"{classifiers[0]} — a guard that runs first always fails")
guard = steps[guard_idx[0]]
assert str(guard.get("if", "")).strip() == "always()", (
f"the dropped-step guard's `if:` is {guard.get('if')!r}; it must be `always()`, or it will "
"be skipped on exactly the runs where the classifier failed")
assert re.search(r"exit\s+1", guard["run"]), (
"the dropped-step guard never exits non-zero, so it observes the failure and still lets the "
"job go green — which is the whole defect")
assert not _EXPR.search(guard["run"]), (
"the dropped-step guard's own run body contains an expression delimiter, so the mechanism "
"it guards against can drop the guard too — and that absence would be silent as well")