diff --git a/bin/plan_store/jira_epic.py b/bin/plan_store/jira_epic.py index 272a8fbb..17d2867a 100644 --- a/bin/plan_store/jira_epic.py +++ b/bin/plan_store/jira_epic.py @@ -336,8 +336,8 @@ def placing(answered: list[object], new: Item, value: float, scoring: ranking.Sc 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}") - # Release, tagline and blockers don't change a score. - other = ranking.item_score(dataclasses.replace(new, id=issue.number, exempt=exempt, scores=levels, moves=moves), scoring, issue.key) + # 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 return None diff --git a/bin/plan_store/test_jira_epic.py b/bin/plan_store/test_jira_epic.py index fc0d31ed..8b4aac28 100644 --- a/bin/plan_store/test_jira_epic.py +++ b/bin/plan_store/test_jira_epic.py @@ -394,6 +394,12 @@ class Filing(unittest.TestCase): self.assertEqual(self.add(FIELDS | {"Moves": "2 by 1", "S": "3"}), Failure("the item to file scores 0.1, under the bar 1; don't file it, or mark it with a reason the bar doesn't apply")) self.assertEqual(self.calls, []) + def test_the_bar_holds_the_score_rounded_to_one_decimal(self): + for formula, bar, filed_ in (("0.96", 1, True), ("0.6", 0.7, False)): + with self.subTest(formula=formula, bar=bar): + self.scoring = Stated(formula=formula, bar=bar) + self.assertEqual(self.add() == Written(40), filed_) + def test_an_exempt_item_under_the_bar_files(self): self.assertEqual(self.add(FIELDS | {"Moves": "", "Exempt": "owner"}), Written(40)) @@ -410,6 +416,11 @@ class Filing(unittest.TestCase): self.assertEqual(self.add(), Failure("cannot score the item to file: the formula 'V +' does not parse")) self.assertEqual(self.calls, []) + def test_a_formula_that_gives_the_item_no_finite_score_fails_before_any_request(self): + self.scoring = Stated(formula="1 ** (1 / (S - S))") + 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")) @@ -436,6 +447,7 @@ class Filing(unittest.TestCase): refusals = ( (Failure("PUT /rest/agile/1.0/issue/rank answered 403: Forbidden"), "PUT /rest/agile/1.0/issue/rank answered 403: Forbidden"), ({"entries": [{"issueKey": "ABC-40", "status": 400, "errors": ["Rank is not configured"]}]}, "Rank is not configured"), + ({"entries": [{"status": 200}, {"status": 400}, {"status": 404, "errors": ["gone", "locked"]}]}, "Jira answered 400; gone; locked"), ) for answer, reason in refusals: with self.subTest(answer=answer): @@ -443,9 +455,17 @@ class Filing(unittest.TestCase): self.assertEqual(self.add(), Written(40, (f"filed ABC-40, but cannot rank it before ABC-34: {reason}; rank it in Jira",))) def test_an_issue_the_loop_filed_that_does_not_score_leaves_the_item_filed_unranked_with_a_note(self): - self.open = [filed("ABC-34", moves="3 by 1", s=2)] - self.assertEqual(self.add(), Written(40, ("filed ABC-40, but cannot rank it: ABC-34 cites goal 3, which the goals file's ## Goals does not number; rank it in Jira",))) - self.assertEqual(self.sent(RANK), []) + unscored = {name: value for name, value in PROPERTY.items() if name != "S"} + for open_, reason in ( + (filed("ABC-34", moves="3 by 1", s=2), "ABC-34 cites goal 3, which the goals file's ## Goals does not number"), + (issue("ABC-34", scores=unscored), "ABC-34 holds no S"), + (issue("ABC-34", scores=PROPERTY | {"L": 11}), "item ABC-34's L '11' is not a whole number from 1 to 4"), + ): + with self.subTest(reason=reason): + self.calls.clear() + self.open = [open_] + self.assertEqual(self.add(), Written(40, (f"filed ABC-40, but cannot rank it: {reason}; rank it in Jira",))) + self.assertEqual(self.sent(RANK), []) TRANSITIONS = "https://acme.atlassian.net/rest/api/3/issue/ABC-34/transitions" diff --git a/bin/plan_store/test_stores.py b/bin/plan_store/test_stores.py index 1df6855e..d4428e97 100644 --- a/bin/plan_store/test_stores.py +++ b/bin/plan_store/test_stores.py @@ -227,6 +227,13 @@ class StatedScoring(unittest.TestCase): 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() + 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): diff --git a/bin/project_config/test_project_config.py b/bin/project_config/test_project_config.py index 9f4b344a..12e1687a 100644 --- a/bin/project_config/test_project_config.py +++ b/bin/project_config/test_project_config.py @@ -327,6 +327,12 @@ class LoadTest(ConfigCase): assert isinstance(named, ProjectConfig), named self.assertEqual(named.jira_scoring, Scoring("100 * V / (2**S + 8)", 0.5)) + def test_a_plan_in_a_file_holds_no_formula_or_bar_of_the_configs(self) -> None: + self.write("acme", CLIENT) + named = load(self.checkout, self.checkout, self.home) + assert isinstance(named, ProjectConfig), named + self.assertIsNone(named.jira_scoring) + def test_a_jira_plan_without_a_formula_or_a_bar_fails_naming_each(self) -> None: self.write("acme", JIRA_CLIENT.replace(JIRA_SCORING, "")) self.assertIn("`plan` names a Jira epic, so `jira-score-formula` must be set, as `project-config --help` shows; `plan` names a Jira epic, so `jira-score-bar` must be set", self.failure()) diff --git a/bin/release_plan/test_ranking.py b/bin/release_plan/test_ranking.py index f96bb301..60944ce0 100644 --- a/bin/release_plan/test_ranking.py +++ b/bin/release_plan/test_ranking.py @@ -271,6 +271,14 @@ class CodeHealth(unittest.TestCase): """A scoring run's entry, without the history's title.""" return SCORED.format(overall=overall).removeprefix("# Comprehension history\n\n").replace("2026-10-08T12", at).replace("PR #1 at aaaaaaa", read) + def test_a_plan_in_jira_weighs_the_goals_as_todo_md_does(self): + opted_out = "## review opt-out: the comprehension check\n\nCosts rounds.\n" + for decisions, history, floor in (("", SCORED.format(overall="6.99"), DEFAULT_FLOOR), ("", SCORED.format(overall="6.99"), decimal.Decimal("6.0")), (opted_out, "", DEFAULT_FLOOR)): + with self.subTest(decisions=decisions, history=history, floor=floor): + stated = ranking.config_scoring("V", 1, self.readme, decisions, history, floor) + read = ranking.read_scoring(self.todo, self.todo.split("\n"), self.readme, decisions, history, ranking.SHAPE, floor) + self.assertEqual(stated if isinstance(stated, Failure) else stated.weights, read if isinstance(read, Failure) else read.weights) + def test_ranks_code_health_first_among_the_achieve_goals_at_an_overall_of_7_or_above(self): # Code health, then goal 1: weights 1 / 1.97 and 0.97 / 1.97, an item moving one by 1 at S 1 scoring 50 times its weight. self.assertEqual(self.scores(SCORED.format(overall="7.00")), {"| 1": "25.4", "| 2": "24.6"}) @@ -461,6 +469,16 @@ class OldShape(unittest.TestCase): def test_refuses_an_item_citing_a_goal_the_weights_do_not_list(self): self.assertEqual(self.ranked(OLD_SHAPE.replace("| 2.1, 1 | 0 |", "| 2.1, 9 | 0 |")), Failure("item 3 cites goal 9, which the goal weights do not list")) + self.assertEqual(self.ranked(OLD_SHAPE.replace("| 2.1, 1 | 0 |", "| 9, 8 | 0 |")), Failure("item 3 cites goal 9, 8, which the goal weights do not list")) + + def test_refuses_a_bar_or_next_id_that_is_no_number_naming_the_line(self): + for todo, reason in ( + (TODO.replace("`Bar = 2`", "`Bar = x`"), "the bar 'x' is not a finite number"), + (TODO.replace("`Next ID = 6`\n", ""), "todo.md states `Next ID = ...` 0 times; state it once, on a line of its own under ## Scoring"), + (TODO.replace("`Next ID = 6`", "`Next ID = x`"), "Next ID 'x' is not a whole number"), + ): + with self.subTest(reason=reason): + self.assertEqual(self.ranked(todo), Failure(reason)) def test_refuses_a_formula_over_v(self): self.assertEqual(self.ranked(OLD_SHAPE.replace("-R - S/4 + 2*A + 2*G*W", "V")), Failure("the formula 'V' may hold only numbers, A, G, R, S, W, + - * / ** and parentheses"))