Answer stability round 1: 0 🔴, 2 🟡 (0 misread); score the person's issue in the contract test, and hold scores, moves and exempt apart from blockers

This commit is contained in:
2026-11-18 18:32:38 +01:00
parent f0d99c8141
commit e8255be534
6 changed files with 25 additions and 19 deletions
+8 -8
View File
@@ -1,10 +1,9 @@
"""What every backend of an epic's plan must hold, as tests. A backend's test case inherits EpicStoreContract and unittest.TestCase, and builds an epic with no issues in new_store. Its assign, close, person_files, score and block change the tracker as a person, or the plan store, would."""
"""What every backend of an epic's plan must hold, as tests. A backend's test case inherits EpicStoreContract and unittest.TestCase, and builds an epic with no issues in new_store. Its assign, close, person_files, score and block change the tracker as a person or the plan store would."""
import re
import typing
from do_epic.backend.protocol import EpicIssue, EpicStore
from failure import Failure
from plan.todo_table import ItemFields
class EpicStoreContract:
@@ -27,8 +26,8 @@ class EpicStoreContract:
"""Files a child issue of the epic as a person does in the tracker, not through the store, and answers its key."""
raise NotImplementedError
def score(self, store: EpicStore, key: str, scores: dict[str, str]) -> None:
"""Sets the scores of the issue named key, as `plan_store` writes them: each column's name with its value as text, such as {"L": "2", "Moves": "1 by 5"}."""
def score(self, store: EpicStore, key: str, scores: dict[str, object]) -> None:
"""Sets the scores of the issue named key as `plan_store` writes them: each column's name with its value, a whole number for a score and text for Moves and Exempt, such as {"L": 2, "Moves": "1 by 5"}."""
raise NotImplementedError
def block(self, store: EpicStore, key: str, blocker: str) -> None:
@@ -125,15 +124,14 @@ class EpicStoreContract:
store = self.new_store()
key = self.filed(store, store.epic_key, "Count the runs.")
[issue] = self.issues(store)
self.assertEqual((issue.key, issue.scores, issue.blockers), (key, ItemFields(), ()))
self.assertEqual((issue.key, issue.scores, issue.moves, issue.exempt, issue.blockers), (key, {}, (), "", ()))
def test_reads_the_scores_a_person_or_the_plan_store_set(self) -> None:
store = self.new_store()
key = self.filed(store, store.epic_key, "Count the runs.")
self.score(store, key, {"L": "2", "E": "3", "I": "4", "S": "3", "Moves": "1 by 5", "Exempt": "security"})
self.score(store, key, {"L": 2, "E": 3, "I": 4, "S": 3, "Moves": "1 by 5", "Exempt": "security"})
[issue] = self.issues(store)
self.assertEqual((issue.scores.scores, issue.scores.moves, issue.scores.exempt), ({"L": 2, "E": 3, "I": 4, "S": 3}, (("1", 5),), "security"))
self.assertEqual((issue.scores.release, issue.scores.blocked_by), (None, ()))
self.assertEqual((issue.scores, issue.moves, issue.exempt), ({"L": 2, "E": 3, "I": 4, "S": 3}, (("1", 5),), "security"))
def test_reads_each_blocker_of_an_issue_and_none_for_a_blocker_of_another(self) -> None:
store = self.new_store()
@@ -147,6 +145,8 @@ class EpicStoreContract:
store = self.new_store()
ours = self.filed(store, store.epic_key, "Count the runs.")
theirs = self.person_files(store, "A person's issue.")
# The plan store scores an issue a person filed without making it the loop's.
self.score(store, theirs, {"L": 2, "E": 3, "I": 4, "S": 3, "Moves": "1 by 5"})
task = self.filed(store, ours, "Count them in the api.")
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])
+2 -2
View File
@@ -60,7 +60,7 @@ class JiraEpic:
if refused := unfit(summary, labels) or self.not_a_parent(parent, authorization):
return refused
fields: dict[str, typing.Any] = {"project": {"key": project_of(parent)}, "parent": {"key": parent}, "summary": summary, "labels": list(labels)}
# The mark that tells the loop's issues from a person's, as plan_store marks the items it files.
# Marks the issue as the loop's, as plan_store marks the items it files.
properties = [{"key": PROPERTY, "value": {FILED_BY[0]: FILED_BY[1]}}]
kind = {"name": ISSUE_TYPE} if parent == self.epic_key else self.sub_task_type(project_of(parent), authorization)
if isinstance(kind, Failure):
@@ -173,4 +173,4 @@ def found_of(raw: object) -> Found | Failure:
read = scores(key, held)
if isinstance(read, Failure):
return read
return Found(EpicIssue(key, summary.strip(), "", tuple(sorted(labels)), name, state, done, parent, read, blockers, held.get(FILED_BY[0]) == FILED_BY[1]), description)
return Found(EpicIssue(key, summary.strip(), "", tuple(sorted(labels)), name, state, done, parent, read.scores, read.moves, read.exempt, blockers, held.get(FILED_BY[0]) == FILED_BY[1]), description)
+9 -5
View File
@@ -5,8 +5,8 @@ import dataclasses
import re
import typing
from plan.todo_table import Exempt, Moves
from failure import Failure
from plan.todo_table import ItemFields
# What a tracker accepts as a label: Jira refuses a label holding white space.
LABEL = re.compile(r"\S+")
@@ -29,11 +29,15 @@ class EpicIssue:
done: bool
# The epic's key for a child issue, the child's key for a sub-task.
parent: str
# The scores, Moves and Exempt a plan-item issue property holds, as `plan_store` reads them; its release and blocked_by stay unset, since an epic's items have no release and `blockers` holds theirs. Empty where the issue holds none, as a person's issue does.
scores: ItemFields = dataclasses.field(default_factory=ItemFields)
# The key of each issue this one is blocked by, in the tracker's order.
# The score of each column the issue has one for, such as {"L": 2}, as `plan_store` reads them from the issue's `plan-item` property. Empty where the issue has no scores.
scores: dict[str, int] = dataclasses.field(default_factory=dict)
# The goals the issue moves, and how far (the plan's Moves cell); empty where it names none.
moves: Moves = ()
# Why the issue is exempt from the plan's score bar, as the plan's Exempt cell names it; empty where it isn't.
exempt: Exempt = ""
# The key of each issue that blocks this one, in the tracker's order.
blockers: tuple[str, ...] = ()
# Whether the loop filed the issue, through EpicStore.file, rather than a person.
# True where the loop filed the issue through EpicStore.file; False for an issue a person filed.
by_loop: bool = False
+4 -2
View File
@@ -25,8 +25,10 @@ class MemoryEpicContract(EpicStoreContract, unittest.TestCase):
store.change(key, by_loop=False)
return key
def score(self, store: MemoryEpic, key: str, scores: dict[str, str]) -> None: # type: ignore[override]
store.change(key, scores=jira_epic.scores(key, scores))
def score(self, store: MemoryEpic, key: str, scores: dict[str, object]) -> None: # type: ignore[override]
read = jira_epic.scores(key, scores)
assert not isinstance(read, Failure), read
store.change(key, scores=read.scores, moves=read.moves, exempt=read.exempt)
def block(self, store: MemoryEpic, key: str, blocker: str) -> None: # type: ignore[override]
store.change(key, blockers=(*next(issue for issue in store.issues if issue.key == key).blockers, blocker))
+1 -1
View File
@@ -123,7 +123,7 @@ class JiraEpicContract(Case, EpicStoreContract):
def person_files(self, store: JiraEpic, summary: str) -> str: # type: ignore[override]
return self.jira.person_files(summary)
def score(self, store: JiraEpic, key: str, scores: dict[str, str]) -> None: # type: ignore[override]
def score(self, store: JiraEpic, key: str, scores: dict[str, object]) -> None: # type: ignore[override]
held = next(issue for issue in self.jira.issues if issue["key"] == key).get("properties", {}).get("plan-item", {}) # type: ignore[attr-defined, union-attr]
self.jira.set_property(key, held | scores)
+1 -1
View File
@@ -490,7 +490,7 @@ def issue_of(raw: object) -> Issue | Failure:
def blocked_by_links(fields: dict[str, typing.Any]) -> tuple[Link, ...]:
"""The "is blocked by" links among an issue's `issuelinks` field; a KeyError, TypeError or AttributeError where it isn't in the shape Jira documents."""
"""The "is blocked by" links among an issue's `issuelinks` field. A field not in the shape Jira documents raises a KeyError or TypeError, which the caller turns into a Failure."""
return tuple(Link(link["inwardIssue"]["key"], link["id"]) for link in fields["issuelinks"] if "inwardIssue" in link and link["type"]["inward"] == "is blocked by")