|
|
|
@@ -8,6 +8,7 @@ import unittest
|
|
|
|
|
|
|
|
|
|
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
|
|
|
|
|
|
|
|
|
from project_config.templates import BRANCH
|
|
|
|
|
from failure import Failure
|
|
|
|
|
from chunk_preflight.choices import forge_of, planned, worktree_add
|
|
|
|
|
from chunk_preflight.gathered import Gathered, ItemFacts, NamedPath, NoItem, Ran, Worktree
|
|
|
|
@@ -148,7 +149,7 @@ class ChunkPreflightTool(unittest.TestCase):
|
|
|
|
|
repo = Repo(self)
|
|
|
|
|
repo.push_from_elsewhere("todo.md", SHIPPED)
|
|
|
|
|
plain = repo.preflight()
|
|
|
|
|
self.assertIn("- The project's config names: language English; commit-title {summary}; pull-request-title {summary}; branch item-{id}.\n", plain.stdout)
|
|
|
|
|
self.assertIn("- The project's config sets: language English; commit-title {summary}; pull-request-title {summary}; branch item-{id}.\n", plain.stdout)
|
|
|
|
|
config = repo.temp / "home" / ".claude-projects" / "proj" / "config.toml"
|
|
|
|
|
config.write_text(config.read_text() + 'language = "Swedish"\ncommit-title = "PAY-{id} - {summary}"\nbranch = "feature/PAY-{id}"\n')
|
|
|
|
|
done = repo.preflight("--worktree")
|
|
|
|
@@ -156,7 +157,7 @@ class ChunkPreflightTool(unittest.TestCase):
|
|
|
|
|
worktree = repo.temp / "proj-feature-PAY-7"
|
|
|
|
|
self.assertEqual(repo.git(worktree, "rev-parse", "--abbrev-ref", "HEAD").strip(), "feature/PAY-7")
|
|
|
|
|
self.assertIn("- Open pull requests from feature/PAY-7: ", done.stdout)
|
|
|
|
|
self.assertIn("- The project's config names: language Swedish; commit-title PAY-{id} - {summary}; pull-request-title {summary}; branch feature/PAY-{id}.\n", done.stdout)
|
|
|
|
|
self.assertIn("- The project's config sets: language Swedish; commit-title PAY-{id} - {summary}; pull-request-title {summary}; branch feature/PAY-{id}.\n", done.stdout)
|
|
|
|
|
|
|
|
|
|
def test_reads_the_fetched_default_branchs_plan_and_makes_the_items_worktree_off_it_leaving_the_checkout_as_it_was(self):
|
|
|
|
|
repo = Repo(self)
|
|
|
|
@@ -358,7 +359,7 @@ class ChunkPreflightTool(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def item_facts(todo=TODO, **fields):
|
|
|
|
|
"""The facts of todo's next item, its worktree made, with fields given replacing the rest."""
|
|
|
|
|
return ItemFacts(**{"plan": planned(todo, CUT, "origin/main"), "worktree": Worktree(pathlib.Path("/c/proj-item-3"), "added on the new branch item-3, made off origin/main."), "pulls": None, "named": [], "tools": [], **fields})
|
|
|
|
|
return ItemFacts(**{"plan": planned(todo, CUT, "origin/main", BRANCH), "worktree": Worktree(pathlib.Path("/c/proj-item-3"), "added on the new branch item-3, made off origin/main."), "pulls": None, "named": [], "tools": [], **fields})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def gathered(item, release=CUT, note=None, plan_outside=False):
|
|
|
|
@@ -380,7 +381,7 @@ class Render(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_states_each_fact_once_with_the_paths_between_the_worktree_and_the_open_pull_requests(self):
|
|
|
|
|
lines = render(gathered(item_facts()))
|
|
|
|
|
self.assertEqual([line.partition(":")[0] for line in lines[:6]], ["- Last version cut", "- The earliest release in origin/main's todo.md", "- Worktree", "- The project's config puts its files at", "- The project's config names", "- Open pull requests from item-3"])
|
|
|
|
|
self.assertEqual([line.partition(":")[0] for line in lines[:6]], ["- Last version cut", "- The earliest release in origin/main's todo.md", "- Worktree", "- The project's config puts its files at", "- The project's config sets", "- Open pull requests from item-3"])
|
|
|
|
|
self.assertEqual([line for line in lines[6:] if line.startswith("- Open pull requests")], [])
|
|
|
|
|
|
|
|
|
|
def test_says_that_a_plan_outside_the_checkout_hides_a_release_whose_items_are_all_done(self):
|
|
|
|
@@ -507,40 +508,40 @@ class OpenPulls(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
class Plans(unittest.TestCase):
|
|
|
|
|
def test_picks_the_earliest_releases_first_item_that_does_not_wait_or_says_why_there_is_none(self):
|
|
|
|
|
self.assertEqual(planned(TODO, CUT, "origin/main").first.id, 3)
|
|
|
|
|
waits = planned(TODO.replace("| 3 | 0.2.0 | | |", "| 3 | 0.2.0 | | question |"), CUT, "origin/main")
|
|
|
|
|
self.assertEqual(planned(TODO, CUT, "origin/main", BRANCH).first.id, 3)
|
|
|
|
|
waits = planned(TODO.replace("| 3 | 0.2.0 | | |", "| 3 | 0.2.0 | | question |"), CUT, "origin/main", BRANCH)
|
|
|
|
|
self.assertIn("waits", waits.why)
|
|
|
|
|
self.assertIn("0.2.0", waits.why)
|
|
|
|
|
self.assertIn("Permission denied", planned(Failure("Permission denied"), CUT, "origin/main").why)
|
|
|
|
|
self.assertEqual(planned(Failure("Permission denied"), CUT, "origin/main").why, "origin/main's todo.md cannot be read: Permission denied.")
|
|
|
|
|
self.assertEqual(planned(Failure("Permission denied"), CUT, "origin/main", pathlib.Path("/projects/acme/todo.md")).why, "/projects/acme/todo.md cannot be read: Permission denied.")
|
|
|
|
|
self.assertIn("L 'x'", planned(TODO.replace("| 2 | 2 | 3 | 5 |", "| x | 2 | 3 | 5 |"), CUT, "origin/main").why)
|
|
|
|
|
self.assertIn("details cannot be read", planned(TODO + "```\n", CUT, "origin/main").text)
|
|
|
|
|
self.assertIn("Permission denied", planned(Failure("Permission denied"), CUT, "origin/main", BRANCH).why)
|
|
|
|
|
self.assertEqual(planned(Failure("Permission denied"), CUT, "origin/main", BRANCH).why, "origin/main's todo.md cannot be read: Permission denied.")
|
|
|
|
|
self.assertEqual(planned(Failure("Permission denied"), CUT, "origin/main", BRANCH, pathlib.Path("/projects/acme/todo.md")).why, "/projects/acme/todo.md cannot be read: Permission denied.")
|
|
|
|
|
self.assertIn("L 'x'", planned(TODO.replace("| 2 | 2 | 3 | 5 |", "| x | 2 | 3 | 5 |"), CUT, "origin/main", BRANCH).why)
|
|
|
|
|
self.assertIn("details cannot be read", planned(TODO + "```\n", CUT, "origin/main", BRANCH).text)
|
|
|
|
|
|
|
|
|
|
def test_tells_a_plan_with_no_items_table_from_one_whose_table_holds_no_item(self):
|
|
|
|
|
without = planned("", CUT, "origin/main").why
|
|
|
|
|
without = planned("", CUT, "origin/main", BRANCH).why
|
|
|
|
|
self.assertIn("origin/main", without)
|
|
|
|
|
self.assertIn("no items table", without)
|
|
|
|
|
self.assertNotIn("cannot be read", without)
|
|
|
|
|
empty = planned(EMPTY, LastCut(None, "", 4, []), "origin/main").why
|
|
|
|
|
empty = planned(EMPTY, LastCut(None, "", 4, []), "origin/main", BRANCH).why
|
|
|
|
|
self.assertIn("holds no item", empty)
|
|
|
|
|
self.assertNotIn("no items table", empty)
|
|
|
|
|
|
|
|
|
|
def test_names_a_release_cut_under_a_dated_heading_as_the_last_cut_on_a_branch_with_no_tag(self):
|
|
|
|
|
said = planned(EMPTY, LastCut(None, "## 0.0.1 - 2026-10-03\n", 0, []), "origin/main").why
|
|
|
|
|
said = planned(EMPTY, LastCut(None, "## 0.0.1 - 2026-10-03\n", 0, []), "origin/main", BRANCH).why
|
|
|
|
|
self.assertIn("the next release after the last cut, 0.0.1 (dated in CHANGELOG.md)", said)
|
|
|
|
|
|
|
|
|
|
def test_says_the_tags_cannot_be_read_with_gits_reason_and_names_no_cut(self):
|
|
|
|
|
said = planned(EMPTY, LastCut(Failure("git exited 128: not a git repository"), "", 4, []), "origin/main").why
|
|
|
|
|
said = planned(EMPTY, LastCut(Failure("git exited 128: not a git repository"), "", 4, []), "origin/main", BRANCH).why
|
|
|
|
|
self.assertIn("origin/main's tags cannot be read: git exited 128: not a git repository.", said)
|
|
|
|
|
self.assertIn("Find the next release yourself.", said)
|
|
|
|
|
self.assertNotIn("no release is cut yet", said)
|
|
|
|
|
|
|
|
|
|
def test_names_the_start_as_the_last_cut_where_nothing_is_cut(self):
|
|
|
|
|
said = planned(EMPTY, LastCut(None, "", 4, [TODO]), "origin/main").why
|
|
|
|
|
said = planned(EMPTY, LastCut(None, "", 4, [TODO]), "origin/main", BRANCH).why
|
|
|
|
|
self.assertIn("release 0.2.0, the next after the start, since no release is cut yet,", said)
|
|
|
|
|
self.assertIn("has landed yet.", said)
|
|
|
|
|
self.assertIn("since the cut.", planned(EMPTY, LastCut(None, "## 0.1.0 - 2026-10-03\n", 4, [TODO]), "origin/main").why)
|
|
|
|
|
self.assertIn("since the cut.", planned(EMPTY, LastCut(None, "## 0.1.0 - 2026-10-03\n", 4, [TODO]), "origin/main", BRANCH).why)
|
|
|
|
|
|
|
|
|
|
def test_finds_the_release_after_the_last_cut_finished_or_to_be_planned_where_the_plan_holds_no_item_for_it(self):
|
|
|
|
|
named = "release 0.2.0, the next after the last cut, v0.1.0"
|
|
|
|
@@ -556,24 +557,24 @@ class Plans(unittest.TestCase):
|
|
|
|
|
)
|
|
|
|
|
for todo, commits, todos, reviewed, fact, release in cases:
|
|
|
|
|
with self.subTest(todo=todo, commits=commits, todos=todos, reviewed=reviewed):
|
|
|
|
|
why = planned(todo, LastCut("v0.1.0", "", commits, todos, reviewed), "origin/main").why
|
|
|
|
|
why = planned(todo, LastCut("v0.1.0", "", commits, todos, reviewed), "origin/main", BRANCH).why
|
|
|
|
|
self.assertIn(fact, why)
|
|
|
|
|
self.assertIn(release, 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)
|
|
|
|
|
self.assertIn("cannot be read", planned(LATER, LastCut("v0.1.0", "", 4, Failure("log unreadable")), "origin/main", BRANCH).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)
|
|
|
|
|
self.assertEqual(planned(LATER, LastCut("v0.1.0", "", 4, [LATER]), "origin/main", BRANCH).first.id, 9)
|
|
|
|
|
|
|
|
|
|
def test_says_the_plan_files_items_under_a_release_already_cut(self):
|
|
|
|
|
why = planned(TODO, LastCut("v0.2.0", "", 4, []), "origin/main").why
|
|
|
|
|
why = planned(TODO, LastCut("v0.2.0", "", 4, []), "origin/main", BRANCH).why
|
|
|
|
|
self.assertIn("release 0.2.0", why)
|
|
|
|
|
self.assertIn("v0.2.0", why)
|
|
|
|
|
self.assertIn("not after", why)
|
|
|
|
|
|
|
|
|
|
def test_takes_an_item_without_a_detail_as_its_tagline_alone(self):
|
|
|
|
|
self.assertEqual(planned(TODO[:TODO.index("## Details")], CUT, "origin/main").text, "**Do the next thing.**")
|
|
|
|
|
self.assertEqual(planned(TODO[:TODO.index("## Details")], CUT, "origin/main", BRANCH).text, "**Do the next thing.**")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Gathering(unittest.TestCase):
|
|
|
|
|