Kill the mutants that survived on the epic branch's changed lines
CI / tests (pull_request) Successful in 3m45s

This commit is contained in:
Lilleman
2026-11-20 20:47:46 +01:00
parent e3a964a73f
commit 525f3f8836
9 changed files with 187 additions and 8 deletions
+12
View File
@@ -51,6 +51,18 @@ class Failing(unittest.TestCase):
self.assertEqual(MemoryEpic("ABC-12", fails="Jira is down").start_issue("ABC-100"), Failure("Jira is down"))
self.assertEqual(MemoryEpic("ABC-12").start_issue("ABC-100"), Failure("ABC-100 is not one of the child issues of the epic ABC-12, so it cannot be started"))
def test_a_move_fails_with_the_reason_given_and_one_outside_the_epic_says_so(self) -> None:
self.assertEqual(MemoryEpic("ABC-12", fails="Jira is down").move_issue("ABC-100", "Done"), Failure("Jira is down"))
self.assertEqual(MemoryEpic("ABC-12").move_issue("ABC-100", "Done"), Failure("ABC-100 is not one of the child issues of the epic ABC-12, so it cannot be moved"))
class Moving(unittest.TestCase):
def test_an_issue_moved_to_done_in_any_case_reads_as_done_and_one_moved_elsewhere_as_open(self) -> None:
store = MemoryEpic("ABC-12")
done, review = store.file("ABC-12", "Count the runs.", "", ()), store.file("ABC-12", "Ship the later thing.", "", ())
self.assertEqual([store.move_issue(done, "DONE"), store.move_issue(review, "Code Review")], [None, None])
self.assertEqual({issue.key: (issue.status, issue.done) for issue in store.issues}, {done: ("DONE", True), review: ("Code Review", False)})
class Blocking(unittest.TestCase):
def test_refuses_a_blocker_that_is_an_issue_of_another_epic(self) -> None:
+18
View File
@@ -411,6 +411,8 @@ class Jira(Case):
store = self.new_store()
key = store.file("ABC-12", "Count the runs.", "", ())
self.assertEqual(store.move_issue(key, "Code Review"), Failure(f"{key} has no transition to the status 'Code Review' from its status 'To Do', only 'Mark as done' to 'Done'"))
self.jira.workflow.append({"id": "11", "name": "Start", "to": {"name": "In Progress", "statusCategory": {"key": "indeterminate"}}})
self.assertEqual(store.move_issue(key, "Code Review"), Failure(f"{key} has no transition to the status 'Code Review' from its status 'To Do', only 'Mark as done' to 'Done' and 'Start' to 'In Progress'"))
self.jira.workflow = []
self.assertEqual(store.move_issue(key, "Code Review"), Failure(f"{key} has no transition to the status 'Code Review' from its status 'To Do', nor any other the account may make"))
self.assertEqual(self.jira.transitioned, [])
@@ -419,7 +421,10 @@ class Jira(Case):
store = self.new_store()
key = store.file("ABC-12", "Count the runs.", "", ())
transitions = f"{ISSUES}/{key}/transitions"
status = f"{ISSUES}/{key}?fields=status"
for answers, reason in (
({("GET", status): Failure("Jira answered 503")}, f"cannot read {key} to move it: Jira answered 503"),
({("GET", status): {"key": key, "fields": {}}}, f"{key} is not in the shape Jira Cloud's REST API version 3 documents: KeyError('status')"),
({("GET", transitions): Failure("Jira answered 503")}, f"cannot read {key}'s transitions: Jira answered 503"),
({("GET", transitions): {"transitions": [{"id": "21"}]}}, f"Jira answered {key}'s transitions in a shape other than the one it documents"),
({("POST", transitions): Failure("Jira answered 400")}, f"cannot move {key} to 'Done': Jira answered 400"),
@@ -428,6 +433,19 @@ class Jira(Case):
self.jira.answers = answers
self.assertEqual(store.move_issue(key, "Done"), Failure(reason))
def test_a_move_says_which_issue_jira_cannot_read_and_refuses_one_outside_the_epic(self) -> None:
store = self.new_store()
child = store.file("ABC-12", "Count the runs.", "", ())
task = store.file(child, "Count them in the api.", "", ())
self.jira.issues.append({"key": "ABC-61", "fields": {"summary": "Other.", "description": None, "labels": [], "assignee": None, "status": TO_DO, "parent": None, "issuelinks": []}})
self.assertEqual(store.move_issue("ABC-61", "Done"), Failure("ABC-61 is not one of the child issues of the epic ABC-12, so it cannot be moved"))
self.jira.answers[("GET", f"{ISSUES}/{task}?fields=parent,status")] = Failure("Jira answered 503")
self.assertEqual(store.move_issue(task, "Done"), Failure(f"cannot read {task} to move it: Jira answered 503"))
del self.jira.answers[("GET", f"{ISSUES}/{task}?fields=parent,status")]
self.jira.answers[("GET", f"{ISSUES}/{child}?fields=parent,status")] = Failure("Jira answered 503")
self.assertEqual(store.move_issue(task, "Done"), Failure(f"cannot read {child} to move its sub-task: Jira answered 503"))
self.assertEqual(self.jira.transitioned, [])
def test_finishes_an_issue_by_the_transition_the_settings_name(self) -> None:
store = self.new_store()
key = store.file("ABC-12", "Count the runs.", "", ())
+1 -1
View File
@@ -170,7 +170,7 @@ class ConfigTest(unittest.TestCase):
def test_refuses_a_pull_request_status_that_is_no_name_and_a_merged_one_that_does_not_unblock(self) -> None:
self.write(SETTINGS + 'jira-pull-request-open-status = " "\njira-pull-request-merged-status = 5\n')
self.assertIn("`jira-pull-request-open-status` is ' ', not the name Jira shows, such as \"Code Review\"; `jira-pull-request-merged-status` is 5, not the name Jira shows, such as \"Release Ready\"", self.failure())
for unblocking in ("", 'jira-unblocking-statuses = ["Shipped"]\n'):
for unblocking in ("", 'jira-unblocking-statuses = ["Shipped"]\n', "jira-unblocking-statuses = 5\n"):
with self.subTest(unblocking=unblocking):
self.write(SETTINGS + unblocking + 'jira-pull-request-merged-status = "Release Ready"\n')
self.assertIn("`jira-pull-request-merged-status` is 'Release Ready', so `jira-unblocking-statuses` must list it: an issue at any other status reads as open, and its chunk would start again", self.failure())
+67
View File
@@ -1000,6 +1000,19 @@ class StepwiseStore:
return self.store.move_issue(key, status)
class LaggingStore:
"""A store whose every read answers `read`, as a search that doesn't show the latest move yet; every other call is the wrapped store's."""
def __init__(self, store: typing.Any, read: typing.Any) -> None:
self.store, self.answer = store, read
def __getattr__(self, name: str) -> typing.Any:
return getattr(self.store, name)
def read(self) -> typing.Any:
return self.answer
class AnEpicsWorkingBranch(DoEpicTest):
"""A chunk in a repo whose config sets `epic-branch`, so its pull request goes into the branch ABC-12."""
@@ -1033,6 +1046,19 @@ class AnEpicsWorkingBranch(DoEpicTest):
self.assertEqual(self.git_calls, [(args, self.checkout) for args in (("symbolic-ref", "--short", "refs/remotes/origin/HEAD"), ("fetch", "--quiet", "origin"), ("rev-parse", "--quiet", "--verify", "refs/remotes/origin/ABC-12"), ("rev-list", "--count", "origin/ABC-12..origin/main"), ("config", "branch.ABC-20.chunk-base", "ABC-12"))])
self.assertIn("origin/ABC-12 already holds origin/main; ABC-20's pull request goes into ABC-12\n", out.getvalue())
def test_says_the_default_branchs_whole_name_however_it_ends(self) -> None:
out = io.StringIO()
with contextlib.redirect_stdout(out):
main.epic_based("ABC-20", self.checkout, self.epic_run(self.with_git(FakeEffects(), symbolic_ref="origin/BOX\n")))
self.assertIn("origin/ABC-12 already holds origin/BOX; ABC-20's pull request goes into ABC-12\n", out.getvalue())
def test_a_folder_no_checkout_holds_stops_with_the_reason_its_config_cannot_be_found(self) -> None:
elsewhere = self.home / "elsewhere"
elsewhere.mkdir()
unnamed = main.config_located(str(elsewhere), self.home)
assert isinstance(unnamed, Failure), unnamed
self.assertEqual(main.epic_based("ABC-20", str(elsewhere), self.epic_run(self.with_git(FakeEffects()))), main.Stop(1, unnamed.reason))
def test_a_repo_whose_config_sets_no_epic_branch_has_none_and_runs_no_git(self) -> None:
self.repo_config.write_text(self.repo_config.read_text(encoding="utf-8").replace('epic-branch = "{epic}"\n', ""), encoding="utf-8")
self.assertIsNone(main.epic_based("ABC-20", self.checkout, self.epic_run(self.with_git(FakeEffects()))))
@@ -1069,6 +1095,47 @@ class AnEpicsWorkingBranch(DoEpicTest):
self.assertIn("parked: pull request #7 awaits an approval\n", out)
self.assertIn("the chunk finished; started ABC-22\n", out)
self.assertIn("The chunk's pull request goes into the epic's working branch `ABC-12`", prompts[0])
self.assertIn(("config", "branch.ABC-20.chunk-base", "ABC-12"), [args for args, _ in self.git_calls])
def test_an_issue_that_cannot_move_to_the_open_status_says_so_and_its_chunk_goes_on(self) -> None:
self.settings('jira-unblocking-statuses = ["Release Ready"]\njira-pull-request-open-status = "Code Review"\njira-pull-request-merged-status = "Release Ready"\n')
self.backend = lambda config, key: (StepwiseStore(self.store, {"Code Review": "QA"}), EpicRecord(Description(self.description))) # type: ignore[method-assign,arg-type]
self.forges = [awaiting(), awaiting(), awaiting(decision="APPROVED")]
fake = self.with_git(FakeEffects(streams=[self.worker(), self.worker()], claude=[judged("finished"), judged("finished")], windows=PARKED_WINDOW))
code, out, err = self.run_main(["--chunk", "ABC-20", "ABC-12"], fake, MODELS)
self.assertEqual(code, 0, err)
self.assertIn("ABC-20 did not move to 'Code Review' though its pull request is open: ABC-20 has no transition to 'Code Review' from its status 'To Do'\n", out)
def test_a_finished_chunk_whose_issue_has_no_pull_request_into_the_epic_branch_moves_it_to_done(self) -> None:
self.settings('jira-unblocking-statuses = ["Release Ready"]\njira-pull-request-merged-status = "Release Ready"\n')
with contextlib.redirect_stdout(io.StringIO()):
self.assertEqual(main.handed_on("ABC-20", self.epic_run(FakeEffects(windows="")), humans=True).code, 0)
self.assertEqual((self.store.issues[0].status, self.store.issues[0].done), ("Done", True))
# A chunk not marked as in a repo moves its issue to done itself, even where the automation moves issues.
self.settings('jira-unblocking-statuses = ["Release Ready"]\njira-automation-moves-issues = true\n')
self.store.change("ABC-22", status="Release Ready")
with contextlib.redirect_stdout(io.StringIO()):
self.assertEqual(main.handed_on("ABC-22", self.epic_run(FakeEffects(windows=""))).code, 0)
self.assertEqual((self.store.issues[1].status, self.store.issues[1].done), ("Done", True))
def test_a_read_that_does_not_show_the_move_yet_still_counts_the_issue_moved(self) -> None:
self.settings('jira-unblocking-statuses = ["Release Ready"]\njira-pull-request-merged-status = "Release Ready"\n')
before = self.store.read()
lagging = LaggingStore(self.store, before)
out = io.StringIO()
with contextlib.redirect_stdout(out):
stop = main.handed_on("ABC-20", dataclasses.replace(self.epic_run(FakeEffects(windows="")), store=lagging), in_repo=True, to_epic_branch=True)
self.assertEqual(stop.code, 0, stop.reason)
self.assertIn("the chunk finished; started ABC-22\n", out.getvalue())
unread = LaggingStore(self.store, Failure("Jira answered 503"))
stop = main.handed_on("ABC-22", dataclasses.replace(self.epic_run(FakeEffects(windows="")), store=unread), in_repo=True, to_epic_branch=True)
self.assertEqual(stop, main.Stop(1, "the chunk finished, but the next could not start: Jira answered 503"))
def test_the_epics_finishing_is_due_once_every_issue_has_the_merged_status(self) -> None:
self.settings('jira-unblocking-statuses = ["Release Ready"]\njira-pull-request-merged-status = "Release Ready"\n')
for each in ("ABC-20", "ABC-22"):
self.store.change(each, status="Release Ready")
self.assertIsInstance(main.chunk_work("ABC-12", None, "English", self.epic_run(FakeEffects())), tuple)
def test_without_a_merged_status_a_finished_chunk_stops_where_automation_moves_issues_and_is_done_where_it_doesnt(self) -> None:
self.settings('jira-unblocking-statuses = ["Release Ready"]\njira-automation-moves-issues = true\n')
+6 -3
View File
@@ -470,18 +470,21 @@ class TheFirstPrompt(unittest.TestCase):
task = chunk_prompt.task(issue("ABC-20"), "ABC-12", {}, "/code/api", pathlib.Path("/b/do-epic"), "Swedish", config)
self.assertIn("The chunk's pull request goes into the epic's working branch `epic/ABC-12`, not into the default branch", task)
self.assertIn("make the chunk's worktree and branch off `origin/epic/ABC-12`", task)
self.assertIn("`chunk-pr merge` merges into `epic/ABC-12` without waiting for a person", task)
self.assertIn("`chunk-pr merge` merges into `epic/ABC-12` without waiting for a person. Where the chunk's tests run", task)
self.assertNotIn("leaves the pull request ready for a person to merge", task)
self.assertIn("Where the chunk's tests run other repos of the epic, run each at its branch `epic/ABC-12` where it has one, else at its default branch, and name in the chunk's summary each repo that ran at its default branch.", task)
self.assertNotIn("chunk-pr push", task)
self.assertIn(f"{chunk_prompt.shipping(config)} {chunk_prompt.epic_branch_rule(config, 'ABC-12')} Its summary: ", task)
def test_a_repo_whose_reviewer_is_asked_by_a_comment_is_told_to_push_with_chunk_pr(self) -> None:
config = dataclasses.replace(CONFIG, epic_branch="{epic}", review_request_comment="@reviewbot review")
task = chunk_prompt.task(issue("ABC-20"), "ABC-12", {}, "/code/api", pathlib.Path("/b/do-epic"), "Swedish", config)
self.assertIn("After `chunk-pr ready`, push each commit with `chunk-pr push`, which asks the repo's auto-reviewer to review the new head, and wait for that review.", task)
self.assertIn("`chunk-pr merge` merges into `ABC-12` without waiting for a person. After `chunk-pr ready`, push each commit with `chunk-pr push`, which asks the repo's auto-reviewer to review the new head, and wait for that review. Where the chunk's tests run", task)
def test_a_repo_without_an_epic_branch_is_told_nothing_of_one(self) -> None:
task = chunk_prompt.task(issue("ABC-20"), "ABC-12", {}, "/code/api", pathlib.Path("/b/do-epic"), "Swedish", dataclasses.replace(CONFIG, merge="human"))
config = dataclasses.replace(CONFIG, merge="human")
task = chunk_prompt.task(issue("ABC-20"), "ABC-12", {}, "/code/api", pathlib.Path("/b/do-epic"), "Swedish", config)
self.assertEqual(chunk_prompt.epic_branch_rule(config, "ABC-12"), "")
self.assertNotIn("working branch", task)
self.assertIn("leaves the pull request ready for a person to merge", task)