Answer product-owner round 1: 0 🔴, 4 🟡 (0 misread); move through the open status, refuse open-epic without a branch, tell a conflict from git's other failures

This commit is contained in:
Lilleman
2026-11-20 20:15:33 +01:00
parent 9f367e90ca
commit ce2e9dc0e5
9 changed files with 143 additions and 21 deletions
+56
View File
@@ -9,12 +9,23 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from failure import Failure
from git_cli import git_repo
from git_cli.epic_branch import levelled
from forge.commands import runner
def sh(cwd: pathlib.Path, *args: str) -> str:
return subprocess.run(["git", "-c", "user.name=T", "-c", "user.email=t@example.com", *args], cwd=cwd, check=True, capture_output=True, text=True).stdout.strip()
def scripted(calls: list[tuple[str, ...]], **answers: str | Failure) -> git_repo.Git:
"""A git that records each command in calls and answers it by its first word: as answers has it, else as a checkout where origin/ABC-1 lacks a commit of origin/main that merges in cleanly."""
answered = {"fetch": "", "rev-parse": "abc\n", "rev-list": "1\n", "merge-tree": "7ree\n", "commit-tree": "c0mm17\n", "push": ""} | {name.replace("_", "-"): answer for name, answer in answers.items()}
def run(*args: str, cwd: str | None = None, timeout: float | None = None, guarded: bool = False, errors: str = "strict") -> str | Failure:
calls.append(args)
return answered[args[0]]
return run
class Levelled(unittest.TestCase):
def setUp(self) -> None:
folder = tempfile.TemporaryDirectory()
@@ -69,6 +80,51 @@ class Levelled(unittest.TestCase):
self.assertEqual(done.reason, "origin/main doesn't merge into origin/ABC-1 cleanly, so a person merges it: check ABC-1 out, run `git merge origin/main`, resolve the conflicts and push")
self.assertEqual(sh(self.origin, "rev-parse", "ABC-1"), before)
def test_a_conflict_fails_for_a_person_from_a_runner_that_shows_stdout_where_stderr_is_empty(self) -> None:
self.commit("ABC-1", "a.txt", "epic\n")
self.commit("main", "a.txt", "main\n")
run = runner(str(self.clone))
done = levelled("ABC-1", "origin/main", run=lambda *args, **more: run(["git", *args]))
self.assertEqual(done, Failure("origin/main doesn't merge into origin/ABC-1 cleanly, so a person merges it: check ABC-1 out, run `git merge origin/main`, resolve the conflicts and push"))
def test_a_merge_that_fails_other_than_by_a_conflict_fails_with_gits_reason(self) -> None:
sh(self.clone, "checkout", "--quiet", "--orphan", "stray")
sh(self.clone, "commit", "--quiet", "-m", "stray")
sh(self.clone, "push", "--quiet", "origin", "HEAD:refs/heads/ABC-1")
before = sh(self.origin, "rev-parse", "ABC-1")
self.assertEqual(levelled("ABC-1", "origin/main", cwd=str(self.clone)), Failure("git merge-tree --write-tree origin/ABC-1 origin/main: fatal: refusing to merge unrelated histories"))
self.assertEqual(sh(self.origin, "rev-parse", "ABC-1"), before)
def test_a_git_older_than_2_38_fails_naming_the_git_levelling_needs(self) -> None:
# What git 2.36 prints: it reads --write-tree as a commit.
old = Failure("git merge-tree --write-tree origin/ABC-1 origin/main: fatal: unknown rev --write-tree")
self.assertEqual(levelled("ABC-1", "origin/main", run=scripted([], merge_tree=old)), Failure("levelling origin/ABC-1 with origin/main needs git 2.38 or later: git merge-tree --write-tree origin/ABC-1 origin/main: fatal: unknown rev --write-tree"))
def test_a_merge_another_chunk_pushed_first_is_fetched_and_found_level(self) -> None:
self.commit("ABC-1", "b.txt", "epic\n")
self.commit("main", "c.txt", "main\n")
other = self.clone.parent / "other"
sh(self.clone.parent, "clone", "--quiet", str(self.origin), str(other))
sh(other, "config", "user.name", "Other")
sh(other, "config", "user.email", "other@example.com")
raced: list[str | Failure] = []
def racing(*args: str, cwd: str | None = None, timeout: float | None = None, guarded: bool = False, errors: str = "strict") -> str | Failure:
"""Runs git, after the other clone levels the branch just before this clone's first push."""
if args[0] == "push" and not raced:
raced.append(levelled("ABC-1", "origin/main", cwd=str(other)))
return git_repo.git(*args, cwd=cwd, timeout=timeout, guarded=guarded, errors=errors)
self.assertEqual(levelled("ABC-1", "origin/main", cwd=str(self.clone), run=racing), "origin/ABC-1 already holds origin/main.")
self.assertEqual(raced, ["Merged origin/main into origin/ABC-1."])
self.assertEqual(sh(self.clone, "rev-parse", "origin/ABC-1"), sh(other, "rev-parse", "origin/ABC-1"))
def test_a_push_that_fails_again_after_a_fresh_fetch_fails_with_gits_reason(self) -> None:
calls: list[tuple[str, ...]] = []
declined = Failure("git push --quiet origin c0mm17:refs/heads/ABC-1: ! [remote rejected] c0mm17 -> ABC-1 (protected branch hook declined)")
self.assertEqual(levelled("ABC-1", "origin/main", run=scripted(calls, push=declined)), declined)
self.assertEqual([args[0] for args in calls], ["fetch", "rev-parse", "rev-list", "merge-tree", "commit-tree", "push"] * 2)
class ChunkBase(unittest.TestCase):
def setUp(self) -> None: