diff --git a/scripts/pr_review_copilot.py b/scripts/pr_review_copilot.py index c70cbf094..31dfdfbb0 100755 --- a/scripts/pr_review_copilot.py +++ b/scripts/pr_review_copilot.py @@ -192,6 +192,13 @@ def matched(patterns: list[re.Pattern[str]], text: str) -> re.Match[str] | None: return next((m for p in patterns if (m := p.fullmatch(text))), None) +def count_state(got: str, of: str) -> str: + """A reviewed-of-changed count as `full`, `partial`, or `unknown` where either is too long or `got` exceeds `of`.""" + if len(got) > COUNT_DIGITS or len(of) > COUNT_DIGITS or int(got) > int(of): + return "unknown" + return "full" if int(got) == int(of) else "partial" + + def stated(match: re.Match[str]) -> int: """The count a matched label states: its `n` group, zero for a spelled none, one without one.""" value = match.groupdict().get("n") @@ -347,11 +354,7 @@ def unread(note: str, start: int, end: int) -> None: rank = {"full": 0, "unknown": 1, "partial": 2} for h in html: for m in FLEET_REVIEW.finditer(h): - got, of = m.group(1), m.group(2) - if len(got) > COUNT_DIGITS or len(of) > COUNT_DIGITS or int(got) > int(of): - state = "unknown" - else: - state = "full" if got == of else "partial" + state = count_state(m.group(1), m.group(2)) if coverage == "none" or rank[state] > rank[coverage]: coverage, coverage_line = state, m.group(0) # A body in another layout is one note, rather than one note per part of it. @@ -518,8 +521,7 @@ def placed(n: int, t: Token) -> bool: m = next((m for p in vocab["coverage_prose"] if (m := p.match(said))), None) if m is None: continue - got, of = int(m.group("got")[:COUNT_DIGITS]), int(m.group("of")[:COUNT_DIGITS]) - state = "partial" if got < of else "full" if got == of else "unknown" + state = count_state(m.group("got"), m.group("of")) if state == "unknown": notes.append(f"a coverage count this reader cannot believe: `{said}`") if coverage == "none" or rank[state] > rank[coverage]: diff --git a/tests/test_pr_review_copilot.py b/tests/test_pr_review_copilot.py index ad5d1816c..11b0377ec 100755 --- a/tests/test_pr_review_copilot.py +++ b/tests/test_pr_review_copilot.py @@ -175,6 +175,8 @@ def test_a_count_stated_in_a_paragraph_of_its_own_is_read(self) -> None: ("Copilot reviewed 4 out of 4 changed files.", "full", False), ("Copilot reviewed 3 out of\n4 changed files.", "partial", False), ("Copilot reviewed 5 out of 4 changed files.", "unknown", True), + ("Copilot reviewed 12345 out of 12345 changed files.", "unknown", True), + ("Copilot reviewed 12340 out of 12349 changed files.", "unknown", True), ): with self.subTest(line=line): found = adapter.read(body(sections=line))