Answer principles round 1: 0 🔴, 3 🟡; take the next release from chunk_item's pick, read default_plan once, and test the changelog, the next release and the unreadable case

This commit is contained in:
2026-10-22 01:54:08 +02:00
parent 4e5902fcc5
commit 8e1d166534
5 changed files with 77 additions and 41 deletions
+28 -15
View File
@@ -1,13 +1,13 @@
import pathlib
from larv_review.git import changes_unreleased
from chunk_pick import chunk_item, default_plan, LastCut, Next, Unknown, unreleased_changes
from failure import Failure
from git_repo import file_at, top
from todo_table import Item, items, NoItemsTable, renames, version
from git_repo import top
def scoring_run_due(before: list[Item], after: list[Item], ships: list[int], unreleased: bool, renamed: set[tuple[int, int, int]]) -> list[str] | Failure:
"""Why the plan calls a scoring run, empty when it does not. before is the default branch's plan, after the chunk's, ships the IDs of the items the chunk ships, unreleased whether `changes_unreleased` holds for the default branch, and renamed the releases the chunk's plan marks renamed.
def scoring_run_due(before: list[Item], after: list[Item], ships: list[int], landed: tuple[int, int, int] | None, renamed: set[tuple[int, int, int]]) -> list[str] | Failure:
"""Why the plan calls a scoring run, empty when it does not. before is the default branch's plan, after the chunk's, ships the IDs of the items the chunk ships, landed the release unreleased changes have landed towards (`landed_towards`), and renamed the releases the chunk's plan marks renamed.
A chunk that ships an item naming the floor is due one, so it can prove the floor met. So is a chunk that empties a release after work has landed towards it, so no release ends unmeasured. A release the chunk's plan marks renamed is due none.
"""
@@ -16,19 +16,31 @@ def scoring_run_due(before: list[Item], after: list[Item], ships: list[int], unr
return Failure(f"neither plan holds item {', '.join(map(str, unknown))}")
shipped = [plan[id_] for id_ in ships]
reasons = [f"ships item {item.id}, which names the comprehension floor" for item in shipped if "comprehension floor" in item.tagline.lower()]
# The earliest release the default branch's plan names. chunk_pick.standing reads "next release" from the last cut and the renames since, which the chunk's own plan marks here through renamed.
next_release = min((item.release for item in before), default=None)
for release in emptied(before, after, shipped, renamed):
if work_landed(release, shipped, next_release, unreleased):
if work_landed(release, shipped, landed):
# SKILL.md → "Second run" keys on this wording.
reasons.append(f"leaves release {version(release)} with no plan item")
return reasons
# larv-review --help points here rather than restating the rule, so the rule is written once.
def work_landed(release: tuple[int, int, int], shipped: list[Item], next_release: tuple[int, int, int] | None, unreleased: bool) -> bool:
"""Whether work has landed towards release, for the scoring-run trigger. It has when the chunk ships one of the release's items. It has too when the release is next_release, the earliest the default branch's plan names, and unreleased holds: the default branch has an unreleased change, which `chunk_pick.unreleased_changes` counts for chunk-preflight too."""
return any(item.release == release for item in shipped) or (release == next_release and unreleased)
def work_landed(release: tuple[int, int, int], shipped: list[Item], landed: tuple[int, int, int] | None) -> bool:
"""Whether work has landed towards release, for the scoring-run trigger. It has when the chunk ships one of the release's items. It has too when release is landed, the release that unreleased changes on the default branch landed towards."""
return any(item.release == release for item in shipped) or release == landed
def landed_towards(found: list[Item], cut: LastCut) -> tuple[int, int, int] | None | Failure:
"""The release unreleased changes on the default branch have landed towards: the next release, as chunk-preflight names it (`chunk_pick.chunk_item`), where `chunk_pick.unreleased_changes` counts one or more. None where there is no such release or no such change; a Failure where either cannot be read. found is the default branch's plan."""
pick = chunk_item(found, cut)
if isinstance(pick, Unknown):
return Failure("could not tell the next release from the default branch's tags and todo.md history")
# Next is the one pick with a release that holds items; Cut, Finished and Unplanned have none to empty.
if not isinstance(pick, Next):
return None
changes = unreleased_changes(cut)
if isinstance(changes, Failure):
return changes
return pick.release if changes else None
def emptied(before: list[Item], after: list[Item], shipped: list[Item], renamed: set[tuple[int, int, int]]) -> list[tuple[int, int, int]]:
@@ -43,7 +55,8 @@ def plan_reasons(default: str, ids: list[int]) -> list[str] | Failure:
checkout = top()
if isinstance(checkout, Failure):
return checkout
before = file_at(default, "todo.md")
held = default_plan(checkout, default)
before = held.todo
if isinstance(before, Failure):
return before
try:
@@ -64,7 +77,7 @@ def plan_reasons(default: str, ids: list[int]) -> list[str] | Failure:
renamed = renames(after)
if isinstance(renamed, Failure):
return Failure(f"the checkout's todo.md: {renamed.reason}")
unreleased = changes_unreleased(checkout, default)
if isinstance(unreleased, Failure):
return unreleased
return scoring_run_due(planned, chunk, ids, unreleased, renamed)
landed = landed_towards(planned, held.cut)
if isinstance(landed, Failure):
return landed
return scoring_run_due(planned, chunk, ids, landed, renamed)