fix(632): bind a review verdict to its BASE branch, not only to its head sha
#622 made `review-verdict/h10` a per-sha required status, so a new commit cannot inherit an old verdict — the required context is simply absent on the new head. Retargeting a PR's base reaches the same end from the opposite direction: the head sha and the status both hold still while the merge-base, and therefore the effective diff the verdict was formed against, changes underneath them. #622's record claimed the invariant holds "by construction"; this was the documented exception, and an unrecorded exception is how a guarantee degrades into a habit. `post-review-verdict.sh` now records the base branch in the status description as a trailing `(base: <ref>)`, and refuses to write a status at all if the base moved between reading the PR and posting — the same TOCTOU window the head check already covers, which the head check cannot see because retargeting does not move the head. `pretooluse-merge-consent.sh` reads the field back and denies when it no longer matches the PR's live `base.ref`. Two choices are load-bearing, and each is pinned by a test rather than left to a comment: - The comparator is `base.ref`, NOT `base.sha`. `base.sha` tracks the base branch's tip, which moves whenever anything merges to `main` — comparing it would invalidate every open verdict on every unrelated merge, converting a rare-event guard into a permanent merge deadlock. A base that merely advances is out of scope by design: rebasing onto it moves the head sha, which the per-sha binding already covers. - The field goes in the status DESCRIPTION, not the verdict comment. The comment body is parsed by `scripts/check-review-verdict.sh`, whose grammar had three false-opens in its history (#629); nothing parses the description, so this adds a field without reopening that surface. Scope is stated honestly rather than overclaimed: this is DETECTION on the hook path only. A commit status carries no base of its own, so the server-side required check cannot see a retarget, and a merge driven through the Gitea UI or API is unaffected. That is the accepted exposure — base changes are rare, manual, and this is a two-account repo — but it now fails loud in the one place that evaluates consent, instead of living only in a doc. Verdicts posted before this change carry no `(base: …)` and get NO opinion rather than a deny; denying 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. Verified by mutation, six mutants, each killed by its intended test: remove the hook's deny; compare base.sha instead of base.ref; drop graceful adoption; stop recording the base; drop the TOCTOU guard; accept a PR with no resolvable base. The positive controls matter more than usual here — the test PR is deliberately non-docs (a docs-only PR short-circuits the whole gate and would never reach the base check) and the rest of the gate is unstubbed, so "the hook denied" alone proves nothing. Refs #632 Decisions-Edit: yes
This commit is contained in:
@@ -785,6 +785,14 @@ hook's condition (c)) and the `review-verdict/h10` status on the same sha. `BLOC
|
||||
a commit landed mid-flight it writes **no** status and exits non-zero rather than retargeting your
|
||||
verdict at a commit you never read.
|
||||
|
||||
The status description also records the base branch — `Review-verdict: MERGEABLE @ abc1234 (base:
|
||||
main)` — and the merge-consent hook denies when that no longer matches the PR's live `base.ref`
|
||||
(ersatztv#632). Retargeting a PR changes the effective diff without moving the head sha, so the
|
||||
per-sha binding alone cannot see it. This is **detection on the hook path only**: a commit status
|
||||
carries no base of its own, so a merge driven through the Gitea UI or API is unaffected. The
|
||||
comparator is the base *branch*, never its tip sha — a base that merely advances is ordinary churn,
|
||||
and comparing tips would invalidate every open verdict on every unrelated merge to `main`.
|
||||
|
||||
**Exemptions** are handled by `review-verdict.yml` on every `pull_request` event, which posts the
|
||||
status as `success` for **Renovate-authored** PRs (it uses `platformAutomerge: true`, so a required
|
||||
verdict with no exemption would stall every dependency bump) and for **docs-only** PRs, and as
|
||||
|
||||
@@ -142,8 +142,27 @@ described as one:
|
||||
`GET /commits/{sha}/status`, which returns latest-per-context, and the workflow refuses to post
|
||||
anything at all when that read fails or is unparseable, rather than treating it as "no verdict yet".
|
||||
3. **Changing a PR's base does not change its head sha**, so a verdict status keeps applying to a diff
|
||||
that has materially changed. Not currently handled; low exposure here because base changes are rare
|
||||
and manual.
|
||||
that has materially changed. **Detected, not prevented** (#632): `post-review-verdict.sh` records
|
||||
the base branch in the status description as a trailing `(base: <ref>)`, and the merge-consent hook
|
||||
reads it back and denies when it no longer matches the PR's live `base.ref`. That covers the hook
|
||||
path only — a commit status carries no base of its own, so the server-side required check cannot
|
||||
see this, and a merge driven through the Gitea UI or API is unaffected. Accepted: base changes are
|
||||
rare, manual, and this is a two-account repo.
|
||||
|
||||
Two details are load-bearing and each was chosen against a plausible alternative:
|
||||
|
||||
- **The comparator is `base.ref`, not `base.sha`.** `base.sha` tracks the base branch's *tip*,
|
||||
which moves whenever anything merges to `main`; comparing it would invalidate every open verdict
|
||||
on every unrelated merge — a rare-event guard turned into a permanent merge deadlock. A base
|
||||
branch that merely *advances* is deliberately out of scope: rebasing onto it moves the head sha,
|
||||
which the per-sha binding already covers.
|
||||
- **The field goes in the status description, not the verdict comment.** The comment body is parsed
|
||||
by `scripts/check-review-verdict.sh`, whose grammar had three false-opens in its history (#629);
|
||||
nothing parses the description, so this adds a field without reopening that surface.
|
||||
|
||||
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.
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user