Answer stability round 1: 0 🔴, 7 🟡 (0 misread); parse the formula on load, require the scoring, share the bar rule and split add

This commit is contained in:
2026-11-16 03:07:39 +01:00
parent 727ed70ecb
commit cf1180734c
12 changed files with 109 additions and 71 deletions
+17 -16
View File
@@ -13,7 +13,7 @@ from adf_codec.convert import adfs_to_markdown, markdown_to_adf, Refused
from release_plan.todo_table import BLOCKED_BY, EXEMPTIONS, is_exempt, Item, MOVES, parse_ids, parse_moves, parse_scores, SHAPE
from plan_store.markdown_edits import bold_cell, plain, unfit_text
from plan_store.stores import cells, Plan, Written
from project_config.settings import Epic, Finish, JIRA_FINISH_STATUS, JIRA_FINISH_TRANSITION, JIRA_SCORE_BAR, JIRA_SCORE_FORMULA
from project_config.settings import Epic, Finish, JIRA_FINISH_STATUS, JIRA_FINISH_TRANSITION
from failure import Failure
from rest_client import json_request
from release_plan.release import parsed, Release, tagged
@@ -101,8 +101,8 @@ class JiraPlan:
to_adf: ToAdf = markdown_to_adf
# How a finished item moves; None where the config doesn't say, and then `finish` is a Failure.
finish_by: Finish | None = None
# None where the config states no formula and bar, and then `add` is a Failure.
scoring: ReadsScoring | None = None
# How add scores an item: by the config's formula and bar, with the goal weights the project's records give.
scoring: ReadsScoring = dataclasses.field(kw_only=True)
@property
def label(self) -> str:
@@ -129,8 +129,6 @@ class JiraPlan:
filing = filing_of(fields, detail, self.epic)
if isinstance(filing, Failure):
return filing
if self.scoring is None:
return Failure(f"the config states no formula and bar to score the item by: set `{JIRA_SCORE_FORMULA}` and `{JIRA_SCORE_BAR}`, as `project-config --help` shows")
scoring = self.scoring.read()
if isinstance(scoring, Failure):
return Failure(f"cannot score the item to file: {scoring.reason}")
@@ -163,8 +161,12 @@ class JiraPlan:
key = created.get("key") if isinstance(created, dict) else None
if not isinstance(key, str) or not ISSUE_KEY.fullmatch(key) or project_of(key) != project_of(self.epic.key):
return Failure(f"Jira answered the new issue without an issue key in {project_of(self.epic.key)}; {PERHAPS_FILED.format(epic=self.epic.key)}")
return Written(number(key), self.linked_and_ranked(key, filing.blockers, before, authorization))
def linked_and_ranked(self, key: str, blockers: tuple[str, ...], before: str | None | Failure, authorization: str) -> tuple[str, ...]:
"""Links the filed issue named key as blocked by each of blockers, and ranks it just before the issue named before; a note for each Jira refuses."""
notes = []
for blocker in filing.blockers:
for blocker in blockers:
# Jira names the two ends by the link type's sides: the inward issue blocks the outward one, which then reads "is blocked by" it.
linked = self.http("POST", f"{self.epic.site}/rest/api/3/issueLink", authorization, {"type": {"name": BLOCKS}, "inwardIssue": {"key": blocker}, "outwardIssue": {"key": key}})
if isinstance(linked, Failure):
@@ -173,7 +175,7 @@ class JiraPlan:
notes.append(f"filed {key}, but cannot rank it: {before.reason}; rank it in Jira")
elif before is not None and (refused := self.rank_refusal(key, before, authorization)):
notes.append(f"filed {key}, but cannot rank it before {before}: {refused}; rank it in Jira")
return Written(number(key), tuple(notes))
return tuple(notes)
def rank_refusal(self, key: str, before: str, authorization: str) -> str | None:
"""Ranks the issue named key just before the issue named before; why Jira refused, or None where it didn't. Jira answers a rank it made with no body, and one it refused with an error, or with an entry per issue that holds the errors."""
@@ -311,7 +313,7 @@ def filed_score(item: Item, scoring: ranking.Scoring) -> float | Failure:
if missing := next((name for name in SET_SCORES if name not in item.scores), None):
return Failure(f"the item to file has no {missing}: score it on {', '.join(SET_SCORES[:-1])} and {SET_SCORES[-1]}")
value = ranking.item_score(item, scoring, "the item to file")
if not isinstance(value, Failure) and not item.exempt and round(value, 1) < scoring.bar:
if not isinstance(value, Failure) and ranking.falls_under(item, value, scoring.bar):
return Failure(f"the item to file scores {value:.1f}, under the bar {scoring.bar:g}; don't file it, or mark it with a reason the bar doesn't apply")
return value
@@ -319,7 +321,8 @@ def filed_score(item: Item, scoring: ranking.Scoring) -> float | Failure:
def placing(answered: list[object], new: Item, value: float, scoring: ranking.Scoring) -> str | None | Failure:
"""The key of the issue to rank the new item, which scores value, just before; None where it stays last, where Jira files it. answered is the epic's open children in backlog order.
Only the issues the loop filed count, so the team's rank of every other issue stays as it is. A security finding goes before the first of them that isn't one, and any other item before the first that isn't one and scores lower, as todo.md ranks its items."""
Only the issues the loop filed count, so the team's rank of every other issue stays as it is. The new item goes before the first of them that ranks after it as todo.md orders a release's items, blockers aside: a question first, then a security finding, as ranking.FIRST orders them, then the higher score. A tie goes after the older issue. Release doesn't count, as docs/decisions.md records."""
place = (ranking.FIRST.get(new.exempt, len(ranking.FIRST)), -value)
for raw in answered:
issue = issue_of(raw)
if isinstance(issue, Failure):
@@ -330,16 +333,14 @@ def placing(answered: list[object], new: Item, value: float, scoring: ranking.Sc
if isinstance(scored, Failure):
return scored
levels, moves, exempt = scored
if exempt == SECURITY:
continue
if new.exempt == SECURITY:
return issue.key
if missing := next((name for name in SET_SCORES if name not in levels), None):
return Failure(f"{issue.key} holds no {missing}")
# Only the scores and the moves change a score.
other = ranking.item_score(dataclasses.replace(new, scores=levels, moves=moves), scoring, issue.key)
if isinstance(other, Failure) or other < value:
return other if isinstance(other, Failure) else issue.key
if isinstance(other, Failure):
return other
if (ranking.FIRST.get(exempt, len(ranking.FIRST)), -other) > place:
return issue.key
return None
@@ -436,7 +437,7 @@ def basic_auth(env_file: pathlib.Path) -> str | Failure:
def children(epic: Epic, authorization: str, http: Http) -> list[object] | Failure:
"""The epic's open child issues in backlog order, which is the order the team ranks them in. An issue in a done status is a finished item, so it is no longer in the plan."""
"""The epic's open child issues in backlog order, which the team ranks, apart from where add ranks an issue it files. An issue in a done status is a finished item, so it is no longer in the plan."""
# The search answers no issues for an epic the account cannot see, as for one whose children are all done; asking for the epic itself tells them apart.
seen = http("GET", f"{epic.site}/rest/api/3/issue/{epic.key}?fields=summary", authorization, None)
if isinstance(seen, Failure):
+6 -4
View File
@@ -12,8 +12,8 @@ from release_plan.todo_table import BLOCKED_BY, Item, item_details, items, MOVES
from failure import Failure
from git_cli.git_repo import file_at, git, Git
from record_store.stores import goals_store, store as record_store, RecordStore
from project_config.settings import JiraScoring, ProjectConfig
from plan_store import markdown_edits
from project_config.settings import ProjectConfig, Scoring
from release_plan import ranking
from release_plan.release import Release
from text_files.file_writes import replace_file
@@ -145,8 +145,8 @@ class FilePlan:
@dataclasses.dataclass(frozen=True)
class StatedScoring:
"""The scoring that the project's config states for a plan in Jira, whose goal weights ranking reads from the goals file, the decision log and the comprehension history."""
stated: Scoring
"""The scoring of a plan in Jira: the formula and bar the project's config states, with goal weights that ranking reads from the goals file, the decision log and the comprehension history."""
stated: JiraScoring
goals: RecordStore
decisions: RecordStore
history: RecordStore
@@ -179,7 +179,9 @@ def store(config: ProjectConfig) -> PlanStore:
from plan_store.jira_epic import JiraPlan
# load refuses a config that names an epic and no env-file.
assert config.env_file is not None
scoring = StatedScoring(config.jira_scoring, goals_store(config), record_store(config, "decisions"), record_store(config, "comprehension-history"), config.readability_floor) if config.jira_scoring else None
# load refuses a config that names an epic and no formula or bar.
assert config.jira_scoring is not None
scoring = StatedScoring(config.jira_scoring, goals_store(config), record_store(config, "decisions"), record_store(config, "comprehension-history"), config.readability_floor)
return JiraPlan(config.epic, config.env_file, finish_by=config.jira_finish, scoring=scoring)
+13 -12
View File
@@ -65,7 +65,7 @@ class JiraPlan(unittest.TestCase):
return [text_of(document) for document in documents]
def store(self) -> jira_epic.JiraPlan:
return jira_epic.JiraPlan(EPIC, self.env, self.http, self.to_markdown)
return jira_epic.JiraPlan(EPIC, self.env, self.http, self.to_markdown, scoring=Stated())
def read(self, *issues: dict[str, object]) -> Plan | Failure:
self.pages, self.calls = [{"issues": list(issues)}], []
@@ -183,12 +183,12 @@ class JiraPlan(unittest.TestCase):
self.assertEqual(self.converted, [[adf("One."), adf("Three."), adf("Four.")]])
def test_a_description_the_codec_refuses_fails_the_read_naming_the_issue(self):
store = jira_epic.JiraPlan(EPIC, self.env, self.http, lambda documents: Refused(1, Failure("adf-codec refused")))
store = jira_epic.JiraPlan(EPIC, self.env, self.http, lambda documents: Refused(1, Failure("adf-codec refused")), scoring=Stated())
self.pages = [{"issues": [issue("ABC-33", description=adf("x")), issue("ABC-34"), issue("ABC-35", description=adf("y"))]}]
self.assertEqual(store.read(), Failure("ABC-35's description: adf-codec refused"))
def test_a_codec_that_cannot_run_fails_the_read(self):
store = jira_epic.JiraPlan(EPIC, self.env, self.http, lambda documents: Failure("docker is not installed"))
store = jira_epic.JiraPlan(EPIC, self.env, self.http, lambda documents: Failure("docker is not installed"), scoring=Stated())
self.pages = [{"issues": [issue("ABC-34", description=adf("x"))]}]
self.assertEqual(store.read(), Failure("cannot convert the descriptions of ABC-12's children to markdown: docker is not installed"))
@@ -253,10 +253,10 @@ class Filing(unittest.TestCase):
self.linked: object = None
self.versions: object = [{"name": "0.1.0"}, {"name": "v0.2.0"}, "odd", {"name": ["0.1.0"]}, {"name": {"en": "0.1.0"}}]
self.ranked: object = None
self.scoring: Stated | None = Stated()
self.scoring = Stated()
def http(self, method: str, url: str, authorization: str, body: object) -> object:
"""Stands in for Jira: answers the epic, self.versions for the project's Fix Versions, self.open to the search, self.created to a new issue and self.linked to a new link."""
"""Stands in for Jira: answers the epic, self.versions for the project's Fix Versions, self.open to the search, self.created to a new issue, self.linked to a new link and self.ranked to a rank."""
self.calls.append((method, url, body))
assert authorization == AUTHORIZATION
return {SEARCH: {"issues": self.open}, ISSUES: self.created, LINKS: self.linked, VERSIONS: self.versions, RANK: self.ranked}.get(url, {"key": "ABC-12"})
@@ -421,10 +421,6 @@ class Filing(unittest.TestCase):
self.assertEqual(self.add(), Failure("the formula gives the item to file no finite score"))
self.assertEqual(self.calls, [])
def test_a_config_without_a_formula_fails(self):
self.scoring = None
self.assertEqual(self.add(), Failure("the config states no formula and bar to score the item by: set `jira-score-formula` and `jira-score-bar`, as `project-config --help` shows"))
def test_ranks_the_item_just_before_the_first_issue_the_loop_filed_that_scores_lower(self):
# ABC-30 and ABC-33 are a person's, ABC-31 a security finding, and ABC-32 scores as much as the new item.
self.open = [issue("ABC-30"), filed("ABC-31", s=4, exempt="security"), filed("ABC-32"), issue("ABC-33", scores={"L": 1, "E": 1, "I": 1, "S": 4, "Moves": "1 by 1"}), filed("ABC-34", s=2), filed("ABC-35", s=3)]
@@ -437,6 +433,11 @@ class Filing(unittest.TestCase):
self.assertEqual(self.add(FIELDS | {"Exempt": "security", "S": "4"}), Written(40))
self.assertEqual(self.sent(RANK), [{"issues": ["ABC-40"], "rankBeforeIssue": "ABC-32"}])
def test_ranks_a_question_just_before_the_first_issue_the_loop_filed_that_isnt_one(self):
self.open = [filed("ABC-31", exempt="question"), filed("ABC-32", s=4, exempt="security")]
self.assertEqual(self.add(FIELDS | {"Exempt": "question"}), Written(40))
self.assertEqual(self.sent(RANK), [{"issues": ["ABC-40"], "rankBeforeIssue": "ABC-32"}])
def test_leaves_the_item_last_where_no_issue_the_loop_filed_scores_lower(self):
self.open = [issue("ABC-30", scores={}), filed("ABC-31"), filed("ABC-32", s=2, exempt="security")]
self.assertEqual(self.add(), Written(40))
@@ -499,7 +500,7 @@ class Editing(unittest.TestCase):
return adf(markdown)
def edit(self, id_: int, fields: dict[str, str], detail: str | None = None, comment: str | None = None):
return jira_epic.JiraPlan(EPIC, self.env, self.http, text_of, self.to_adf).edit(id_, fields, detail, comment)
return jira_epic.JiraPlan(EPIC, self.env, self.http, text_of, self.to_adf, scoring=Stated()).edit(id_, fields, detail, comment)
def writes(self) -> list[tuple[str, str, object]]:
"""Each request that changes Jira, in order."""
@@ -636,7 +637,7 @@ class Editing(unittest.TestCase):
body = self.writes()[0][2]
held = issue("ABC-34", summary=body["fields"]["summary"], scores=body["properties"][0]["value"], description=body["fields"]["description"]) # type: ignore[index]
self.open = [held]
plan = jira_epic.JiraPlan(EPIC, self.env, self.http, lambda documents: [text_of(document) for document in documents]).read()
plan = jira_epic.JiraPlan(EPIC, self.env, self.http, lambda documents: [text_of(document) for document in documents], scoring=Stated()).read()
assert isinstance(plan, Plan), plan
self.assertEqual((plan.items[0].tagline, plan.items[0].scores["S"], plan.items[0].scores["L"], plan.items[0].detail), ("**Count every run.**", 4, 1, "Why it counts."))
@@ -664,7 +665,7 @@ class Finishing(unittest.TestCase):
return {SEARCH: {"issues": self.open}}.get(url, {"key": "ABC-12"})
def finish(self, id_: int = 34, by: Finish | None = Finish("Mark as done", "Done")):
return jira_epic.JiraPlan(EPIC, self.env, self.http, text_of, finish_by=by).finish(id_)
return jira_epic.JiraPlan(EPIC, self.env, self.http, text_of, finish_by=by, scoring=Stated()).finish(id_)
def posts(self) -> list[tuple[str, str, object]]:
return [call for call in self.calls if call[0] == "POST" and call[1] != SEARCH]
+9 -9
View File
@@ -8,7 +8,7 @@ import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from project_config.settings import DEFAULT_FLOOR, Epic, Finish, ProjectConfig, Scoring, SETTINGS
from project_config.settings import DEFAULT_FLOOR, Epic, Finish, JiraScoring, ProjectConfig, SETTINGS
from failure import Failure
from record_store.stores import FileStore, goals_store, store as record_store
from plan_store.contract import FIRST, MOVES, PlanStoreContract, SECOND
@@ -207,37 +207,37 @@ class Store(unittest.TestCase):
def test_an_epic_picks_jira_with_the_env_files_credentials(self):
epic = Epic("https://acme.atlassian.net", "ABC-12")
picked = stores.store(self.config(epic=epic, env_file=pathlib.Path("/secrets/acme.env")))
self.assertEqual(picked, JiraPlan(epic, pathlib.Path("/secrets/acme.env"), picked.http))
picked = stores.store(self.config(epic=epic, env_file=pathlib.Path("/secrets/acme.env"), jira_scoring=JiraScoring("V", 1)))
self.assertEqual(picked, JiraPlan(epic, pathlib.Path("/secrets/acme.env"), picked.http, scoring=picked.scoring))
def test_an_epic_finishes_an_item_as_the_config_says(self):
finish = Finish("Mark as done", "Done")
picked = stores.store(self.config(epic=Epic("https://acme.atlassian.net", "ABC-12"), env_file=pathlib.Path("/secrets/acme.env"), jira_finish=finish))
picked = stores.store(self.config(epic=Epic("https://acme.atlassian.net", "ABC-12"), env_file=pathlib.Path("/secrets/acme.env"), jira_finish=finish, jira_scoring=JiraScoring("V", 1)))
self.assertEqual(picked.finish_by, finish)
def test_an_epic_scores_by_the_configs_formula_and_bar_and_the_projects_records(self):
config = self.config(epic=Epic("https://acme.atlassian.net", "ABC-12"), env_file=pathlib.Path("/secrets/acme.env"), jira_scoring=Scoring("V / 2**S", 1.5), readability_floor=decimal.Decimal("6.5"))
config = self.config(epic=Epic("https://acme.atlassian.net", "ABC-12"), env_file=pathlib.Path("/secrets/acme.env"), jira_scoring=JiraScoring("V / 2**S", 1.5), readability_floor=decimal.Decimal("6.5"))
picked = stores.store(config)
self.assertEqual(picked.scoring, stores.StatedScoring(Scoring("V / 2**S", 1.5), goals_store(config), record_store(config, "decisions"), record_store(config, "comprehension-history"), decimal.Decimal("6.5")))
self.assertEqual(picked.scoring, stores.StatedScoring(JiraScoring("V / 2**S", 1.5), goals_store(config), record_store(config, "decisions"), record_store(config, "comprehension-history"), decimal.Decimal("6.5")))
class StatedScoring(unittest.TestCase):
def test_weighs_the_goals_the_goals_file_holds(self):
scoring = stores.StatedScoring(Scoring("V / 2**S", 1.5), MemoryStore(README), MemoryStore(), MemoryStore(), DEFAULT_FLOOR).read()
scoring = stores.StatedScoring(JiraScoring("V / 2**S", 1.5), MemoryStore(README), MemoryStore(), MemoryStore(), DEFAULT_FLOOR).read()
assert not isinstance(scoring, Failure), scoring
self.assertEqual((scoring.bar, list(scoring.goals)), (1.5, ["1", "2", "2.1"]))
def test_weighs_code_health_by_the_history_and_the_floor_it_is_given(self):
for floor, under in ((DEFAULT_FLOOR, True), (decimal.Decimal("6.0"), False)):
with self.subTest(floor=floor):
scoring = stores.StatedScoring(Scoring("V", 1), MemoryStore("## Goals\n\n1. **Achieve:** A.\n"), MemoryStore(), MemoryStore(SCORED.format(overall="6.99")), floor).read()
scoring = stores.StatedScoring(JiraScoring("V", 1), MemoryStore("## Goals\n\n1. **Achieve:** A.\n"), MemoryStore(), MemoryStore(SCORED.format(overall="6.99")), floor).read()
assert not isinstance(scoring, Failure), scoring
self.assertEqual(scoring.weights["code health"] > scoring.weights["1"] * 2, under)
def test_a_goals_file_that_is_empty_or_cannot_be_read_fails(self):
for goals, reason in ((MemoryStore(), "the record in memory: missing or empty"), (MemoryStore(fails="Jira answered 403"), "Jira answered 403")):
with self.subTest(reason=reason):
read = stores.StatedScoring(Scoring("V", 1), goals, MemoryStore(), MemoryStore(), DEFAULT_FLOOR).read()
read = stores.StatedScoring(JiraScoring("V", 1), goals, MemoryStore(), MemoryStore(), DEFAULT_FLOOR).read()
assert isinstance(read, Failure), read
self.assertTrue(read.reason.startswith(reason), read.reason)