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:
@@ -393,16 +393,10 @@ else
|
||||
# there. It is deliberately NOT re-read a second time here: two reads would create a window
|
||||
# between them for no gain, and the hoisted check already covers the enumeration gap that made
|
||||
# this necessary.
|
||||
# 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.
|
||||
# A 404 on this endpoint is the STRONGEST possible form of the thing being checked — the base is
|
||||
# entirely unprotected, so `review-verdict/h10` is definitively not required and a scheduled
|
||||
# auto-merge is exactly #622's hole — while a 403 or a timeout says only that we could not look.
|
||||
# Verified against this Gitea (2026-08-16): an unprotected branch returns 404 with a JSON body.
|
||||
# Collapsing the two, which the first version of this guard did, sends the single most likely
|
||||
# real-world trigger ("branch protection was removed") to a human prompt that reads like a
|
||||
# transient hiccup.
|
||||
# A read failure here is NOT evidence about the branch. The deleted by-name endpoint answered 404
|
||||
# for "no rule with this name", which was a finding; the LIST endpoint's 404 means the repo was not
|
||||
# found or is invisible to this credential, which is a read failure. Absence is now established by
|
||||
# the classifier returning `nomatch` over a list that WAS read, never by an HTTP status.
|
||||
# ALWAYS enumerate the rule LIST; never look a rule up by name. The by-name endpoint
|
||||
# (`branch_protections/{name}`) is an exact DB lookup — `GetProtectedBranchRuleByName` — which
|
||||
# performs no matching and knows nothing about precedence, so a 200 from it means only "a rule
|
||||
@@ -425,91 +419,96 @@ else
|
||||
bp_list=$(cat "$bp_file" 2>/dev/null || true)
|
||||
bp=""
|
||||
if [ "$bp_code" = "200" ] && printf '%s' "$bp_list" | jq -e 'type == "array"' >/dev/null 2>&1; then
|
||||
# DO NOT claim parity with Gitea's matcher — this code cannot have it, and asserting it would
|
||||
# be the exact defect this PR records (a mitigation outside the code, asserted rather than
|
||||
# verified). Gitea compiles a rule name with gobwas/glob and a `/` separator, so its `*` does
|
||||
# NOT cross a slash, `?`/`[…]`/`{a,b}` are wildcards, and a plain name is folded case-
|
||||
# insensitively. Reimplementing that here would be a second copy of somebody else's parser.
|
||||
#
|
||||
# So the classification is deliberately THREE-way, and each arm is safe without knowing the
|
||||
# dialect:
|
||||
# exact — no glob rule could apply, AND some rule name has no glob metacharacter and
|
||||
# equals the base case-insensitively. Only then is a single rule decidable.
|
||||
#
|
||||
# UNDECIDABLE IS EVALUATED FIRST, and the order is the point. Gitea picks the
|
||||
# governing rule with `GetFirstMatched` over a list sorted by Priority, THEN
|
||||
# by plain-name-ness — so a glob rule with a better Priority outranks an
|
||||
# exactly-named one. Preferring `exact` would therefore inspect a rule Gitea
|
||||
# might not be applying: if the exact rule requires `review-verdict/h10` and a
|
||||
# higher-priority glob rule does not, the gate auto-grants on a base where the
|
||||
# check is not enforced. Asking whenever ANY glob rule could apply is sound
|
||||
# without knowing the precedence rules at all, which is the only claim this
|
||||
# code is entitled to make about somebody else's resolver.
|
||||
#
|
||||
# Case folding is ASCII-only here, while Gitea's `EqualFold` is
|
||||
# Unicode-aware — so a rule `ünstable` and a base `Ünstable` fold equal there
|
||||
# and not here. ASCII-fold equality implies EqualFold equality, so the gap can
|
||||
# only MISS a match, never invent one; but a miss lands on `none`, which
|
||||
# DENIES with the stated cause "no branch protection at all". The backslash
|
||||
# paragraph below rejects "nearly unreachable" as a standard for that arm, and
|
||||
# the same standard has to apply here, so a rule name carrying any non-ASCII
|
||||
# byte is `undecidable` rather than fold-compared. Two fold-equal plain names
|
||||
# are undecidable too: this code picks by list order while Gitea picks by
|
||||
# Priority, and guessing which one is enforced is the defect the arm order
|
||||
# above exists to avoid.
|
||||
# undecidable — some glob rule COULD govern this base. Tested with a provable SUPERSET of any
|
||||
# glob dialect: literal prefix before the first metacharacter, `.*`, literal
|
||||
# suffix after the last. If even that does not match, no dialect can, because
|
||||
# every dialect requires the literal head and tail to match literally.
|
||||
#
|
||||
# BACKSLASH counts as a metacharacter for that purpose, and it is the one case that breaks the
|
||||
# superset proof if it does not. gobwas/glob reads `\{` as a LITERAL brace, so a rule `a\{b`
|
||||
# governs the base `a{b` — while a superset that treated `\` as literal would build `a\.*b`,
|
||||
# fail to match, and answer `none`, i.e. deny a base that IS protected. Git ref rules make this
|
||||
# nearly unreachable (a branch name may not contain `*`, `?`, `[` or `\`, though it MAY contain
|
||||
# `{`), but `none` is the arm that authorises a DENY on the stated grounds "nothing can govern
|
||||
# this base", so its premise has to hold unconditionally rather than usually.
|
||||
# none — nothing can possibly govern the base, so it is genuinely unprotected.
|
||||
#
|
||||
# `undecidable` asks rather than granting or denying. Over-matching would auto-grant on a base
|
||||
# whose protection we never established (#622's hole, reached through the block written to
|
||||
# close it); under-matching would deny with a stated cause that is false, which this block's
|
||||
# own comment calls the worse outcome. Asking is the only answer that is honest in both
|
||||
# directions, and it is rare in practice: as of 2026-08-19 this repo's only rule is the plain
|
||||
# name `main`, so the by-name lookup returns 200 and this classifier is never reached at all.
|
||||
# That is a dated observation about mutable remote config, not a property to rely on.
|
||||
bp_verdict=$(printf '%s' "$bp_list" | jq --arg b "$base_ref" -c '
|
||||
def esc: gsub("(?<c>[.+?^${}()|\\[\\]\\\\])"; "\\" + .c);
|
||||
def offs: [match("[*?\\[\\]{}\\\\]"; "g").offset];
|
||||
def superset: . as $n | (offs) as $o
|
||||
| ($n[0:$o[0]] | esc) + ".*" + ($n[($o[-1]+1):] | esc);
|
||||
def nonascii: explode | any(. > 127);
|
||||
. as $rules | $b as $base |
|
||||
($rules | map(select((.branch_name // .rule_name // "") as $n
|
||||
| (($n|offs|length) == 0)
|
||||
and (($n|ascii_downcase) == ($base|ascii_downcase))))) as $exacts |
|
||||
(($base|nonascii) or ($rules | any((.branch_name // .rule_name // "") as $n
|
||||
| ($n|offs|length) == 0 and ($n|nonascii)))) as $unfoldable |
|
||||
if ($rules | any((.branch_name // .rule_name // "") as $n
|
||||
| (($n|offs|length) > 0)
|
||||
and ($base | test("^" + ($n|superset) + "$")))) then {verdict:"undecidable"}
|
||||
elif $unfoldable then {verdict:"undecidable"}
|
||||
elif ($exacts | length) > 1 then {verdict:"undecidable"}
|
||||
elif ($exacts | length) == 1 then {verdict:"exact", rule:($exacts | first)}
|
||||
else {verdict:"none"} end' 2>/dev/null || true)
|
||||
case $(printf '%s' "$bp_verdict" | jq -r '.verdict // ""' 2>/dev/null || true) in
|
||||
exact) bp=$(printf '%s' "$bp_verdict" | jq -c '.rule' 2>/dev/null || true); bp_code=200 ;;
|
||||
undecidable) rm -f "$bp_file"
|
||||
decide ask "H6/H10 merge gate: no branch-protection rule on this repo governs '$base_ref' decidably — a GLOB rule could govern it, or two rule names fold-equal, or a name is non-ASCII. This hook deliberately does not reimplement Gitea's glob matcher, so whether 'review-verdict/h10' is required on this base cannot be derived here (ersatztv#778). Confirm it in the repo's branch-protection settings, or merge immediately instead of scheduling." ;;
|
||||
none) bp_code=404; bp="" ;;
|
||||
*) bp_code=000; bp="" ;;
|
||||
esac
|
||||
# DO NOT claim parity with Gitea's matcher — this code cannot have it, and asserting it would
|
||||
# be the exact defect this PR records (a mitigation outside the code, asserted rather than
|
||||
# verified). Gitea compiles a rule name with gobwas/glob and a `/` separator, so its `*` does
|
||||
# NOT cross a slash, `?`/`[…]`/`{a,b}` are wildcards, and a plain name is folded case-
|
||||
# insensitively. Reimplementing that here would be a second copy of somebody else's parser.
|
||||
#
|
||||
# So the classification is deliberately THREE-way, and each arm is safe without knowing the
|
||||
# dialect:
|
||||
# exact — no glob rule could apply, AND some rule name has no glob metacharacter and
|
||||
# equals the base case-insensitively. Only then is a single rule decidable.
|
||||
#
|
||||
# UNDECIDABLE IS EVALUATED FIRST, and the order is the point. Gitea picks the
|
||||
# governing rule with `GetFirstMatched` over a list sorted by Priority, THEN
|
||||
# by plain-name-ness — so a glob rule with a better Priority outranks an
|
||||
# exactly-named one. Preferring `exact` would therefore inspect a rule Gitea
|
||||
# might not be applying: if the exact rule requires `review-verdict/h10` and a
|
||||
# higher-priority glob rule does not, the gate auto-grants on a base where the
|
||||
# check is not enforced. Asking whenever ANY glob rule could apply is sound
|
||||
# without knowing the precedence rules at all, which is the only claim this
|
||||
# code is entitled to make about somebody else's resolver.
|
||||
#
|
||||
# Case folding is ASCII-only here, while Gitea's `EqualFold` is
|
||||
# Unicode-aware — so a rule `ünstable` and a base `Ünstable` fold equal there
|
||||
# and not here. ASCII-fold equality implies EqualFold equality, so the gap can
|
||||
# only MISS a match, never invent one; but a miss lands on `none`, which
|
||||
# DENIES with the stated cause "no branch protection at all". The backslash
|
||||
# paragraph below rejects "nearly unreachable" as a standard for that arm, and
|
||||
# the same standard has to apply here, so a rule name carrying any non-ASCII
|
||||
# byte is `undecidable` rather than fold-compared. Two fold-equal plain names
|
||||
# are undecidable too: this code picks by list order while Gitea picks by
|
||||
# Priority, and guessing which one is enforced is the defect the arm order
|
||||
# above exists to avoid.
|
||||
# undecidable — some glob rule COULD govern this base. Tested with a provable SUPERSET of any
|
||||
# glob dialect: literal prefix before the first metacharacter, `.*`, literal
|
||||
# suffix after the last. If even that does not match, no dialect can, because
|
||||
# every dialect requires the literal head and tail to match literally.
|
||||
#
|
||||
# BACKSLASH counts as a metacharacter for that purpose, and it is the one case that breaks the
|
||||
# superset proof if it does not. gobwas/glob reads `\{` as a LITERAL brace, so a rule `a\{b`
|
||||
# governs the base `a{b` — while a superset that treated `\` as literal would build `a\.*b`,
|
||||
# fail to match, and answer `none`, i.e. deny a base that IS protected. Git ref rules make this
|
||||
# nearly unreachable (a branch name may not contain `*`, `?`, `[` or `\`, though it MAY contain
|
||||
# `{`), but `none` is the arm that authorises a DENY on the stated grounds "nothing can govern
|
||||
# this base", so its premise has to hold unconditionally rather than usually.
|
||||
# none — nothing can possibly govern the base, so it is genuinely unprotected.
|
||||
#
|
||||
# `undecidable` asks rather than granting or denying. Over-matching would auto-grant on a base
|
||||
# whose protection we never established (#622's hole, reached through the block written to
|
||||
# close it); under-matching would deny with a stated cause that is false, which this block's
|
||||
# own comment calls the worse outcome. Asking is the only answer that is honest in both
|
||||
# directions, and it is rare in practice: as of 2026-08-19 this repo's only rule is the plain
|
||||
# name `main`, which the classifier resolves to `exact` on every run. That is a dated
|
||||
# observation about mutable remote config, not a property to rely on.
|
||||
bp_verdict=$(printf '%s' "$bp_list" | jq --arg b "$base_ref" -c '
|
||||
def esc: gsub("(?<c>[.+?^${}()|\\[\\]\\\\])"; "\\" + .c);
|
||||
def offs: [match("[*?\\[\\]{}\\\\]"; "g").offset];
|
||||
def superset: . as $n | (offs) as $o
|
||||
| ($n[0:$o[0]] | esc) + ".*" + ($n[($o[-1]+1):] | esc);
|
||||
def nonascii: explode | any(. > 127);
|
||||
. as $rules | $b as $base |
|
||||
($rules | map(select((.branch_name // .rule_name // "") as $n
|
||||
| (($n|offs|length) == 0)
|
||||
and (($n|ascii_downcase) == ($base|ascii_downcase))))) as $exacts |
|
||||
(($base|nonascii) or ($rules | any((.branch_name // .rule_name // "") as $n
|
||||
| ($n|offs|length) == 0 and ($n|nonascii)))) as $unfoldable |
|
||||
if ($rules | any((.branch_name // .rule_name // "") as $n
|
||||
| (($n|offs|length) > 0)
|
||||
and ($base | test("^" + ($n|superset) + "$")))) then {verdict:"undecidable"}
|
||||
elif $unfoldable then {verdict:"undecidable"}
|
||||
elif ($exacts | length) > 1 then {verdict:"undecidable"}
|
||||
elif ($exacts | length) == 1 then {verdict:"exact", rule:($exacts | first)}
|
||||
else {verdict:"none"} end' 2>/dev/null || true)
|
||||
case $(printf '%s' "$bp_verdict" | jq -r '.verdict // ""' 2>/dev/null || true) in
|
||||
exact) bp=$(printf '%s' "$bp_verdict" | jq -c '.rule' 2>/dev/null || true); bp_code=200 ;;
|
||||
undecidable) rm -f "$bp_file"
|
||||
decide ask "H6/H10 merge gate: no branch-protection rule on this repo governs '$base_ref' decidably — a GLOB rule could govern it, or two rule names fold-equal, or a name is non-ASCII. This hook deliberately does not reimplement Gitea's glob matcher, so whether 'review-verdict/h10' is required on this base cannot be derived here (ersatztv#778). Confirm it in the repo's branch-protection settings, or merge immediately instead of scheduling." ;;
|
||||
none) bp_code=nomatch; bp="" ;;
|
||||
*) bp_code=000; bp="" ;;
|
||||
esac
|
||||
else
|
||||
bp_code=${bp_code:-000} # unreadable list -> the ask arm below
|
||||
bp=""
|
||||
fi
|
||||
rm -f "$bp_file"
|
||||
if [ "$bp_code" = "404" ]; then
|
||||
# `nomatch` is the CLASSIFIER's verdict, deliberately not an HTTP code. Reusing 404 for it made
|
||||
# this deny reachable from an HTTP 404 on the list read too — repo not found, or invisible to the
|
||||
# credential, which Gitea also answers 404 — and then the reason claimed "the full rule list was
|
||||
# read and none matches" about a read that never happened. A transport failure must reach the ask
|
||||
# below, not a deny stating a finding.
|
||||
if [ "$bp_code" = "nomatch" ]; then
|
||||
decide deny "H6/H10 merge gate: BLOCKED — no branch-protection rule on this repo can govern '$base_ref' (the full rule list was read and none matches), so 'review-verdict/h10' is not a required check on it. A scheduled auto-merge is safe ONLY because that per-sha required check stops a commit pushed after scheduling from merging unreviewed (ersatztv#622). Restore branch protection on '$base_ref', or merge immediately (without merge_when_checks_succeed) once CI is green."
|
||||
fi
|
||||
if [ "$bp_code" != "200" ] || [ -z "${bp//[[:space:]]/}" ] || ! printf '%s' "$bp" | jq -e 'type == "object"' >/dev/null 2>&1; then
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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