From 5af8bce9b1ee8f426e290010181ea7518a446b14 Mon Sep 17 00:00:00 2001 From: huang47 <157390+huang47@users.noreply.github.com> Date: Thu, 29 Oct 2026 00:44:53 +0800 Subject: [PATCH 1/2] fix: stop strict review cap on unknown review fields --- .github/cursor-review/auto-approve.py | 20 +++++++++- .../cursor-review/tests/test_auto_approve.py | 38 ++++++++++++++++++- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/.github/cursor-review/auto-approve.py b/.github/cursor-review/auto-approve.py index 773cd85e..a83f3c03 100644 --- a/.github/cursor-review/auto-approve.py +++ b/.github/cursor-review/auto-approve.py @@ -2489,7 +2489,7 @@ def _review_node(node: dict) -> dict: } -def list_reviews(repo: str, pr_number) -> list: +def list_reviews(repo: str, pr_number, *, round_poster=None, round_marker=None) -> list: """Every review on the PR, REST-shaped, plus `edited`. A missing `pullRequest` or `reviews` connection, a page claiming more with @@ -2532,6 +2532,21 @@ def list_reviews(repo: str, pr_number) -> list: nodes = reviews.get("nodes") if not isinstance(nodes, list): raise ValueError(f"the GraphQL reviews of {repo}#{pr_number} are not a list ({type(nodes).__name__})") + if round_poster is not None: + for node in nodes: + if not isinstance(node, dict): + continue # _review_node reports this below + author, review_body = node.get("author"), node.get("body") + login = author.get("login") if isinstance(author, dict) else None + could_be_round = not isinstance(review_body, str) or review_body.startswith(round_marker) + if could_be_round and (not isinstance(login, str) or not login): + raise ValueError("a possible review round has no readable author") + poster_base = round_poster.removesuffix("[bot]").lower() + if isinstance(login, str) and login.lower() == poster_base: + if not isinstance(review_body, str): + raise ValueError("a possible review round has no readable body") + if review_body.startswith(round_marker) and author.get("__typename") not in ("Bot", "User"): + raise ValueError("a possible review round has no readable author type") out += [_review_node(n) for n in nodes] if not page.get("hasNextPage"): return out @@ -4287,7 +4302,8 @@ def cmd_round_cap(args) -> int: _paginate(f"repos/{args.repo}/issues/{args.pr_number}/timeline?per_page=100"), HUMAN_REVIEW_LABEL ) preserve = getattr(args, "preserve_round_count", False) - rounds = round_reviews(list_reviews(args.repo, args.pr_number), args.poster_login, None if preserve else since, marker, + review_options = {"round_poster": args.poster_login, "round_marker": marker} if strict else {} + rounds = round_reviews(list_reviews(args.repo, args.pr_number, **review_options), args.poster_login, None if preserve else since, marker, 0 if getattr(args, "count_superseded_rounds", False) else max_rounds) except (RuntimeError, ValueError) as e: # Legacy callers fail open; strict callers stop the panel. diff --git a/.github/cursor-review/tests/test_auto_approve.py b/.github/cursor-review/tests/test_auto_approve.py index a0059e0f..b87e102f 100644 --- a/.github/cursor-review/tests/test_auto_approve.py +++ b/.github/cursor-review/tests/test_auto_approve.py @@ -1930,7 +1930,7 @@ class RoundCapCommandTest(unittest.TestCase): 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, - pr_payload=None): + pr_payload=None, review_response=None): writes = [] def fake_gh(args, payload=None): @@ -1950,7 +1950,7 @@ def fake_gh(args, payload=None): if "/timeline" in path: return json.dumps([list(timeline)]) if path.endswith("/reviews?per_page=100"): - return graphql_reviews(list(reviews)) + return review_response if review_response is not None else graphql_reviews(list(reviews)) if "/issues/1/comments" in path: return json.dumps([list(comments)]) if "/reviews/" in path and path.endswith("/comments?per_page=100"): @@ -1978,6 +1978,40 @@ def fake_gh(args, payload=None): FIVE = [review(i, f"2026-01-0{i}T00:00:00Z") for i in range(1, 6)] + def test_strict_cap_stops_when_review_author_or_body_is_unknown(self): + for field in ("author", "body"): + page = json.loads(graphql_reviews(self.FIVE[:1])) + page["data"]["repository"]["pullRequest"]["reviews"]["nodes"][0][field] = None + with self.subTest(field=field): + rc, out, writes = self.run_cap([], strict=True, review_response=json.dumps(page)) + self.assertEqual((rc, out["capped"], writes), (1, "false", [])) + self.assertNotIn("rounds", out) + + def test_unknown_author_on_unmarked_review_does_not_stop_strict_cap(self): + page = json.loads(graphql_reviews([review(1, "2026-01-01T00:00:00Z", body="Looks good")])) + page["data"]["repository"]["pullRequest"]["reviews"]["nodes"][0]["author"] = None + rc, out, writes = self.run_cap([], strict=True, review_response=json.dumps(page)) + self.assertEqual((rc, out["rounds"], writes), (0, "0", [])) + + def test_legacy_cap_retains_fail_open_for_unknown_review_author(self): + page = json.loads(graphql_reviews(self.FIVE[:1])) + page["data"]["repository"]["pullRequest"]["reviews"]["nodes"][0]["author"] = None + rc, out, writes = self.run_cap([], review_response=json.dumps(page)) + self.assertEqual((rc, out["rounds"], writes), (0, "0", [])) + + def test_unknown_review_after_delivery_attempts_human_handoff(self): + page = json.loads(graphql_reviews(self.FIVE[:1])) + page["data"]["repository"]["pullRequest"]["reviews"]["nodes"][0]["body"] = None + rc, out, writes = self.run_cap([], strict=True, after_review=True, review_response=json.dumps(page)) + self.assertEqual((rc, out["capped"]), (1, "false")) + self.assertEqual([(m, p) for m, p, _ in writes], [("POST", "repos/o/r/issues/1/labels")]) + + def test_missing_author_type_on_potential_round_stops_strict_cap(self): + page = json.loads(graphql_reviews(self.FIVE[:1])) + del page["data"]["repository"]["pullRequest"]["reviews"]["nodes"][0]["author"]["__typename"] + rc, out, writes = self.run_cap([], strict=True, review_response=json.dumps(page)) + self.assertEqual((rc, out["capped"], writes), (1, "false", [])) + def test_under_the_cap_runs_the_panel_and_writes_nothing(self): rc, out, writes = self.run_cap(self.FIVE[:4]) self.assertEqual((rc, out["capped"], out["rounds"], writes), (0, "false", "4", [])) From 5b7d27c42c4c8a6b9e87c1794fe3b73e6ce73d32 Mon Sep 17 00:00:00 2001 From: huang47 <157390+huang47@users.noreply.github.com> Date: Thu, 29 Oct 2026 01:13:56 +0800 Subject: [PATCH 2/2] fix: stop strict reset count without review time --- .github/cursor-review/auto-approve.py | 10 ++++++++- .../cursor-review/tests/test_auto_approve.py | 21 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/.github/cursor-review/auto-approve.py b/.github/cursor-review/auto-approve.py index a83f3c03..4d6f9cab 100644 --- a/.github/cursor-review/auto-approve.py +++ b/.github/cursor-review/auto-approve.py @@ -4303,7 +4303,15 @@ def cmd_round_cap(args) -> int: ) preserve = getattr(args, "preserve_round_count", False) review_options = {"round_poster": args.poster_login, "round_marker": marker} if strict else {} - rounds = round_reviews(list_reviews(args.repo, args.pr_number, **review_options), args.poster_login, None if preserve else since, marker, + reviews = list_reviews(args.repo, args.pr_number, **review_options) + if strict and since and not preserve: + for review in reviews: + if (review["user"]["login"].lower() == args.poster_login.lower() + and review["body"].startswith(marker) + and not any(b in _lf(review["body"]) for b in NON_ROUND_BANNERS) + and (not isinstance(review["submitted_at"], str) or not review["submitted_at"])): + raise ValueError("a possible review round has no submission time for the reset window") + rounds = round_reviews(reviews, args.poster_login, None if preserve else since, marker, 0 if getattr(args, "count_superseded_rounds", False) else max_rounds) except (RuntimeError, ValueError) as e: # Legacy callers fail open; strict callers stop the panel. diff --git a/.github/cursor-review/tests/test_auto_approve.py b/.github/cursor-review/tests/test_auto_approve.py index b87e102f..d5c609a7 100644 --- a/.github/cursor-review/tests/test_auto_approve.py +++ b/.github/cursor-review/tests/test_auto_approve.py @@ -2012,6 +2012,27 @@ def test_missing_author_type_on_potential_round_stops_strict_cap(self): rc, out, writes = self.run_cap([], strict=True, review_response=json.dumps(page)) self.assertEqual((rc, out["capped"], writes), (1, "false", [])) + def test_strict_reset_window_does_not_ignore_round_with_unknown_submission_time(self): + marked = review(1, None) + rc, out, writes = self.run_cap([marked], strict=True, timeline=[unlabeled("2026-01-01T00:00:00Z")]) + self.assertEqual((rc, out["capped"], writes), (1, "false", [])) + self.assertNotIn("rounds", out) + + def test_unknown_submission_time_is_safe_when_count_is_preserved(self): + rc, out, writes = self.run_cap([review(1, None)], strict=True, preserve=True, + timeline=[unlabeled("2026-01-01T00:00:00Z")]) + self.assertEqual((rc, out["rounds"], writes), (0, "1", [])) + + def test_legacy_reset_window_retains_existing_unknown_time_behavior(self): + rc, out, writes = self.run_cap([review(1, None)], timeline=[unlabeled("2026-01-01T00:00:00Z")]) + self.assertEqual((rc, out["rounds"], writes), (0, "0", [])) + + def test_unknown_time_after_delivery_attempts_handoff(self): + rc, out, writes = self.run_cap([review(1, None)], strict=True, after_review=True, + timeline=[unlabeled("2026-01-01T00:00:00Z")]) + self.assertEqual((rc, out["capped"]), (1, "false")) + self.assertEqual([(m, p) for m, p, _ in writes], [("POST", "repos/o/r/issues/1/labels")]) + def test_under_the_cap_runs_the_panel_and_writes_nothing(self): rc, out, writes = self.run_cap(self.FIVE[:4]) self.assertEqual((rc, out["capped"], out["rounds"], writes), (0, "false", "4", []))