Answer stability round 1: 2 🔴, 5 🟡 (0 misread); fixed the import order and the unused return, tested the scenario steps offline, passed env and timeout in, reused the paged search

This commit is contained in:
2026-11-19 04:52:10 +01:00
parent 6ee55681a3
commit 587363c3ed
7 changed files with 255 additions and 59 deletions
+13 -3
View File
@@ -20,6 +20,7 @@ class JiraStub:
self.bodies: list[object] = []
self.refuses = refuses
self.search_answer: object = {"issues": [{"key": "SBX-2"}, {"key": "SBX-3"}]}
self.later_pages: list[object] = []
def __call__(self, method: str, url: str, authorization: str, body: object) -> object:
self.requests.append((method, url.split("/rest/api/3/")[1]))
@@ -30,7 +31,7 @@ class JiraStub:
if method == "POST" and url.endswith("/issue"):
return {"key": "SBX-1"}
if method == "POST":
return self.search_answer
return self.later_pages.pop(0) if self.later_pages and isinstance(body, dict) and "nextPageToken" in body else self.search_answer
return None
@@ -56,6 +57,15 @@ class EpicMadeTest(unittest.TestCase):
("DELETE", "issue/SBX-1?deleteSubtasks=true"),
])
def test_deletes_the_children_on_every_page_of_the_search(self) -> None:
jira = JiraStub()
jira.search_answer = {"issues": [{"key": "SBX-2"}], "nextPageToken": "more"}
jira.later_pages = [{"issues": [{"key": "SBX-3"}]}]
with epic_made(self.sandbox, "An epic", jira, lambda markdown: {"type": "doc"}):
pass
self.assertEqual(jira.bodies[2], {"jql": "parent = SBX-1", "fields": ["summary"], "maxResults": 100, "nextPageToken": "more"})
self.assertEqual([url for method, url in jira.requests if method == "DELETE"], [f"issue/SBX-{n}?deleteSubtasks=true" for n in (2, 3, 1)])
def test_deletes_them_when_the_block_raises(self) -> None:
jira = JiraStub()
with self.assertRaises(ZeroDivisionError):
@@ -75,7 +85,7 @@ class EpicMadeTest(unittest.TestCase):
with self.assertRaises(Leftover) as left:
with epic_made(self.sandbox, "An epic", jira, lambda markdown: {"type": "doc"}):
pass
self.assertIn("holds no issues", str(left.exception))
self.assertIn("something other than a page of issues", str(left.exception))
self.assertEqual(jira.requests[1:], [("POST", "search/jql"), ("DELETE", "issue/SBX-1?deleteSubtasks=true")])
def test_deletes_the_epic_all_the_same_and_gives_the_reason_when_the_search_for_its_issues_is_refused(self) -> None:
@@ -84,7 +94,7 @@ class EpicMadeTest(unittest.TestCase):
with epic_made(self.sandbox, "An epic", jira, lambda markdown: {"type": "doc"}):
pass
self.assertIn("POST https://acme.atlassian.net/rest/api/3/search/jql answered 403", str(left.exception))
self.assertNotIn("holds no issues", str(left.exception))
self.assertNotIn("something other than a page of issues", str(left.exception))
self.assertEqual(jira.requests[1:], [("POST", "search/jql"), ("DELETE", "issue/SBX-1?deleteSubtasks=true")])
def test_yields_a_failure_and_deletes_nothing_when_the_epic_cannot_be_made(self) -> None: