Answer stability round 2: 0 🔴, 2 🟡; take the next release as the earliest todo.md has named since the last cut, so an emptied patch or a major jump stops the loop too, count work landed by the Unreleased entries before commits, read the default branch once, and test the emptied release and the stalled origin through real git

This commit is contained in:
2026-10-17 02:34:15 +02:00
parent 4cf3c2bd8c
commit 5ba8920dbf
13 changed files with 224 additions and 142 deletions
+5 -11
View File
@@ -1,20 +1,20 @@
"""The lines the preflight prints, stated from what it gathered."""
from todo_table import bundle_candidates, Item
from todo_table import bundle_candidates, Item, LastCut, unreleased_entries
from failure import Failure
from chunk_preflight.gathered import Forge, Gathered, ItemFacts, NamedPath, NoItem, Plan, PULLS_LIST, Ran, Release, version
from markdown_text import quoted, sections
from chunk_preflight.gathered import Forge, Gathered, ItemFacts, NamedPath, NoItem, Plan, PULLS_LIST, Ran, version
from markdown_text import quoted
def render(found: Gathered) -> list[str]:
"""One `- ` line per fact, then the item's tagline and detail, and what each tool printed."""
note = [f"- {found.note}"] if found.note else []
head = [*note, f"- {last_release(found.default, found.release)}"]
head = [*note, f"- {last_release(found.default, found.cut)}"]
if isinstance(found.item, NoItem):
return [*head, f"- No plan item: {found.item.why} No worktree was made."]
return [*head, *item_lines(found.default, found.item)]
def last_release(default: str, release: Release) -> str:
def last_release(default: str, release: LastCut) -> str:
if isinstance(release.tag, Failure):
return f"Last version cut: cannot be read: {release.tag.reason}"
cut = f"Last version cut: {release.tag or 'none'}."
@@ -27,12 +27,6 @@ def last_release(default: str, release: Release) -> str:
return f"{cut} Unreleased: {commits}; {changelog}."
def unreleased_entries(changelog: str) -> int | None:
"""How many top-level `- ` entries CHANGELOG.md holds under ## Unreleased; None without that section."""
found = sections(changelog).get("Unreleased")
return None if found is None else sum(line.startswith("- ") for line in found[0].splitlines())
def item_lines(default: str, item: ItemFacts) -> list[str]:
first = item.plan.first
worktree = item.worktree.reason if isinstance(item.worktree, Failure) else f"{item.worktree.path}, {item.worktree.how}"
+9 -18
View File
@@ -4,7 +4,7 @@ import pathlib
import re
import typing
from todo_table import chunk_item, Item, item_details, items
from todo_table import chunk_item, Item, item_details, items, LastCut
from failure import Failure
# The CLI that lists a forge's pull requests: gh for a github.com origin, tea for any other.
@@ -21,15 +21,6 @@ class Ran:
stderr: str
@dataclasses.dataclass(frozen=True)
class Release:
"""What the last release fact rests on, each read from the default branch."""
tag: str | None | Failure
changelog: str | Failure
# How many commits follow the tag, or make up the branch where it has none.
commits: int | Failure
@dataclasses.dataclass(frozen=True)
class Plan:
"""The default branch's todo.md items, and first, the item the next chunk takes first."""
@@ -85,12 +76,12 @@ class Gathered:
default: str
# Why origin reads as last fetched; None after a fetch.
note: str | None
release: Release
cut: LastCut
# What was found or made for the plan's first item; else why the plan names none.
item: ItemFacts | NoItem
def planned(todo: str | Failure, release: Release, default: str) -> Plan | NoItem:
def planned(todo: str | Failure, cut: LastCut, default: str) -> Plan | NoItem:
"""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):
@@ -101,16 +92,16 @@ 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, first = chunk_item(found, release.tag, release.commits)
stands, first = chunk_item(found, cut)
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"
return NoItem(f"{where} files items under release {version(earliest)}, which is not after the last cut, {cut.tag}.")
gap = f"{where} holds no item for the next release after the last cut, {cut.tag}, and"
if stands == "finished":
return NoItem(f"{gap} commits have landed since, so that release is finished and ready to cut, and the working loop stops here.")
return NoItem(f"{gap} work has landed since, so that release is finished and ready to cut, and the working loop stops here.")
if stands == "unplanned":
return NoItem(f"{gap} no commit has landed since, so that release is to be planned first.")
return NoItem(f"{gap} no work 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.")
return NoItem(f"{gap} the work landed since it cannot be counted.")
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)
+9 -11
View File
@@ -12,10 +12,11 @@ that branch holds it, the plan loop-claude routes on, and prints:
holds under ## Unreleased, or else how many commits followed the tag;
- the earliest release in todo.md, and that release's first item that does not wait, the item
loop-claude routes on, with its L and E + I. It names that item only where the tag names no
version x.y.z, or the release is x.y.z+1, x.y+1.0 or x+1.0.0. For a later release, or a todo.md
that holds no item, it says the release after the tag holds none: finished and ready to cut where
commits followed the tag, and else to be planned first. For x.y.z or an earlier release, it says
todo.md files items under a release already cut;
version x.y.z, or the release is the earliest after x.y.z that todo.md has named at the tag or
since: the next release. Where the next release holds no item, it says so: finished and ready to
cut where work landed since the tag, counted as the ## Unreleased entries or else the commits, and
else to be planned first. For x.y.z or an earlier release, it says todo.md files items under a
release already cut;
- the item's worktree: a sibling of the checkout named <checkout>-item-<ID>, on the branch
item-<ID>. It continues a worktree already on that branch; else it adds one on the local branch,
else on a new branch tracking origin's, else on a new branch off the default branch;
@@ -46,7 +47,7 @@ import typing
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.gathered import Forge, forge_of, Gathered, ItemFacts, named_paths, NamedPath, NoItem, Plan, planned, pulls_command, Ran, Worktree, worktree_add, worktree_on
from chunk_preflight.facts import render
BIN = pathlib.Path(__file__).resolve().parents[1]
@@ -96,13 +97,10 @@ def preflight(root: pathlib.Path, timeout: float) -> list[str] | Failure:
if isinstance(default, Failure):
return default
ref, note = default
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)
held = default_plan(str(root), ref)
plan = planned(held.todo, held.cut, ref)
item = plan if isinstance(plan, NoItem) else item_facts(root, ref, plan, timeout)
return render(Gathered(ref, note, cut, item))
return render(Gathered(ref, note, held.cut, item))
def item_facts(root: pathlib.Path, default: str, plan: Plan, timeout: float) -> ItemFacts:
+29 -12
View File
@@ -9,10 +9,11 @@ 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, Worktree, worktree_add
from chunk_preflight.gathered import forge_of, Gathered, ItemFacts, named_paths, NamedPath, NoItem, planned, Ran, Worktree, worktree_add
from test_env import isolated_env
from todo_table import LastCut, unreleased_entries
from chunk_preflight.main import line_count, ran, seconds, TIMEOUT
from chunk_preflight.facts import open_pulls, render, unreleased_entries
from chunk_preflight.facts import open_pulls, render
BIN = pathlib.Path(__file__).resolve().parents[1]
README = "# Project\n\n## Goals\n\n1. **Achieve:** Work.\n\n## Audience\n\nMe.\n"
@@ -51,7 +52,7 @@ LATER = TODO[:TODO.index("| 5 |")] + "| 9 | 0.3.0 | | | **Do a later thing.**
EMPTY = TODO[:TODO.index("| 5 |")]
CHANGELOG = "# Changelog\n\n## Unreleased\n\n- One.\n - A nested line.\n- Two.\n\n## 0.1.0\n\n- Old.\n"
# What the preflight reads of the last release: tag v0.1.0, two entries under ## Unreleased, and 4 commits since the tag.
CUT = Release("v0.1.0", CHANGELOG, 4)
CUT = LastCut("v0.1.0", CHANGELOG, 4, [])
# Two open pull requests, as `tea pulls list --fields index,head,url --output tsv` prints them; anything else exits 1.
FAKE_TEA = "#!/bin/sh\n[ \"$*\" = 'pulls list --fields index,head,url --output tsv' ] || exit 1\nprintf 'index\\thead\\turl\\n12\\titem-7\\thttps://forge/pulls/12\\n13\\tother\\thttps://forge/pulls/13\\n'\n"
# Item 3's open pull request, as `gh pr list` prints it through the preflight's template; any other arguments exit 1.
@@ -66,7 +67,7 @@ print("12\\thttps://github.com/o/r/pull/12")
class Repo:
"""An origin with a tagged release, a clone of it at <temp>/proj, and a fake tea and gh on PATH."""
def __init__(self, test, todo=TODO, origin="origin.git"):
def __init__(self, test, todo=TODO, origin="origin.git", changelog=CHANGELOG):
temp = tempfile.TemporaryDirectory()
test.addCleanup(temp.cleanup)
self.temp = pathlib.Path(os.path.realpath(temp.name))
@@ -85,7 +86,7 @@ class Repo:
self.write(self.root, "src/app.py", "def run():\n\treturn 1\n\n")
self.commit(self.root, "start")
self.git(self.root, "tag", "v0.1.0")
self.write(self.root, "CHANGELOG.md", CHANGELOG)
self.write(self.root, "CHANGELOG.md", changelog)
if todo:
self.write(self.root, "todo.md", todo)
self.commit(self.root, "plan")
@@ -152,6 +153,19 @@ class ChunkPreflightTool(unittest.TestCase):
self.assertNotIn("#13", done.stdout)
self.assertNotIn("`gone.py`:", done.stdout)
def test_names_no_item_and_makes_no_worktree_where_the_release_after_the_last_cut_has_emptied(self):
for changelog, fact in ((CHANGELOG, "finished and ready to cut"), ("# Changelog\n\n## Unreleased\n\n## 0.1.0\n\n- Old.\n", "planned first")):
with self.subTest(fact=fact):
repo = Repo(self, changelog=changelog)
repo.write(repo.root, "todo.md", LATER)
repo.commit(repo.root, "ship 0.2.0")
repo.git(repo.root, "push", "--quiet", "origin", "main")
done = repo.preflight()
self.assertEqual(done.returncode, 0, done.stderr)
self.assertIn(fact, done.stdout)
self.assertNotIn("item 9", done.stdout)
self.assertFalse((repo.temp / "proj-item-9").exists())
def test_continues_the_items_worktree_and_else_its_pushed_branch(self):
repo = Repo(self)
repo.preflight()
@@ -277,16 +291,16 @@ class Render(unittest.TestCase):
def test_states_the_unreleased_entries_and_else_the_commits_since_the_last_cut(self):
self.assertIn("v0.1.0. Unreleased: 2 entries", rendered(NoItem("x.")))
self.assertIn("1 entry", rendered(NoItem("x."), Release("v0.1.0", "## Unreleased\n\n- One.\n", 4)))
without = rendered(NoItem("x."), Release("v0.1.0", "# Changelog\n", 4))
self.assertIn("1 entry", rendered(NoItem("x."), LastCut("v0.1.0", "## Unreleased\n\n- One.\n", 4, [])))
without = rendered(NoItem("x."), LastCut("v0.1.0", "# Changelog\n", 4, []))
self.assertIn("4 commits since v0.1.0", without)
self.assertIn("no ## Unreleased", without)
untagged = rendered(NoItem("x."), Release(None, "", 1))
untagged = rendered(NoItem("x."), LastCut(None, "", 1, []))
self.assertIn("cut: none", untagged)
self.assertIn("1 commit on origin/main", untagged)
def test_states_why_the_changelog_and_the_commits_since_the_last_cut_cannot_be_read(self):
said = rendered(NoItem("x."), Release("v0.1.0", Failure("changelog unreadable"), Failure("count unreadable")))
said = rendered(NoItem("x."), LastCut("v0.1.0", Failure("changelog unreadable"), Failure("count unreadable"), []))
self.assertIn("changelog unreadable", said)
self.assertIn("cannot be counted: count unreadable", said)
self.assertNotIn("no ## Unreleased", said)
@@ -359,7 +373,7 @@ class Plans(unittest.TestCase):
without = planned("", CUT, "origin/main").why
self.assertIn("origin/main", without)
self.assertIn("no items table", without)
empty = planned(EMPTY, Release(None, "", 4), "origin/main").why
empty = planned(EMPTY, LastCut(None, "", 4, []), "origin/main").why
self.assertIn("holds no item", empty)
self.assertNotIn("no items table", empty)
@@ -373,12 +387,15 @@ class Plans(unittest.TestCase):
)
for todo, commits, fact in cases:
with self.subTest(todo=todo, commits=commits):
why = planned(todo, Release("v0.1.0", "", commits), "origin/main").why
why = planned(todo, LastCut("v0.1.0", "", commits, [TODO]), "origin/main").why
self.assertIn(fact, why)
self.assertIn("v0.1.0", why)
def test_takes_the_earliest_release_where_no_earlier_one_was_named_since_the_last_cut(self):
self.assertEqual(planned(LATER, LastCut("v0.1.0", "", 4, [LATER]), "origin/main").first.id, 9)
def test_says_the_plan_files_items_under_a_release_already_cut(self):
why = planned(TODO, Release("v0.2.0", "", 4), "origin/main").why
why = planned(TODO, LastCut("v0.2.0", "", 4, []), "origin/main").why
self.assertIn("release 0.2.0", why)
self.assertIn("v0.2.0", why)
self.assertIn("not after", why)