fix(629): review fixes — tilde fences, an unbounded sha field, and a forgeable comment boundary

Cross-family review of 38a96f47 returned BLOCKED with three findings. All reproduced first:

  ~~~ fence           -> positive   fences were stripped for ``` only; markdown also takes ~~~
  @ <40hex>f / ZZZ    -> positive   the sha matched {7,40} with NO right boundary, so an
                                    over-long or malformed token was TRUNCATED into a passing one
  \x01BODY-BOUNDARY\x01 -> positive an in-band separator joined comment bodies, so a body
                                    containing that line forged a boundary, reset fence state
                                    mid-comment, and exposed a verdict inside an unclosed fence

Fixes: both fence markers honoured; the hex run matched whole, required to end at a
non-alphanumeric boundary, with its length validated separately so an out-of-range token is
rejected rather than trimmed to fit; and bodies carried OUT-OF-BAND (one JSON-encoded string
per line), which removes the forgery class instead of escaping the sentinel.

The third is the one worth remembering: an in-band delimiter is forgeable by whoever writes the
data, and here that is anyone who can comment on the PR.

Two of these fixes broke previously-green tests, both of which were right to break:
- an over-long token now classifies `no-sha`, not `stale`. The fixture asserting `stale` was 45
  hex chars, so it had been exercising the length guard while claiming to test the prefix rule.
  Rebuilt as a well-formed 40-char sha that contains the head prefix without starting with it.
- `jq -e` exits 4 when a filter produces NO output, which is the legitimate empty-comment-list
  case. Treating it as an error turned "no comments yet" into an input error — and callers fail
  closed on those, so a new PR would have read as unclassifiable. Exit 4 is now accepted.

44 classifier tests, 155 total. `~~~` and the boundary fixes are each mutation-verified; the
out-of-band fix has no equivalent mutation (it is structural, not a regex) so its evidence is the
direct reproduction against the previous commit.

refs #629

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

Decisions-Edit: yes
This commit is contained in:
2026-07-26 00:17:17 +02:00
co-authored by Claude Opus 5
parent 38a96f47cc
commit 8d0df55398
3 changed files with 116 additions and 17 deletions
@@ -45,11 +45,31 @@ lived inline in the hook with no tests, and each of these graded as a positive v
from the verdict's **own** `@ <sha>` field, the one immediately following the token, which also
makes multi-`@` lines unambiguous.
A cross-family review of that first fix found **three more**, all reproduced before fixing — worth
recording because each is the same fix done half-way:
- fences were stripped for ` ``` ` only, but markdown also accepts **`~~~`**;
- the sha field matched `{7,40}` with **no right boundary**, so an over-long or malformed token was
silently *truncated* into a passing one: `@ <40-hex-head>f` and `@ <40-hex-head>ZZZ` both graded as
a verdict for head. The hex run is now matched whole, must end at a non-alphanumeric boundary, and
its length is validated separately — an out-of-range token is rejected, never trimmed to fit;
- comment bodies were joined with a literal `\x01BODY-BOUNDARY\x01` line so fence state could reset
per comment. **An in-band delimiter is forgeable by whoever writes the data** — and here that is
anyone who can comment on the PR: a body containing that line reset the fence mid-comment and
exposed a verdict still inside an unclosed fence. Bodies are now carried out-of-band (one
JSON-encoded string per line), which removes the class rather than escaping the sentinel.
The lesson is about where a grammar lives, not about any one regex: this record described the intended
behaviour accurately, the code did something looser, and nothing compared them. The grammar now lives
in `scripts/check-review-verdict.sh` — one implementation, called by the hook and by
`post-review-verdict.sh`'s cross-check, covered by `scripts/tests/test_check_review_verdict.py`.
Two of those fixes also broke previously-green tests, which is the useful part: an over-long token
became `no-sha` where a fixture expected `stale` (the fixture was 45 hex chars, so it had been
testing the length guard while claiming to test the prefix rule), and `jq -e` exits **4** on no
output, so an empty comment list started reading as a malformed payload — turning "no comments yet"
into an input error on a gate whose callers fail closed.
The classifications:
- a MERGEABLE/APPROVED/LGTM verdict whose `@ <sha>` is the current head → **allow**;
- a **negative** verdict (BLOCKED/NOT-MERGEABLE) *on the head* → **deny**, and it *wins over* a positive