diff --git a/bin/chunk_preflight/gathered.py b/bin/chunk_preflight/gathered.py index 2b582b66..248f0ae4 100644 --- a/bin/chunk_preflight/gathered.py +++ b/bin/chunk_preflight/gathered.py @@ -101,7 +101,7 @@ def planned(todo: str | Failure, cut: LastCut, default: str) -> Plan | NoItem: if stands == "unplanned": 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 work landed since it cannot be counted.") + return NoItem(f"{where} may hold no item for the next release after the last cut, {cut.tag}: what todo.md named, or the work landed, since then cannot be read. Find the next release yourself.") 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) diff --git a/bin/chunk_preflight/test_chunk_preflight.py b/bin/chunk_preflight/test_chunk_preflight.py index dc785be4..0c8e9efa 100644 --- a/bin/chunk_preflight/test_chunk_preflight.py +++ b/bin/chunk_preflight/test_chunk_preflight.py @@ -166,6 +166,37 @@ class ChunkPreflightTool(unittest.TestCase): self.assertNotIn("item 9", done.stdout) self.assertFalse((repo.temp / "proj-item-9").exists()) + def test_weighs_todo_md_at_the_last_cut_and_on_the_default_branch_after_it_alone(self): + """Each case's plans: before the tag, at it, on a side branch merged after it, and after it, each committed in turn where given.""" + cases = ( + ("a release named only before the cut", TODO, LATER, None, None, "item 9"), + ("a release named at the cut", None, TODO, None, LATER, "finished and ready to cut"), + ("a release named only on a side branch", None, LATER, TODO, None, "item 9"), + ) + for name, before, at, side, after, fact in cases: + with self.subTest(name): + repo = Repo(self, todo="") + for todo, title in ((before, "before"), (at, "at")): + if todo is not None: + repo.write(repo.root, "todo.md", todo) + repo.commit(repo.root, title) + repo.git(repo.root, "tag", "--force", "v0.1.0") + if side is not None: + repo.git(repo.root, "switch", "--quiet", "-c", "side") + # The branch ends on a plan main never held, so the merge changes todo.md. + for todo in (side, LATER + "| 10 | 0.3.0 | | | **Do another later thing.** | 1 | 1 | 1 | 1 | 1 | 1 by 9 | 90.0 |\n"): + repo.write(repo.root, "todo.md", todo) + repo.commit(repo.root, "side") + repo.git(repo.root, "switch", "--quiet", "main") + repo.git(repo.root, "merge", "--quiet", "--no-ff", "-m", "merge side", "side") + if after is not None: + repo.write(repo.root, "todo.md", after) + repo.commit(repo.root, "after") + repo.git(repo.root, "push", "--quiet", "--force", "origin", "main", "v0.1.0") + done = repo.preflight() + self.assertEqual(done.returncode, 0, done.stderr) + self.assertIn(fact, done.stdout) + def test_continues_the_items_worktree_and_else_its_pushed_branch(self): repo = Repo(self) repo.preflight() @@ -383,7 +414,7 @@ class Plans(unittest.TestCase): (LATER, 0, "planned first"), (EMPTY, 4, "finished and ready to cut"), (EMPTY, 0, "planned first"), - (LATER, Failure("count unreadable"), "cannot be counted"), + (LATER, Failure("count unreadable"), "cannot be read"), ) for todo, commits, fact in cases: with self.subTest(todo=todo, commits=commits): @@ -391,6 +422,9 @@ class Plans(unittest.TestCase): self.assertIn(fact, why) self.assertIn("v0.1.0", why) + def test_says_what_todo_md_named_since_the_last_cut_cannot_be_read(self): + self.assertIn("cannot be read", planned(LATER, LastCut("v0.1.0", "", 4, Failure("log unreadable")), "origin/main").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) diff --git a/bin/git_repo.py b/bin/git_repo.py index d776eb9f..aa9e8496 100644 --- a/bin/git_repo.py +++ b/bin/git_repo.py @@ -79,10 +79,10 @@ def default_plan(root: str, ref: str) -> DefaultPlan: def todos_since(tag: str | None | Failure, ref: str, cwd: str) -> list[str] | Failure: - """todo.md's text at tag and at each later commit on ref that changed it, read in cwd; empty where there is no tag.""" + """todo.md's text at tag and at each later commit on ref that changed it, read in cwd; empty where there is no tag. A pull request's own commits do not count, only the merge that landed it: --first-parent.""" if not isinstance(tag, str): return [] - changed = git("log", "--format=%H", f"{tag}..{ref}", "--", "todo.md", cwd=cwd) + changed = git("log", "--first-parent", "--format=%H", f"{tag}..{ref}", "--", "todo.md", cwd=cwd) if isinstance(changed, Failure): return changed texts = [] diff --git a/bin/test_git_repo.py b/bin/test_git_repo.py index 0d32f6f7..291509a4 100644 --- a/bin/test_git_repo.py +++ b/bin/test_git_repo.py @@ -3,7 +3,6 @@ import pathlib import subprocess import sys import tempfile -import time import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) @@ -12,6 +11,22 @@ from failure import Failure import git_repo +class Git(unittest.TestCase): + # Each command is a shell alias, so it touches no repository, whatever GIT_DIR the test runs under. + + def test_stops_git_still_running_after_the_timeout_and_says_so(self): + done = git_repo.git("-c", "alias.hang=!sleep 5", "hang", timeout=0.2) + self.assertIsInstance(done, Failure) + self.assertIn("hang", done.reason) + self.assertIn("0.2 s", done.reason) + + def test_says_git_printed_text_that_is_not_utf_8(self): + done = git_repo.git("-c", "alias.latin=!printf 'caf\\351'", "latin") + self.assertIsInstance(done, Failure) + self.assertIn("latin", done.reason) + self.assertIn("UTF-8", done.reason) + + class StalledOrigin(unittest.TestCase): """A checkout whose origin, run through git's ext transport, answers nothing for 10 s, and which records no default branch for it.""" @@ -23,17 +38,13 @@ class StalledOrigin(unittest.TestCase): subprocess.run(["git", *args], capture_output=True, check=True, cwd=self.root) def test_reading_the_default_branch_fails_after_the_timeout(self): - started = time.monotonic() ref = git_repo.default_ref(self.root, 0.5) - self.assertLess(time.monotonic() - started, 5) self.assertIsInstance(ref, Failure) self.assertIn("stopped after 0.5 s", ref.reason) def test_fetching_the_default_branch_fails_after_the_timeout(self): - started = time.monotonic() with contextlib.chdir(self.root): found = git_repo.default_branch(stale_ok=True, timeout=0.5) - self.assertLess(time.monotonic() - started, 5) self.assertIsInstance(found, Failure) self.assertIn("stopped after 0.5 s", found.reason) diff --git a/bin/test_rank_todo.py b/bin/test_rank_todo.py index f81255e6..18a6ccb3 100644 --- a/bin/test_rank_todo.py +++ b/bin/test_rank_todo.py @@ -420,6 +420,7 @@ class Standing(unittest.TestCase): cases = ( ("v1.2.3", 4, (1, 2, 4), set(), "next"), ("v1.2.3", 4, (1, 3, 0), {(1, 3, 0)}, "next"), + ("v1.2.3", 4, (1, 3, 0), {(1, 2, 3), (1, 3, 0)}, "next"), ("v0.2.0", 4, (0, 4, 0), set(), "next"), (None, 4, (0, 2, 0), set(), "next"), (None, 4, None, set(), "next"), @@ -435,6 +436,8 @@ class Standing(unittest.TestCase): ("v1.2.3", 0, (1, 3, 0), {(1, 2, 4)}, "unplanned"), ("v1.2.3", 0, None, set(), "unplanned"), ("v1.2.3", Failure("count unreadable"), None, set(), "unknown"), + ("v1.2.3", 4, (1, 3, 0), Failure("log unreadable"), "unknown"), + ("v1.2.3", 4, (1, 2, 3), Failure("log unreadable"), "cut"), ) for tag, landed, earliest, named, stands in cases: with self.subTest(tag=tag, landed=landed, earliest=earliest, named=named): @@ -452,7 +455,7 @@ class Standing(unittest.TestCase): header = "## Items\n\n| ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score |\n|---|---|---|---|---|---|---|---|---|---|---|---|\n" texts = [header + row.format(id=1, release="0.2.0"), "", "not a table | x |", header + row.format(id=2, release="0.3.0")] self.assertEqual(todo_table.named_releases(texts), {(0, 2, 0), (0, 3, 0)}) - self.assertEqual(todo_table.named_releases(Failure("log unreadable")), set()) + self.assertEqual(todo_table.named_releases(Failure("log unreadable")), Failure("log unreadable")) class Main(unittest.TestCase): diff --git a/bin/todo_table.py b/bin/todo_table.py index bb3ea8c2..c06fe5ec 100644 --- a/bin/todo_table.py +++ b/bin/todo_table.py @@ -18,7 +18,8 @@ MOVES = "Moves" # How the items table's header opens, which tells it from any other table in todo.md. HEADER_START = "| ID | Release |" # How the plan's earliest release stands to the version x.y.z the newest tag names, the last cut. "next": it is the earliest release after x.y.z that todo.md has named since the cut, or no tag names a version. "cut": it is x.y.z or earlier. -# Else the next release, the earliest named since the cut, holds no item: "finished" where work landed since the cut, "unplanned" where none did, and "unknown" where that cannot be read. +# Else the next release, the earliest named since the cut, holds no item: "finished" where work landed since the cut, and "unplanned" where none did. "unknown": what todo.md named, or the work landed, since the cut cannot be read. +# A release named since the cut stays the next until a tag cuts it, even once its items moved to a later release: larv_review/plan.py's emptied counts such a release emptied too, and `~/.claude/CLAUDE.md` → "Working loop" then stops for the human, or plans the release with their approval. Standing = typing.Literal["next", "cut", "finished", "unplanned", "unknown"] # todo.md's ## Details section, its body the first group. DETAILS = re.compile(r"^## Details\n(.*?)(?=^## |\Z)", re.M | re.S) @@ -201,13 +202,14 @@ def landed(cut: LastCut) -> int | Failure: return cut.commits if entries is None else entries -def named_releases(todos: list[str] | Failure) -> set[tuple[int, int, int]]: - """Each release the todo.md texts file items under. A text that does not parse names none, and so does a history that cannot be read, which leaves the plan's earliest release as the next.""" - found = [items(todo) for todo in todos] if isinstance(todos, list) else [] - return {item.release for parsed in found if isinstance(parsed, list) for item in parsed} +def named_releases(todos: list[str] | Failure) -> set[tuple[int, int, int]] | Failure: + """Each release the todo.md texts file items under; a text that does not parse names none.""" + if isinstance(todos, Failure): + return todos + return {item.release for parsed in map(items, todos) if isinstance(parsed, list) for item in parsed} -def standing(tag: str | None | Failure, landed: int | Failure, earliest: tuple[int, int, int] | None, named: set[tuple[int, int, int]]) -> Standing: +def standing(tag: str | None | Failure, landed: int | Failure, earliest: tuple[int, int, int] | None, named: set[tuple[int, int, int]] | Failure) -> Standing: """How the plan's earliest release, None where the plan holds no item, stands to the newest v* tag, as Standing says. named holds each release todo.md named since that tag, and landed the work landed since it.""" cut = re.fullmatch(r"v([0-9]+)\.([0-9]+)\.([0-9]+)", tag) if isinstance(tag, str) else None if cut is None: @@ -215,6 +217,8 @@ def standing(tag: str | None | Failure, landed: int | Failure, earliest: tuple[i version = tuple(int(part) for part in cut.groups()) if earliest is not None and earliest <= version: return "cut" + if isinstance(named, Failure): + return "unknown" if earliest is not None and earliest == min(release for release in named | {earliest} if release > version): return "next" if isinstance(landed, Failure):