fix(778): stop claiming parity with Gitea's glob matcher — classify, or ask
Build ErsatzTV Image / Delimiter ban (release path) (pull_request) Successful in 27s
PR Gates / Docs update reminder (pull_request) Successful in 29s
PR Gates / Fix proofs (Proves trailers) (pull_request) Successful in 23s
PR Gates / CI image pin matches docker/ci (pull_request) Successful in 15s
PR Gates / decisions lifecycle (pull_request) Successful in 28s
review-verdict/h10 Awaiting review verdict for 456042e
Review verdict / Set review-verdict status (pull_request_target) Successful in 15s
PR Gates / Script tests (pytest) (pull_request) Successful in 4m56s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Canceled after 7m16s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Canceled after 0s
Build ErsatzTV Image / Functional E2E (curl + UI contracts) (pull_request) Canceled after 0s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Canceled after 0s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Canceled after 0s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Canceled after 0s
Build ErsatzTV Image / Delimiter ban (release path) (pull_request) Successful in 27s
PR Gates / Docs update reminder (pull_request) Successful in 29s
PR Gates / Fix proofs (Proves trailers) (pull_request) Successful in 23s
PR Gates / CI image pin matches docker/ci (pull_request) Successful in 15s
PR Gates / decisions lifecycle (pull_request) Successful in 28s
review-verdict/h10 Awaiting review verdict for 456042e
Review verdict / Set review-verdict status (pull_request_target) Successful in 15s
PR Gates / Script tests (pytest) (pull_request) Successful in 4m56s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Canceled after 7m16s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Canceled after 0s
Build ErsatzTV Image / Functional E2E (curl + UI contracts) (pull_request) Canceled after 0s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Canceled after 0s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Canceled after 0s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Canceled after 0s
Eighth cold review: no Blocker, no High. Three Medium, two Low, one Nit.
MEDIUM — the substantive one. The glob fallback asserted it matched rules "the same
way Gitea applies them", and it does not. Gitea compiles a rule name with gobwas/glob
and a `/` separator: its `*` does NOT cross a slash, `?`/`[…]`/`{a,b}` are wildcards,
and a plain name is folded case-insensitively. Mine used `.*` for `*` and escaped the
rest. The divergence has a false-OPEN direction — `release/*` does not govern
`release/26/hotfix` in Gitea, but `release/.*` matched it here, which would auto-grant
a scheduled merge on a base where the check is not required. That is #622's hole,
reached through the block written to close it, via exactly the failure this PR
records: a claim about an external system asserted rather than verified.
Reimplementing somebody else's glob dialect would be a second copy of a parser, which
this repo has already withdrawn a change for. So the classification is three-way and
each arm is safe WITHOUT knowing the dialect: an exact non-glob name folded
case-insensitively is decidable; a glob rule that could govern the base is
UNDECIDABLE and asks; and "could" is tested with a provable superset of any glob
dialect — literal prefix, `.*`, literal suffix — so if even that cannot match, no
dialect can. Over-matching would grant on unestablished protection; under-matching
would deny with a false cause. Asking is the only answer honest in both directions,
and it is rare: this repo's rule is the plain name `main`.
MEDIUM — a count that was wrong the moment it was written ("46 of the 69 rows are
N/A"; it is 44). It was added by the same commit that demoted two rows. That is the
FOURTH stale number in this change, in the deliverable whose own record argues against
hand-maintained counts. Removed rather than corrected, with the reason stated.
MEDIUM — `migration-smoke.sh` still said "Same shape" as `security-scan.sh`, whose
note had just been rewritten to the opposite conclusion, so the backreference had
silently inverted. It is the same pull-then-run over a mutable tag and deserves the
grade MORE, not less: `security-scan.sh` boots a throwaway container and authorizes
nothing, while this gates a production stack recreation. Regraded.
LOW/NIT: an `end <= start` guard that `str.index(…, start)` makes unreachable by
construction is replaced with the reachable failure it was describing; a docstring
still named a fixture from an earlier draft; a reflowed `#707.` was line-initial.
Two mutations were ineffective on the first attempt — one left the `decide ask`
continuation in place, the other had no test covering case-folding. Both redone; each
arm now reddens a named test.
Decisions-Edit: yes
refs #778
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -425,29 +425,47 @@ else
|
||||
bp_code=$(bp_get "branch_protections")
|
||||
bp_list=$(cat "$bp_file" 2>/dev/null || true)
|
||||
if [ "$bp_code" = "200" ] && printf '%s' "$bp_list" | jq -e 'type == "array"' >/dev/null 2>&1; then
|
||||
# Match a rule by exact name or by its glob, the same way Gitea applies them.
|
||||
# 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.
|
||||
#
|
||||
# `*` is the ONLY wildcard: every other regex metacharacter in a rule name is escaped before
|
||||
# the pattern is built. Substituting `*` into a raw regex made a rule named `main.x` match the
|
||||
# base `mainax`, and `a+b` match `aab` — a spurious match to some OTHER rule that happens to
|
||||
# require `review-verdict/h10` would report this base as protected when nothing governs it,
|
||||
# which is a false-open in a consent gate. Escaping is done per literal segment, so the
|
||||
# wildcard survives and nothing else does.
|
||||
# So the classification is deliberately THREE-way, and each arm is safe without knowing the
|
||||
# dialect:
|
||||
# exact — the rule name has no glob metacharacter at all, and equals the base
|
||||
# case-insensitively (matching Gitea's EqualFold). Decidable; inspect the rule.
|
||||
# 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.
|
||||
# none — nothing can possibly govern the base, so it is genuinely unprotected.
|
||||
#
|
||||
# The REPLACEMENT string is `"\\" + .c`, one backslash in jq source, and the first version
|
||||
# wrote two. That is not a near-miss: `\\.` means "a literal backslash then any character",
|
||||
# so every rule containing a metacharacter became UNMATCHABLE and the fallback fell through to
|
||||
# a hard deny stating "no branch protection at all" — turning a false-open into a false
|
||||
# DENY, which this block's own comment calls the worse outcome. A rule name containing `[`
|
||||
# additionally crashed jq outright. Both are covered below, and the tests assert BOTH
|
||||
# directions: a negative-only assertion cannot tell "matched literally" from "made
|
||||
# unmatchable", which is exactly why the first attempt looked green.
|
||||
bp=$(printf '%s' "$bp_list" | jq --arg b "$base_ref" -c 'map(select((.branch_name // .rule_name // "") as $n | (($n | split("*") | map(gsub("(?<c>[.+?^${}()|\\[\\]\\\\])"; "\\" + .c)) | join(".*")) as $re | ($n == $b) or ($b | test("^" + $re + "$"))))) | first // empty' 2>/dev/null || true)
|
||||
if [ -n "${bp//[[:space:]]/}" ]; then
|
||||
bp_code=200 # a rule DOES cover this base; fall through and inspect it
|
||||
else
|
||||
bp_code=404 # the list was readable and nothing matches: truly unprotected
|
||||
fi
|
||||
# `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: the repo's rule today is the plain name `main`.
|
||||
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);
|
||||
. 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)))) | first) as $exact |
|
||||
if $exact then {verdict:"exact", rule:$exact}
|
||||
elif ($rules | any((.branch_name // .rule_name // "") as $n
|
||||
| (($n|offs|length) > 0)
|
||||
and ($base | test("^" + ($n|superset) + "$")))) then {verdict:"undecidable"}
|
||||
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'); bp_code=200 ;;
|
||||
undecidable) rm -f "$bp_file"
|
||||
decide ask "H6/H10 merge gate: '$base_ref' has no branch-protection rule under its own name, but a GLOB rule on this repo could govern it. 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
|
||||
else
|
||||
bp_code=${bp_code:-000} # could not read the list either -> the ask arm below
|
||||
bp=""
|
||||
|
||||
@@ -23,8 +23,8 @@ is wrong; the answer was simply computed about a different world than the one th
|
||||
**The repo had already solved this twice without noticing it was one problem.** #536 was fixed with
|
||||
a compare-exchange claim. The whole `/api/v1` write surface was given RFC 7232 `If-Match` a year
|
||||
earlier. Both are this rule; neither pointed at the other, and the tooling — the third substrate,
|
||||
where the state is somebody else's server — got the fix a third time from scratch at #706 and
|
||||
#707. That is the same one-record-per-instance growth `defect-shapes-773.md` §4 criticises in this
|
||||
where the state is somebody else's server — got the fix a third time from scratch at #706 and #707.
|
||||
That is the same one-record-per-instance growth `defect-shapes-773.md` §4 criticises in this
|
||||
repo's own knowledge base, and it is the reason this record is written at the class level.
|
||||
|
||||
**Binding is the easy half; re-validation is the half that gets skipped.** A sha captured into a
|
||||
|
||||
@@ -101,7 +101,7 @@ classifications differ; otherwise the strictest applies and the Note names the e
|
||||
| `scripts/ci-detect-already-validated.sh` — prior-head combined status | `UNSAFE-KNOWN` | Reads the PR head's status and emits `skip=true`, with nothing re-checking before the consuming job runs. Accepted and narrow: the skip elides only **re-running** test/migrations on a tree already validated; the `build` job still builds and pushes unconditionally, so no image ever ships from unvalidated source. |
|
||||
| `scripts/issue-qualification-audit.sh` — paged issue list, then a report | `UNSAFE-KNOWN` | Pages the open-issue list and reports which issues lack a `priority:` label, so like every paged read here its pages can straddle a change and the report can name a state no single instant held. Graded to match `select-queue.sh` rather than `N/A`: the two run the same shape, and the reason offered for accepting `select-queue.sh` — it authorizes no write — cannot simultaneously be the reason this one is out of the class. Accepted on the same terms: it is advisory, session-end, human-read, and the labels it prompts for are applied by hand afterwards. |
|
||||
| `scripts/security-scan.sh` — `docker pull`, then `docker run` the same tag | `UNSAFE-KNOWN` | Pull and run are two steps over a MUTABLE tag, which is the same shape the registry rows below were graded down for; "resolution and use are one step" overstated it. In practice the second step resolves against the local daemon, which holds the image the pull just placed, so a mid-window retag does not change what runs. Accepted on that, plus the scope: this boots a throwaway container and scans it, authorizing nothing. |
|
||||
| `scripts/migration-smoke.sh` | `N/A` | Same shape. The resolved image id is **reported** for the operator rather than compared against a prior read, which is an operator-trust gap (the script says so) and not a race. |
|
||||
| `scripts/migration-smoke.sh` — `docker pull`, then `docker run` the same tag | `UNSAFE-KNOWN` | The same pull-then-run over a mutable tag as `security-scan.sh` above, and graded with it rather than left behind: its row previously said "Same shape" as a note that has since been rewritten to the opposite conclusion, so the backreference had quietly inverted. This one deserves the grade MORE, not less — `security-scan.sh` boots a throwaway container and authorizes nothing, while this is the pre-deploy migration smoke that gates a production stack recreation. Accepted on the same bound (the run resolves against the local daemon holding the image the pull just placed) plus its own stated operator-trust gap: the resolved image id is **reported** for a human rather than compared against a prior read. |
|
||||
| `scripts/hook-fire-log.sh` | `N/A` | Entirely local: reads stdin and writes JSONL under the cache dir; the only `curl` in the file is in a comment. |
|
||||
| `scripts/e2e-local.sh` | `N/A` | No outbound call at all; readiness is a local log grep and a local port probe against a subprocess it started. |
|
||||
| `scripts/e2e-ui.sh` | `N/A` | Launches a local Chromium and runs specs against `http://localhost:$PORT`. |
|
||||
|
||||
@@ -65,6 +65,11 @@ if url.rstrip("/").endswith("/branch_protections"):
|
||||
# The LIST endpoint, consulted only after a 404 on the by-name lookup. Gitea keys the by-name
|
||||
# endpoint on the RULE name, so a base covered by a glob rule 404s there while being protected.
|
||||
mode = (state / "bp").read_text().strip()
|
||||
if mode == "CASEFOLD-RULE":
|
||||
# Gitea compares a plain (non-glob) rule name with EqualFold, so a rule named `MAIN`
|
||||
# governs base `main`. A case-SENSITIVE comparison here would miss it and deny.
|
||||
respond(json.dumps([{"branch_name": "MAIN", "enable_status_check": True,
|
||||
"status_check_contexts": ["review-verdict/h10"]}]))
|
||||
if mode == "GLOB-WITH-DOT-RULE":
|
||||
# The POSITIVE control: a glob rule whose literal segment contains a metacharacter, which
|
||||
# genuinely governs this base. Must MATCH — an over-escaped pattern makes it unmatchable and
|
||||
@@ -102,7 +107,7 @@ if "/branch_protections/" in url:
|
||||
# curl itself fails: no body, and `-w` prints 000.
|
||||
respond("", "000")
|
||||
if mode in ("NOT-FOUND", "GLOB-RULE", "LIST-UNREADABLE", "REGEX-META-RULE",
|
||||
"GLOB-WITH-DOT-RULE", "CHARCLASS-RULE"):
|
||||
"GLOB-WITH-DOT-RULE", "CHARCLASS-RULE", "CASEFOLD-RULE"):
|
||||
respond('{"message":"not found"}', "404")
|
||||
if mode == "FORBIDDEN":
|
||||
respond('{"message":"token does not have at least one of required scope(s)"}', "403")
|
||||
@@ -536,20 +541,22 @@ def test_a_NON_STRING_status_reaches_the_scheduled_validator(hook):
|
||||
assert "ask" in reason, "a non-string .status produced a verdict-shaped decision"
|
||||
|
||||
|
||||
def test_a_base_covered_by_a_GLOB_rule_is_not_reported_as_unprotected(hook):
|
||||
"""Gitea keys the by-name branch-protection endpoint on the RULE name, so a base covered by a
|
||||
glob rule (`m*`, `rel/*`) 404s on its own name while being fully protected.
|
||||
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.
|
||||
|
||||
Reading that 404 as "unprotected" produced a hard DENY stating a specific, false cause — and a
|
||||
deny is not a prompt, it blocks the operation outright. The list endpoint is consulted before
|
||||
denying, and a matching rule is inspected like any other.
|
||||
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 `*`
|
||||
does not cross `/`, and `?`/`[…]`/`{a,b}` are wildcards), so a glob rule that COULD govern the
|
||||
base is undecidable and asks — the only answer honest in both directions.
|
||||
"""
|
||||
hook.set_branch_protection("GLOB-RULE")
|
||||
reason = hook.reason()
|
||||
assert "ask" in reason, (
|
||||
"a base a glob rule could govern was decided rather than referred to a human")
|
||||
assert "NO branch protection" not in reason, (
|
||||
"a base protected by a glob rule was reported as having no protection at all")
|
||||
assert "deny" not in reason, (
|
||||
"a glob rule that DOES require review-verdict/h10 was not honoured")
|
||||
"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):
|
||||
@@ -594,6 +601,9 @@ def test_a_rule_name_with_REGEX_METACHARACTERS_does_not_match_a_different_base(h
|
||||
reason = hook.reason()
|
||||
assert "deny" in reason, (
|
||||
"a rule named 'mai.' was regex-matched against base 'main' and read as protection")
|
||||
assert "NO branch protection" in reason, (
|
||||
"'mai.' contains no GLOB metacharacter, so it is decidable: it simply does not govern "
|
||||
"'main', and the base is genuinely unprotected")
|
||||
|
||||
|
||||
def test_a_GLOB_rule_whose_literal_part_has_a_metacharacter_still_MATCHES(hook):
|
||||
@@ -605,18 +615,20 @@ def test_a_GLOB_rule_whose_literal_part_has_a_metacharacter_still_MATCHES(hook):
|
||||
stated cause "has NO branch protection at all", 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
|
||||
`ma*n.x` genuinely governs the base, so the gate must not deny.
|
||||
both fail to match the wrong base. Only a rule that SHOULD match distinguishes them. Here the rule
|
||||
`release/26.*` could govern the base `release/26.4`, so the gate must reach a decision about it
|
||||
rather than reporting the base as unprotected.
|
||||
"""
|
||||
hook.set_base("release/26.4")
|
||||
hook.drop_recorded_base() # keep the #632 comparison out of this test's way
|
||||
hook.set_branch_protection("GLOB-WITH-DOT-RULE")
|
||||
reason = hook.reason()
|
||||
assert "ask" in reason, (
|
||||
"the glob rule 'release/26.*' could govern base 'release/26.4', which is undecidable here "
|
||||
"and must ask")
|
||||
assert "NO branch protection" not in reason, (
|
||||
"the glob rule 'release/26.*' governs base 'release/26.4' but was made unmatchable by "
|
||||
"over-escaping, so the gate reported the base as entirely unprotected")
|
||||
assert "deny" not in reason, (
|
||||
"a rule requiring review-verdict/h10 and matching this base was not honoured")
|
||||
"a base a glob rule could govern was reported as entirely unprotected — the over-escaping "
|
||||
"failure this test exists to catch")
|
||||
|
||||
|
||||
def test_a_rule_name_containing_a_CHAR_CLASS_bracket_does_not_crash_the_matcher(hook):
|
||||
@@ -625,7 +637,20 @@ def test_a_rule_name_containing_a_CHAR_CLASS_bracket_does_not_crash_the_matcher(
|
||||
poison the lookup and deny a base that a later rule in the same list protects."""
|
||||
hook.set_branch_protection("CHARCLASS-RULE")
|
||||
reason = hook.reason()
|
||||
assert reason, "the hook emitted no decision at all"
|
||||
assert "NO branch protection" not in reason, (
|
||||
"one rule with a bracket in its name discarded the whole list, including the rule that "
|
||||
"actually protects this base")
|
||||
"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, (
|
||||
"an exact-name rule requiring review-verdict/h10 was present and was not honoured")
|
||||
|
||||
|
||||
def test_a_plain_rule_name_is_matched_CASE_INSENSITIVELY(hook):
|
||||
"""Gitea compares a rule name with no glob metacharacter using `EqualFold`, so a rule named
|
||||
`MAIN` governs the base `main`. Comparing case-sensitively here would find no rule, conclude the
|
||||
base is unprotected, and deny with a false stated cause."""
|
||||
hook.set_branch_protection("CASEFOLD-RULE")
|
||||
reason = hook.reason()
|
||||
assert "NO branch protection" 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
|
||||
|
||||
@@ -19,7 +19,12 @@ SCOPE vs POPULATION, per `testing.guard-derives-population-from-source`: the SCO
|
||||
directories, their per-directory file patterns, and one excluded subdirectory — is a hand-written
|
||||
policy choice and is reviewable as one. The POPULATION inside that scope is derived on every run
|
||||
from the git index, with no content predicate at all: a file that reads no remote state earns an
|
||||
explicit `N/A` row rather than staying out, which is why 46 of the 69 rows are `N/A`.
|
||||
explicit `N/A` row rather than staying out, which is why most rows are `N/A`.
|
||||
|
||||
No count is written here on purpose. An exact "N of M" has now gone stale FOUR times in this change,
|
||||
most recently in the same commit that demoted two rows — a hand-maintained number is a second copy of
|
||||
the table, and `docs/guard-inventory.md` earns its counts by having a test assert them. Nothing
|
||||
asserts one here, so nothing states one.
|
||||
|
||||
That is the fourth version, and the history is the point — see the `SCOPE` comment below for the
|
||||
three that failed and what each one hid.
|
||||
@@ -147,11 +152,16 @@ def _inventory_section(text: str) -> str:
|
||||
"'## The inventory' and '## Limits'; renaming or reordering either one would "
|
||||
"silently change which rows are checked, so it fails here instead.")
|
||||
start = text.index("## The inventory")
|
||||
end = text.index("## Limits", start)
|
||||
if end <= start:
|
||||
try:
|
||||
end = text.index("## Limits", start)
|
||||
except ValueError:
|
||||
# Reachable when '## Limits' exists but PRECEDES '## The inventory' — the presence check
|
||||
# above passes and the bounded search does not. An earlier version put an `end <= start`
|
||||
# guard here instead, which `str.index(…, start)` makes unreachable by construction: it
|
||||
# either returns an index >= start or raises. A guard that cannot execute proves nothing.
|
||||
raise AssertionError(
|
||||
f"{INVENTORY.name}: '## Limits' precedes '## The inventory'; the parsed window would "
|
||||
"be empty and every completeness assertion would pass vacuously.")
|
||||
f"{INVENTORY.name}: '## Limits' precedes '## The inventory', so the parsed window "
|
||||
"would be empty and every completeness assertion would pass vacuously.") from None
|
||||
return text[start:end]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user