Answer stability round 1: 0 🔴, 1 🟡 (0 misread); split the re-rank into the pure rank_moves, rank only just before, as the item says, and name ranking in the README and the protocol

This commit is contained in:
2026-11-18 19:56:29 +01:00
parent 7bd192735a
commit ddce0f2cb0
10 changed files with 93 additions and 57 deletions
+3 -3
View File
@@ -151,11 +151,11 @@ class EpicStoreContract:
read = {issue.key: issue for issue in self.issues(store)}
self.assertEqual([read[key].by_loop for key in (ours, theirs, task)], [True, False, True])
def test_ranks_a_child_issue_just_before_or_just_after_another_and_its_sub_tasks_follow_it(self) -> None:
def test_ranks_a_child_issue_just_before_another_and_its_sub_tasks_follow_it(self) -> None:
store = self.new_store()
first, second, third = (self.filed(store, store.epic_key, f"Item {n}.") for n in range(3))
task = self.filed(store, third, "A task.")
self.assertEqual(store.rank(third, first), None)
self.assertEqual([issue.key for issue in self.issues(store)], [third, task, first, second])
self.assertEqual(store.rank(third, second, after=True), None)
self.assertEqual([issue.key for issue in self.issues(store)], [first, second, third, task])
self.assertEqual(store.rank(first, third), None)
self.assertEqual([issue.key for issue in self.issues(store)], [first, third, task, second])
+5 -5
View File
@@ -7,7 +7,7 @@ from failure import Failure
@dataclasses.dataclass
class MemoryEpic:
"""An epic whose issues rank in the order filed, until one is ranked. Where fails is set, every call fails with it as the reason."""
"""An epic whose issues rank in the order filed, until one is ranked. Where fails is set, every call but change fails with it as the reason."""
epic_key: str
issues: list[EpicIssue] = dataclasses.field(default_factory=list)
fails: str | None = None
@@ -39,14 +39,14 @@ class MemoryEpic:
self.change(key, labels=tuple(sorted({*child.labels, label})))
return None
def rank(self, key: str, other: str, after: bool = False) -> None | Failure:
def rank(self, key: str, before: str) -> None | Failure:
if self.fails:
return Failure(self.fails)
children = {issue.key: issue for issue in self.issues if issue.parent == self.epic_key}
if stray := next((each for each in (key, other) if each not in children), None):
return Failure(f"{stray} is not one of the child issues of the epic {self.epic_key}, so it cannot be ranked")
if stray := next((each for each in (key, before) if each not in children), None):
return Failure(f"{stray} is not one of the child issues of the epic {self.epic_key}, so {key} is not ranked")
self.issues.remove(children[key])
self.issues.insert(self.issues.index(children[other]) + after, children[key])
self.issues.insert(self.issues.index(children[before]), children[key])
return None
def change(self, key: str, **fields: object) -> None:
+2 -2
View File
@@ -92,11 +92,11 @@ class JiraEpic:
edited = self.http("PUT", f"{self.epic.site}/rest/api/3/issue/{key}", authorization, {"update": {"labels": [{"add": label}]}})
return Failure(f"cannot label {key}: {edited.reason}") if isinstance(edited, Failure) else None
def rank(self, key: str, other: str, after: bool = False) -> None | Failure:
def rank(self, key: str, before: str) -> None | Failure:
authorization = basic_auth(self.env_file)
if isinstance(authorization, Failure):
return authorization
refused = rank_refusal(self.epic.site, key, other, after, authorization, self.http)
refused = rank_refusal(self.epic.site, key, before, authorization, self.http)
return Failure(refused) if refused else None
def not_a_parent(self, parent: str, authorization: str) -> Failure | None:
+3 -3
View File
@@ -1,4 +1,4 @@
"""What every backend of an epic's plan reads, files and labels: an EpicIssue, and the EpicStore protocol they all meet. do-epic reads an epic only through EpicStore, so another tracker can stand behind it; contract.py holds the tests every backend passes.
"""What every backend of an epic's plan reads, files, labels and ranks: an EpicIssue, and the EpicStore protocol they all meet. do-epic reads an epic only through EpicStore, so another tracker can stand behind it; contract.py holds the tests every backend passes.
EpicStore is not plan_store's PlanStore. A PlanStore item names a release, but an epic item has none (`docs/decisions.md` → `do-epic: drives one Jira epic …`), and it may be a sub-task."""
import dataclasses
@@ -57,8 +57,8 @@ class EpicStore(typing.Protocol):
def add_label(self, key: str, label: str) -> None | Failure:
"""Adds label to the epic's child issue named key, leaving its other labels as they are; adding one it already has leaves the labels as they are. A sub-task, or an issue outside the epic, is refused."""
def rank(self, key: str, other: str, after: bool = False) -> None | Failure:
"""Ranks the child issue named key just before the child issue named other, or just after it where after is True; its sub-tasks follow it. Both must be child issues of the epic, as read answers them: a backend may not check, and Jira ranks any issue it is given."""
def rank(self, key: str, before: str) -> None | Failure:
"""Ranks the child issue named key just before the child issue named before. The sub-tasks of key follow key. Pass only keys of the epic's child issues, as read answers them: some backends don't check, and Jira ranks any issue it is given."""
def unfit(summary: str, labels: tuple[str, ...]) -> Failure | None:
+1 -1
View File
@@ -44,7 +44,7 @@ class Ranking(unittest.TestCase):
def test_refuses_to_rank_beside_an_issue_that_isnt_a_child_of_the_epic(self) -> None:
store = MemoryEpic("ABC-12")
child = store.file("ABC-12", "Count the runs.", "", ())
self.assertEqual(store.rank(str(child), "ZZZ-1"), Failure("ZZZ-1 is not one of the child issues of the epic ABC-12, so it cannot be ranked"))
self.assertEqual(store.rank(str(child), "ZZZ-1"), Failure(f"ZZZ-1 is not one of the child issues of the epic ABC-12, so {child} is not ranked"))
if __name__ == "__main__":
+3 -3
View File
@@ -91,12 +91,12 @@ class FakeJira:
return {"id": "1", "key": key}
def ranked(self, body: object) -> object:
"""Moves the one issue named just before or just after another, and answers no body, as Jira does for a rank it made."""
"""Moves the issue the body names to just before the other issue it names, and answers no body, as Jira does for a rank it made."""
assert isinstance(body, dict)
[key], other = body["issues"], body.get("rankBeforeIssue") or body["rankAfterIssue"]
[key], before = body["issues"], body["rankBeforeIssue"]
moved = next(issue for issue in self.issues if issue["key"] == key)
self.issues.remove(moved)
self.issues.insert(next(place for place, issue in enumerate(self.issues) if issue["key"] == other) + ("rankAfterIssue" in body), moved)
self.issues.insert(next(place for place, issue in enumerate(self.issues) if issue["key"] == before), moved)
return None
def change(self, key: str, **fields: object) -> None: