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:
@@ -121,7 +121,7 @@ A project whose pull requests need a human's approval sets `wait-for-approval =
|
||||
|
||||
A project whose team merges its pull requests itself sets `merge = "human"`. `chunk-pr merge` then brings the branch level with origin's default branch, finishes the chunk's plan items, waits for the checks and marks the pull request ready, but leaves the merge to a person. A plan or changelog kept in the checkout is finished on the branch, so it lands with that merge; one kept in Jira, or in the config's folder, is finished at once; where you close the pull request unmerged, file the item again. A do-epic chunk parks until the pull request is merged, and its window's name says `awaits your merge`. The chunk resumes and brings the branch level again once the pull request conflicts with the default branch. It does so too once the branch is behind a default branch whose protection, on GitHub, requires an up-to-date branch. loop-claude doesn't start a chunk for an item that a ready pull request finishes. Once no item left in the release can start and one awaits a merge, loop-claude stops and names the pull requests to merge; run it again after you merge one. The first chunk after a merge runs `chunk-pr clean` in the worktree the merged pull request left, where nobody pushed to the pull request after the chunk did. Nobody works on a pull request that awaits your merge. To have a reviewer's comment answered, turn the pull request back into a draft: a chunk then takes its item up again. Left out, the setting is `"chunk"`: the chunk merges.
|
||||
|
||||
A project whose team wants an epic's work in one pull request sets `epic-branch`, a template with `{epic}` for the epic's key, such as `epic-branch = "{epic}"`. The plan must name a Jira epic. Each chunk then branches off the epic's working branch, here `ABC-123` for the epic ABC-123, and `chunk-pr` opens its pull request into that branch and merges it there without a person, also under `merge = "human"` and `wait-for-approval`: those two keep guarding the default branch. `chunk-preflight`, and do-epic as a chunk starts, make the branch on origin off the default branch, or merge the default branch into it with a merge commit. Where that merge conflicts, they stop, and a person merges it. That needs git 2.38 or later. Once the epic's last issue has landed, `chunk-pr open-epic <epic's key> <title>` brings the branch level once more and opens the pull request from it into the default branch, which a person merges. An auto-reviewer that reviews only pull requests into the default branch is asked by a comment: set `review-request-comment` to the comment's text, such as `"@reviewbot review"`. `chunk-pr ready` then posts it on a pull request into the working branch, and `chunk-pr push` pushes later commits and posts it again.
|
||||
A project whose team wants an epic's work in one pull request sets `epic-branch`, a template with `{epic}` for the epic's key, such as `epic-branch = "{epic}"`. Under loop-claude the epic is the Jira epic the config's `plan` names, so a plan kept in a file gets no working branch. Under do-epic it is the epic do-epic drives. Each chunk then branches off the epic's working branch, here `ABC-123` for the epic ABC-123, and `chunk-pr` opens its pull request into that branch and merges it there without a person, also under `merge = "human"` and `wait-for-approval`: those two keep guarding the default branch. `chunk-preflight`, and do-epic as a chunk starts, make the branch on origin off the default branch, or merge the default branch into it with a merge commit, which needs git 2.38 or later. Where that merge conflicts, they stop, and a person merges it. Once the epic's last issue has landed, do-epic's finishing chunk runs `chunk-pr open-epic <epic's key> <title>`, which brings the branch level once more and opens the pull request from it into the default branch. Under loop-claude, run it yourself. A person merges that pull request, and its checks and reviews are theirs to answer. An auto-reviewer that reviews only pull requests into the default branch is asked by a comment: set `review-request-comment` to the comment's text, such as `"@reviewbot review"`. `chunk-pr ready` then posts it on a pull request into the working branch, and `chunk-pr push` pushes later commits and posts it again.
|
||||
|
||||
For a client's project, use one sandbox VM per client, so that one client's code, transcripts and credentials never share a machine with another's. What the client's repo should not hold lives in the config's folder, at paths written as `folder:<path>`, as `project-config --help` shows: the plan, the working rules in an `AGENTS.md` I write for the agents, the records, and the goals and audience, as `goals-and-audience = "folder:goals.md"`. Name that file `goals.md`, so the rules for goals and audience load when an agent writes it. A file outside the checkout has no commits in the checkout's history, so four things are not supported for it yet. `score-outcomes` and loop-claude's routing figures count a project's chunks only where `todo.md`, `docs/comprehension-history.md` and `docs/reading-cost.md` are at those paths in the checkout; otherwise each says so, and the loop goes on. For a plan or a comprehension history outside the checkout, `larv-review` says it cannot tell whether a scoring run is owed, and for such a history it cannot find a paired ruling's base. For a plan outside the checkout, chunk-preflight and loop-claude don't see a release whose last item has shipped, and say that its release review and its cut are yours to call. And rule-hook checks a plan outside the checkout on every call, not only when it changed.
|
||||
|
||||
@@ -160,7 +160,7 @@ The last line prints each setting's path once the config is complete.
|
||||
- `config.toml` fits do-epic to a team whose own automation moves issues, such as a CI job that moves an issue when its pull request merges. Two settings do:
|
||||
- `jira-unblocking-statuses` lists the statuses at which an issue's work has landed though Jira doesn't count it done yet, such as `["Release Ready"]`, in upper or lower case. An issue in one of them takes no chunk and no longer blocks the issues it blocks, and `--status` names the statuses beside each blocker. A status Jira counts as done always does both. The release reviews, which are the epic's last chunk, still wait until Jira counts every issue done: run `do-epic <EPIC-KEY>` then, to start them.
|
||||
- `jira-automation-moves-issues = true` keeps do-epic from moving the issue of a finished chunk in a repo: the automation moves it, and do-epic waits for that move before it starts what the issue blocks. An issue without a repo has no pull request, so do-epic still moves it, with `jira-finish-transition`. The setting needs `jira-unblocking-statuses`, which names the status the automation gives an issue whose pull request merged.
|
||||
- `config.toml` names the statuses do-epic itself gives an issue whose chunk merges into an epic's working branch, in a repo whose config sets `epic-branch`. A team's automation moves an issue only for a pull request into the default branch, so there do-epic makes both moves, whatever `jira-automation-moves-issues` says. `jira-pull-request-open-status`, such as `"Code Review"`, is the status of an issue whose chunk parks with its pull request open; a pull request that opens and merges within one run of the worker skips it. `jira-pull-request-merged-status`, such as `"Release Ready"`, is the status once the pull request has merged into the working branch. `jira-unblocking-statuses` must list it, and an issue that has it counts as done when the release reviews and the finishing chunk fall due, since both come before a person merges the working branch. Without it, a finished chunk's issue moves to done, and where `jira-automation-moves-issues` is set do-epic stops and asks you to move it.
|
||||
- `config.toml` names the statuses do-epic itself gives an issue whose chunk merges into an epic's working branch, in a repo whose config sets `epic-branch`. A team's automation moves an issue only for a pull request into the default branch, so there do-epic makes both moves, whatever `jira-automation-moves-issues` says. `jira-pull-request-open-status`, such as `"Code Review"`, is the status of an issue whose chunk parks with its pull request open; a pull request that opens and merges within one run of the worker skips it, unless the workflow leads to the merged status only through it. `jira-pull-request-merged-status`, such as `"Release Ready"`, is the status once the pull request has merged into the working branch. `jira-unblocking-statuses` must list it, and an issue that has it counts as done when the release reviews and the finishing chunk fall due, since both come before a person merges the working branch. Without it, do-epic moves a finished chunk's issue to done. Where `jira-automation-moves-issues` is set, it stops instead and asks you to move the issue.
|
||||
- `config.toml` also says how a starting chunk's issue shows on its team's board. A starting chunk always assigns its issue to the account do-epic works as, unless someone else holds it; that issue keeps its assignee, and moves and joins the sprint like any other. `jira-start-transition` names the workflow transition that then moves the issue, such as `"In Progress"`; an issue whose work has started already keeps its status. `jira-sprint-board` is the ID of the board whose active sprint the issue joins, such as `6`. Where a setting is left out, do-epic doesn't take its step.
|
||||
- `config.toml` may set `jira-finding-type`, the issue type do-epic files a finding as, and `jira-review-type`, the one it files a repo's release review as, such as `"Feature"` and `"Chore"`. Both are Task where left out. do-epic doesn't file anything where the Jira project lacks the type, and says which types it has.
|
||||
- `config.toml` may set `sub-task-summary`, which shapes the summary of each sub-task do-epic files for an issue that changes several repos, such as `sub-task-summary = "{label}: {Summary}"`. `{label}` is the team's label for the repo, else the repo's name, and `{Summary}` is the issue's summary with a capital first letter. It must hold `{Summary}`. Without it a summary is `[<repo>] <the issue's summary>`.
|
||||
|
||||
@@ -95,11 +95,11 @@ clean acts once the forge reports the branch's pull request merged at the com
|
||||
still removes the worktree and the branch, and fails saying why.
|
||||
open-epic runs in any checkout of the repository, once the epic's last chunk has merged. It
|
||||
fetches origin and brings the working branch of the epic named level with origin's
|
||||
default branch, by a merge commit pushed to origin, or makes the branch where origin has
|
||||
none. Then it opens the pull request from that branch into the default branch, ready and
|
||||
titled <title>, and leaves it to a person to merge. Where the two don't merge cleanly it
|
||||
opens nothing and says how a person merges them. Where the pull request is open
|
||||
already, it opens no second one. It fails where the config sets no `epic-branch`.
|
||||
default branch, by a merge commit pushed to origin. Then it opens the pull request from
|
||||
that branch into the default branch, ready and titled <title>, and leaves it to a person
|
||||
to merge. Where the two don't merge cleanly it doesn't open anything and says how a
|
||||
person merges them. Where the pull request is open already, it doesn't open a second
|
||||
one. It fails where the config sets no `epic-branch`, or origin has no such branch.
|
||||
|
||||
It prints what it did, exit 0, or why it failed, exit 1.
|
||||
"""
|
||||
@@ -168,6 +168,7 @@ def step(argv: list[str], run: Run, config: Config, parks: bool = False) -> str
|
||||
return synced(run, config)
|
||||
case ["ready", *title] if len(title) <= 1 and not any(given.startswith("-") for given in title):
|
||||
return Failure("give a title of one line") if title and not one_line(title[0]) else (misfit(title[0], run, config) if title else None) or readied(run, title[0] if title else None, config)
|
||||
# Three readers, seated as those who run `chunk-pr`, picked the spellings `push`, 3-0, and `open-epic`, 2-1.
|
||||
case ["push"]:
|
||||
return pushed(run, config)
|
||||
case ["open-epic", epic, title, *body] if len(body) <= 1 and not any(given.startswith("-") for given in (epic, title)):
|
||||
@@ -401,6 +402,9 @@ def epic_opened(epic: str, title: str, body: str, run: Run, config: Config) -> s
|
||||
if isinstance(default, Failure):
|
||||
return default
|
||||
forge = forge_of(found[0])
|
||||
# `levelled` makes a branch origin lacks, which here would be a stray one: a mistyped key, or a branch its merge deleted.
|
||||
if isinstance(held := answers(run, ["fetch", "--quiet", "origin"]), Failure) or isinstance(run(["git", "rev-parse", "--quiet", "--verify", f"refs/remotes/origin/{branch}"]), Failure):
|
||||
return held if isinstance(held, Failure) else Failure(f"origin has no branch {branch}, so no chunk of {epic} has merged into one: check the epic's key, and whether the branch's pull request merged already")
|
||||
level = epic_branch.levelled(branch, f"origin/{default}", run=lambda *args, cwd=None, timeout=None, guarded=False, errors="strict": run(["git", *args]))
|
||||
head = level if isinstance(level, Failure) else answers(run, ["rev-parse", f"origin/{branch}"])
|
||||
number = head if isinstance(head, Failure) else open_pull(forge, branch, head[0], run)
|
||||
|
||||
@@ -1131,12 +1131,18 @@ class EpicBranch(unittest.TestCase):
|
||||
def test_open_epic_leaves_a_conflict_with_the_default_branch_to_a_person_and_opens_nothing(self):
|
||||
checkout = self.epic()
|
||||
checkout.answers[("git", "rev-list", "--count", "origin/ABC-1..origin/main")] = "3\n"
|
||||
checkout.answers[("git", "merge-tree", "--write-tree", "origin/ABC-1", "origin/main")] = Failure("git merge-tree: CONFLICT")
|
||||
checkout.answers[("git", "merge-tree", "--write-tree", "origin/ABC-1", "origin/main")] = Failure("git merge-tree --write-tree: " + "a" * 40 + "\nCONFLICT (content): Merge conflict in a.txt")
|
||||
done = step(["open-epic", "ABC-1", "Ship the epic"], checkout, checkout.config)
|
||||
self.assertIsInstance(done, Failure)
|
||||
self.assertIn("a person merges it", done.reason)
|
||||
self.assertFalse(any(command[:3] == ["gh", "pr", "create"] for command in checkout.ran))
|
||||
|
||||
def test_open_epic_makes_no_branch_where_origin_has_none_for_the_epic(self):
|
||||
checkout = self.epic()
|
||||
checkout.answers[("git", "rev-parse", "--quiet", "--verify", "refs/remotes/origin/ABC-1")] = Failure("git rev-parse: no such ref")
|
||||
self.assertEqual(step(["open-epic", "ABC-1", "Ship the epic"], checkout, checkout.config), Failure("origin has no branch ABC-1, so no chunk of ABC-1 has merged into one: check the epic's key, and whether the branch's pull request merged already"))
|
||||
self.assertFalse(any(command[:2] in (["git", "push"], ["gh", "pr"]) for command in checkout.ran))
|
||||
|
||||
def test_open_epic_opens_no_second_pull_request(self):
|
||||
checkout = self.epic()
|
||||
checkout.answers[("gh", "pr", "list", "--head", "ABC-1", *GH_LIST[5:])] = "31\tabc123\tfalse\n"
|
||||
|
||||
@@ -31,12 +31,12 @@ def shipping(config: ProjectConfig) -> str:
|
||||
|
||||
|
||||
def epic_branch_rule(config: ProjectConfig, epic: str) -> str:
|
||||
"""What a chunk is told where the repo's config sets `epic-branch`, empty where it doesn't: its base, that its merge needs no person, how a later push asks for a review, and which branch its sibling repos are tested at (docs/decisions.md → `epic-branch: an epic's chunks branch off and merge into a working branch …`)."""
|
||||
"""What a chunk is told where the repo's config sets `epic-branch`, empty where it doesn't: its base, that its merge needs no person, how a later push asks for a review, and which branch the epic's other repos are tested at (docs/decisions.md → `epic-branch: an epic's chunks branch off and merge into a working branch …`)."""
|
||||
if config.epic_branch is None:
|
||||
return ""
|
||||
branch = templates.epic_branch(config.epic_branch, epic)
|
||||
pushed = " Push each later commit to the open pull request with `chunk-pr push`, which asks the repo's auto-reviewer for a review of the new head, and wait for that review." if config.review_request_comment else ""
|
||||
return f"The chunk's pull request goes into the epic's working branch `{branch}`, not into the default branch: {DRIVER} has made that branch level with the default branch and recorded it as the base of the chunk's branch, so make the chunk's worktree and branch off `origin/{branch}`. `chunk-pr merge` merges into `{branch}` without waiting for a person.{pushed} Test each sibling repo at its branch `{branch}` where it has one, else at its default branch, and name in the chunk's summary each sibling that ran at its default branch."
|
||||
pushed = " After `chunk-pr ready`, push each commit with `chunk-pr push`, which asks the repo's auto-reviewer to review the new head, and wait for that review." if config.review_request_comment else ""
|
||||
return f"The chunk's pull request goes into the epic's working branch `{branch}`, not into the default branch: {DRIVER} has made that branch level with the default branch and recorded it as the base of the chunk's branch, so make the chunk's worktree and branch off `origin/{branch}`. `chunk-pr merge` merges into `{branch}` without waiting for a person.{pushed} Where the chunk's tests run other repos of the epic, run each at its branch `{branch}` where it has one, else at its default branch, and name in the chunk's summary each repo that ran at its default branch."
|
||||
|
||||
|
||||
def task(issue: EpicIssue, epic: str, team: LabelRepos, checkout: str | None, launcher: pathlib.Path, language: str, config: ProjectConfig | None) -> str:
|
||||
|
||||
+6
-3
@@ -311,12 +311,12 @@ def chunk_run(key: str, epic: EpicRun) -> Stop:
|
||||
root, repo = place
|
||||
if unmade := folder_made(root):
|
||||
return Stop(1, unmade.reason)
|
||||
if issue:
|
||||
issue_started(key, epic)
|
||||
# The epic's working branch the chunk merges into; None where its repo keeps none, as for a chunk without a repo.
|
||||
based = epic_based(key, root, epic) if repo is not None else None
|
||||
if isinstance(based, Stop):
|
||||
return based
|
||||
if issue:
|
||||
issue_started(key, epic)
|
||||
session = session_named(f"A {epic.key} do-epic {key}", epic.paths.claude_code_transcripts)
|
||||
loop = Loop(root=root, session=session, window=tmux.Window(epic.session, key, pane), paths=epic.paths, env=epic.env, launcher=epic.launcher, effects=epic.effects)
|
||||
run = ChunkRun()
|
||||
@@ -521,13 +521,16 @@ def folder_made(root: str) -> Failure | None:
|
||||
|
||||
|
||||
def handed_on(key: str, epic: EpicRun, in_repo: bool = False, humans: bool = False, to_epic_branch: bool = False) -> Stop:
|
||||
"""The stop of a do-epic whose chunk finished. It first moves the chunk's issue to done (the epic's finishing has none), and its split item too where that was the last of the item's sub-tasks, so that no finished chunk starts again and what they block may start, then starts each chunk that may start now. Where the team's automation moves issues, others move two kinds of issue. The automation moves the issue of a chunk in a repo, which in_repo marks, from its pull request: the stop waits for that move (`moved_by_automation`). The human moves their own task, which humans marks: the stop moves and awaits nothing. A chunk without a repo has no pull request, so its issue moves to done as ever, and so does a split item, once Jira counts each of its sub-tasks done. The automation doesn't see a pull request that merged into an epic's working branch, which to_epic_branch marks: the stop moves that chunk's issue to the status `jira-pull-request-merged-status` names. Where none is named, it moves the issue to done, or stops where the automation moves issues, since nothing would. Its window closes as it exits."""
|
||||
"""The stop of a do-epic whose chunk finished. It first moves the chunk's issue to done (the epic's finishing has none), and its split item too where that was the last of the item's sub-tasks, so that no finished chunk starts again and what they block may start, then starts each chunk that may start now. Where the team's automation moves issues, others move two kinds of issue. The automation moves the issue of a chunk in a repo, which in_repo marks, from its pull request: the stop waits for that move (`moved_by_automation`). The human moves their own task, which humans marks: the stop doesn't move or await anything. A chunk without a repo has no pull request, so its issue moves to done as ever, and so does a split item, once Jira counts each of its sub-tasks done. The automation doesn't see a pull request that merged into an epic's working branch, which to_epic_branch marks: the stop moves that chunk's issue to the status `jira-pull-request-merged-status` names. Where none is named, it moves the issue to done, or stops where the automation moves issues, since then nobody would move it. do-epic's window closes as it exits."""
|
||||
automated = epic.config.automation_moves
|
||||
# The epic's finishing has no issue to move: the epic is closed by `--close-epic`. Nor has a human's task where the human moves it: its window waited until it holds up no issue.
|
||||
if key == epic.key or (humans and automated):
|
||||
issues: list[EpicIssue] | Failure = epic.store.read()
|
||||
elif to_epic_branch and (status := epic.config.pull_merged_status):
|
||||
moved = epic.store.move_issue(key, status)
|
||||
# A chunk that never parked left its issue before the open status, from which a workflow may offer no way to the merged one.
|
||||
if isinstance(moved, Failure) and (opened := epic.config.pull_open_status) and not isinstance(epic.store.move_issue(key, opened), Failure):
|
||||
moved = epic.store.move_issue(key, status)
|
||||
if isinstance(moved, Failure):
|
||||
return Stop(1, f"the chunk finished, but its issue could not move to {status!r}: {moved.reason}; once it has that status in Jira, run `do-epic {epic.key}` to start the chunks it blocks")
|
||||
issues = epic.store.read()
|
||||
|
||||
@@ -7,6 +7,7 @@ import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import typing
|
||||
import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
@@ -983,6 +984,22 @@ class AChunkWhosePullRequestWaitsOnAGate(DoEpicTest):
|
||||
self.assertIn(f"cannot remove {self.file}: Permission denied", err)
|
||||
|
||||
|
||||
class StepwiseStore:
|
||||
"""A store whose workflow reaches each status in `after` only from the status it names there; every other call is the wrapped store's."""
|
||||
|
||||
def __init__(self, store: typing.Any, after: dict[str, str]) -> None:
|
||||
self.store, self.after = store, after
|
||||
|
||||
def __getattr__(self, name: str) -> typing.Any:
|
||||
return getattr(self.store, name)
|
||||
|
||||
def move_issue(self, key: str, status: str) -> None | Failure:
|
||||
now = self.store.within(key).status
|
||||
if status in self.after and now not in (status, self.after[status]):
|
||||
return Failure(f"{key} has no transition to {status!r} from its status {now!r}")
|
||||
return self.store.move_issue(key, status)
|
||||
|
||||
|
||||
class AnEpicsWorkingBranch(DoEpicTest):
|
||||
"""A chunk in a repo whose config sets `epic-branch`, so its pull request goes into the branch ABC-12."""
|
||||
|
||||
@@ -1022,7 +1039,7 @@ class AnEpicsWorkingBranch(DoEpicTest):
|
||||
self.assertEqual(self.git_calls, [])
|
||||
|
||||
def test_a_default_branch_that_conflicts_stops_the_loop_for_a_person_and_records_no_base(self) -> None:
|
||||
stop = main.epic_based("ABC-20", self.checkout, self.epic_run(self.with_git(FakeEffects(), rev_list="1\n", merge_tree=Failure("CONFLICT"))))
|
||||
stop = main.epic_based("ABC-20", self.checkout, self.epic_run(self.with_git(FakeEffects(), rev_list="1\n", merge_tree=Failure("git merge-tree --write-tree origin/ABC-12 origin/main: "))))
|
||||
self.assertEqual(stop, main.Stop(1, f"cannot ready the epic's working branch ABC-12 in {self.checkout} for ABC-20: origin/main doesn't merge into origin/ABC-12 cleanly, so a person merges it: check ABC-12 out, run `git merge origin/main`, resolve the conflicts and push; once that is settled, run `do-epic ABC-12` to start the chunk again"))
|
||||
self.assertNotIn("config", [args[0] for args, _ in self.git_calls])
|
||||
|
||||
@@ -1032,6 +1049,12 @@ class AnEpicsWorkingBranch(DoEpicTest):
|
||||
self.assertIn("no origin/HEAD", stop.reason)
|
||||
self.assertEqual(len(self.git_calls), 1)
|
||||
|
||||
def test_a_chunk_whose_working_branch_cannot_be_readied_leaves_its_issue_unstarted(self) -> None:
|
||||
code, _, err = self.run_main(["--chunk", "ABC-20", "ABC-12"], self.with_git(FakeEffects(), rev_list="1\n", merge_tree=Failure("git merge-tree --write-tree origin/ABC-12 origin/main: ")), MODELS)
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn("cannot ready the epic's working branch ABC-12", err)
|
||||
self.assertEqual(self.store.writes, [])
|
||||
|
||||
def test_its_issue_moves_as_the_pull_request_opens_and_merges_and_no_person_merges_it(self) -> None:
|
||||
self.settings('jira-unblocking-statuses = ["Release Ready"]\njira-automation-moves-issues = true\njira-pull-request-open-status = "Code Review"\njira-pull-request-merged-status = "Release Ready"\n')
|
||||
self.forges = [awaiting(), awaiting(), awaiting(decision="APPROVED")]
|
||||
@@ -1058,6 +1081,19 @@ class AnEpicsWorkingBranch(DoEpicTest):
|
||||
self.assertEqual(main.handed_on("ABC-20", self.epic_run(FakeEffects(windows="")), in_repo=True, to_epic_branch=True).code, 0)
|
||||
self.assertTrue(self.store.issues[0].done)
|
||||
|
||||
def test_an_issue_whose_workflow_reaches_the_merged_status_only_through_the_open_status_moves_through_it(self) -> None:
|
||||
self.settings('jira-unblocking-statuses = ["Release Ready"]\njira-pull-request-open-status = "Code Review"\njira-pull-request-merged-status = "Release Ready"\n')
|
||||
epic = self.epic_run(FakeEffects(windows=""))
|
||||
stepwise = StepwiseStore(self.store, {"Release Ready": "Code Review"})
|
||||
with contextlib.redirect_stdout(io.StringIO()):
|
||||
stop = main.handed_on("ABC-20", dataclasses.replace(epic, store=stepwise), in_repo=True, to_epic_branch=True)
|
||||
self.assertEqual(stop.code, 0, stop.reason)
|
||||
self.assertEqual(self.store.writes, ["move ABC-20 to Code Review", "move ABC-20 to Release Ready"])
|
||||
# An issue the open status doesn't lead on from stops on the move it asked for.
|
||||
stuck = StepwiseStore(self.store, {"Release Ready": "QA", "Code Review": "QA"})
|
||||
stop = main.handed_on("ABC-22", dataclasses.replace(epic, store=stuck), in_repo=True, to_epic_branch=True)
|
||||
self.assertTrue(stop.reason.startswith("the chunk finished, but its issue could not move to 'Release Ready': ABC-22 has no transition to 'Release Ready'"), stop.reason)
|
||||
|
||||
def test_an_issue_that_cannot_move_to_the_merged_status_stops_and_says_what_to_do(self) -> None:
|
||||
self.settings('jira-unblocking-statuses = ["Release Ready"]\njira-pull-request-merged-status = "Release Ready"\n')
|
||||
self.store.fails = "Jira answered 503"
|
||||
|
||||
@@ -472,13 +472,13 @@ class TheFirstPrompt(unittest.TestCase):
|
||||
self.assertIn("make the chunk's worktree and branch off `origin/epic/ABC-12`", task)
|
||||
self.assertIn("`chunk-pr merge` merges into `epic/ABC-12` without waiting for a person", task)
|
||||
self.assertNotIn("leaves the pull request ready for a person to merge", task)
|
||||
self.assertIn("Test each sibling repo at its branch `epic/ABC-12` where it has one, else at its default branch, and name in the chunk's summary each sibling that ran at its default branch.", task)
|
||||
self.assertIn("Where the chunk's tests run other repos of the epic, run each at its branch `epic/ABC-12` where it has one, else at its default branch, and name in the chunk's summary each repo that ran at its default branch.", task)
|
||||
self.assertNotIn("chunk-pr push", task)
|
||||
|
||||
def test_a_repo_whose_reviewer_is_asked_by_a_comment_is_told_to_push_with_chunk_pr(self) -> None:
|
||||
config = dataclasses.replace(CONFIG, epic_branch="{epic}", review_request_comment="@reviewbot review")
|
||||
task = chunk_prompt.task(issue("ABC-20"), "ABC-12", {}, "/code/api", pathlib.Path("/b/do-epic"), "Swedish", config)
|
||||
self.assertIn("Push each later commit to the open pull request with `chunk-pr push`, which asks the repo's auto-reviewer for a review of the new head, and wait for that review.", task)
|
||||
self.assertIn("After `chunk-pr ready`, push each commit with `chunk-pr push`, which asks the repo's auto-reviewer to review the new head, and wait for that review.", task)
|
||||
|
||||
def test_a_repo_without_an_epic_branch_is_told_nothing_of_one(self) -> None:
|
||||
task = chunk_prompt.task(issue("ABC-20"), "ABC-12", {}, "/code/api", pathlib.Path("/b/do-epic"), "Swedish", dataclasses.replace(CONFIG, merge="human"))
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
"""Keep an epic's working branch on origin: made off the default branch by the epic's first chunk, and level with it before each chunk starts and before the epic's own pull request opens (docs/decisions.md → `epic-branch: an epic's chunks branch off and merge into a working branch …`)."""
|
||||
import re
|
||||
|
||||
from failure import Failure
|
||||
from git_cli.git_repo import Git, git
|
||||
|
||||
|
||||
def levelled(branch: str, default: str, cwd: str | None = None, timeout: float | None = None, run: Git = git) -> str | Failure:
|
||||
def levelled(branch: str, default: str, cwd: str | None = None, timeout: float | None = None, run: Git = git, again: bool = True) -> str | Failure:
|
||||
"""Brings origin's branch level with default, the default branch's ref, such as `origin/main`, and fetches it: what it did, as a sentence. Where origin has no such branch, it makes one at default.
|
||||
|
||||
It merges with a merge commit, never a rebase, since several chunks share the branch, and without a checkout, since no worktree has the branch checked out. A Failure where the two don't merge cleanly: a person resolves that, never the loop. A call to origin still running after timeout seconds fails."""
|
||||
It merges with a merge commit, never a rebase, since several chunks share the branch, and without a checkout, since no worktree has the branch checked out. A Failure where the two don't merge cleanly: a person resolves that, never the loop. A call to origin still running after timeout seconds fails. Where the merge's push fails, as when another chunk pushed its own merge first, it fetches and levels once more, unless again is False."""
|
||||
fetched = run("fetch", "--quiet", "origin", cwd=cwd, timeout=timeout)
|
||||
if isinstance(fetched, Failure):
|
||||
return fetched
|
||||
@@ -21,11 +23,26 @@ def levelled(branch: str, default: str, cwd: str | None = None, timeout: float |
|
||||
# git 2.38 or later: merges two commits into a tree without a checkout.
|
||||
tree = run("merge-tree", "--write-tree", ours, default, cwd=cwd)
|
||||
if isinstance(tree, Failure):
|
||||
return Failure(f"{default} doesn't merge into {ours} cleanly, so a person merges it: check {branch} out, run `git merge {default}`, resolve the conflicts and push")
|
||||
return unmerged(tree, branch, default)
|
||||
commit = run("commit-tree", tree.strip(), "-p", ours, "-p", default, "-m", f"Merge remote-tracking branch '{default}' into {branch}", cwd=cwd)
|
||||
if isinstance(commit, Failure):
|
||||
return commit
|
||||
return pushed(commit.strip(), branch, cwd, timeout, run) or f"Merged {default} into {ours}."
|
||||
failed = pushed(commit.strip(), branch, cwd, timeout, run)
|
||||
if failed and again:
|
||||
return levelled(branch, default, cwd, timeout, run, again=False)
|
||||
return failed or f"Merged {default} into {ours}."
|
||||
|
||||
|
||||
def unmerged(failed: Failure, branch: str, default: str) -> Failure:
|
||||
"""Why `git merge-tree --write-tree` didn't merge default into origin's branch, from its Failure.
|
||||
|
||||
A conflict prints nothing on stderr, so its reason ends at `git <command>:`, or, from a runner that shows stdout in place of an empty stderr, goes on with the merged tree's id. Git older than 2.38 reads --write-tree as a commit, which it doesn't find. Any other Failure is git's own."""
|
||||
ours = f"origin/{branch}"
|
||||
if re.fullmatch(r"git merge-tree [^:]*:\s*(?:[0-9a-f]{40,64}\b.*)?", failed.reason, re.DOTALL):
|
||||
return Failure(f"{default} doesn't merge into {ours} cleanly, so a person merges it: check {branch} out, run `git merge {default}`, resolve the conflicts and push")
|
||||
if "unknown rev --write-tree" in failed.reason:
|
||||
return Failure(f"levelling {ours} with {default} needs git 2.38 or later: {failed.reason}")
|
||||
return failed
|
||||
|
||||
|
||||
def pushed(commit: str, branch: str, cwd: str | None, timeout: float | None, run: Git) -> Failure | None:
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user