Let a project's config name a working branch per epic that chunks branch off and merge into
CI / tests (pull_request) Successful in 5m4s

This commit is contained in:
Lilleman
2026-11-20 19:32:59 +01:00
parent 9531e5c337
commit 72a4d346d7
33 changed files with 991 additions and 56 deletions
+49 -1
View File
@@ -1,3 +1,4 @@
import contextlib
import dataclasses
import os
import pathlib
@@ -11,11 +12,13 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from project_config.templates import BRANCH
from release_plan.next_chunk import CarriedOver, NoItem
from project_config.settings import Epic, ProjectConfig
from chunk_preflight.main import epic_branch_of, item_worktree, line_count, ran, seconds, TIMEOUT
from failure import Failure
from chunk_preflight.gathered import Gathered, ItemFacts, LeftWorktree, NamedPath, Ran, Worktree
from git_cli import git_repo
from test_env import isolated_env
from release_plan.release_standing import LastCut, UNSEEN_RELEASES
from chunk_preflight.main import line_count, ran, seconds, TIMEOUT
from release_plan.awaiting_merge import marked
from release_plan import next_chunk
from chunk_preflight.facts import open_pulls, render
@@ -585,6 +588,51 @@ class Render(unittest.TestCase):
self.assertIn("`larv-review places` could not finish: timed out", said)
class EpicBranchWorktree(unittest.TestCase):
"""A chunk's worktree in a project whose config names an epic's working branch, here ABC-1."""
def setUp(self):
self.repo = Repo(self)
self.enterContext(contextlib.chdir(self.repo.root))
# item_worktree runs git in this process's environment, so the identity its merge commit needs is the checkout's own.
for name, value in (("user.name", "t"), ("user.email", "t@example.com")):
self.repo.git(self.repo.root, "config", name, value)
def test_the_first_chunk_makes_the_epic_branch_on_origin_and_branches_off_it_recording_where_it_merges(self):
made = item_worktree(self.repo.root, "ABC-7", "origin/main", 30, "ABC-1")
self.assertEqual(made, Worktree(self.repo.temp / "proj-ABC-7", "added on the new branch ABC-7, made off origin/ABC-1. Made origin/ABC-1 off origin/main. Its pull request goes into ABC-1."))
self.assertEqual(self.repo.git(self.repo.origin, "rev-parse", "ABC-1"), self.repo.git(self.repo.root, "rev-parse", "origin/main"))
self.assertEqual(git_repo.default_ref(str(made.path)), "origin/ABC-1")
def test_a_later_chunk_branches_off_what_the_epic_branch_holds(self):
item_worktree(self.repo.root, "ABC-7", "origin/main", 30, "ABC-1")
first = self.repo.temp / "proj-ABC-7"
self.repo.write(first, "src/first.py", "FIRST = 1\n")
self.repo.commit(first, "first")
self.repo.git(first, "push", "--quiet", "origin", "ABC-7:ABC-1")
made = item_worktree(self.repo.root, "ABC-8", "origin/main", 30, "ABC-1")
self.assertIn("origin/ABC-1 already holds origin/main.", made.how)
self.assertTrue((made.path / "src/first.py").exists())
def test_a_default_branch_that_conflicts_with_the_epic_branch_makes_no_worktree_and_leaves_it_to_a_person(self):
item_worktree(self.repo.root, "ABC-7", "origin/main", 30, "ABC-1")
first = self.repo.temp / "proj-ABC-7"
self.repo.write(first, "src/app.py", "def run():\n\treturn 2\n\n")
self.repo.commit(first, "first")
self.repo.git(first, "push", "--quiet", "origin", "ABC-7:ABC-1")
self.repo.push_from_elsewhere("src/app.py", "def run():\n\treturn 3\n\n")
made = item_worktree(self.repo.root, "ABC-8", "origin/main", 30, "ABC-1")
self.assertIsInstance(made, Failure)
self.assertTrue(made.reason.startswith("none made: origin/main doesn't merge into origin/ABC-1 cleanly, so a person merges it"), made.reason)
self.assertFalse((self.repo.temp / "proj-ABC-8").exists())
def test_names_the_epic_branch_by_the_plans_epic_and_none_where_the_config_sets_no_template(self):
config = ProjectConfig("proj", pathlib.Path("/config"), pathlib.Path("/checkout"), {}, epic=Epic("https://acme.atlassian.net", "ABC-1"), epic_branch="epic/{epic}")
self.assertEqual(epic_branch_of(config), "epic/ABC-1")
self.assertIsNone(epic_branch_of(dataclasses.replace(config, epic_branch=None)))
self.assertEqual(epic_branch_of(dataclasses.replace(config, epic=None)), Failure("none made: the config sets `epic-branch`, but its `plan` names no Jira epic to name the branch by; chunk-preflight makes an epic's chunks only from a plan kept in Jira"))
class OpenPulls(unittest.TestCase):
def test_lists_gh_rows_as_they_come_and_only_teas_rows_from_the_branch(self):
self.assertEqual(open_pulls("12\thttps://github.com/o/r/pull/12\n14\thttps://github.com/o/r/pull/14\n", "gh", "item-3"), ["#12 https://github.com/o/r/pull/12", "#14 https://github.com/o/r/pull/14"])