Answer architecture round 3: 0 🔴, 1 🟡; pick the next chunk's item in one function, todo_table.chunk_item, which routing and the preflight both call, so routing names no item where the release after the last cut has none

This commit is contained in:
2026-10-17 02:19:11 +02:00
parent 45004e1b0b
commit 4cf3c2bd8c
9 changed files with 130 additions and 95 deletions
+3 -22
View File
@@ -4,16 +4,13 @@ import pathlib
import re
import typing
from todo_table import chunk_item, Item, item_details, items
from failure import Failure
from todo_table import Item, item_details, items, next_item
# The CLI that lists a forge's pull requests: gh for a github.com origin, tea for any other.
Forge = typing.Literal["gh", "tea"]
# The command each forge's CLI lists pull requests with; pulls_command adds the flags that pick their rows and fields.
PULLS_LIST: dict[Forge, tuple[str, ...]] = {"gh": ("gh", "pr", "list"), "tea": ("tea", "pulls", "list")}
# How the plan's earliest release stands to the version x.y.z the newest tag names. "next": it is x.y.z+1, x.y+1.0 or x+1.0.0, or no tag names a version. "cut": it is x.y.z or earlier.
# Else the release after the tag holds no item: "finished" where commits followed the tag, "unplanned" where none did, and "unknown" where they cannot be counted.
Standing = typing.Literal["next", "cut", "finished", "unplanned", "unknown"]
@dataclasses.dataclass(frozen=True)
@@ -94,7 +91,7 @@ class Gathered:
def planned(todo: str | Failure, release: Release, default: str) -> Plan | NoItem:
"""The plan in todo, the default branch's todo.md, with the item the next chunk takes first, todo_table.next_item's pick, where standing finds the plan's earliest release next; else why there is none."""
"""The plan in todo, the default branch's todo.md, with the item the next chunk takes first, todo_table.chunk_item's pick, which routing makes too; else why there is none."""
where = f"{default}'s todo.md"
if isinstance(todo, Failure):
return NoItem(f"{where} cannot be read: {todo.reason}.")
@@ -104,7 +101,7 @@ def planned(todo: str | Failure, release: Release, default: str) -> Plan | NoIte
if found is None:
return NoItem(f"{where} holds no items table.")
earliest = min((item.release for item in found), default=None)
stands = standing(release, earliest)
stands, first = chunk_item(found, release.tag, release.commits)
if earliest is not None and stands == "cut":
return NoItem(f"{where} files items under release {version(earliest)}, which is not after the last cut, {release.tag}.")
gap = f"{where} holds no item for the release after the last cut, {release.tag}, and"
@@ -114,7 +111,6 @@ def planned(todo: str | Failure, release: Release, default: str) -> Plan | NoIte
return NoItem(f"{gap} no commit has landed since, so that release is to be planned first.")
if stands == "unknown":
return NoItem(f"{gap} the commits since it cannot be counted.")
first = next_item(found)
if first is None:
return NoItem(f"every item of release {version(earliest)} in {where} waits." if earliest is not None else f"{where}'s items table holds no item.")
details = item_details(todo)
@@ -122,21 +118,6 @@ def planned(todo: str | Failure, release: Release, default: str) -> Plan | NoIte
return Plan(found, first, f"{first.tagline}\n\n{detail}".strip())
def standing(release: Release, earliest: tuple[int, int, int] | None) -> Standing:
"""How the plan's earliest release, None where the plan holds no item, stands to the version the release's tag names, as Standing says."""
cut = re.fullmatch(r"v([0-9]+)\.([0-9]+)\.([0-9]+)", release.tag) if isinstance(release.tag, str) else None
if cut is None:
return "next"
major, minor, patch = (int(part) for part in cut.groups())
if earliest in ((major, minor, patch + 1), (major, minor + 1, 0), (major + 1, 0, 0)):
return "next"
if earliest is not None and earliest <= (major, minor, patch):
return "cut"
if isinstance(release.commits, Failure):
return "unknown"
return "finished" if release.commits else "unplanned"
def version(release: tuple[int, int, int]) -> str:
return ".".join(map(str, release))
+6 -9
View File
@@ -44,7 +44,7 @@ import subprocess
import sys
import typing
from git_repo import commit_exists, commits_since, default_branch, default_branch_todo, file_at, git, newest_release_tag, top
from git_repo import commit_exists, default_branch, default_plan, file_at, git, top
from failure import Failure
from chunk_preflight.gathered import Forge, forge_of, Gathered, ItemFacts, named_paths, NamedPath, NoItem, Plan, planned, pulls_command, Ran, Release, Worktree, worktree_add, worktree_on
from chunk_preflight.facts import render
@@ -96,18 +96,15 @@ def preflight(root: pathlib.Path, timeout: float) -> list[str] | Failure:
if isinstance(default, Failure):
return default
ref, note = default
cut = release(ref, root)
plan = planned(default_branch_todo(str(root), timeout), cut, ref)
held = default_plan(str(root), timeout)
if isinstance(held, Failure):
return held
cut = Release(held.tag, file_at(ref, "CHANGELOG.md", str(root)), held.commits)
plan = planned(held.todo, cut, ref)
item = plan if isinstance(plan, NoItem) else item_facts(root, ref, plan, timeout)
return render(Gathered(ref, note, cut, item))
def release(default: str, root: pathlib.Path) -> Release:
tag = newest_release_tag(default)
commits = tag if isinstance(tag, Failure) else commits_since(tag, default)
return Release(tag, file_at(default, "CHANGELOG.md", str(root)), commits)
def item_facts(root: pathlib.Path, default: str, plan: Plan, timeout: float) -> ItemFacts:
worktree = item_worktree(root, plan.branch, default)
path = worktree.path if isinstance(worktree, Worktree) else None
+1 -26
View File
@@ -9,7 +9,7 @@ import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from failure import Failure
from chunk_preflight.gathered import forge_of, Gathered, ItemFacts, named_paths, NamedPath, NoItem, planned, Ran, Release, standing, Worktree, worktree_add
from chunk_preflight.gathered import forge_of, Gathered, ItemFacts, named_paths, NamedPath, NoItem, planned, Ran, Release, Worktree, worktree_add
from test_env import isolated_env
from chunk_preflight.main import line_count, ran, seconds, TIMEOUT
from chunk_preflight.facts import open_pulls, render, unreleased_entries
@@ -387,31 +387,6 @@ class Plans(unittest.TestCase):
self.assertEqual(planned(TODO[:TODO.index("## Details")], CUT, "origin/main").text, "**Do the next thing.**")
class Standing(unittest.TestCase):
def test_takes_the_earliest_release_where_it_is_the_next_patch_minor_or_major_or_no_tag_names_a_version(self):
cases = (
(Release("v1.2.3", "", 4), (1, 2, 4), "next"),
(Release("v1.2.3", "", 4), (1, 3, 0), "next"),
(Release("v1.2.3", "", 4), (2, 0, 0), "next"),
(Release(None, "", 4), (0, 2, 0), "next"),
(Release(None, "", 4), None, "next"),
(Release("v1.2.3-rc.1", "", 4), (1, 2, 3), "next"),
(Release(Failure("tags unreadable"), "", 4), (0, 2, 0), "next"),
(Release("v1.2.3", "", 4), (1, 2, 3), "cut"),
(Release("v1.2.3", "", 4), (1, 2, 2), "cut"),
(Release("v1.2.3", "", 4), (1, 2, 5), "finished"),
(Release("v1.2.3", "", 4), (1, 3, 1), "finished"),
(Release("v1.2.3", "", 4), (2, 0, 1), "finished"),
(Release("v1.2.3", "", 4), None, "finished"),
(Release("v1.2.3", "", 0), (1, 4, 0), "unplanned"),
(Release("v1.2.3", "", 0), None, "unplanned"),
(Release("v1.2.3", "", Failure("count unreadable")), (1, 4, 0), "unknown"),
)
for release, earliest, stands in cases:
with self.subTest(release=release, earliest=earliest):
self.assertEqual(standing(release, earliest), stands)
class Gathering(unittest.TestCase):
def test_counts_the_top_level_entries_under_unreleased(self):
self.assertEqual(unreleased_entries(CHANGELOG), 2)