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:
@@ -31,9 +31,9 @@ and readme.md, since the reviewers and the rules name those files.
|
||||
Jira's backlog order, and `project-config plan` prints the setting as the config spells it. Such a
|
||||
config must set `env-file`, and that file must hold ATLASSIAN_EMAIL and ATLASSIAN_API_TOKEN.
|
||||
|
||||
Such a config must also set `jira-score-formula` and `jira-score-bar`, which a todo.md states under
|
||||
## Scoring as `Score` and `Bar`, as `rank_todo.py --help` shows: the formula that scores an item, and
|
||||
the lowest score at which `todo-item add` files one that isn't exempt. The bar is a bare number:
|
||||
Such a config must also set two settings. `jira-score-formula` is the formula that scores an item.
|
||||
`jira-score-bar` is the lowest score at which `todo-item add` files an item that isn't exempt, as a
|
||||
bare number. They hold what a todo.md states as `Score` and `Bar`, which `rank_todo.py --help` describes:
|
||||
|
||||
jira-score-formula = "100 * V / (2**S + 8)"
|
||||
jira-score-bar = 1
|
||||
@@ -128,8 +128,9 @@ Exit 1, naming each fault on stderr, where no config names the checkout, or its
|
||||
setting, names an unknown one, misspells a path, a language or a template, sets `wait-for-approval` or
|
||||
`tooling-on-host` to anything but true or false, sets `notifier` to anything but mattermost or slack or
|
||||
without `env-file`, sets `jira-finish-transition` or `jira-finish-status` to anything but a name, without the other or
|
||||
without a `plan` in Jira, names a Jira `plan` without `jira-score-formula` and `jira-score-bar`, sets
|
||||
either without such a plan, or the bar to anything but a number, or sets `readability-floor` to anything but a number
|
||||
without a `plan` in Jira, names a Jira `plan` and leaves out `jira-score-formula` or `jira-score-bar`, sets
|
||||
one of those two without a `plan` in Jira, sets the formula to one that doesn't parse or the bar to anything
|
||||
but a number, or sets `readability-floor` to anything but a number
|
||||
from 1 to 10, and where `env-file`, `jira-finish-transition`, `jira-finish-status`, `notifier` or `touch-predictions` is asked for and not set. No path setting has a default.
|
||||
"""
|
||||
import pathlib
|
||||
|
||||
@@ -10,7 +10,10 @@ import tomllib
|
||||
import typing
|
||||
|
||||
from failure import Failure
|
||||
from release_plan.formula import parse_formula
|
||||
from release_plan.todo_table import SHAPE
|
||||
from project_config import templates
|
||||
from release_plan.ranking import variables
|
||||
|
||||
PROJECTS = ".claude-projects"
|
||||
CONFIG = "config.toml"
|
||||
@@ -43,7 +46,7 @@ TOUCH_PREDICTIONS = "touch-predictions"
|
||||
JIRA_FINISH_TRANSITION = "jira-finish-transition"
|
||||
JIRA_FINISH_STATUS = "jira-finish-status"
|
||||
JIRA_FINISH = (JIRA_FINISH_TRANSITION, JIRA_FINISH_STATUS)
|
||||
# Two settings, needed where `plan` names a Jira epic and allowed only there, which a todo.md states under ## Scoring instead: the formula that scores an item, and the bar, the lowest score at which an item is filed. Three readers, seated as the human who writes a client's config, picked the spelling from four candidates: "formula" says the value is no score, and "score-bar" what the bar applies to.
|
||||
# Two settings, needed where `plan` names a Jira epic and allowed only there: what a todo.md states under ## Scoring.
|
||||
JIRA_SCORE_FORMULA = "jira-score-formula"
|
||||
JIRA_SCORE_BAR = "jira-score-bar"
|
||||
JIRA_SCORE = (JIRA_SCORE_FORMULA, JIRA_SCORE_BAR)
|
||||
@@ -83,7 +86,7 @@ class Finish:
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Scoring:
|
||||
class JiraScoring:
|
||||
"""How a plan in Jira scores an item: by formula, such as `100 * V / (2**S + 8)`, with bar the lowest score at which one is filed."""
|
||||
formula: str
|
||||
bar: float
|
||||
@@ -127,7 +130,7 @@ class ProjectConfig:
|
||||
# The config's `jira-finish-transition` and `jira-finish-status`, or None where it sets neither.
|
||||
jira_finish: Finish | None = None
|
||||
# The config's `jira-score-formula` and `jira-score-bar`, which it sets where `plan` names an epic.
|
||||
jira_scoring: Scoring | None = None
|
||||
jira_scoring: JiraScoring | None = None
|
||||
# The Confluence page of each record the config keeps on one, by the record's setting.
|
||||
pages: dict[str, Page] = dataclasses.field(default_factory=dict)
|
||||
|
||||
@@ -193,6 +196,7 @@ def load(top: pathlib.Path, main: pathlib.Path, home: pathlib.Path) -> ProjectCo
|
||||
floor = floor_of(values[READABILITY_FLOOR]) if READABILITY_FLOOR in values else DEFAULT_FLOOR
|
||||
finish = [name for setting in JIRA_FINISH if (name := name_of(values.get(setting)))]
|
||||
formula, bar = values.get(JIRA_SCORE_FORMULA), values.get(JIRA_SCORE_BAR)
|
||||
scoring = JiraScoring(formula, bar_value) if isinstance(formula, str) and (bar_value := bar_of(bar)) is not None else None
|
||||
checks = {LANGUAGE: language_fault, COMMIT_TITLE: templates.title_fault, PULL_REQUEST_TITLE: templates.title_fault, BRANCH: templates.branch_fault}
|
||||
faults = [
|
||||
*(f"`{name}` is missing" for name in SETTINGS if name not in values),
|
||||
@@ -213,7 +217,7 @@ def load(top: pathlib.Path, main: pathlib.Path, home: pathlib.Path) -> ProjectCo
|
||||
*(f"`{name}` is set, so `plan` must name a Jira epic" for name in JIRA_FINISH if name in values and not epics["plan"]),
|
||||
*(f"`plan` names a Jira epic, so `{name}` must be set, as `project-config --help` shows" for name in JIRA_SCORE if epics["plan"] and name not in values),
|
||||
*(f"`{name}` is set, so `plan` must name a Jira epic" for name in JIRA_SCORE if name in values and not epics["plan"]),
|
||||
*([f"`{JIRA_SCORE_FORMULA}` is {formula!r}, not a formula, such as \"100 * V / (2**S + 8)\""] if JIRA_SCORE_FORMULA in values and not name_of(formula) else []),
|
||||
*([f"`{JIRA_SCORE_FORMULA}` is {formula!r}: {fault}"] if JIRA_SCORE_FORMULA in values and (fault := formula_fault(formula)) else []),
|
||||
*([f"`{JIRA_SCORE_BAR}` is {bar!r}, not a bare number, such as `{JIRA_SCORE_BAR} = 1`"] if JIRA_SCORE_BAR in values and bar_of(bar) is None else []),
|
||||
*(f"`{name}` is {value!r}, not true or false" for name, value in ((WAIT_FOR_APPROVAL, waits), (TOOLING_ON_HOST, on_host)) if not isinstance(value, bool)),
|
||||
*([f"`{READABILITY_FLOOR}` is {values[READABILITY_FLOOR]!r}, not a number from 1 to 10; write a bare number, such as `{READABILITY_FLOOR} = 7.0`"] if floor is None else []),
|
||||
@@ -221,9 +225,18 @@ def load(top: pathlib.Path, main: pathlib.Path, home: pathlib.Path) -> ProjectCo
|
||||
]
|
||||
if faults:
|
||||
return Failure(f"{file}: {'; '.join(faults)}. The settings are {', '.join(SETTINGS)}, and optionally {', '.join(OPTIONAL[:-1])} and {OPTIONAL[-1]}.")
|
||||
# faults names a floor the config misspells.
|
||||
# faults names a floor the config misspells, and a formula or bar a plan in Jira lacks or misspells.
|
||||
assert floor is not None
|
||||
return ProjectConfig(file.parent.name, file.parent, top, {name: path for name, path in paths.items() if path}, env_file, waits is True, on_host is True, floor, **{name.replace("-", "_"): str(values[name]) for name in checks if name in values}, epic=epics["plan"], goals_epic=epics["goals-and-audience"], notifier=notifier, jira_finish=Finish(*finish) if finish else None, jira_scoring=Scoring(typing.cast(str, formula), typing.cast(float, bar_of(bar))) if epics["plan"] else None, pages=pages)
|
||||
assert scoring is not None or not epics["plan"]
|
||||
return ProjectConfig(file.parent.name, file.parent, top, {name: path for name, path in paths.items() if path}, env_file, waits is True, on_host is True, floor, **{name.replace("-", "_"): str(values[name]) for name in checks if name in values}, epic=epics["plan"], goals_epic=epics["goals-and-audience"], notifier=notifier, jira_finish=Finish(*finish) if finish else None, jira_scoring=scoring, pages=pages)
|
||||
|
||||
|
||||
def formula_fault(value: object) -> str | None:
|
||||
"""Why value is no formula that may score an item, as todo.md's `Score` line states one; None where it is one."""
|
||||
if not isinstance(value, str):
|
||||
return "not a formula, such as \"100 * V / (2**S + 8)\""
|
||||
parsed = parse_formula(value, variables(SHAPE))
|
||||
return parsed.reason if isinstance(parsed, Failure) else None
|
||||
|
||||
|
||||
def bar_of(value: object) -> float | None:
|
||||
|
||||
@@ -9,7 +9,7 @@ import unittest.mock
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from project_config.settings import env_files, Epic, Finish, held, load, NOTIFIERS, OUTSIDE, Page, ProjectConfig, Scoring, SETTINGS, Unnamed
|
||||
from project_config.settings import env_files, Epic, Finish, held, JiraScoring, load, NOTIFIERS, OUTSIDE, Page, ProjectConfig, SETTINGS, Unnamed
|
||||
from failure import Failure
|
||||
from test_env import isolated_env
|
||||
from project_config.main import located, title_templates
|
||||
@@ -325,7 +325,7 @@ class LoadTest(ConfigCase):
|
||||
self.write("acme", JIRA_CLIENT.replace("jira-score-bar = 1", "jira-score-bar = 0.5"))
|
||||
named = load(self.checkout, self.checkout, self.home)
|
||||
assert isinstance(named, ProjectConfig), named
|
||||
self.assertEqual(named.jira_scoring, Scoring("100 * V / (2**S + 8)", 0.5))
|
||||
self.assertEqual(named.jira_scoring, JiraScoring("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)
|
||||
@@ -348,6 +348,13 @@ class LoadTest(ConfigCase):
|
||||
config.write_text(CLIENT + JIRA_SCORING)
|
||||
self.assertIn("`jira-score-formula` is set, so `plan` must name a Jira epic; `jira-score-bar` is set, so `plan` must name a Jira epic", self.failure())
|
||||
|
||||
def test_a_formula_that_doesnt_parse_fails_naming_the_setting_and_why(self) -> None:
|
||||
config = self.write("acme", JIRA_CLIENT) / "config.toml"
|
||||
for formula, why in (("V +", "the formula 'V +' does not parse"), ("X", "the formula 'X' may hold only numbers, E, I, L, R, S, V, + - * / ** and parentheses")):
|
||||
with self.subTest(formula=formula):
|
||||
config.write_text(JIRA_CLIENT.replace('"100 * V / (2**S + 8)"', f'"{formula}"'))
|
||||
self.assertIn(f"`jira-score-formula` is '{formula}': {why}", self.failure())
|
||||
|
||||
def test_a_notifier_that_is_unknown_or_has_no_env_file_fails_naming_it(self) -> None:
|
||||
self.write("acme", CLIENT + 'env-file = "~/acme.env"\nnotifier = "teams"\n')
|
||||
self.assertIn("`notifier` is 'teams', not mattermost or slack", self.failure())
|
||||
|
||||
Reference in New Issue
Block a user