fix(778): make the by-name pin falsifiable — it was filtering on the property it asserted

Confirmation pass returned BLOCKED, and its lead finding is the one worth having.

The test forbidding the by-name lookup recorded URLs from INSIDE the
`endswith("/branch_protections")` branch, so the only URLs it could ever record were
ones that already satisfied the assertion. A by-name request was invisible to the very
test written to forbid it. Cold review proved it by reintroducing the lookup in the
hook: the suite stayed 33/33 green. That is the filter-on-the-asserted-property defect
this PR's sibling record exists to describe, committed inside the guard against it —
and the commit message had called the twin "pinned so it cannot come back".

The recorder now sees every branch-protection URL whatever its shape. Re-verified by
the same mutation: reintroducing a by-name call reddens exactly the two tests that
forbid it.

Also from that pass:
- an HTTP 404 on the LIST read reached the "the full rule list was read and none
  matches" deny — a claim about a read that never happened. Gitea answers 404 for a
  repo that is absent or invisible to the credential, so the classifier's own verdict
  is now the sentinel `nomatch` and HTTP failures reach the ask;
- two comment blocks still described the deleted by-name endpoint as live, one of them
  asserting the classifier "is never reached at all";
- the decision record still documented `branch_protections/{base}` and its 404
  semantics as the mechanism, in the record this PR authored — now rewritten to the
  list endpoint, with why reading the LIST is the load-bearing choice;
- seven assertions on a string the hook no longer emits, and three test
  names/docstrings describing the removed 404 flow;
- an unused fixture helper, and 79 lines left over-indented by the removed nesting.

724 tests green.

refs #778

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-19 21:29:09 +02:00
co-authored by Claude Opus 5
parent f3863c3720
commit 7d81f85b38
3 changed files with 136 additions and 123 deletions
@@ -54,15 +54,25 @@ and block the merge."* Switch that context off and every word of that sentence b
the hook keeps printing it and keeps auto-granting.
So the class has a second face: not only "the state moved between the check and the action", but
"the thing that made the action safe was never observed at all". The hook now reads `GET
/repos/{owner}/{repo}/branch_protections/{base}` on that path and treats the result as three
outcomes, not two — present proceeds, unreadable **asks** (a transient failure or a credential
without repo-admin scope is not evidence of safety), absent **denies**. Denying on absence is the
point: that is #622's hole reopened, and its defining property is that it is silent from the merge
caller's side. The 404 is separated from every other failure deliberately, because "this branch
has no protection at all" is the strongest form of the finding while a 403 says only that we could
not look — and `curl -sf`, which the hook's generic helper wraps, collapses both into an empty
string.
"the thing that made the action safe was never observed at all". The hook now reads the repo's FULL
rule list, `GET /repos/{owner}/{repo}/branch_protections`, and classifies it — present proceeds,
unreadable **asks** (a transient failure, or a credential without the repo-admin scope that endpoint
needs, is not evidence of safety), nothing-can-govern **denies**, and anything it cannot decide
**asks**. Denying on absence is the point: that is #622's hole reopened, and its defining property
is that it is silent from the merge caller's side.
**Reading the LIST rather than the rule named after the base is the load-bearing choice**, and the
first version got it wrong in the way this record is about. `GET …/branch_protections/{name}` is an
exact database lookup that performs no matching and knows nothing about precedence, so a 200 from it
establishes only that a rule with that NAME lists the context — never that the context is required
ON that branch. Gitea resolves the governing rule by Priority first and plain-name-ness second, so a
glob rule can outrank an exactly-named one. Using the by-name endpoint first and the list only on a
404 therefore guarded the 404 path while the 200 path — the one that actually fires, since the rule
IS named `main` — granted without the check at all: hardened code that was dead, beside live code
that was not. It was fixed by DELETING the by-name path, not by documenting the gap, so there is one
fetch, one classifier and one argument to keep true. Absence is now established by the classifier
over a list that WAS read, never by an HTTP status, because a 404 from the list endpoint means the
repo was not found rather than that the branch is unprotected.
**And that check is a preflight, not a pin — say so, because the temptation is to bank it.** The
first draft of the inventory graded that path `PINNED`; cold review pointed out that the hook's