From 72b8dd326379f8f531101a120d74c4a9f16a84c4 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 17 Nov 2026 04:51:04 +0100 Subject: [PATCH] Set a Jira issue's blocked-by links from todo-item edit --blocked-by on an issue the loop filed --- README.md | 2 +- bin/plan_store/jira_epic.py | 100 ++++++++++++++++++++++--------- bin/plan_store/plans.py | 2 +- bin/plan_store/test_jira_epic.py | 83 ++++++++++++++++++++++--- bin/todo_item/main.py | 12 ++-- docs/decisions.md | 1 + 6 files changed, 158 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index d4afd2bc..ecca4080 100644 --- a/README.md +++ b/README.md @@ -220,7 +220,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a - `model_routing/` holds the shipped routing ladder (`routing-ladder.json`) and its steps (`ladder.py`), and reads a ladder from that file or a project's own (`ladder_file.py`), for loop-claude, `rule_hook`, both replay tools and `subagent-rung`. It finds a project's config folder through `project_config`. It also holds the list prices, which `routing_figures` and `transcript_archive` read. - `notifier/` sends the human a DM through the notifier a project's config names, for `notify` and for loop-claude through `loop_effects`. Its backends are `mattermost.py` and `slack.py`. - `plan/` is the plan's core, and imports neither `plan_store` nor `release_plan`. It holds an item and the items table's format (`todo_table.py`), releases (`release.py`), the ranking (`ranking.py`, with its score formula in `formula.py` and its blocker order in `blockers.py`), the paths an item's text names (`named_paths.py`) and `citations.py`, which holds `todo.md` and `docs/decisions.md` to each other. `goals_file.py` reads the goals file's sections, goals and goal weights, for the ranking and for `loop_claude`'s premises. -- `plan_store/` reads and writes a project's plan through the store the project's config names (`stores.py`). Every backend meets `plans.py`'s `PlanStore`: a markdown file (`todo_md.py`, which also ranks and checks the file in place, with its text edits in `markdown_edits.py`) or a Jira epic (`jira_epic.py`). `scoring.py` reads the goal weights that both backends rank by. `contract.py` holds the tests every backend that writes must pass, which `jira_epic.py` doesn't yet, since it changes no link, and `fakes.py` a plan in memory. +- `plan_store/` reads and writes a project's plan through the store the project's config names (`stores.py`). Every backend meets `plans.py`'s `PlanStore`: a markdown file (`todo_md.py`, which also ranks and checks the file in place, with its text edits in `markdown_edits.py`) or a Jira epic (`jira_epic.py`). `scoring.py` reads the goal weights that both backends rank by. `contract.py` holds the tests every backend that writes must pass, which `jira_epic.py` doesn't yet, since its own tests stand in for Jira, and `fakes.py` a plan in memory. - `rank_todo.py`, `settings_filter.py` and `statusline.py` are tools of one file each, tested beside them. - `record_store/` reads and writes a project's records, each through the store the project's config names (`stores.py`): a markdown file, a Confluence Cloud page (`confluence_page.py`), or, for the goals, a Jira epic's description (`jira_description.py`). `contract.py` holds the tests every backend must pass, and `fakes.py` a store in memory that the tests of other tools use. - `release_plan/` says which release is next and whether it is ready to cut (`release_standing.py`), from the plan, the changelog and the tags, and picks the item the next chunk takes first (`next_chunk.py`), for `chunk_preflight` and `loop_claude`. diff --git a/bin/plan_store/jira_epic.py b/bin/plan_store/jira_epic.py index baf8a571..3f5f6f49 100644 --- a/bin/plan_store/jira_epic.py +++ b/bin/plan_store/jira_epic.py @@ -50,6 +50,15 @@ class ReadsScoring(typing.Protocol): """The scoring `add` scores an item by: the config's formula and bar, with the goal weights that the goals file, the decision log and the comprehension history give.""" +@dataclasses.dataclass(frozen=True) +class Link: + """One "is blocked by" link of an issue.""" + # The key of the issue that blocks. + blocker: str + # The link's own id, which Jira deletes it by. + id: str + + @dataclasses.dataclass(frozen=True) class Issue: """A child issue as Jira answered it, checked to hold what an item is read from.""" @@ -57,8 +66,8 @@ class Issue: summary: str description: dict[str, typing.Any] | None fix_versions: tuple[str, ...] - # The key of each issue this one "is blocked by". - blockers: tuple[str, ...] + # The issue's "is blocked by" links, one per blocker unless Jira holds a link twice. + links: tuple[Link, ...] # PROPERTY's value; an empty object where the issue holds none. scores: dict[str, typing.Any] @@ -66,6 +75,10 @@ class Issue: def number(self) -> int: return number(self.key) + @property + def blockers(self) -> tuple[str, ...]: + return tuple(link.blocker for link in self.links) + @dataclasses.dataclass(frozen=True) class JiraPlan: @@ -124,10 +137,8 @@ class JiraPlan: answered = children(self.epic, authorization, self.http) if isinstance(answered, Failure): return answered - held = {raw.get("key") for raw in answered if isinstance(raw, dict)} - # `item` reads only an open child as a blocker, so a link to any other issue would be lost on the next read. - if missing := next((blocker for blocker in filing.blockers if blocker not in held), None): - return Failure(f"{self.label} holds no item {number(missing)} to be blocked by") + if missing := missing_blocker(filing.blockers, keys_of(answered), self.label): + return missing before = placing(answered, filing.item, value, scoring) created = self.http("POST", f"{self.epic.site}/rest/api/3/issue", authorization, {"fields": issue_fields | {"fixVersions": [{"name": version}]}, "properties": [{"key": PROPERTY, "value": filing.scores}]}) if isinstance(created, Failure): @@ -141,9 +152,7 @@ class JiraPlan: """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 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): + if isinstance(linked := self.link(key, blocker, authorization), Failure): notes.append(f"filed {key}, but cannot link it as blocked by {blocker}: {linked.reason}; link it in Jira") if isinstance(before, Failure): notes.append(f"filed {key}, but cannot rank it: {before.reason}; rank it in Jira") @@ -151,6 +160,24 @@ class JiraPlan: notes.append(f"filed {key}, but cannot rank it before {before}: {refused}; rank it in Jira") return tuple(notes) + def link(self, key: str, blocker: str, authorization: str) -> object: + """Links the issue named key as blocked by the issue named blocker; a Failure where Jira refuses.""" + # 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. + return self.http("POST", f"{self.epic.site}/rest/api/3/issueLink", authorization, {"type": {"name": BLOCKS}, "inwardIssue": {"key": blocker}, "outwardIssue": {"key": key}}) + + def relinked(self, issue: Issue, wanted: tuple[str, ...] | None, authorization: str) -> tuple[str, ...]: + """Makes issue blocked by exactly the issues named in wanted: a link for each blocker it lacks, and a deletion of each link to one it no longer has. None leaves its links as they are. A note for each request Jira refuses.""" + if wanted is None: + return () + notes = [] + for blocker in (blocker for blocker in wanted if blocker not in issue.blockers): + if isinstance(linked := self.link(issue.key, blocker, authorization), Failure): + notes.append(f"edited {issue.key}, but cannot link it as blocked by {blocker}: {linked.reason}; link it in Jira") + for link in (link for link in issue.links if link.blocker not in wanted): + if isinstance(deleted := self.http("DELETE", f"{self.epic.site}/rest/api/3/issueLink/{link.id}", authorization, None), Failure): + notes.append(f"edited {issue.key}, but cannot delete its link as blocked by {link.blocker}: {deleted.reason}; delete it in Jira") + 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.""" answer = self.http("PUT", f"{self.epic.site}/rest/agile/1.0/issue/rank", authorization, {"issues": [key], "rankBeforeIssue": before}) @@ -172,8 +199,10 @@ class JiraPlan: def child(self, id_: int, authorization: str) -> dict[str, typing.Any] | Failure: """Item id_'s issue, as the epic's open children answer it; a Failure where none of them is item id_.""" answered = children(self.epic, authorization, self.http) - if isinstance(answered, Failure): - return answered + return answered if isinstance(answered, Failure) else self.child_in(answered, id_) + + def child_in(self, answered: list[object], id_: int) -> dict[str, typing.Any] | Failure: + """Item id_'s issue among the epic's open children; a Failure where none of them is item id_.""" key = f"{project_of(self.epic.key)}-{id_}" found = next((raw for raw in answered if isinstance(raw, dict) and raw.get("key") == key), None) return Failure(no_item(self.label, id_)) if found is None else found @@ -193,13 +222,16 @@ class JiraPlan: return isinstance(texts, list) and texts[0].strip() == detail.strip() def edit(self, id_: int, fields: dict[str, str], detail: str | None, comment: str | None = None) -> Written | Failure: - """Sets the fields and the detail in one request, so Jira takes all of the edit or none, and then posts comment on the issue. `revision_of` says what an edit may set. + """Sets the fields and the detail in one request, so Jira takes all of the edit or none, then changes the issue's links, and then posts comment on the issue. `revision_of` says what an edit may set. - A comment Jira refuses leaves the edit made, so the write counts as landed, and a note says to post the comment by hand.""" + A link change or a comment Jira refuses leaves the edit made, so the write counts as landed, and a note says what to do by hand.""" authorization = basic_auth(self.env_file) if isinstance(authorization, Failure): return authorization - raw = self.child(id_, authorization) + answered = children(self.epic, authorization, self.http) + if isinstance(answered, Failure): + return answered + raw = self.child_in(answered, id_) if isinstance(raw, Failure): return raw issue = issue_of(raw) @@ -209,6 +241,8 @@ class JiraPlan: revision = revision_of(issue, cells(fields), detail, comment) if isinstance(revision, Failure): return revision + if revision.blockers is not None and (missing := missing_blocker(revision.blockers, keys_of(answered), self.label)): + return missing body = revision.body if detail is not None and not self.shows(issue, detail): description = self.description_of(detail) @@ -227,10 +261,11 @@ class JiraPlan: edited = self.http("PUT", url, authorization, body) if body else None if isinstance(edited, Failure): return Failure(f"cannot edit {key}: {edited.reason}; {PERHAPS_EDITED.format(key=key)}") + notes = self.relinked(issue, revision.blockers, authorization) if said is None: - return Written(id_) + return Written(id_, notes) posted = self.http("POST", f"{url}/comment", authorization, {"body": said}) - return Written(id_, (f"edited {key}, but cannot post the comment: {posted.reason}; post it in Jira",) if isinstance(posted, Failure) else ()) + return Written(id_, notes + ((f"edited {key}, but cannot post the comment: {posted.reason}; post it in Jira",) if isinstance(posted, Failure) else ())) def finish(self, id_: int) -> Written | Failure: """Moves item id_'s issue by the transition that the config names, to the status it names. Any open child of the epic may move, whoever filed it.""" @@ -331,18 +366,18 @@ class Revision: body: dict[str, typing.Any] # The release to move the issue to; None where the edit names none. release: str | None + # The key of each issue the edit makes the issue blocked by; None where the edit names no Blocked by. + blockers: tuple[str, ...] | None def revision_of(issue: Issue, named: dict[str, str], detail: str | None, comment: str | None) -> Revision | Failure: """The edit of issue that sets the cells in named, and the detail unless None, or why it cannot be made. - The summary, description and Fix Version of an issue a person filed are the team's, so there an edit may set only SCORED. Jira's screens don't show PROPERTY, so such an edit needs a comment, which tells the team. L, E, I and S are set together, so no issue is left partly scored. An issue the loop filed also keeps the label SECURITY in step with its Exempt. No edit changes a link.""" + The summary, description and Fix Version of an issue a person filed are the team's, so there an edit may set only SCORED. Jira's screens don't show PROPERTY, so such an edit needs a comment, which tells the team. L, E, I and S are set together, so no issue is left partly scored. An issue the loop filed also keeps the label SECURITY in step with its Exempt. Only there may an edit name the blockers, whose links `JiraPlan.relinked` changes; each must be an open child, which the caller checks.""" held = issue.scores - if BLOCKED_BY in named: - return Failure(f"the loop doesn't change an issue's links: link {issue.key} in Jira") own = held.get(FILED_BY[0]) == FILED_BY[1] - if not own and ("Item" in named or "Release" in named or detail is not None): - return Failure(f"a person filed {issue.key}, so the loop sets only its scores: change its summary, description and Fix Version in Jira") + if not own and ("Item" in named or "Release" in named or BLOCKED_BY in named or detail is not None): + return Failure(f"a person filed {issue.key}, so the loop sets only its scores: change its summary, description, links and Fix Version in Jira") if not own and not (comment and comment.strip()): return Failure(f"a person filed {issue.key}, and Jira doesn't show its team the scores: pass a comment saying that it is scored, and why") body: dict[str, typing.Any] = {} @@ -354,7 +389,7 @@ def revision_of(issue: Issue, named: dict[str, str], detail: str | None, comment if unfit := unfit_text(named.get("Item", ""), detail or ""): return unfit release = named.get("Release") - if isinstance(checked := item_fields({name: named[name] for name in ("Release", "Exempt") if name in named}, f"item {issue.key}"), Failure): + if isinstance(checked := item_fields({name: named[name] for name in ("Release", "Exempt", BLOCKED_BY) if name in named}, f"item {issue.key}", id_=issue.number), Failure): return checked if any(name in named for name in SCORED): texts = {name: str(value) for name, value in held.items()} | {name: named[name] for name in SCORED if name in named} @@ -367,7 +402,7 @@ def revision_of(issue: Issue, named: dict[str, str], detail: str | None, comment body["properties"] = [{"key": PROPERTY, "value": value}] if own and (scored.exempt == SECURITY) != (held.get("Exempt") == SECURITY): body["update"] = {"labels": [{"add" if scored.exempt == SECURITY else "remove": SECURITY}]} - return Revision(body, release) + return Revision(body, release, tuple(f"{project_of(issue.key)}-{blocker}" for blocker in checked.blocked_by) if BLOCKED_BY in named else None) def offer_of(raw: object) -> tuple[str, str, str, str] | None: @@ -438,19 +473,30 @@ def issue_of(raw: object) -> Issue | Failure: # The answer's nested fields are read as Jira documents them; one missing or of another type ends the read here, as a Failure, so no later step meets it. try: fields = raw["fields"] - blockers = tuple(link["inwardIssue"]["key"] for link in fields["issuelinks"] if "inwardIssue" in link and link["type"]["inward"] == "is blocked by") + links = tuple(Link(link["inwardIssue"]["key"], link["id"]) for link in fields["issuelinks"] if "inwardIssue" in link and link["type"]["inward"] == "is blocked by") held = raw.get("properties", {}).get(PROPERTY, {}) summary, description, versions = fields["summary"].strip(), fields["description"], tuple(version["name"] for version in fields["fixVersions"]) except (AttributeError, KeyError, TypeError) as failure: return Failure(f"{key} is not in the shape Jira Cloud's REST API version 3 documents: {failure!r}") if not isinstance(held, dict): return Failure(f"{key}'s issue property {PROPERTY} is not a JSON object") - issue = Issue(key, summary, description, versions, blockers, held) - if not isinstance(issue.description, dict | None) or not all(isinstance(name, str) for name in issue.fix_versions + issue.blockers) or not all(ISSUE_KEY.fullmatch(blocker) for blocker in issue.blockers): - return Failure(f"{key} is not in the shape Jira Cloud's REST API version 3 documents: its description, a Fix Version's name or a linked issue's key holds another kind of value") + issue = Issue(key, summary, description, versions, links, held) + if not isinstance(issue.description, dict | None) or not all(isinstance(name, str) for name in issue.fix_versions + issue.blockers) or not all(isinstance(link.id, str) for link in links) or not all(ISSUE_KEY.fullmatch(blocker) for blocker in issue.blockers): + return Failure(f"{key} is not in the shape Jira Cloud's REST API version 3 documents: its description, a Fix Version's name or a link's id or linked issue's key holds another kind of value") return issue +def keys_of(answered: list[object]) -> set[object]: + """The key of each issue in the search's answer.""" + return {raw.get("key") for raw in answered if isinstance(raw, dict)} + + +def missing_blocker(blockers: tuple[str, ...], held: set[object], label: str) -> Failure | None: + """A Failure naming the first of blockers that is not among the keys held, the plan's open children, or None. `item` reads only an open child as a blocker, so a link to any other issue would be lost on the next read.""" + missing = next((blocker for blocker in blockers if blocker not in held), None) + return None if missing is None else Failure(f"{label} holds no item {number(missing)} to be blocked by") + + def plan_of(issues: list[Issue], epic: Epic, to_markdown: ToMarkdown) -> Plan | Failure: """The plan the issues hold, in their order.""" project = project_of(epic.key) diff --git a/bin/plan_store/plans.py b/bin/plan_store/plans.py index 8dd38ab0..022c8d65 100644 --- a/bin/plan_store/plans.py +++ b/bin/plan_store/plans.py @@ -29,7 +29,7 @@ class Written: class PlanStore(typing.Protocol): - """A project's plan. plan_store.contract holds every backend that writes to the same behaviour; `jira_epic` doesn't hold it yet: it changes no link, and its own tests stand in for Jira. A write that fails leaves the plan as it was, except where its Failure says the tracker may have taken the write all the same, as when Jira's answer to a new issue, an edit or a finish is lost.""" + """A project's plan. plan_store.contract holds every backend that writes to the same behaviour; `jira_epic` doesn't hold it yet: its own tests stand in for Jira. A write that fails leaves the plan as it was, except where its Failure says the tracker may have taken the write all the same, as when Jira's answer to a new issue, an edit or a finish is lost.""" @property def label(self) -> str: diff --git a/bin/plan_store/test_jira_epic.py b/bin/plan_store/test_jira_epic.py index cba369b9..b0b2b565 100644 --- a/bin/plan_store/test_jira_epic.py +++ b/bin/plan_store/test_jira_epic.py @@ -22,9 +22,14 @@ SEARCH = "https://acme.atlassian.net/rest/api/3/search/jql" AUTHORIZATION = "Basic " + base64.b64encode(b"me@example.com:s3cret").decode() +def link_id(blocked: str, blocker: str) -> str: + """The id Jira gives the link that says blocked is blocked by blocker.""" + return f"{blocked}<{blocker}" + + def issue(key: str, summary: str = "Count the runs.", versions: tuple[str, ...] = ("0.1.0",), scores: dict[str, object] | None = None, blocked_by: tuple[str, ...] = (), description: object = None, blocks: tuple[str, ...] = ()) -> dict[str, object]: - links = [{"type": {"inward": "is blocked by", "outward": "blocks"}, "inwardIssue": {"key": blocker}} for blocker in blocked_by] - links += [{"type": {"inward": "is blocked by", "outward": "blocks"}, "outwardIssue": {"key": blocked}} for blocked in blocks] + links = [{"id": link_id(key, blocker), "type": {"inward": "is blocked by", "outward": "blocks"}, "inwardIssue": {"key": blocker}} for blocker in blocked_by] + links += [{"id": link_id(blocked, key), "type": {"inward": "is blocked by", "outward": "blocks"}, "outwardIssue": {"key": blocked}} for blocked in blocks] return { "key": key, "fields": {"summary": summary, "description": description, "fixVersions": [{"name": name} for name in versions], "issuelinks": links}, @@ -171,7 +176,7 @@ class JiraPlan(unittest.TestCase): def test_an_issue_in_another_shape_fails_the_read_naming_it(self): good = issue("ABC-1") - for wrong in ({"key": "ABC-1"}, issue("ABC-1", summary=None), issue("ABC-1", description="text"), good | {"fields": good["fields"] | {"fixVersions": [{"name": 7}]}}, good | {"fields": good["fields"] | {"issuelinks": [{"type": {"inward": "is blocked by"}, "inwardIssue": {"key": 7}}]}}, good | {"fields": good["fields"] | {"issuelinks": [{"type": {"inward": "is blocked by"}, "inwardIssue": {"key": "ABC-x"}}]}}, good | {"properties": None}): # type: ignore[arg-type, operator] + for wrong in ({"key": "ABC-1"}, issue("ABC-1", summary=None), issue("ABC-1", description="text"), good | {"fields": good["fields"] | {"fixVersions": [{"name": 7}]}}, good | {"fields": good["fields"] | {"issuelinks": [{"id": "1", "type": {"inward": "is blocked by"}, "inwardIssue": {"key": 7}}]}}, good | {"fields": good["fields"] | {"issuelinks": [{"id": "1", "type": {"inward": "is blocked by"}, "inwardIssue": {"key": "ABC-x"}}]}}, good | {"fields": good["fields"] | {"issuelinks": [{"type": {"inward": "is blocked by"}, "inwardIssue": {"key": "ABC-2"}}]}}, good | {"fields": good["fields"] | {"issuelinks": [{"id": 7, "type": {"inward": "is blocked by"}, "inwardIssue": {"key": "ABC-2"}}]}}, good | {"properties": None}): # type: ignore[arg-type, operator] with self.subTest(wrong=wrong): failure = self.read(wrong) # type: ignore[arg-type] self.assertIsInstance(failure, Failure) @@ -487,13 +492,19 @@ class Editing(unittest.TestCase): self.edited: object = None self.commented: object = {"id": "10100"} self.versions: object = [{"name": "0.1.0"}, {"name": "v0.2.0"}] + self.linked: object = None + self.unlinked: object = None 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.edited to an edit and self.commented to a new comment.""" + """Stands in for Jira: answers the epic, self.versions for the project's Fix Versions, self.open to the search, self.edited to an edit, self.commented to a new comment, self.linked to a new link and self.unlinked to a deleted one.""" self.calls.append((method, url, body)) assert authorization == AUTHORIZATION if method == "PUT": return self.edited + if method == "DELETE": + return self.unlinked + if url == LINKS: + return self.linked return self.commented if url.endswith("/comment") else {SEARCH: {"issues": self.open}, VERSIONS: self.versions}.get(url, {"key": "ABC-12"}) def to_adf(self, markdown: str) -> dict[str, object] | Failure: @@ -504,7 +515,7 @@ class Editing(unittest.TestCase): def writes(self) -> list[tuple[str, str, object]]: """Each request that changes Jira, in order.""" - return [call for call in self.calls if call[0] == "PUT" or call[1].endswith("/comment")] + return [call for call in self.calls if call[0] in ("PUT", "DELETE") or call[1].endswith(("/comment", "/issueLink"))] def test_sets_the_summary_description_and_scores_of_an_issue_the_loop_filed_in_one_request(self): self.assertEqual(self.edit(34, {"Tagline": "**Count every run.**", "L": "2", "Moves": ""}, "Why it counts."), Written(34)) @@ -583,7 +594,7 @@ class Editing(unittest.TestCase): def test_what_a_person_wrote_or_planned_is_never_edited(self): for fields, detail in (({"Tagline": "Count every run."}, None), ({}, "Why."), ({}, ""), ({"Release": "0.2.0"}, None), ({"Tagline": "Count.", "Release": "0.2.0", "L": "1"}, "")): with self.subTest(fields=fields, detail=detail): - self.assertEqual(self.edit(36, fields, detail, COMMENT), Failure("a person filed ABC-36, so the loop sets only its scores: change its summary, description and Fix Version in Jira")) + self.assertEqual(self.edit(36, fields, detail, COMMENT), Failure("a person filed ABC-36, so the loop sets only its scores: change its summary, description, links and Fix Version in Jira")) self.assertEqual(self.writes(), []) def test_scoring_an_unscored_issue_in_part_fails_before_any_write(self): @@ -599,8 +610,64 @@ class Editing(unittest.TestCase): self.commented = Failure("HTTP 403") self.assertEqual(self.edit(36, {"L": "2"}, None, COMMENT), Written(36, ("edited ABC-36, but cannot post the comment: HTTP 403; post it in Jira",))) - def test_an_edit_of_the_blockers_fails_since_the_store_changes_no_link(self): - self.assertEqual(self.edit(34, {"Blocked by": "35"}), Failure("the loop doesn't change an issue's links: link ABC-34 in Jira")) + def test_links_each_new_blocker_to_an_issue_the_loop_filed(self): + self.assertEqual(self.edit(34, {"Blocked by": "35, 36"}), Written(34)) + self.assertEqual(self.writes(), [("POST", LINKS, {"type": {"name": "Blocks"}, "inwardIssue": {"key": f"ABC-{blocker}"}, "outwardIssue": {"key": "ABC-34"}}) for blocker in (35, 36)]) + + def test_deletes_the_link_of_each_blocker_the_edit_drops_and_makes_none_for_one_it_keeps(self): + self.open[0] = issue("ABC-34", scores=PROPERTY, blocked_by=("ABC-35", "ABC-36")) + self.assertEqual(self.edit(34, {"Blocked by": "35"}), Written(34)) + self.assertEqual(self.writes(), [("DELETE", f"{LINKS}/{link_id('ABC-34', 'ABC-36')}", None)]) + + def test_an_empty_blocked_by_deletes_every_link_the_issue_holds(self): + self.open[0] = issue("ABC-34", scores=PROPERTY, blocked_by=("ABC-35", "ABC-36"), blocks=("ABC-35",)) + self.assertEqual(self.edit(34, {"Blocked by": ""}), Written(34)) + self.assertEqual(self.writes(), [("DELETE", f"{LINKS}/{link_id('ABC-34', blocker)}", None) for blocker in ("ABC-35", "ABC-36")]) + + def test_a_blocked_by_the_issue_already_holds_writes_nothing(self): + self.open[0] = issue("ABC-34", scores=PROPERTY, blocked_by=("ABC-35", "ABC-36")) + self.assertEqual(self.edit(34, {"Blocked by": "36, 35"}), Written(34)) + self.assertEqual(self.writes(), []) + + def test_a_blocker_swapped_for_another_deletes_one_link_and_makes_one(self): + self.open[0] = issue("ABC-34", scores=PROPERTY, blocked_by=("ABC-35",)) + self.edit(34, {"Blocked by": "36"}) + self.assertEqual([(method, url) for method, url, _ in self.writes()], [("POST", LINKS), ("DELETE", f"{LINKS}/{link_id('ABC-34', 'ABC-35')}")]) + + def test_changes_the_links_after_the_edit_and_before_the_comment(self): + self.assertEqual(self.edit(34, {"L": "2", "Blocked by": "35"}, None, COMMENT), Written(34)) + self.assertEqual([(method, url) for method, url, _ in self.writes()], [("PUT", f"{ISSUES}/ABC-34"), ("POST", LINKS), ("POST", f"{ISSUES}/ABC-34/comment")]) + + def test_a_failed_edit_makes_no_link(self): + self.edited = Failure("HTTP 400") + self.assertIsInstance(self.edit(34, {"L": "2", "Blocked by": "35"}), Failure) + self.assertEqual([method for method, _, _ in self.writes()], ["PUT"]) + + def test_a_link_jira_refuses_leaves_the_edit_made_with_a_note_and_the_other_links_changed(self): + self.open[0] = issue("ABC-34", scores=PROPERTY, blocked_by=("ABC-36",)) + self.linked = Failure("HTTP 403") + self.assertEqual(self.edit(34, {"Blocked by": "35"}), Written(34, ("edited ABC-34, but cannot link it as blocked by ABC-35: HTTP 403; link it in Jira",))) + self.assertEqual([method for method, _, _ in self.writes()], ["POST", "DELETE"]) + + def test_a_link_jira_refuses_to_delete_leaves_a_note_and_the_comment_posted(self): + self.open[0] = issue("ABC-34", scores=PROPERTY, blocked_by=("ABC-35", "ABC-36")) + self.unlinked = Failure("HTTP 404") + self.assertEqual(self.edit(34, {"Blocked by": ""}, None, COMMENT), Written(34, ("edited ABC-34, but cannot delete its link as blocked by ABC-35: HTTP 404; delete it in Jira", "edited ABC-34, but cannot delete its link as blocked by ABC-36: HTTP 404; delete it in Jira"))) + self.assertEqual(self.writes()[-1][1], f"{ISSUES}/ABC-34/comment") + + def test_a_blocker_that_is_no_open_child_fails_before_any_write(self): + self.assertEqual(self.edit(34, {"L": "2", "Blocked by": "35, 40"}), Failure("jira:https://acme.atlassian.net/browse/ABC-12 holds no item 40 to be blocked by")) + self.assertEqual(self.writes(), []) + + def test_a_blocked_by_out_of_format_or_naming_the_issue_itself_fails_before_any_write(self): + for cell in ("ABC-35", "35,36", "34"): + with self.subTest(cell=cell): + self.assertIsInstance(self.edit(34, {"Blocked by": cell}), Failure) + self.assertEqual(self.writes(), []) + + def test_the_links_of_an_issue_a_person_filed_are_never_changed(self): + for id_ in (35, 36): + self.assertEqual(self.edit(id_, {"Blocked by": "34"}, None, COMMENT), Failure(f"a person filed ABC-{id_}, so the loop sets only its scores: change its summary, description, links and Fix Version in Jira")) self.assertEqual(self.writes(), []) def test_an_issue_that_is_no_open_child_of_the_epic_is_not_edited(self): diff --git a/bin/todo_item/main.py b/bin/todo_item/main.py index 096d89f0..1919dfd5 100644 --- a/bin/todo_item/main.py +++ b/bin/todo_item/main.py @@ -42,15 +42,17 @@ empties the cell. --detail replaces the detail with the text on stdin, and --cle Text on stdin without --detail, and --detail without text on stdin, are refused, so no detail is dropped or wiped by mistake. It prints `Edited item in .` It doesn't write anything where ranking fails or scores the item under the bar. -In a Jira epic, edit changes an issue the loop filed: its summary, description and scores, and -the label `security` with --exempt. It doesn't change a link, so --blocked-by fails. -Of an issue a person filed it sets only the scores, --moves and --exempt, and only with --comment. +In a Jira epic, edit changes an issue the loop filed: its summary, description and scores, the label +`security` with --exempt, and its "is blocked by" links with --blocked-by: it makes a link for each +blocker added and deletes the link of each blocker dropped. Each blocker must be an open child of the epic. +Of an issue a person filed it sets only the scores, --moves and --exempt, and only with --comment; +--blocked-by fails there, since its links are the team's. The four scores are set together where the issue holds none yet. --comment is posted as a comment on the Jira issue, for the client's team, in the project's language. Jira doesn't show the team the scores, so say that the issue is scored, and why. A todo.md keeps no comment, so there the flag doesn't do anything. -Where Jira takes the edit and then refuses the comment, edit still prints `Edited item …`, -and says on stderr to post the comment in Jira. +Where Jira takes the edit and then refuses a link or the comment, edit still prints `Edited item …`, +and says on stderr what to do in Jira. move sets the item's release, as edit sets a cell. It prints `Moved item to release in .` In a Jira epic, move sets the Fix Version of an issue the loop filed; a person moves their own. diff --git a/docs/decisions.md b/docs/decisions.md index 0cbde6c8..4729151a 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -375,6 +375,7 @@ Messages keep each file's usual name, such as `todo.md`, as its label, since the - **The scores sit in one issue property, `plan-item`**, which needs no Jira admin (lilleman, 2026-11-12). An issue without it reads as an item nobody scored. - **The release is the earliest Fix Version named as a semver version**, and an issue with none fails the read, naming it. - **The loop files an item as a Task under the epic, and marks it as its own** (lilleman's calls of 2026-11-12). `"Filed by": "loop"` in the `plan-item` property tells such an issue from one a person filed, whose summary and description the loop never edits. Task is an issue type every Jira Software project template has; a project without it refuses the issue, saying so. The issue takes the project's Fix Version named as the release, with a leading v or without, and the store refuses an item whose release the project has no Fix Version for, before it files anything. A security finding also gets the label `security`, and its text never holds a secret's value. Jira takes a blocker's link only after the issue exists, so the store first checks that each blocker is an open child. A link Jira still refuses leaves the issue filed: the write counts as landed, with a note naming the link to make by hand. A failed create says the issue may exist all the same, since a lost answer doesn't tell. +- **The loop changes the "is blocked by" links only of an issue it filed** (lilleman's rule of 2026-11-12 that the loop writes only the scores of such an issue, applied to links; goal 1.6). A link is on the team's board where a score is not, since the scores sit in an issue property Jira's screens don't show, so a person's issue keeps the team's own links and `edit --blocked-by` there fails, as an edit of its summary, description or Fix Version does. On an issue the loop filed, `edit --blocked-by` makes a link per blocker added and deletes one per blocker dropped, each blocker an open child, as `add` checks. A link Jira refuses leaves the edit made, with a note naming the link to change by hand, as at `add`. - **The config states the formula and the bar, and the store ranks a new issue among the loop's own** (lilleman, 2026-11-12 and 2026-11-15). A plan in Jira has no `## Scoring`, so a config whose `plan` names an epic must set `jira-score-formula` and `jira-score-bar`. It fails to load without them, or with a formula that doesn't parse, since no setting a config needs has a default. A bench of readers picked the spelling: three fresh readers, seated as the person who writes a client's `config.toml`, each picked those keys over `jira-score` and `jira-bar`, `score-formula` and `score-bar`, and bare `score` and `bar`. The prefix matches the other Jira-only settings, "formula" says the value is no score, and "score-bar" says what the bar applies to. The store scores the item as `rank_todo.py` scores a row, with the goal weights from the goals file, the decision log and the comprehension history. It refuses an item under the bar that isn't exempt, or one whose Moves names a goal the goals file lacks, before it files anything. Then it ranks the issue just before the first issue the loop filed that ranks after it. A person's issues don't count, so the team's rank of each stays as it is. The order is todo.md's within a release: a question first, then a security finding, then the higher score, with a tie after the older issue. Questions go first because `rank_todo.py` ranks them ahead of security findings, since an answer may change other items (the loop's choice, 2026-11-16). Release doesn't count, since lilleman's call ranks by score among the loop's issues. A rank Jira refuses, or an issue of the loop's that no longer scores, leaves the new issue filed and last, with a note to rank it by hand. - **The store edits and moves only an issue the loop filed, and of an issue a person filed it sets only the scores** (lilleman's calls of 2026-11-12). On its own issue it sets the summary, description, scores and Fix Version in one request, so Jira takes all of an edit or none, and it keeps the label `security` in step with Exempt. Of a person's issue it writes only the `plan-item` property, and a comment: the team's screens don't show the property, so the comment tells the team why the scores changed, and the store refuses the edit without one. The comment's text comes from whoever scores, in the project's `language`. Where Jira takes the edit and then refuses the comment, the edit counts as made, and a note says to post the comment by hand. No edit changes a link, until `todo.md` item 389. - **The loop may re-score a person's issue that already holds scores, and never moves it.** lilleman's calls of 2026-11-12 cover an issue nobody scored, and say nothing of one that holds scores; larv-review chose on 2026-11-16, through todo item 382. A re-score changes only the loop's own reading of the issue, and not what the person wrote, so it is allowed, with a comment as the first scores need. L, E, I and S are set together, so no issue is left partly scored. The Fix Version says when the team ships the issue, and a release is its team's, so the store refuses the move and `CLAUDE.md` has the worker ask the human to move the issue.