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:
@@ -66,12 +66,20 @@ def respond(body, code="200"):
|
||||
sys.stdout.write(code)
|
||||
sys.exit(0)
|
||||
|
||||
if url.rstrip("/").endswith("/branch_protections"):
|
||||
# The hook reads ONLY this endpoint now — the by-name lookup was deleted because it performs no
|
||||
# matching and knows nothing about rule precedence, so a 200 from it proved less than it looked.
|
||||
# RECORD BEFORE FILTERING. This recorder used to live inside the `endswith` branch below, which
|
||||
# made the "no ref reaches the URL" assertion unfalsifiable: the only URLs it could record were ones
|
||||
# that already satisfied it, so a by-name request was invisible to the very test written to forbid
|
||||
# it. Cold review reintroduced a by-name lookup in the hook and the suite stayed 33/33 green. That is
|
||||
# the filter-on-the-asserted-property defect this PR's sibling record is about, committed inside the
|
||||
# guard against it — so the recorder now sees EVERY branch-protection URL, whatever its shape.
|
||||
if "/branch_protections" in url:
|
||||
(state / "bp_called").write_text("yes")
|
||||
with (state / "bp_urls").open("a") as fh:
|
||||
fh.write(url + "\n")
|
||||
|
||||
if url.rstrip("/").endswith("/branch_protections"):
|
||||
# The hook reads ONLY this endpoint now — the by-name lookup was deleted because it performs no
|
||||
# matching and knows nothing about rule precedence, so a 200 from it proved less than it looked.
|
||||
mode = (state / "bp").read_text().strip()
|
||||
|
||||
if mode == "TRANSPORT-ERROR":
|
||||
@@ -258,9 +266,6 @@ def hook(tmp_path):
|
||||
"""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()
|
||||
|
||||
def branch_protection_urls(self):
|
||||
f = state / "bp_urls"
|
||||
return f.read_text().splitlines() if f.exists() else []
|
||||
@@ -315,7 +320,7 @@ def test_positive_control_a_guarded_base_REACHES_the_check_and_still_auto_grants
|
||||
`allow`, and the reason is the satisfied-gate message rather than any refusal.
|
||||
"""
|
||||
decision = hook.decision()
|
||||
assert hook.branch_protection_was_fetched(), (
|
||||
assert hook.branch_protection_urls(), (
|
||||
"the guarded case never reached the branch-protection endpoint, so the other tests are not "
|
||||
"exercising the code they claim to")
|
||||
assert decision is not None, "the hook passed through instead of auto-granting"
|
||||
@@ -393,8 +398,7 @@ def test_a_base_with_NO_branch_protection_at_all_denies_rather_than_asking(hook)
|
||||
404 — "this branch is entirely unprotected", i.e. `review-verdict/h10` is definitively not
|
||||
required — was indistinguishable from "Gitea is down". Those are opposite answers, and routing
|
||||
the first to a human prompt makes the single most likely real-world trigger (branch protection
|
||||
removed) read like a transient hiccup. Verified against the live instance 2026-08-16: an
|
||||
unprotected branch returns 404.
|
||||
removed) read like a transient hiccup.
|
||||
"""
|
||||
hook.set_branch_protection("NOT-FOUND")
|
||||
reason = hook.reason()
|
||||
@@ -543,9 +547,9 @@ def test_a_NON_STRING_status_reaches_the_scheduled_validator(hook):
|
||||
|
||||
|
||||
def test_a_base_that_a_GLOB_rule_could_govern_ASKS(hook):
|
||||
"""Gitea keys the by-name endpoint on the RULE name, so a base covered by a glob rule 404s on
|
||||
its own name while being fully protected. Reading that 404 as "unprotected" produced a hard DENY
|
||||
with a specific, false cause.
|
||||
"""A base covered only by a glob rule has no rule bearing its own name, and the deleted by-name
|
||||
endpoint answered 404 for exactly that — read as "unprotected", producing a hard DENY with a
|
||||
specific, false cause.
|
||||
|
||||
But the opposite error is worse: deciding the glob DOES match would auto-grant on a base whose
|
||||
protection was never established. This hook does not reimplement Gitea's glob dialect (its `*`
|
||||
@@ -559,17 +563,17 @@ def test_a_base_that_a_GLOB_rule_could_govern_ASKS(hook):
|
||||
assert "could govern it" in reason, (
|
||||
"the ask came from the generic could-not-read arm, not the undecidable-glob arm — those "
|
||||
"are different outcomes and a crashed classifier must not pass as a correct classification")
|
||||
assert "NO branch protection" not in reason, (
|
||||
assert "none matches" not in reason, (
|
||||
"a base a glob rule could govern was reported as having no protection at all")
|
||||
|
||||
|
||||
def test_an_unreadable_LIST_asks_rather_than_denying_on_the_404(hook):
|
||||
"""The 404 fallback must not convert 'could not confirm' into 'confirmed absent'. If the by-name
|
||||
lookup 404s and the list cannot be read, nothing has been established either way."""
|
||||
def test_an_unreadable_rule_LIST_asks_rather_than_denying(hook):
|
||||
"""A read failure must not convert 'could not confirm' into 'confirmed absent'. Absence is
|
||||
established only by the classifier returning `nomatch` over a list that WAS read."""
|
||||
hook.set_branch_protection("LIST-UNREADABLE")
|
||||
reason = hook.reason()
|
||||
assert "ask" in reason, "an unreadable rule list was treated as proof of absence"
|
||||
assert "NO branch protection" not in reason
|
||||
assert "none matches" not in reason
|
||||
|
||||
|
||||
def test_the_protection_lookup_puts_NO_ref_in_the_url(hook):
|
||||
@@ -618,7 +622,7 @@ def test_a_GLOB_rule_whose_literal_part_has_a_metacharacter_still_MATCHES(hook):
|
||||
Escaping is only half the property: `*` must still span. The first version emitted TWO
|
||||
backslashes (`\\.` = "a literal backslash, then any character"), which made every rule
|
||||
containing a metacharacter UNMATCHABLE — so the fallback found nothing and hard-denied with the
|
||||
stated cause "has NO branch protection at all", a false-open converted into a false DENY.
|
||||
stated cause that no rule can govern the base — a false-open converted into a false DENY.
|
||||
|
||||
A negative-only assertion cannot see that: a rule matched literally and a rule made unmatchable
|
||||
both fail to match the wrong base. Only a rule that SHOULD match distinguishes them. Here the rule
|
||||
@@ -634,7 +638,7 @@ def test_a_GLOB_rule_whose_literal_part_has_a_metacharacter_still_MATCHES(hook):
|
||||
"and must ask")
|
||||
assert "could govern it" in reason, (
|
||||
"the ask must come from the undecidable-glob arm, not from the classifier failing")
|
||||
assert "NO branch protection" not in reason, (
|
||||
assert "none matches" not in reason, (
|
||||
"a base a glob rule could govern was reported as entirely unprotected — the over-escaping "
|
||||
"failure this test exists to catch")
|
||||
|
||||
@@ -649,7 +653,7 @@ def test_a_rule_name_containing_a_CHAR_CLASS_bracket_does_not_crash_the_matcher(
|
||||
assert "ask" not in reason, (
|
||||
"the exact-name rule was decidable and must have been honoured; an ask here means the "
|
||||
"classifier failed rather than classified")
|
||||
assert "NO branch protection" not in reason, (
|
||||
assert "none matches" not in reason, (
|
||||
"one rule with a bracket in its name discarded the whole list, including the exact-name "
|
||||
"rule that actually protects this base")
|
||||
assert "deny" not in reason, (
|
||||
@@ -665,7 +669,7 @@ def test_a_plain_rule_name_is_matched_CASE_INSENSITIVELY(hook):
|
||||
assert "ask" not in reason, (
|
||||
"the case-folded exact rule was decidable and must have been honoured; an ask means the "
|
||||
"classifier failed rather than classified")
|
||||
assert "NO branch protection" not in reason, (
|
||||
assert "none matches" not in reason, (
|
||||
"a rule named 'MAIN' governs base 'main' in Gitea but was missed by a case-sensitive compare")
|
||||
assert "deny" not in reason
|
||||
|
||||
@@ -687,7 +691,7 @@ def test_a_BACKSLASH_ESCAPED_metacharacter_in_a_rule_name_is_undecidable_not_abs
|
||||
hook.drop_recorded_base()
|
||||
hook.set_branch_protection("ESCAPED-META-RULE")
|
||||
reason = hook.reason()
|
||||
assert "NO branch protection" not in reason, (
|
||||
assert "none matches" not in reason, (
|
||||
"a rule whose escaped brace governs this base was reported as unable to govern it")
|
||||
assert "ask" in reason, (
|
||||
"an escaped-metacharacter rule is undecidable here and must ask")
|
||||
@@ -758,12 +762,12 @@ def test_two_rules_differing_only_in_CASE_are_undecidable(hook):
|
||||
def test_a_NON_ASCII_rule_or_base_is_undecidable_rather_than_fold_compared(hook):
|
||||
"""`ascii_downcase` is not Gitea's Unicode-aware `EqualFold`, so a rule `ünstable` and a base
|
||||
`Ünstable` fold equal there and not here. The miss lands on `none`, which DENIES with the stated
|
||||
cause "no branch protection at all" — and the backslash arm already rejects "nearly unreachable"
|
||||
cause "none matches" — and the backslash arm already rejects "nearly unreachable"
|
||||
as a standard for the arm that issues a deny, so the same standard applies here."""
|
||||
hook.set_base("\u00dcnstable")
|
||||
hook.drop_recorded_base()
|
||||
hook.set_branch_protection("NONASCII-RULE")
|
||||
reason = hook.reason()
|
||||
assert "NO branch protection" not in reason, (
|
||||
assert "none matches" not in reason, (
|
||||
"a rule that folds equal to this base under EqualFold was reported as unable to govern it")
|
||||
assert "ask" in reason
|
||||
|
||||
Reference in New Issue
Block a user