Answer stability round 1: 0 🔴, 4 🟡 (0 misread); a cycle's close takes the task from the cycle, a resolved thread is skipped unread, and tests run git in their own environment
CI / tests (pull_request) Successful in 3m56s

This commit is contained in:
2026-11-19 14:04:11 +01:00
parent aafe75e16f
commit 914b8dc2d4
19 changed files with 143 additions and 87 deletions
+12 -7
View File
@@ -148,15 +148,14 @@ def waiting_threads(number: str, run: Run) -> list[str] | Failure:
@dataclasses.dataclass(frozen=True)
class Thread:
"""One review thread of a pull request."""
"""One review thread of a pull request that nobody resolved."""
path: str
resolved: bool
# Who wrote its last comment; empty for a thread without one.
last: tuple[str, ...]
def threads_read(printed: str) -> tuple[str, tuple[Thread, ...]] | Failure:
"""Who opened the pull request and its review threads, as gh printed THREADS' answer, with each field checked here."""
"""Who opened the pull request and its review threads that nobody resolved, as gh printed THREADS' answer, with each field checked here."""
unshaped = Failure(f"gh api graphql printed no review threads: {printed.strip()[:200]}")
try:
pull = held(json.loads(printed), "data", "repository", "pullRequest")
@@ -167,16 +166,22 @@ def threads_read(printed: str) -> tuple[str, tuple[Thread, ...]] | Failure:
return unshaped
threads = []
for thread in nodes:
path, resolved, comments = held(thread, "path"), held(thread, "isResolved"), held(thread, "comments", "nodes")
if not isinstance(path, str) or resolved is MISSING or not isinstance(comments, list):
resolved = held(thread, "isResolved")
if resolved is MISSING:
return unshaped
# A resolved thread is skipped unread: its last comment may be a deleted account's, whose author gh prints as null.
if resolved:
continue
path, comments = held(thread, "path"), held(thread, "comments", "nodes")
if not isinstance(path, str) or not isinstance(comments, list):
return unshaped
last = tuple(login for comment in comments if isinstance(login := held(comment, "author", "login"), str))
if len(last) != len(comments):
return unshaped
threads.append(Thread(path, bool(resolved), last))
threads.append(Thread(path, last))
return author, tuple(threads)
def waits(author: str, threads: tuple[Thread, ...]) -> list[str]:
"""The files of the threads that wait for an answer from author, who opened the pull request."""
return sorted({thread.path for thread in threads if not thread.resolved and any(last != author for last in thread.last)})
return sorted({thread.path for thread in threads if any(last != author for last in thread.last)})
+14 -2
View File
@@ -77,8 +77,20 @@ class TheThreadsThatWait(unittest.TestCase):
nodes = [{"isResolved": resolved, "path": path, "comments": {"nodes": [{"author": {"login": last}}]}} for path, resolved, last in threads]
return json.dumps({"data": {"repository": {"pullRequest": {"author": {"login": "me"}, "reviewThreads": {"nodes": nodes}}}}})
def test_parses_what_gh_prints_into_the_author_and_each_thread(self):
self.assertEqual(reviews.threads_read(self.printed(("a.py", False, "rev"), ("b.py", True, "me"))), ("me", (Thread("a.py", False, ("rev",)), Thread("b.py", True, ("me",)))))
def test_parses_what_gh_prints_into_the_author_and_each_thread_nobody_resolved(self):
self.assertEqual(reviews.threads_read(self.printed(("a.py", False, "rev"), ("b.py", True, "me"), ("c.py", False, "me"))), ("me", (Thread("a.py", ("rev",)), Thread("c.py", ("me",)))))
def pull_with(self, *nodes: dict[str, object]) -> str:
return json.dumps({"data": {"repository": {"pullRequest": {"author": {"login": "me"}, "reviewThreads": {"nodes": nodes}}}}})
def test_skips_a_resolved_thread_unread_so_a_deleted_accounts_comment_there_doesnt_fail_the_read(self):
deleted = {"comments": {"nodes": [{"author": None}]}}
printed = self.pull_with({"isResolved": True, "path": "b.py", **deleted}, {"isResolved": True}, {"isResolved": False, "path": "a.py", "comments": {"nodes": [{"author": {"login": "rev"}}]}})
self.assertEqual(reviews.waiting_threads("7", lambda args: printed), ["a.py"])
def test_a_deleted_accounts_last_word_in_a_thread_nobody_resolved_is_a_failure(self):
printed = self.pull_with({"isResolved": False, "path": "a.py", "comments": {"nodes": [{"author": None}]}})
self.assertEqual(reviews.waiting_threads("7", lambda args: printed), Failure(f"gh api graphql printed no review threads: {printed[:200]}"))
def test_a_thread_waits_while_unresolved_with_a_reviewers_last_word(self):
printed = self.printed(("b.py", False, "rev"), ("a.py", False, "rev"), ("a.py", False, "rev"), ("c.py", True, "rev"), ("d.py", False, "me"))