fix(778): round 4 — the guard was checking a stale base, which is the defect it enforces against
PR Gates / decisions lifecycle (pull_request) Successful in 19s
Build ErsatzTV Image / Delimiter ban (release path) (pull_request) Successful in 26s
PR Gates / Docs update reminder (pull_request) Successful in 23s
PR Gates / Fix proofs (Proves trailers) (pull_request) Successful in 21s
review-verdict/h10 Awaiting review verdict for f1e9cce
PR Gates / CI image pin matches docker/ci (pull_request) Successful in 15s
Review verdict / Set review-verdict status (pull_request_target) Successful in 36s
PR Gates / Script tests (pytest) (pull_request) Successful in 4m44s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 9m27s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 6m48s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Skipped
Build ErsatzTV Image / Functional E2E (curl + UI contracts) (pull_request) Successful in 6m34s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 7s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 6s
PR Gates / decisions lifecycle (pull_request) Successful in 19s
Build ErsatzTV Image / Delimiter ban (release path) (pull_request) Successful in 26s
PR Gates / Docs update reminder (pull_request) Successful in 23s
PR Gates / Fix proofs (Proves trailers) (pull_request) Successful in 21s
review-verdict/h10 Awaiting review verdict for f1e9cce
PR Gates / CI image pin matches docker/ci (pull_request) Successful in 15s
Review verdict / Set review-verdict status (pull_request_target) Successful in 36s
PR Gates / Script tests (pytest) (pull_request) Successful in 4m44s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 9m27s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 6m48s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Skipped
Build ErsatzTV Image / Functional E2E (curl + UI contracts) (pull_request) Successful in 6m34s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 7s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 6s
Fifth cold review: no Blockers, no Highs. 1 Medium, 1 Low, both fixed here. It also confirmed the #803 deferral is sound and re-verified every count (59 files, 69 rows, 3 PINNED; guards 34/5/15, proofs 8/6/20). MEDIUM — and it is the one worth the round. The branch-protection lookup used `$base_ref` from the PR snapshot taken at the TOP of the hook, and everything between is round trips (the file enumeration alone can be forty pages). A PERSISTENT retarget in that gap needs no ABA and no force-push: the lookup names the OLD base, confirms `review-verdict/h10` on a branch the PR no longer targets, and grants a scheduled merge onto one that may require nothing. The guard written to enforce "checking a stale identifier is not checking" was doing exactly that. The base is now re-read and compared immediately before the lookup; a move denies and names both branches. Mutation-proven. LOW — my caveat erred in the rare direction, understating a clause instead of overstating it. The scalar-row test's docstring called the whole `.statuses` member validation defence-in-depth because the #632 block masks it. That block validates `.context` and `.description` but NOT `.status`, so an object row with a numeric status passes it and does reach the new validator — where without the clause it becomes `vstate=7` and is reported as "the verdict is '7'" rather than as an unreadable payload. The caveat is now scoped to the payload rather than the clause, and the reachable case has its own test, also mutation-proven. The inventory row now conditions the guarantee on BOTH of its preconditions — the PR still targeting that base (fixed here) and the protection still standing (cannot be closed here, and said so). refs #778 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -356,6 +356,25 @@ else
|
||||
# present -> proceed, ABSENT -> deny. Absence is not a degraded read; it is #622's hole reopened,
|
||||
# and the whole point of that issue is that the failure is silent from the merge caller's side.
|
||||
[ -n "$base_ref" ] || decide ask "H6/H10 merge gate: could not resolve PR #$pr's base branch, so the 'review-verdict/h10' required-check protection that makes a scheduled auto-merge safe (ersatztv#622) can't be confirmed. Verify branch protection on the base, or merge immediately instead of scheduling."
|
||||
# RE-READ THE BASE FIRST — this guard had the very defect it exists to enforce (found in the fifth
|
||||
# cold-review round). `$base_ref` comes from the PR snapshot taken at the top of this hook, and
|
||||
# everything between then and here is round trips: the file enumeration alone can be forty pages.
|
||||
# A PERSISTENT retarget in that gap needs no ABA and no force-push: the protection lookup would
|
||||
# name the OLD base, confirm `review-verdict/h10` on a branch the PR no longer targets, and grant a
|
||||
# scheduled merge onto one that may require nothing. Checking a stale identifier is not checking.
|
||||
# So the identifier is refreshed and compared before it is used, which is this record's own
|
||||
# read-compare-refuse rule applied to the read that implements it.
|
||||
prjson_bp=$(gq "repos/$owner/$repo/pulls/$pr")
|
||||
if [ -z "${prjson_bp//[[:space:]]/}" ] || ! printf '%s' "$prjson_bp" | jq -e 'type == "object"' >/dev/null 2>&1; then
|
||||
decide ask "H6/H10 merge gate: could not re-read PR #$pr to confirm it still targets '$base_ref' before checking that branch's protection. Confirm the target branch and its 'review-verdict/h10' required check manually, or merge immediately instead of scheduling."
|
||||
fi
|
||||
base_now_bp=$(printf '%s' "$prjson_bp" | jq -r '.base.ref // ""' 2>/dev/null || true)
|
||||
if [ -z "$base_now_bp" ]; then
|
||||
decide ask "H6/H10 merge gate: re-read PR #$pr but it reported no base branch, so it is unproven that it still targets '$base_ref'. Confirm the target and its required checks before scheduling an auto-merge."
|
||||
fi
|
||||
if [ "$base_now_bp" != "$base_ref" ]; then
|
||||
decide deny "H6/H10 merge gate: BLOCKED — PR #$pr was retargeted from '$base_ref' to '$base_now_bp' while this gate was evaluating. Every check above was formed against '$base_ref', including the review verdict, so none of them describe the merge that would now happen (ersatztv#632). Re-review against '$base_now_bp' and run: scripts/post-review-verdict.sh $pr MERGEABLE"
|
||||
fi
|
||||
# 404 MUST be separated from every other failure, and `gq` cannot do it: it wraps `curl -sf`,
|
||||
# which turns any HTTP error into exit 22 and empty output, so "no branch protection exists at
|
||||
# all" is indistinguishable from "Gitea is down" through that helper. Those are opposite answers.
|
||||
|
||||
@@ -86,6 +86,9 @@ if "/branch_protections/" in url:
|
||||
# string is substring search, so the naive membership test answers "yes" here.
|
||||
respond('{"enable_status_check": true,'
|
||||
' "status_check_contexts": "prefix-review-verdict/h10-suffix"}')
|
||||
if mode == "NONSTRING-STATUS-ROW":
|
||||
respond('{"enable_status_check": true,'
|
||||
' "status_check_contexts": ["review-verdict/h10"]}')
|
||||
if mode == "STRING-ENABLE":
|
||||
respond('{"enable_status_check": "true",'
|
||||
' "status_check_contexts": ["review-verdict/h10"]}')
|
||||
@@ -127,9 +130,19 @@ if "/status" in url:
|
||||
# A 2xx body whose `.statuses` IS an array but whose members are scalars. `.statuses | type ==
|
||||
# "array"` passes; indexing a number then makes jq exit 5 and, under `set -e`, kills the hook
|
||||
# with no JSON at all.
|
||||
if (state / "bp").read_text().strip() == "SCALAR-STATUS-ROW":
|
||||
_m = (state / "bp").read_text().strip()
|
||||
if _m == "SCALAR-STATUS-ROW":
|
||||
print('{"state":"success","statuses":[1]}')
|
||||
sys.exit(0)
|
||||
if _m == "NONSTRING-STATUS-ROW":
|
||||
# Object shape, string context, valid description — passes the #632 block, which does NOT
|
||||
# validate `.status` — but a NUMERIC status. This is the shape that actually reaches the
|
||||
# scheduled branch's validator, i.e. the new clause's reachable contribution.
|
||||
print(json.dumps({"state": "success", "statuses": [
|
||||
{"context": "review-verdict/h10", "status": 7,
|
||||
"description": "Review-verdict: MERGEABLE @ %s (base: main)"
|
||||
% os.environ["STUB_SHORT"]}]}))
|
||||
sys.exit(0)
|
||||
print(json.dumps({"state": "success", "statuses": [
|
||||
{"context": "review-verdict/h10", "status": "success",
|
||||
"description": "Review-verdict: MERGEABLE @ %s (base: main)" % os.environ["STUB_SHORT"]}]}))
|
||||
@@ -144,8 +157,17 @@ if "/issues/" in url:
|
||||
sys.exit(0)
|
||||
|
||||
if "/pulls/" in url:
|
||||
# The base is served per-GET so a PERSISTENT retarget mid-run can be modelled: the first read
|
||||
# (top of the hook) sees `main`, a later one sees whatever `retarget` names.
|
||||
counter = state / "pr_get_count"
|
||||
n = int(counter.read_text()) if counter.exists() else 0
|
||||
counter.write_text(str(n + 1))
|
||||
base = "main"
|
||||
rt = state / "retarget"
|
||||
if rt.exists() and n >= 1:
|
||||
base = rt.read_text().strip()
|
||||
print(json.dumps({"head": {"sha": os.environ["STUB_SHA"]},
|
||||
"base": {"ref": "main", "sha": "b" * 40},
|
||||
"base": {"ref": base, "sha": "b" * 40},
|
||||
"body": "fixes #1"}))
|
||||
sys.exit(0)
|
||||
|
||||
@@ -174,6 +196,10 @@ def hook(tmp_path):
|
||||
def set_branch_protection(self, mode):
|
||||
(state / "bp").write_text(mode)
|
||||
|
||||
def set_retarget(self, ref):
|
||||
"""Persistent retarget: every PR read after the first reports `ref`."""
|
||||
(state / "retarget").write_text(ref)
|
||||
|
||||
def branch_protection_was_fetched(self):
|
||||
return (state / "bp_called").exists()
|
||||
|
||||
@@ -378,11 +404,16 @@ def test_a_SCALAR_status_row_asks_instead_of_killing_the_hook(hook):
|
||||
|
||||
WHAT THIS TEST DOES *NOT* PROVE, stated because the mutation showed it. Restoring the
|
||||
scheduled-branch validation to its predecessor leaves this test GREEN, because the #632
|
||||
base-retarget block runs FIRST and already validates every member it consumes — so it catches
|
||||
this payload and asks before the scheduled branch is ever reached. The two guards overlap, which
|
||||
is the masking shape `duplicate guards mask each other` describes, and it means the member
|
||||
validation added to the scheduled branch is DEFENCE IN DEPTH against a reordering or a removal
|
||||
of the earlier block, not a fix for a reachable live defect.
|
||||
base-retarget block runs FIRST and validates the members it consumes — so it catches THIS
|
||||
payload and asks before the scheduled branch is reached. The two guards overlap, which is the
|
||||
masking shape `duplicate guards mask each other` describes.
|
||||
|
||||
The caveat is scoped to this payload, NOT to the clause. The earlier block validates `.context`
|
||||
and `.description` but not `.status`, so an object row with a numeric status passes it and does
|
||||
reach the new validator — `test_a_NON_STRING_status_reaches_the_scheduled_validator` covers that
|
||||
and goes red when the clause is removed. So the clause is masked for scalar rows and load-bearing
|
||||
for that one. An earlier draft called the whole clause defence-in-depth, understating it in the
|
||||
opposite direction from this repo's usual error.
|
||||
|
||||
So this asserts the OBSERVABLE contract — a decision is always emitted for this payload — which
|
||||
is true and worth pinning whichever guard supplies it. It is deliberately not offered as a
|
||||
@@ -394,3 +425,37 @@ def test_a_SCALAR_status_row_asks_instead_of_killing_the_hook(hook):
|
||||
"the hook emitted no decision at all for a malformed statuses payload — it neither granted, "
|
||||
"denied nor asked")
|
||||
assert decision["hookSpecificOutput"]["permissionDecision"] == "ask"
|
||||
|
||||
|
||||
def test_a_PERSISTENT_retarget_after_the_first_read_denies(hook):
|
||||
"""The defect this guard had itself, found in the fifth cold-review round.
|
||||
|
||||
`$base_ref` is captured from the PR snapshot at the top of the hook, and everything between
|
||||
then and the branch-protection lookup is round trips — the file enumeration alone can be forty
|
||||
pages. A retarget in that gap needs no ABA and no force-push: the lookup would name the OLD
|
||||
base, confirm `review-verdict/h10` on a branch the PR no longer targets, and grant a scheduled
|
||||
merge onto one that may require nothing. Checking a stale identifier is not checking, which is
|
||||
the whole of `process.check-and-use-pins-a-version` — so the guard enforcing that rule had to
|
||||
stop breaking it.
|
||||
"""
|
||||
hook.set_retarget("scratch")
|
||||
reason = hook.reason()
|
||||
assert "deny" in reason, (
|
||||
"the PR was retargeted mid-evaluation and the gate still granted on the original base")
|
||||
assert "scratch" in reason and "main" in reason, (
|
||||
"the deny must name both branches; a reader cannot act on 'the base changed'")
|
||||
|
||||
|
||||
def test_a_NON_STRING_status_reaches_the_scheduled_validator(hook):
|
||||
"""The reachable contribution of the scheduled-branch member validation, which the previous
|
||||
caveat understated.
|
||||
|
||||
The #632 block validates `.context` and `.description` but NOT `.status`, so an object row with
|
||||
a numeric status passes it and arrives here. Without this clause it becomes `vstate=7` and falls
|
||||
to the catch-all deny arm — fail-closed, but reported as "the verdict is '7'" rather than as a
|
||||
payload that could not be read. So the clause is masked for scalar rows and load-bearing for
|
||||
this one; the caveat on the scalar test is scoped accordingly.
|
||||
"""
|
||||
hook.set_branch_protection("NONSTRING-STATUS-ROW")
|
||||
reason = hook.reason()
|
||||
assert "ask" in reason, "a non-string .status produced a verdict-shaped decision"
|
||||
|
||||
Reference in New Issue
Block a user