Skip to content
Draft
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
5 changes: 4 additions & 1 deletion .github/cursor-review/auto-approve.py
Original file line number Diff line number Diff line change
Expand Up @@ -4269,7 +4269,10 @@ def cmd_round_cap(args) -> int:
try:
# For the `approve_gate` output only: a PR a human already handed to a
# human reports `capped` even when auto-approve (and so decide) is off.
if has_label(read_pr(args.repo, args.pr_number), HUMAN_REVIEW_LABEL):
pr = read_pr(args.repo, args.pr_number)
if strict and not live_labels_readable(pr):
raise ValueError("the PR label list is missing or malformed")
if has_label(pr, HUMAN_REVIEW_LABEL):
set_output("labelled", "true")
except (RuntimeError, ValueError) as e:
print(f"::warning::Could not read this PR's labels: {e}")
Expand Down
22 changes: 20 additions & 2 deletions .github/cursor-review/tests/test_auto_approve.py
Original file line number Diff line number Diff line change
Expand Up @@ -1907,7 +1907,8 @@ class RoundCapCommandTest(unittest.TestCase):
"""The cap path end to end, with gh stubbed by endpoint."""

def run_cap(self, reviews, max_rounds="5", timeline=(), comments=(), label_exists=True, fail=(), labels=(),
probe_error="HTTP 404", strict=False, count_superseded=False, preserve=False, after_review=False):
probe_error="HTTP 404", strict=False, count_superseded=False, preserve=False, after_review=False,
pr_payload=None):
writes = []

def fake_gh(args, payload=None):
Expand Down Expand Up @@ -1937,7 +1938,7 @@ def fake_gh(args, payload=None):
raise RuntimeError(probe_error)
return "{}"
if path == "repos/o/r/pulls/1":
return json.dumps({"labels": [{"name": n} for n in labels]})
return json.dumps(pr_payload if pr_payload is not None else {"labels": [{"name": n} for n in labels]})
raise AssertionError(path)

with tempfile.TemporaryDirectory() as d:
Expand Down Expand Up @@ -2069,6 +2070,23 @@ def test_strict_cap_allows_two_and_hands_off_at_three(self):
rc, out, _ = self.run_cap(self.FIVE[:3], max_rounds="3", strict=True)
self.assertEqual((rc, out["capped"], out["rounds"]), (0, "true", "3"))

def test_fail_closed_rejects_malformed_label_payloads(self):
for payload in ({}, {"labels": None}, {"labels": "bad"}, {"labels": [{"name": 4}]}):
with self.subTest(payload=payload):
rc, _, writes = self.run_cap(self.FIVE[:2], max_rounds="3", strict=True, pr_payload=payload)
self.assertNotEqual(rc, 0)
self.assertFalse(writes)

def test_default_policy_keeps_legacy_behavior_for_missing_labels(self):
rc, out, writes = self.run_cap(self.FIVE[:2], max_rounds="3", pr_payload={})
self.assertEqual((rc, out["capped"], out["rounds"], writes), (0, "false", "2", []))

def test_after_review_marks_handoff_when_label_payload_is_malformed(self):
rc, _, writes = self.run_cap(self.FIVE[:3], max_rounds="3", after_review=True,
pr_payload={"labels": None})
self.assertNotEqual(rc, 0)
self.assertIn(("POST", "repos/o/r/issues/1/labels"), [(m, p) for m, p, _ in writes])

def test_strict_cap_stops_if_labels_cannot_be_read(self):
rc, _, _ = self.run_cap(self.FIVE[:2], max_rounds="3", fail=("repos/o/r/pulls/1$",), strict=True)
self.assertNotEqual(rc, 0)
Expand Down
Loading