Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
200 changes: 200 additions & 0 deletions .github/scripts/review-deferrals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
"""Fails a pull request that leaves a defect for the release quality pass.

A review point may wait for the release quality pass when the reply to it ends with
`<!-- quality-sweep -->`, but only a quality point may (AGENTS.md, "Review comments"). The Claude
review (claude-code-review.yml, posting as github-actions) ends each inline finding with its
category, a last line `Category: bug` and so on, so the reviewer classifies a finding and the
author doesn't. This check refuses a deferral reply in a thread that the reviewer opened with a
`bug`, `security` or `agents-md` finding, or whose opening comment someone else has since edited.

Threads opened by anyone else (CodeRabbit, people) or by a review from before categories carry no
category and are let through: a reviewer there can answer the reply. They are listed in a notice.
An edited review finding is refused whatever category it now shows, since the edit may have
removed or changed it; the override below settles a harmless edit.

`performance` is left out on purpose: a faster path may wait. A performance finding that is also a
crash path or breaks "Size for real data" carries `bug` or `agents-md`, the more serious category.

Both markers err towards refusing. The deferral marker counts wherever it sits in a reply, as the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "same definition" claim doesn't hold for the repo's other consumer. This docstring and the PR description say the release pass collects the marker wherever it sits, and that the check uses that same definition. But .github/workflows/claude-autofix.yml (the jq program around line 249) treats a thread as deferred only when the last writer reply ends with \s*$. Either autofix misreads a mid-reply marker, or the sweep is end-anchored and this check over-refuses. Confirm the sweep's search and align the two, and say which one this docstring describes.

Category: quality

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change. The header describes the release quality pass, which collects the marker anywhere, and the check matches that. Autofix's narrower reading only decides which threads autofix leaves alone; the description now notes the difference.

release quality pass collects it, so a reply that only mentions it is refused too: reword it. The
override counts only when it ends its reply, so a mention doesn't approve.

A maintainer overrides the check for a finding, misclassified or accepted as it is, by replying in
its thread with `<!-- deferral-approved -->`. A maintainer here is the repository's owner, a member
of its organization or a collaborator, as GitHub labels the reply. The author may be that maintainer: the
override is a deliberate, recorded decision, not a second opinion.

CI runs this on each push and again in the merge queue, which sees replies posted after the last
push. It needs GH_TOKEN (read access to pull requests), GITHUB_REPOSITORY, and PR_NUMBER or, in the
merge queue, MERGE_GROUP_REF.
"""

import json
import os
import re
import subprocess
import sys

DEFER = "<!-- quality-sweep -->"
APPROVE = "<!-- deferral-approved -->"
# Visible text on a line of its own: the review's inline-comment tool strips hidden comments.
# Markdown emphasis and code marks around the label or the value, and capitals, are let through.
CATEGORY = re.compile(r"^[*_`]*Category[*_`]*:[*_` \t]*([A-Za-z-]+)[*_`]*\.?[ \t\r]*$", re.M)
MUST_FIX = {"bug", "security", "agents-md"}
MAY_WAIT = {"performance", "quality"}
REVIEWER = "github-actions"
MAINTAINERS = {"OWNER", "MEMBER", "COLLABORATOR"}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReDoS in the marker pattern. (?:\s|)* lets each .*? run past a -->, so one hidden comment can be split between several iterations. When the reply fails at its end (for example a trailing character after the marker), the engine tries every such split, which grows exponentially with the number of hidden comments. About 40 short `` comments after the marker, plus one trailing character, should make check() hang. Anyone who can comment on a thread can do this, and `Tests pass` is required, so the PR stays blocked until the job times out.

Each hidden comment should end at its first -->, so the split is unique:

Suggested change
MAINTAINERS = {"OWNER", "MEMBER", "COLLABORATOR"}
DEFER = re.compile(r"(?:\s|).)*-->)*\Z", re.S)

Please add a regression test with a long run of hidden comments and a trailing character.

