Answer principles round 1: 0 🔴, 4 🟡; one class per standing, cases in the table, test chunk_start's open session and the earlier-release case

This commit is contained in:
2026-10-18 10:53:12 +02:00
parent ab081dd33f
commit e9cc88ed27
9 changed files with 119 additions and 91 deletions
+47 -36
View File
@@ -1,28 +1,12 @@
"""The next chunk's pick: the item it takes first, weighed against the last release cut, and what the default branch holds for it."""
import dataclasses
import re
import typing
from git_repo import commits_since, file_at, git, newest_release_tag
from failure import Failure
from todo_table import Item, items, next_item, renames
from markdown_text import sections
# How the plan's earliest release stands to the last cut, the version x.y.z the newest v* tag names.
Standing = typing.Literal[
# It is the next release: the earliest after x.y.z that todo.md has named since the cut, or there is no cut to weigh it against.
"next",
# It is x.y.z or earlier.
"cut",
# The next release holds no item, and work has landed since the cut.
"finished",
# The next release holds no item, and no work has landed since the cut.
"unplanned",
# todo.md's texts since the cut, or the changes since it, cannot be read.
"unknown",
]
@dataclasses.dataclass(frozen=True)
class LastCut:
"""What the default branch holds about its last release, which chunk_item weighs the plan against."""
@@ -37,15 +21,43 @@ class LastCut:
@dataclasses.dataclass(frozen=True)
class Pick:
"""How the plan stands to the last cut, the next release, and the item the next chunk takes first."""
standing: Standing
# None where standing is cut or unknown, or todo.md names no next release.
class Next:
"""The plan's earliest release is the next release: the earliest after the last cut that todo.md has named since it, or there is no cut to weigh it against."""
# None where the plan holds no item.
release: tuple[int, int, int] | None
# next_item's pick where standing is next; else None.
# The item the next chunk takes first, next_item's pick; None where every item waits or the plan holds none.
item: Item | None
@dataclasses.dataclass(frozen=True)
class Cut:
"""The plan's earliest release is the last cut's version or earlier."""
release: tuple[int, int, int]
@dataclasses.dataclass(frozen=True)
class Finished:
"""The next release holds no item, and work has landed since the cut."""
# The next release, None where todo.md has named none since the cut.
release: tuple[int, int, int] | None
@dataclasses.dataclass(frozen=True)
class Unplanned:
"""The next release holds no item, and no work has landed since the cut."""
# The next release, None where todo.md has named none since the cut.
release: tuple[int, int, int] | None
@dataclasses.dataclass(frozen=True)
class Unknown:
"""todo.md's texts since the cut, or the changes since it, cannot be read."""
# How the plan stands to the last cut, the version x.y.z the newest v* tag names, with the item the next chunk takes first where there is one.
Pick = Next | Cut | Finished | Unplanned | Unknown
@dataclasses.dataclass(frozen=True)
class DefaultPlan:
"""What the default branch, as last fetched, holds for chunk_item."""
@@ -79,26 +91,25 @@ def todos_since(tag: str | None | Failure, ref: str, cwd: str) -> list[str] | Fa
def chunk_item(found: list[Item], cut: LastCut) -> Pick:
"""The pick from todo.md's items, weighed against the last cut. Routing and chunk-preflight both pick with it, so they name one item."""
stands, release = standing(cut.tag, unreleased_changes(cut), min((item.release for item in found), default=None), named_releases(cut.todos_since))
return Pick(stands, release, next_item(found) if stands == "next" else None)
return standing(cut.tag, unreleased_changes(cut), min((item.release for item in found), default=None), next_item(found), named_releases(cut.todos_since))
def standing(tag: str | None | Failure, changes: int | Failure, earliest: tuple[int, int, int] | None, named: set[tuple[int, int, int]] | Failure) -> tuple[Standing, tuple[int, int, int] | None]:
"""How earliest, the plan's earliest release, None where the plan holds no item, stands to tag, the newest v* tag; and the next release: earliest where it is next, else the earliest release todo.md named since the cut, None for cut and unknown. changes counts the changes since the tag, and named holds each release todo.md named since it."""
cut = re.fullmatch(r"v([0-9]+)\.([0-9]+)\.([0-9]+)", tag) if isinstance(tag, str) else None
if cut is None:
return "next", earliest
version = tuple(int(part) for part in cut.groups())
if earliest is not None and earliest <= version:
return "cut", None
def standing(tag: str | None | Failure, changes: int | Failure, earliest: tuple[int, int, int] | None, first: Item | None, named: set[tuple[int, int, int]] | Failure) -> Pick:
"""How earliest, the plan's earliest release, None where the plan holds no item, stands to tag, the newest v* tag. first is the earliest release's first item that does not wait, changes counts the changes since the tag, and named holds each release todo.md named since it."""
tagged = re.fullmatch(r"v([0-9]+)\.([0-9]+)\.([0-9]+)", tag) if isinstance(tag, str) else None
if tagged is None:
return Next(earliest, first)
cut_version = tuple(int(part) for part in tagged.groups())
if earliest is not None and earliest <= cut_version:
return Cut(earliest)
if isinstance(named, Failure):
return "unknown", None
first_named = min((release for release in named if release > version), default=None)
return Unknown()
first_named = min((release for release in named if release > cut_version), default=None)
if earliest is not None and (first_named is None or earliest <= first_named):
return "next", earliest
return Next(earliest, first)
if isinstance(changes, Failure):
return "unknown", None
return ("finished" if changes else "unplanned"), first_named
return Unknown()
return Finished(first_named) if changes else Unplanned(first_named)
def unreleased_changes(cut: LastCut) -> int | Failure: