Answer stability round 2: 0 🔴, 1 🟡 (0 misread); run two looped tests under subTest, refuse a blocker that is no issue key, and test the page cap, the four conversions at once and the search's failure messages

This commit is contained in:
2026-11-14 19:50:47 +01:00
parent 4e0e7e655d
commit 98c28cc244
5 changed files with 37 additions and 10 deletions
+2 -2
View File
@@ -150,8 +150,8 @@ def issue_of(raw: object) -> Issue | Failure:
issue = Issue(key, fields["summary"].strip(), fields["description"], tuple(version["name"] for version in fields["fixVersions"]), blockers, typing.cast(dict[str, typing.Any], raw).get("properties", {}).get(PROPERTY, {}))
except (AttributeError, KeyError, TypeError) as failure:
return Failure(f"{key} is not in the shape Jira Cloud's REST API version 3 documents: {failure!r}")
if not isinstance(issue.description, dict | None) or not all(isinstance(name, str) for name in issue.fix_versions + issue.blockers):
return Failure(f"{key} is not in the shape Jira Cloud's REST API version 3 documents: its description, a Fix Version's name or a linked issue's key is of another type")
if not isinstance(issue.description, dict | None) or not all(isinstance(name, str) for name in issue.fix_versions + issue.blockers) or not all(ISSUE_KEY.fullmatch(blocker) for blocker in issue.blockers):
return Failure(f"{key} is not in the shape Jira Cloud's REST API version 3 documents: its description, a Fix Version's name or a linked issue's key holds another kind of value")
return issue
+29 -4
View File
@@ -2,6 +2,8 @@ import base64
import pathlib
import sys
import tempfile
import threading
import time
import unittest
import unittest.mock
@@ -107,7 +109,8 @@ class JiraPlan(unittest.TestCase):
bare = issue("ABC-35")
del bare["properties"]
for item in self.items(issue("ABC-34"), bare):
self.assertEqual((item.scores, item.moves, item.exempt, item.detail, item.likelihood), ({}, (), "", "", 0))
with self.subTest(item=item.id):
self.assertEqual((item.scores, item.moves, item.exempt, item.detail, item.likelihood), ({}, (), "", "", 0))
def test_an_issue_is_blocked_by_each_blocker_still_in_the_plan(self):
blocked, _ = self.items(issue("ABC-34", blocked_by=("ABC-35", "ABC-2", "OTHER-9"), blocks=("ABC-35",)), issue("ABC-35", blocks=("ABC-34",)))
@@ -153,14 +156,36 @@ class JiraPlan(unittest.TestCase):
self.assertEqual(self.store().read(), Failure("POST /rest/api/3/search/jql answered 401: no"))
def test_an_answer_in_another_shape_fails_the_read(self):
for page in ([], {"issues": "none"}, {"issues": ["ABC-1"]}, {"issues": [{"key": 7, "fields": {}}]}, {"issues": [{"key": "abc", "fields": {}}]}):
no_page, no_key = "the search answered something other than a page of issues", "the search answered an issue without an issue key"
for page, reason in (([], no_page), ({"issues": "none"}, no_page), ({"issues": ["ABC-1"]}, no_key), ({"issues": [{"key": 7, "fields": {}}]}, no_key), ({"issues": [{"key": "abc", "fields": {}}]}, no_key)):
with self.subTest(page=page):
self.pages, self.calls = [page], []
self.assertIsInstance(self.store().read(), Failure)
self.assertEqual(self.store().read(), Failure(reason))
def test_a_search_that_never_names_a_last_page_fails_the_read(self):
self.pages = [{"issues": [], "nextPageToken": "more"}] * 2
with unittest.mock.patch.object(jira_epic, "MAX_PAGES", 2):
self.assertEqual(self.store().read(), Failure("the search for ABC-12's children did not end within 2 pages"))
def test_converts_at_most_four_descriptions_at_once(self):
lock, running, most = threading.Lock(), [0], [0]
def slow(document: dict[str, object]) -> str:
with lock:
running[0] += 1
most[0] = max(most[0], running[0])
time.sleep(0.02)
with lock:
running[0] -= 1
return "text"
self.pages = [{"issues": [issue(f"ABC-{number}", description=adf("Why.")) for number in range(1, 41)]}]
self.assertIsInstance(jira_epic.JiraPlan(EPIC, self.env, self.http, slow).read(), Plan)
self.assertLessEqual(most[0], 4)
def test_an_issue_in_another_shape_fails_the_read_naming_it(self):
good = issue("ABC-1")
for wrong in ({"key": "ABC-1"}, issue("ABC-1", summary=None), issue("ABC-1", description="text"), good | {"fields": good["fields"] | {"fixVersions": [{"name": 7}]}}, good | {"fields": good["fields"] | {"issuelinks": [{"type": {"inward": "is blocked by"}, "inwardIssue": {"key": 7}}]}}, good | {"properties": None}): # type: ignore[arg-type, operator]
for wrong in ({"key": "ABC-1"}, issue("ABC-1", summary=None), issue("ABC-1", description="text"), good | {"fields": good["fields"] | {"fixVersions": [{"name": 7}]}}, good | {"fields": good["fields"] | {"issuelinks": [{"type": {"inward": "is blocked by"}, "inwardIssue": {"key": 7}}]}}, good | {"fields": good["fields"] | {"issuelinks": [{"type": {"inward": "is blocked by"}, "inwardIssue": {"key": "ABC-x"}}]}}, good | {"properties": None}): # type: ignore[arg-type, operator]
with self.subTest(wrong=wrong):
failure = self.read(wrong) # type: ignore[arg-type]
self.assertIsInstance(failure, Failure)
+2 -2
View File
@@ -107,9 +107,9 @@ class LoadTest(ConfigCase):
self.assertIn("`plan` names a Jira epic, so `env-file` must name the file that holds its credentials", self.failure())
def test_a_plan_that_spells_no_path_and_no_epic_names_both_spellings(self) -> None:
for spelled in ("jira:http://acme.atlassian.net/browse/ABC-12", "jira:https://acme.atlassian.net/browse/abc-12", "jira:https://acme.atlassian.net/browse/ABC-12/x", "jira:https://acme.atlassian.net@evil.example/browse/ABC-12", "jira:ABC-12", "https://acme.atlassian.net/browse/ABC-12"):
for count, spelled in enumerate(("jira:http://acme.atlassian.net/browse/ABC-12", "jira:https://acme.atlassian.net/browse/abc-12", "jira:https://acme.atlassian.net/browse/ABC-12/x", "jira:https://acme.atlassian.net@evil.example/browse/ABC-12", "jira:ABC-12", "https://acme.atlassian.net/browse/ABC-12")):
with self.subTest(spelled):
self.write(f"acme-{len(spelled)}-{hash(spelled) % 1000}", CLIENT.replace("folder:todo.md", spelled) + 'env-file = "~/acme.env"\n')
self.write(f"acme-{count}", CLIENT.replace("folder:todo.md", spelled) + 'env-file = "~/acme.env"\n')
reason = self.failure()
self.assertIn(f"`plan` is {spelled!r}, not ", reason)
self.assertIn("jira:https://<site>/browse/<epic's key>", reason)
+1 -1
View File
@@ -43,7 +43,7 @@ class ReadEnv(unittest.TestCase):
self.assertTrue(isinstance(failed, Failure) and failed.reason.startswith(f"cannot read {self.path}: "), failed)
def test_parses_quotes_comments_and_spaces(self):
self.assertEqual(parse_env("# note\nA = 1 \nB=\"two words\"\nC='3'\nnot a pair\n#D=4\nE=a=b\n"), {"A": "1", "B": "two words", "C": "3", "E": "a=b"})
self.assertEqual(parse_env("# note\nA = 1 \nB=\"two words\"\nC='3'\nnot a pair\n#D=4\nE=a=b\nF=\"\"\nG='\n"), {"A": "1", "B": "two words", "C": "3", "E": "a=b", "F": "", "G": "'"})
if __name__ == "__main__":
+3 -1
View File
@@ -109,7 +109,9 @@ class HttpJson(unittest.TestCase):
self.server.server_close()
failed = send("GET", f"{base}/api/v4/users/me", "t", None)
self.assertIsInstance(failed, Failure)
self.assertTrue(str(getattr(failed, "reason", "")).startswith(f"cannot reach {base}: "), failed)
reason = str(getattr(failed, "reason", ""))
self.assertTrue(reason.startswith(f"cannot reach {base}: "), failed)
self.assertNotIn("urlopen", reason)
def test_an_error_whose_body_is_not_json_names_the_status_alone(self):
base = self.serve((403, b"<html>"))