diff --git a/docs/host-setup.md b/docs/host-setup.md index b8bee55ce..4e8912224 100644 --- a/docs/host-setup.md +++ b/docs/host-setup.md @@ -384,7 +384,7 @@ Verified on Windows 11 Pro 10.0.26200 with PowerShell 7.6.4, where `python3 scri | --- | --- | | Stand up a new repo through [`STANDUP.md`][standup] | step 0 verifies identity and signing, and its window closes at the first commit | | Run the four linters locally, matching CI | `docker` runs each as the same pinned image CI uses | -| Run the repo's own gates and tests | Python 3 and `uv` cover `scripts/`, `spec/`, and `tests/` with no packages to install, `uv` supplying `tests/requirements.txt` | +| Run the repo's own gates and tests | Python 3 and `uv` cover `scripts/`, `spec/`, and `tests/`, with `uv` installing `tests/requirements.txt` for the tests | | Drive the PR and Copilot review loop | `gh` and an authenticated session | | Let an agent work with the `gh` credentials live | the host-safety kit is installed | | Have the fleet skills surface in every agent session | the skills snapshot is current per `skills_install.py --report` | diff --git a/scripts/README.md b/scripts/README.md index 5dd401b18..1add2febe 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -226,7 +226,7 @@ The digest reports the completed head review's effective effort as `lite`, `bala **`coverage=` names how the head's diff is shown read, and only a stated partial is an exit.** `full` and `PARTIAL` are the reviewer's own statement, the `fleet-review` marker the fleet's review instructions ask for, and `UNKNOWN` is a statement this cannot believe, such as one reading more files than changed, or a body the reader failed on, the reason printed beside it. A count Copilot states in a top-level paragraph that opens on it, never a list item and never inside a counted finding section, is read too, and a partial wins over any other reading beside it. A head round stating nothing while an earlier round states partial reads as `PARTIAL`, so a pull request that ever had a partial round goes to the maintainer. Where nothing states coverage, a round covering the head whose own file table names exactly the changed files reads as `table`, and the newest round on any commit whose table does reads as `carried:table`. A table stands in only where no round states partial coverage and the review history is not cut by its window, since a table names the whole changed set on a partial round too. The changed-file list is paged to GitHub's own ceiling of 3,000 files, and a list not read whole, or read empty, is read again before a table is matched against nothing. A table row matches a changed path exactly, or by a `*` or `?` glob. Otherwise `coverage=none` prints with the reason no table stood in, `status` adds a note, and the exit stays `0`, since Merge Gate item 2 in `pr-review-conduct` reads this field rather than an exit code. A partial round is reported and handed over rather than retried into, since every partial on record stayed partial at the identical ratio across every later round. -**Findings no thread carries are counted and printed whole.** `suppressed=`, `previously_missed=`, and `cr_outside_diff=` count the findings a review body collapses into a counted section, read over every round rather than the head's alone, since a push does not answer a finding nobody replied to. Each reads `N (on_head=X earlier=Y)` with a trailing `+` where the reviews window was cut. `previously_missed=` and `cr_outside_diff=` print only where one was raised or the window was cut. `qodo_open=` counts the entries in Qodo's findings comment carrying neither its `Resolved` nor `Dismissed` badge, `unknown` where that comment can sit behind the window. `overview=T/M` is the open findings the round covering the head states beside the threads it opened, `?` where it states no count. `FINDINGS WITH NO THREAD` names findings the round names, in its count or its findings list, that no open entry links to a thread on the pull request. None of these decides an exit code, and each takes the triage a suppressed finding gets, answered with `comment` since no thread exists to reply on. +**Findings no thread carries are counted and printed whole.** `suppressed=`, `previously_missed=`, and `cr_outside_diff=` count the findings a review body collapses into a counted section, read over every round rather than the head's alone, since a push does not answer a finding nobody replied to. Each reads `N (on_head=X earlier=Y)` with a trailing `+` where the reviews window was cut. A tally holding a count the reader cannot believe reads `?`. `previously_missed=` and `cr_outside_diff=` print only where one was raised or the window was cut. `qodo_open=` counts the entries in Qodo's findings comment carrying neither its `Resolved` nor `Dismissed` badge, `unknown` where that comment can sit behind the window. `overview=T/M` is the open findings the round covering the head states beside the threads it opened, `?` where it states no count. A count it cannot believe reads `?` too. `FINDINGS WITH NO THREAD` names findings the round names, in its count or its findings list, that no open entry links to a thread on the pull request. None of these decides an exit code, and each takes the triage a suppressed finding gets, answered with `comment` since no thread exists to reply on. `status` and `wait` exit `50` where the round covering the head opens on a verdict other than the clean one while it states no open finding, lists none, opened no thread, and collapsed nothing, and no thread is open. Its headline prints under `VERDICT WITH NO COUNTED FINDING`, since it is the one place that round names what it flags. The code repeats on that head after the answer, since nothing here reads one, and where a check on that head has not concluded, `wait` names a bounded `gh pr checks --watch` to watch it with. A clean verdict on the same terms prints its headline under `CLEAN VERDICT HEADLINE`, advisory and gating nothing. diff --git a/scripts/pr_review.py b/scripts/pr_review.py index 32e9031fb..6566d614d 100755 --- a/scripts/pr_review.py +++ b/scripts/pr_review.py @@ -83,11 +83,12 @@ `previously_missed=`, and `cr_outside_diff=N (on_head=X earlier=Y)` count findings collapsed into review bodies over every round, split into the head's and earlier ones, each printed whole since no thread carries it, a trailing `+` marking a cut reviews - window. `qodo_open=N` counts Qodo's findings comment entries with no Resolved or Dismissed badge, `unknown` + window. A tally holding a count the reader cannot believe reads `?`. `qodo_open=N` + counts Qodo's findings comment entries with no Resolved or Dismissed badge, `unknown` where that comment can sit behind the window. `overview=T/M` is the open findings the round covering the head states beside the threads that round opened, `?` where it - states no count, and `FINDINGS WITH NO THREAD` names findings the round names that no - thread on the pull request carries. Each of these is owed the triage a suppressed + states no count. A count it cannot believe reads `?` too. `FINDINGS WITH NO THREAD` + names findings the round names that no thread on the pull request carries. Each of these is owed the triage a suppressed finding gets, and none decides an exit code. reply Answer one thread selected by its text, and resolve it on request. Exists because the hand-run form keeps failing the same way: a node id typed into a @@ -1403,7 +1404,8 @@ def collected(pr: dict, login: str, kind: str) -> tuple[list[tuple[str, adapter. """Each section of `kind` in this login's rounds, with where it was raised, and the field. Every round rather than the head's, since an unanswered finding survives a push. The field - reads `N (on_head=X earlier=Y)`, a trailing `+` on N where the reviews window was cut. + reads `N (on_head=X earlier=Y)`, a trailing `+` on N where the reviews window was cut. A tally + holding a count the reader cannot believe reads `?`. """ head = pr["headRefOid"] found = [] @@ -1417,10 +1419,13 @@ def collected(pr: dict, login: str, kind: str) -> tuple[list[tuple[str, adapter. else f"raised on {oid[:8]}, earlier round" ) found += [(where, s) for s in reading(node, login).sections if s.kind == kind] - total = sum(s.findings for _, s in found) - on_head = sum(s.findings for w, s in found if w == "on head") + + def tally(on: bool | None) -> str: + n = adapter.total(s.findings for w, s in found if on is None or (w == "on head") == on) + return "?" if n is None else str(n) + mark = "+" if reviews_truncated(pr) else "" - return found, f"{total}{mark} (on_head={on_head} earlier={total - on_head})" + return found, f"{tally(None)}{mark} (on_head={tally(True)} earlier={tally(False)})" def thread_author(t: dict) -> str: diff --git a/scripts/pr_review_copilot.py b/scripts/pr_review_copilot.py index 31dfdfbb0..53164524d 100755 --- a/scripts/pr_review_copilot.py +++ b/scripts/pr_review_copilot.py @@ -26,6 +26,7 @@ import re import sys import unicodedata +from collections.abc import Iterable from pathlib import Path from typing import NamedTuple @@ -83,10 +84,13 @@ class Section(NamedTuple): - """One counted section: its kind, the count its label states, its title, and its text.""" + """One counted section: its kind, the count its label states, its title, and its text. + + `findings` is None where the label states a count this reader cannot believe. + """ kind: str - findings: int + findings: int | None title: str text: str @@ -101,8 +105,9 @@ class Unplaced(NamedTuple): class Reading(NamedTuple): """What one body says, in the fields the gate reads. - `open` is the count of open findings the body states, None where it states none. `unthreaded` - is how many findings it names that no thread on the pull request carries. `table` is the + `open` is the count of open findings the body states, None where it states none or one this + reader cannot believe. `unthreaded` is how many findings it names that no thread on the pull + request carries. `table` is the paths the body's file table names, None where it carries no table. `unplaced` is each part the reader cannot place, with its text, the subset of `notes` that can hold a finding. """ @@ -125,12 +130,12 @@ class Reading(NamedTuple): notes: tuple[str, ...] = () unplaced: tuple[Unplaced, ...] = () - def held(self, kind: str) -> int: - """The findings this body holds in sections of `kind`, by the counts their labels state.""" - return sum(s.findings for s in self.sections if s.kind == kind) + def held(self, kind: str) -> int | None: + """The findings in sections of `kind`, by their stated counts, None where one is unbelievable.""" + return total(s.findings for s in self.sections if s.kind == kind) @property - def counts(self) -> dict[str, int]: + def counts(self) -> dict[str, int | None]: """The findings by section: threaded, suppressed, and previously missed.""" return { "threaded": self.open or 0, @@ -192,21 +197,34 @@ 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 total(counts: Iterable[int | None]) -> int | None: + """The sum of `counts`, or None where any of them is a count the reader cannot believe.""" + found = list(counts) + return None if None in found else sum(c or 0 for c in found) + + +def believed(digits: str) -> int | None: + """`digits` as a count, or None where it is longer than COUNT_DIGITS.""" + return int(digits) if len(digits) <= COUNT_DIGITS else 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): + reviewed, changed = believed(got), believed(of) + if reviewed is None or changed is None or reviewed > changed: return "unknown" - return "full" if int(got) == int(of) else "partial" + return "full" if reviewed == changed else "partial" + +def stated(match: re.Match[str]) -> int | None: + """The count a matched label states: its `n` group, zero for a spelled none, one without one. -def stated(match: re.Match[str]) -> int: - """The count a matched label states: its `n` group, zero for a spelled none, one without one.""" + A count longer than COUNT_DIGITS is None, since reading it as zero would report a clean round. + """ value = match.groupdict().get("n") if value is None: return 1 - if value.isdigit(): - return int(value) if len(value) <= COUNT_DIGITS else 0 - return 0 + return believed(value) if value.isdigit() else 0 class _Details: @@ -321,6 +339,11 @@ def unread(note: str, start: int, end: int) -> None: notes.append(note) unplaced.append(Unplaced(note, "\n".join(lines[start:end]).strip())) + def count_of(match: re.Match[str], name: str) -> int | None: + if (count := stated(match)) is None: + notes.append(f"a finding count this reader cannot believe: `{name}`") + return count + html = [t.content for t in tokens if t.type == "html_block"] + [ c.content for t in tokens @@ -375,7 +398,7 @@ def unread(note: str, start: int, end: int) -> None: claimed: list[tuple[int, int]] = [] opaque: list[tuple[int, int]] = [] counted: list[tuple[int, int]] = [] - open_count: int | None = None + opens: list[int | None] = [] entries = linked = 0 for node in found: end = node.end if node.end is not None else len(lines) @@ -402,7 +425,7 @@ def unread(note: str, start: int, end: int) -> None: counted.append((node.start, end + 1)) if kind == "vetted" or any(p.search(summary) for p in vocab["closed_badges"]): continue - count = stated(match) + count = count_of(match, name) content = "\n".join( ln.rstrip() for raw in lines[node.body : end] @@ -410,7 +433,7 @@ def unread(note: str, start: int, end: int) -> None: ) sections.append(Section(kind, count, " ".join(plain(summary).split()), content)) if kind == "open": - open_count = (open_count or 0) + count + opens.append(count) got, links = entries_in(tokens, node.body, end, found, vocab) entries += got linked += sum( @@ -479,7 +502,7 @@ def placed(n: int, t: Token) -> bool: ) ): if found_kind[0] == "open": - open_count = (open_count or 0) + stated(found_kind[1]) + opens.append(count_of(found_kind[1], name)) elif matched(vocab["finding_lists"], name): listed += items_after(tokens, i + 3) elif ( @@ -527,6 +550,7 @@ def placed(n: int, t: Token) -> bool: if coverage == "none" or rank[state] > rank[coverage]: coverage, coverage_line = state, said + open_count = total(opens) if opens else None named = max(open_count or 0, listed) return Reading( coverage=coverage, diff --git a/tests/test_pr_review.py b/tests/test_pr_review.py index 65068395f..a21583659 100755 --- a/tests/test_pr_review.py +++ b/tests/test_pr_review.py @@ -2067,6 +2067,24 @@ def test_a_previously_missed_finding_is_counted_by_round_and_printed(self) -> No self.assertIn("Guard the write.", out) self.assertIn("suppressed=0 (on_head=0 earlier=0)", out) + def test_an_unbelievable_previously_missed_count_tallies_as_unknown(self) -> None: + missed = ( + f"{OVERVIEW}\n
\nPreviously missed (99999)" + "\n\nIn code that has not changed since last review\n\n[P2] Guard the write.\n
" + ) + rounds = [review(oid=OLD, body=missed, rid="A"), review(rid="B")] + self.assertEqual(0, self.status(payload(rounds, files=["a.py"]))) + out = self.out.getvalue() + self.assertIn("previously_missed=? (on_head=0 earlier=?)", out) + self.assertIn("a finding count this reader cannot believe", out) + + def test_an_unbelievable_open_count_reads_unknown_and_holds_the_round(self) -> None: + text = overview_v2(open_count="99999 open findings", entries=0) + self.assertEqual(50, self.status(payload([review(body=text)], files=["a.py"]))) + out = self.out.getvalue() + self.assertIn("overview=?/0 ", out) + self.assertIn("a finding count this reader cannot believe", out) + def test_coderabbit_s_outside_diff_findings_are_its_own_field(self) -> None: cr = { "author": {"login": pr_review.CODERABBIT_LOGIN}, diff --git a/tests/test_pr_review_copilot.py b/tests/test_pr_review_copilot.py index 11b0377ec..b927dcad7 100755 --- a/tests/test_pr_review_copilot.py +++ b/tests/test_pr_review_copilot.py @@ -300,6 +300,17 @@ def test_a_bold_count_line_states_zero(self) -> None: def test_no_count_reads_as_none_rather_than_zero(self) -> None: self.assertIsNone(adapter.read(body()).open) + def test_an_oversized_count_reads_as_none_and_is_noted(self) -> None: + for sections in ( + open_section("99999 open findings"), + "**99999 open findings**", + f"{open_section('1 open issue', ('101',))}\n\n**99999 open findings**", + ): + with self.subTest(sections=sections): + found = adapter.read(body(sections=sections)) + self.assertIsNone(found.open) + self.assertTrue(any("cannot believe" in n for n in found.notes), found.notes) + def test_an_entry_linking_no_thread_on_the_pull_request_is_unthreaded(self) -> None: found = adapter.read(body(sections=open_section()), threads=("101",)) self.assertEqual(1, found.unthreaded) @@ -346,6 +357,18 @@ def test_suppressed_in_both_spellings(self) -> None: 2, adapter.read(body(sections=collapsed(label))).counts["suppressed"] ) + def test_an_unbelievable_section_count_is_none_beside_a_believed_open_count(self) -> None: + for label, kind in ( + ("Comments suppressed due to low confidence (99999)", "suppressed"), + ("Previously missed (99999)", "previously_missed"), + ): + with self.subTest(label=label): + sections = f"{open_section('1 open issue', ('101',))}\n\n{collapsed(label)}" + found = adapter.read(body(sections=sections)) + self.assertIsNone(found.counts[kind]) + self.assertEqual(1, found.open) + self.assertTrue(any("cannot believe" in n for n in found.notes), found.notes) + def test_a_resolved_section_counts_nothing(self) -> None: resolved = open_section("3 resolved since last review", ("1", "2", "3")) found = adapter.read(body(sections=resolved))