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
7 changes: 3 additions & 4 deletions scripts/pr_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,16 +843,15 @@ def digest(
checks = check_nodes(pr) if checks is None else checks
refusal = digest_refusal(pr)
quota = confirmed_quota(owner, repo, refusal) if refusal else ""
out, unresolved = render(
owner, repo, num, pr, checks, now, grace, stall, quota, seen, HUB, WINDOW
)
reading = ""
if refusal and possible_quota(refusal) and not quota:
reading = run_log_reading(*transient_state(owner, repo, num, pr, refusal)) or (
" RUN LOG READING: possible quota. The run log was unread or names neither a rate "
"limit nor a transient fetch failure"
)
return (f"{out}\n{reading}" if reading else out), unresolved
return render(
owner, repo, num, pr, checks, now, grace, stall, quota, reading, seen, HUB, WINDOW
)


def report_verdict(pr: dict) -> int:
Expand Down
10 changes: 7 additions & 3 deletions scripts/pr_review_digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,16 @@ def render(
grace: float,
stall: float,
quota: str,
run_log: str,
seen: set[str] | None,
hub: str,
window: int,
) -> tuple[str, int]:
"""Render the digest and return it with the unresolved count.

`quota` is the run log's rate-limit sentence for the refusal `digest_refusal` names, read by the
caller. Where `seen` is a set, only threads absent from it print, marked new, and are added.
caller. `run_log` is the caller's `RUN LOG READING` line for that refusal, empty for none.
Where `seen` is a set, only threads absent from it print, marked new, and are added.
"""
head = pr["headRefOid"]
revs = reviewer_nodes(pr, "reviews")
Expand Down Expand Up @@ -213,14 +215,16 @@ def render(
if refusal:
lines.append(
" COPILOT REFUSED THIS ROUND: the newest Copilot review on this pull request says "
"it did not review, so it covers nothing and re-requesting repeats it, and the body "
"below is what says which remedy applies"
"it did not review, so it covers nothing. The body below says which remedy applies, "
"and any run log line under it says whether a re-request is owed"
)
lines += [
f" {ln.rstrip()}" for ln in (refusal.get("body") or "").splitlines() if ln.strip()
]
if quota:
lines.append(f" RATE LIMIT FROM THE REVIEWER'S RUN LOG: {quota}")
if run_log:
lines.append(run_log)
if notes:
lines.append(
f" REVIEWER OUTPUT NOTED ({len(notes)}): the reader placed part of what the reviewer "
Expand Down
34 changes: 34 additions & 0 deletions tests/test_pr_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -4719,6 +4719,40 @@ def test_the_digest_names_the_run_log_reading_it_took(self) -> None:
else:
self.assertIn(line, out)

def test_the_run_log_line_sits_inside_the_refusal_block_for_either_reading(self) -> None:
"""A line printed after the block reads as advice of its own, apart from the refusal.

An open thread prints after the block, so a line appended to the digest's end lands past it.
Only the refusal's own body, indented under the marker, may sit between the two.
"""
open_thread = [thread("PRRT_after", login="someone", body="A finding after the block.")]
for body, log, field, want in (
(ERROR_REFUSED, TRANSIENT_LOG, "refusal=ERROR", " RUN LOG READING: transient."),
(ERROR_REFUSED, None, "refusal=ERROR", " RUN LOG READING: possible quota."),
(ERROR_REFUSED, RATE_LIMIT_LOG, "refusal=QUOTA", " RATE LIMIT FROM THE REVIEWER'S"),
(QUOTA_REFUSED, None, "refusal=QUOTA", None),
(REFUSED, None, "refusal=YES", None),
):
with self.subTest(field=field, want=want):
pr_review.run_cause.cache_clear()
self.answer(payload([review(body=body, at=LATE)], threads=open_thread))
self.wire_history([], RECORDED)
self.run_log(log)
out, _ = pr_review.digest("o", "r", 7)
self.assertIn(field, out)
self.assertNotIn("re-requesting repeats it", out)
self.assertIn("The body below says which remedy applies", out)
lines = out.splitlines()
start = next(i for i, ln in enumerate(lines) if "COPILOT REFUSED" in ln)
after = next(i for i, ln in enumerate(lines) if "PRRT_after" in ln)
if want is None:
self.assertNotIn("RUN LOG READING", out)
self.assertNotIn("RATE LIMIT FROM THE REVIEWER'S RUN LOG", out)
continue
at = next(i for i, ln in enumerate(lines) if ln.startswith(want))
self.assertTrue(all(ln.startswith(" ") for ln in lines[start + 1 : at]))
self.assertLess(at, after)


class TestCopilotHistoryReadings(GqlCase):
"""The readings built from the reviewer's own review history across the repository."""
Expand Down
Loading