From d51255a8ef0b168c6a993fe7e680f7c4e4864956 Mon Sep 17 00:00:00 2001 From: Timothy Date: Sun, 26 Jul 2026 23:27:22 +0200 Subject: [PATCH] fix(632): "could not check" is a third outcome, not a quiet synonym for "nothing to check" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cold review's substantive finding. The first draft collapsed an unreadable status response into the graceful-adoption path: `vdesc` came back empty, so `recorded_base` was empty, so the comparison was skipped IN SILENCE — and a later, successful status read could then auto-grant, emitting "merge gate: satisfied" for a comparison that never happened. A transient Gitea hiccup is not evidence that the base is unchanged. The unreadable status response and a PR with no resolvable `.base.ref` now both fall through to a human `ask`, leaving exactly one benign silent case: a verdict that predates #632 and could not have carried the field. The emptiness check is done in SHELL before jq sees it, same jq-1.6 rule as the rest of this file. Also from review: the graceful-adoption test asserted only that the decision lacked the issue tag, so it would have passed for a base-specific ask or deny whose wording omitted it — the failure mode most likely to appear when someone edits these messages. It now asserts on the word "base". Recorded rather than fixed, because fixing it would be worse: docs-only PRs exit before this check, since that carve-out short-circuits the gate earlier. It does not auto-grant — it passes through to an ordinary permission prompt — so the exposure is a missing warning on a merge a human is already confirming, not a silent merge. The record now says so instead of implying the deny is unconditional. Mutation-verified: collapsing the unreadable case back into graceful adoption, skipping the check on a missing live base, and dropping the mismatch deny each redden their own test and nothing else. Refs #632 --- .claude/hooks/pretooluse-merge-consent.sh | 26 ++++++++-- .../records/release/verdict-status-check.md | 11 ++++- .../tests/test_merge_consent_base_change.py | 49 ++++++++++++++++--- 3 files changed, 73 insertions(+), 13 deletions(-) diff --git a/.claude/hooks/pretooluse-merge-consent.sh b/.claude/hooks/pretooluse-merge-consent.sh index b2851a664..251da314a 100755 --- a/.claude/hooks/pretooluse-merge-consent.sh +++ b/.claude/hooks/pretooluse-merge-consent.sh @@ -136,12 +136,30 @@ fi # posted before ersatztv#632 and gets NO opinion, rather than denying every in-flight PR the day # this lands. The window closes on its own — verdicts are per-head and short-lived, so every verdict # posted after this carries the field. +# "Could not check" is a THIRD outcome, distinct from both "matches" and "no base recorded". Cold +# review found the first draft collapsing it into the latter: an unreadable status response yielded +# an empty `recorded_base`, which took the graceful-adoption path and skipped validation silently — +# after which a later, successful status read could still auto-grant. A transient failure would then +# have produced a "merge gate: satisfied" message for a comparison that never happened. Every +# unreadable input here therefore falls through to a human (`ask`), never to silence. live_base=$(printf '%s' "$prjson" | jq -r '.base.ref // ""' 2>/dev/null || true) -if [ -n "$sha" ] && [ -n "$live_base" ]; then - vdesc=$(gq "repos/$owner/$repo/commits/$sha/status?limit=100" \ - | jq -r '[.statuses[]? | select(.context == "review-verdict/h10")] | first | .description // ""' \ +if [ -z "$live_base" ]; then + decide ask "H10 merge gate: PR #$pr reports no base branch (.base.ref), so the verdict cannot be checked against the branch it was formed for (ersatztv#632). Confirm the PR still targets the branch it was reviewed against before merging." +fi +if [ -n "$sha" ]; then + vjson_base=$(gq "repos/$owner/$repo/commits/$sha/status?limit=100") + # Same jq-1.6 rule as everywhere else in this file: check emptiness in SHELL first, never via + # `jq -e`'s exit status over empty input. + if [ -z "${vjson_base//[[:space:]]/}" ] || ! printf '%s' "$vjson_base" | jq -e '.statuses | type == "array"' >/dev/null 2>&1; then + decide ask "H10 merge gate: could not read the commit statuses for PR #$pr head ${sha:0:7}, so the verdict could not be checked against the PR's base branch (ersatztv#632). Confirm the review covered the branch this PR currently targets ('$live_base') before merging." + fi + vdesc=$(printf '%s' "$vjson_base" \ + | jq -r '[.statuses[] | select(.context == "review-verdict/h10")] | first | .description // ""' \ 2>/dev/null || true) - # The field is written by scripts/post-review-verdict.sh as a trailing `(base: )`. + # The field is written by scripts/post-review-verdict.sh as a trailing `(base: )`. Its + # ABSENCE is the one benign case: a verdict posted before ersatztv#632 could not have carried it, + # and denying those would block every in-flight PR the day this lands. The window closes on its + # own, since verdicts are per-head and short-lived. recorded_base=$(printf '%s' "$vdesc" | sed -n 's/.*(base: \(.*\))$/\1/p') if [ -n "$recorded_base" ] && [ "$recorded_base" != "$live_base" ]; then decide deny "H10 merge gate: BLOCKED — the review verdict on head ${sha:0:7} was formed while PR #$pr targeted '$recorded_base', but it now targets '$live_base'. Retargeting a base does not move the head sha, so the per-sha verdict status still reads green even though the effective diff has changed (ersatztv#632). Re-review against the new base and run: scripts/post-review-verdict.sh $pr MERGEABLE" diff --git a/docs/decisions/records/release/verdict-status-check.md b/docs/decisions/records/release/verdict-status-check.md index 83ed38a27..9175d1f3b 100644 --- a/docs/decisions/records/release/verdict-status-check.md +++ b/docs/decisions/records/release/verdict-status-check.md @@ -162,7 +162,16 @@ described as one: Verdicts posted before #632 carry no `(base: …)` and get **no opinion** rather than a deny — the alternative would block every in-flight PR the day it lands, and the window closes on its own since - verdicts are per-head and short-lived. + verdicts are per-head and short-lived. **"Could not check" is a third outcome**, deliberately not + folded into that one: an unreadable status response or a PR with no resolvable `.base.ref` falls + through to a human `ask`. The first draft collapsed them, so a transient Gitea hiccup skipped the + comparison in silence and a later successful read could still emit "merge gate: satisfied" for a + check that never ran. + + **Docs-only PRs exit before this check**, because the docs-only carve-out short-circuits the whole + gate earlier in the hook. That carve-out does not auto-grant — it passes through to an ordinary + permission prompt — so the exposure is a missing warning on a merge a human is already confirming, + not a silent merge. Worth knowing before reading "the hook denies on a retarget" as unconditional. 4. **A PR that edits `review-verdict.yml` is judged by its own edited copy.** Gitea runs `pull_request` workflows from the PR **head**, not the base — confirmed on the very PR that introduced this workflow (#630): `review-verdict.yml` does not exist on `main`, yet its job ran diff --git a/scripts/tests/test_merge_consent_base_change.py b/scripts/tests/test_merge_consent_base_change.py index 8e4b294ce..5018599b2 100644 --- a/scripts/tests/test_merge_consent_base_change.py +++ b/scripts/tests/test_merge_consent_base_change.py @@ -51,17 +51,21 @@ if "/pulls/" in url and "/files" in url: if "/status" in url: desc = (state / "verdict_desc").read_text() + if desc == "TRANSPORT-ERROR": + sys.exit(22) + if desc == "GARBAGE": + print('{"message":"internal error"}'); sys.exit(0) rows = [] if desc == "NONE" else [ {"context": "review-verdict/h10", "status": "success", "description": desc}] print(json.dumps({"state": "success", "statuses": rows})) sys.exit(0) if "/pulls/" in url: - print(json.dumps({ - "head": {"sha": os.environ["STUB_SHA"]}, - "base": {"ref": (state / "live_base").read_text().strip()}, - "body": "fixes #1", - })) + body = {"head": {"sha": os.environ["STUB_SHA"]}, "body": "fixes #1"} + live = (state / "live_base").read_text().strip() + if live != "MISSING": + body["base"] = {"ref": live} + print(json.dumps(body)) sys.exit(0) print("{}") @@ -132,11 +136,40 @@ def test_positive_control_an_unchanged_base_does_not_trigger_the_base_deny(hook) def test_a_verdict_with_no_recorded_base_gets_no_opinion(hook, desc): """Graceful adoption. Denying here would block every in-flight PR the day this lands, and the window closes on its own: verdicts are per-head and short-lived, so every verdict posted after - #632 carries the field.""" + #632 carries the field. + + Asserting on the word "base" rather than on the issue tag, per cold review: the tag-only check + would have passed for a base-specific ask or deny whose wording happened to omit it, which is + the failure mode most likely to appear when someone edits these messages. + """ hook.set_live_base("release/26.4") hook.set_verdict_description(desc) - assert "ersatztv#632" not in hook.reason(), ( - "a pre-#632 verdict was denied for a field it could not have carried") + assert "base" not in hook.reason(), ( + "a pre-#632 verdict drew a base-related decision for a field it could not have carried") + + +@pytest.mark.parametrize("failure", ["TRANSPORT-ERROR", "GARBAGE"]) +def test_an_UNREADABLE_status_response_asks_rather_than_skipping_the_check(hook, failure): + """"Could not check" is a third outcome, not a quiet synonym for "no base recorded". + + The first draft collapsed the two: an unreadable status response produced an empty + `recorded_base`, took the graceful-adoption path, and skipped validation in silence — after + which a later successful status read could still auto-grant, emitting "merge gate: satisfied" + for a comparison that never happened. A transient Gitea hiccup is not evidence that the base is + unchanged. + """ + hook.set_live_base("release/26.4") + hook.set_verdict_description(failure) + reason = hook.reason() + assert "ask" in reason, "an unreadable status response silently skipped the base check" + assert "base" in reason, "the ask must name what could not be checked" + + +def test_a_pr_with_no_resolvable_base_asks(hook): + """A null/absent `.base.ref` is also 'could not check', not 'nothing to check'.""" + hook.set_live_base("MISSING") + reason = hook.reason() + assert "ask" in reason and "base" in reason def test_the_comparator_is_the_base_REF_not_its_tip_sha():