Category: bug

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reproduced: 24 hidden comments and a trailing character took 2.3 s with the old pattern, doubling per comment. Fixed in 54d05b8 without a nested pattern: the text after the last marker has its hidden comments removed and must then be blank. Regression test with 5,000 hidden comments and a trailing character.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub's authorAssociation gives COLLABORATOR to anyone invited to collaborate on the repository, including an outside collaborator with read-only access, and read-only accounts can still comment. Such an account can post `` and clear a refused bug or `security` deferral, while the docstring and docs present the override as a maintainer's decision. Either limit the override to accounts with write access (check the reply author's permission through the API), or say in the docs that any invited collaborator may override.

Confidence: medium. It depends on how the repository invites collaborators, which I can't see from the diff.

Category: security

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change. The docs and the script's header say who may override: the owner, an organization member or a collaborator, as GitHub labels the reply. This is a process guard that leaves a visible reply in the thread, not an access control, so it doesn't look up write permission.

QUEUE_REF = re.compile(r"/pr-(\d+)-[0-9a-f]{40}$")

THREADS = """

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The category line fails open. The pattern is case-sensitive and needs the exact text on its own line. A line such as **Category:** bug, Category: \bug`orCategory: Bugmatches nothing, socategory()returns None, the thread goes tounclassified`, and a deferral of a real bug passes with only a notice. The check depends on the model writing the line exactly, so a formatting slip silently turns off enforcement.

Tolerate markdown around the label and lowercase the value (category() should .lower() it). Whether a bot finding with no recognisable category line should be refused, rather than noticed, is a decision for you. The PR description says a missed marker is accepted, so I'm raising this for a decision, not as a settled bug.

Category: bug

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 54d05b8: emphasis and code marks around the label or value are accepted and the value is lowercased, with a test for four spellings. A review finding with no recognisable category stays a notice, not a refusal: every review thread written before this change has none, and refusing them would hold the open pull requests.

query($owner: String!, $name: String!, $number: Int!, $endCursor: String) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

performance findings can be deferred, but AGENTS.md allows only quality points to wait. The Review comments rule says only a quality point may wait for the release quality pass. A performance problem can still be a crash path under "Size for real data" (memory growing with input). MUST_FIX leaves performance out, so a deferred performance finding passes with no notice.

Either add it, or record in the PR that performance is deliberately excluded and why:

Suggested change
query($owner: String!, $name: String!, $number: Int!, $endCursor: String) {
MUST_FIX = {"bug", "security", "agents-md", "performance"}

Category: agents-md

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deliberately excluded, and now recorded in the script's header and the pull request description. A faster path is work the release quality pass handles. A performance finding that is also a crash path or breaks "Size for real data" carries bug or agents-md, because a comment takes its most serious category.

repository(owner: $owner, name: $name) {
pullRequest(number: $number) {
reviewThreads(first: 50, after: $endCursor) {
pageInfo { hasNextPage endCursor }
nodes { id path line originalLine comments(first: 100) { %s } }
}
}
}
}
"""
COMMENTS = """pageInfo { hasNextPage endCursor }
nodes { url body authorAssociation lastEditedAt author { login __typename } editor { login } }"""
MORE_COMMENTS = """
query($id: ID!, $endCursor: String) {
node(id: $id) { ... on PullRequestReviewThread { comments(first: 100, after: $endCursor) { %s } } }
}
"""


def is_reviewer(comment):
"""Whether a comment was posted by the Claude review workflow's bot account."""
author = comment.get("author") or {}
return author.get("login") == REVIEWER and author.get("__typename") == "Bot"


def category(opening):
"""The category a reviewer finding gives itself: the most serious of its markers, or None."""
if not is_reviewer(opening):
return None
found = [c.lower() for c in CATEGORY.findall(opening.get("body") or "")]
found = [c for c in found if c in MUST_FIX | MAY_WAIT] # an unknown word is no category
serious = [c for c in found if c in MUST_FIX]
return (serious or found or [None])[0]


def edited_by_someone_else(opening):
"""Whether a human or other account edited the reviewer's comment, which may have changed its category."""
if not opening.get("lastEditedAt"):
return False
return ((opening.get("editor") or {}).get("login")) != REVIEWER


def approved(replies):
"""Whether a maintainer overrode the check for the thread's deferral."""
for reply in replies:
author = reply.get("author") or {}
if (
(reply.get("body") or "").rstrip().endswith(APPROVE)
and author.get("__typename") != "Bot"
and reply.get("authorAssociation") in MAINTAINERS
):
return True
return False


def check(threads):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check reads review threads only, so a deferral made elsewhere escapes it. The reviewer's summary is a PR comment (the workflow publishes the final message as one) and lists the same findings under Bugs and Security, with no inline thread and no category line. A reply to it, or any other PR comment carrying ``, is never seen by this check. The rule is only as strong as the sweep's search: if the release pass collects markers from issue comments as well as thread replies, a bug can be deferred with no refusal. Either the check should also scan issue comments (the summary is authored by github-actions, so the same category rule can apply), or the PR should say the sweep reads thread replies only and what stops a deferral in a PR comment.

Category: bug

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope by design, now stated in the description under "What this doesn't do": the check reads review threads only. A marker in a top-level comment has no finding or category to judge it by; the release quality pass still collects it, and reviewers can see it.

"""Sorts the threads that hold a deferral reply into (refused, unclassified) lists of messages."""
refused, unclassified = [], []
for thread in threads:
comments = thread.get("comments") or []
if not comments:
continue
opening, replies = comments[0], comments[1:]
deferral = next((r for r in replies if DEFER in (r.get("body") or "")), None)
if deferral is None:
continue
where = f"{thread.get('path')}:{thread.get('line') or thread.get('originalLine') or '?'}"
if not is_reviewer(opening):
unclassified.append(f"{where} ({(opening.get('author') or {}).get('login', 'ghost')}): {deferral.get('url')}")
continue
kind = category(opening)
if edited_by_someone_else(opening):
reason = "its finding was edited after the review posted it"
elif kind in MUST_FIX:
reason = f"the reviewer classed it as {kind}"
else:
if kind is None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A category the check doesn't know passes with no notice. category() returns the raw value, so Category: bugs (or correctness, data-loss) is a non-None kind that is not in MUST_FIX. The else branch then runs continue without a notice. A reply with the marker on a real data-loss finding that the reviewer labelled Category: bugs passes silently, which breaks "Never silent". The one-category-per-value design should treat an unrecognised value like a missing one: a notice, or a refusal.

Suggested change
if kind is None:
if kind not in CATEGORIES:
unclassified.append(f"{where} (review with an unknown category {kind!r}): {deferral.get('url')}")
continue

(CATEGORIES = {"bug", "security", "performance", "quality", "agents-md"} would need adding beside MUST_FIX. A test with Category: bugs and a notice expectation belongs beside test_a_deferred_quality_point_passes.)

Category: bug

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 72c71ff: a category word the check doesn't know counts as no category, so the deferral is listed in a notice. Test added with Category: bugs.

unclassified.append(f"{where} (review without a category): {deferral.get('url')}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The edit check runs before the no-category case, so it refuses threads the docstring says pass. The module docstring says threads from reviews before categories "are let through" with a notice. This line comes first, though: a human edit to an uncategorised review comment (a typo fix, say) makes check() refuse it with "its finding was edited", and the uncategorised branch below is never reached.

Checking for an uncategorised finding first would match the docstring. If an edit to a categorised finding could have changed its category, keep the edit check for that case. Test both paths: an edited uncategorised review should give a notice, not a refusal.

Category: bug

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order is intended; the docstring was wrong and is corrected in 54d05b8. Checking for no category first would let an edit that deletes the category line turn a refused finding into a noticed one. An edited finding is refused whatever it now shows, and the maintainer's override settles a typo fix. Test added for an edited finding with no category.

continue
if not approved(replies):
refused.append(f"{where}: left for the release quality pass, but {reason}. {deferral.get('url')}")
return refused, unclassified


def graphql(query, **variables):
"""Runs one GraphQL query through the gh CLI and returns its data."""
args = ["gh", "api", "graphql", "-f", f"query={query}"]
for key, value in variables.items():
args += ["-F" if isinstance(value, int) else "-f", f"{key}={value}"]
out = subprocess.run(args, check=True, stdout=subprocess.PIPE, text=True, timeout=120).stdout
return json.loads(out)["data"]


def fetch(repo, number):
"""The pull request's review threads, every comment of each in order."""
owner, name = repo.split("/", 1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

capture_output hides why gh failed. gh writes its auth, permission and GraphQL errors to stderr. With capture_output=True and check=True, the job log shows only "returned non-zero exit status 1", not the reason. Let stderr through to the job log:

Suggested change
owner, name = repo.split("/", 1)
out = subprocess.run(args, check=True, stdout=subprocess.PIPE, text=True).stdout

Category: quality

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in 54d05b8.

threads, cursor = [], None
while True:
extra = {"endCursor": cursor} if cursor else {}
pr = graphql(THREADS % COMMENTS, owner=owner, name=name, number=number, **extra)["repository"]["pullRequest"]
page = pr["reviewThreads"]
for node in page["nodes"]:
comments, more = node["comments"]["nodes"], node["comments"]["pageInfo"]
while more["hasNextPage"]:
rest = graphql(MORE_COMMENTS % COMMENTS, id=node["id"], endCursor=more["endCursor"])["node"]["comments"]
comments, more = comments + rest["nodes"], rest["pageInfo"]
threads.append({**node, "comments": comments})
if not page["pageInfo"]["hasNextPage"]:
return threads
cursor = page["pageInfo"]["endCursor"]


def pr_number():
"""The pull request to check, from PR_NUMBER or the merge queue's branch name."""
if os.environ.get("PR_NUMBER"):
return int(os.environ["PR_NUMBER"])
match = QUEUE_REF.search(os.environ.get("MERGE_GROUP_REF", ""))
if match is None:
raise SystemExit("::error::No PR_NUMBER, and MERGE_GROUP_REF names no pull request.")
return int(match.group(1))


def escape(text):
"""Text for a workflow command line: a path with a newline must not start a command of its own."""
return text.replace("%", "%25").replace("\r", "%0D").replace("\n", "%0A")


def main():
"""Checks the pull request and exits 1 if it defers a finding that must be fixed."""
number = pr_number()
refused, unclassified = check(fetch(os.environ["GITHUB_REPOSITORY"], number))
for line in unclassified:
print(f"::notice::Deferred without a review category, not checked: {escape(line)}")
for line in refused:
print(f"::error::{escape(line)}")
if refused:
print(
f"#{number} leaves {len(refused)} finding(s) that must be fixed for the release quality pass. "
"Fix each in the pull request and take the marker out of the reply; for a defect too large "
"for it, link a filed issue in the reply instead of the marker. To let one wait all the same, "
"a maintainer replies in its thread with <!-- deferral-approved -->. "
"Then run the checks again (re-run the job, or queue the pull request again)."
)
return 1
print(f"#{number}: no deferral to the release quality pass is on a finding that must be fixed.")
return 0


if __name__ == "__main__":
sys.exit(main())
138 changes: 138 additions & 0 deletions .github/scripts/test_review_deferrals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
"""Checks for review-deferrals.py on review threads recorded from pull requests, cut down to the fields it reads."""

import importlib.util
from pathlib import Path
import unittest
import unittest.mock

SPEC = importlib.util.spec_from_file_location("review_deferrals", Path(__file__).with_name("review-deferrals.py"))
MODULE = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(MODULE)

AUTHOR = "contributor"
REVIEWER = {"login": "github-actions", "__typename": "Bot"}
CODERABBIT = {"login": "coderabbitai", "__typename": "Bot"}


def comment(author, body, association="CONTRIBUTOR", editor=None):
return {
"url": f"https://github.com/o/r/pull/1#discussion_r{abs(hash(body)) % 10**9}",
"body": body,
"authorAssociation": association,
"lastEditedAt": "2026-11-16T03:39:59Z" if editor else None,
"author": author,
"editor": {"login": editor} if editor else None,
}


def thread(*comments, path="crates/data/src/dbf.rs"):
return {"path": path, "line": 120, "comments": list(comments)}


def finding(text, kind=None, editor=None):
marker = f"\n\nCategory: {kind}" if kind else ""
return comment(REVIEWER, text + marker, editor=editor)


def reply(text, author=AUTHOR, association="MEMBER"):
return comment({"login": author, "__typename": "User"}, text, association)


DEFER = reply("The reader skipping deleted records predates this PR; left for the release quality pass. <!-- quality-sweep -->")
BUG = "**Bug:** a deleted record shifts every later row's attributes by one."


class ReviewDeferrals(unittest.TestCase):
def check(self, *threads):
return MODULE.check(list(threads))

def test_a_deferred_bug_is_refused(self):
refused, unclassified = self.check(thread(finding(BUG, "bug"), DEFER))
self.assertEqual(len(refused), 1)
self.assertIn("classed it as bug", refused[0])
self.assertEqual(unclassified, [])

def test_a_deferred_quality_point_passes(self):
quality = finding("**Quality:** appending `dbf` keeps the fuzz corpus's extension indexes.", "quality")
self.assertEqual(self.check(thread(quality, DEFER)), ([], []))

def test_an_undeferred_bug_is_not_this_checks_business(self):
answer = reply("Fixed in d3eda9c78.")
self.assertEqual(self.check(thread(finding(BUG, "bug"), answer)), ([], []))

def test_a_grouped_comment_takes_its_most_serious_category(self):
both = finding(BUG + "\nCategory: quality", "agents-md")
refused, _ = self.check(thread(both, DEFER))
self.assertIn("classed it as agents-md", refused[0])

def test_only_a_maintainer_overrides_the_check(self):
rule = finding("**Never silent:** the deleted-record notice has no test.", "agents-md")
by_contributor = reply("Misclassified. <!-- deferral-approved -->", association="CONTRIBUTOR")
by_bot = comment(CODERABBIT, "<!-- deferral-approved -->", "MEMBER")
by_maintainer_author = reply("An extra test for working code. <!-- deferral-approved -->")
mention = reply("I won't reply `<!-- deferral-approved -->` to this one.")
self.assertEqual(len(self.check(thread(rule, DEFER, by_contributor, by_bot, mention))[0]), 1)
self.assertEqual(self.check(thread(rule, DEFER, by_maintainer_author)), ([], []))

def test_an_edited_finding_counts_as_must_fix(self):
edited = finding(BUG, "quality", editor=AUTHOR)
refused, _ = self.check(thread(edited, DEFER))
self.assertIn("edited after the review posted it", refused[0])

def test_threads_without_a_category_pass_with_a_notice(self):
rabbit = thread(comment(CODERABBIT, "_Potential issue_ | **Major** Record the uppercase DBF sidecar."), DEFER)
person = thread(reply("Should this clamp?", author="maintainer"), DEFER)
old_review = thread(finding("**Bug risk (low):** every non-I/O record error is counted."), DEFER)
unknown = thread(finding(BUG, "bugs"), DEFER)
refused, unclassified = self.check(rabbit, person, old_review, unknown)
self.assertEqual(refused, [])
self.assertEqual(len(unclassified), 4)

def test_the_marker_counts_wherever_it_sits_as_the_sweep_collects_it(self):
trailing = reply("Left for the release quality pass. <!-- quality-sweep --> Will do after the merge.")
tracked = reply("Left for the release quality pass. <!-- quality-sweep -->\n<!-- followup:inline:42 -->\n")
for deferral in (trailing, tracked):
self.assertEqual(len(self.check(thread(finding(BUG, "bug"), deferral))[0]), 1)

def test_a_category_line_may_be_emphasised_or_capitalised(self):
for line in ("**Category:** bug", "Category: `bug`", "Category: Bug", "_Category_: BUG", "Category: bug.", "Category: bug\r"):
refused, _ = self.check(thread(comment(REVIEWER, BUG + "\n\n" + line), DEFER))
self.assertEqual(len(refused), 1, line)

def test_an_edited_finding_without_a_category_is_refused_too(self):
refused, unclassified = self.check(thread(finding(BUG, editor=AUTHOR), DEFER))
self.assertEqual((len(refused), unclassified), (1, []))

def test_a_category_is_a_line_of_its_own(self):
prose = finding("The Category: bug label in the legend is cut short.\n\nCategory: quality")
self.assertEqual(self.check(thread(prose, DEFER)), ([], []))

def test_a_marker_in_the_opening_comment_is_not_a_deferral(self):
self.assertEqual(self.check(thread(finding(BUG + " <!-- quality-sweep -->", "bug"))), ([], []))

def test_the_merge_queue_branch_names_the_pull_request(self):
ref = "refs/heads/gh-readonly-queue/main/pr-2655-76a6cd2823b4431c363e30a8023c7f69bccae938"
with unittest.mock.patch.dict(MODULE.os.environ, {"PR_NUMBER": "", "MERGE_GROUP_REF": ref}):
self.assertEqual(MODULE.pr_number(), 2655)

def test_fetch_reads_every_page_of_threads_and_comments(self):
def page(nodes, cursor=None):
return {"pageInfo": {"hasNextPage": cursor is not None, "endCursor": cursor}, "nodes": nodes}

first, second, third = finding(BUG, "bug"), reply("a"), DEFER
answers = iter([
{"repository": {"pullRequest": {"reviewThreads": page(
[{"id": "T1", "path": "a.rs", "line": 1, "comments": page([first], "c1")}], "t1")}}},
{"node": {"comments": page([second], "c2")}},
{"node": {"comments": page([third])}},
{"repository": {"pullRequest": {"reviewThreads": page(
[{"id": "T2", "path": "b.rs", "line": 2, "comments": page([])}])}}},
])
with unittest.mock.patch.object(MODULE, "graphql", lambda *a, **k: next(answers)):
threads = MODULE.fetch("o/r", 1)
self.assertEqual([t["id"] for t in threads], ["T1", "T2"])
self.assertEqual(threads[0]["comments"], [first, second, third])


if __name__ == "__main__":
unittest.main()
25 changes: 23 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ jobs:
echo "run=true" >> "$GITHUB_OUTPUT"
exit 0
fi
if grep -qE '^(Cargo\.lock|(.*/)?Cargo\.toml|deny\.toml|about\.toml|xtask/src/(main|notices)\.rs|(.*/)?THIRD-PARTY-LICENSES\.txt|\.github/scripts/(check-cargo-sources|test_[^/]+)\.py|\.github/workflows/ci\.yml|crates/map/src/color/(scientific|matplotlib)\.rs|crates/tiles/src/(symbols|style)\.rs|crates/data/src/(raster/crs|esripbf)\.rs)$|^(third-party/|\.cargo/)' <<<"$changed"; then
if grep -qE '^(Cargo\.lock|(.*/)?Cargo\.toml|deny\.toml|about\.toml|xtask/src/(main|notices)\.rs|(.*/)?THIRD-PARTY-LICENSES\.txt|\.github/scripts/(check-cargo-sources|review-deferrals|test_[^/]+)\.py|\.github/workflows/ci\.yml|crates/map/src/color/(scientific|matplotlib)\.rs|crates/tiles/src/(symbols|style)\.rs|crates/data/src/(raster/crs|esripbf)\.rs)$|^(third-party/|\.cargo/)' <<<"$changed"; then
echo "run=true" >> "$GITHUB_OUTPUT"
else
echo "No dependency, licence or notice files changed; skipping."
Expand Down Expand Up @@ -292,6 +292,27 @@ jobs:
- name: Count direct row uses
run: cargo run --locked -q -p xtask -- rows

# A review point left for the release quality pass must be a quality point
# (.github/scripts/review-deferrals.py). The merge queue's run sees replies posted after the last
# push. It runs the checkout with a read-only token and no secrets, like every job here.
deferrals:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The licences job's unit-test step (around ci.yml:200) runs only when the scope regex at ci.yml:180 matches a changed file. That regex lists test_*.py but not review-deferrals.py, and line 180 isn't in this diff, so I couldn't anchor the fix there. A PR that changes only the gate script therefore skips test_review_deferrals.py in PR CI, while the new deferrals job still runs the changed script, so a regression in the gate can merge with its tests unrun. The fix is to add review-deferrals to the alternation inside \.github/scripts/(check-cargo-sources|test_[^/]+)\.py on line 180, giving \.github/scripts/(check-cargo-sources|review-deferrals|test_[^/]+)\.py.

Confidence: high (regex read directly from the file).

Category: quality

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in aee6a17: review-deferrals is in the licences job's scope pattern.

name: Review deferrals
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- name: No defect left for the release quality pass
if: github.event_name == 'pull_request' || github.event_name == 'merge_group'
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
MERGE_GROUP_REF: ${{ github.event.merge_group.head_ref }}
run: python3 .github/scripts/review-deferrals.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a pull_request run the checkout is the pull request's merge commit, so this runs the copy of review-deferrals.py that the pull request itself contains. A PR can edit the gate, or its tests, to pass its own check. The token is read-only and no secret is exposed, so the exposure is a bypass of the required check rather than a leak, and a reviewer may miss it in a large diff. This PR can't avoid it, because the script is new and absent from main. Once it is on main, run the base branch's copy (for example by checking out origin/main into a temporary path for this one script) so that a PR can't change the rule that judges it.

Confidence: medium. Whether it matters depends on how much the team relies on this check against its own edits.

Category: security

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change. Every job in ci.yml runs the pull request's own copy of its scripts and of ci.yml itself, so this check is no weaker than the others, and an edit to it shows in the diff. Running the base branch's copy can be a later change if that turns out to matter.


# The packages whose tests this run needs, for `test` (.github/scripts/test-selection.sh). Only
# tests are narrowed: lint, the wasm build, licences and the schema check run whole every time.
select:
Expand Down Expand Up @@ -395,7 +416,7 @@ jobs:
# unless their conditions below hold (the same as on the jobs), and every other job always runs.
tests_pass:
name: Tests pass
needs: [lint, wasm, ios, android, licenses, schema, rows, plan, select, test]
needs: [lint, wasm, ios, android, licenses, schema, rows, deferrals, plan, select, test]
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
Expand Down
Loading
Loading