Answer stability round 1: 0 🔴, 2 🟡 (0 misread); keep a finished chunk open until a person's merge is read and its worktree removed, and assert facts in place of sentences
This commit is contained in:
@@ -372,14 +372,18 @@ class Merge(unittest.TestCase):
|
||||
with self.subTest(origin):
|
||||
checkout = self.merged_by_a_human(origin)
|
||||
done = step(["merge"], checkout, checkout.config)
|
||||
self.assertEqual(done, "Marked pull request #12 ready. It passed its checks and awaits a person's merge, since the project's config sets `merge = \"human\"`: leave the merge to them, and report the chunk as ready to merge. Once it is merged, run chunk-pr clean in this worktree.")
|
||||
for fact in ("pull request #12", "awaits a person's merge", "chunk-pr clean"):
|
||||
self.assertIn(fact, str(done))
|
||||
self.assertNotIn("end your run", str(done))
|
||||
self.assertEqual(checkout.acted()[-1], ready)
|
||||
self.assertFalse(any("merge" in command[1:4] for command in checkout.acted() if command[0] != "git"), checkout.acted())
|
||||
|
||||
def test_under_a_humans_merge_a_chunk_that_parks_is_told_to_end_its_run(self):
|
||||
checkout = self.merged_by_a_human()
|
||||
done = merged(checkout, checkout.config, self.fail, parks=True)
|
||||
self.assertEqual(done, "Marked pull request #12 ready. It passed its checks and awaits a person's merge, since the project's config sets `merge = \"human\"`: end your run now, since do-epic parks the chunk and resumes this session once it is merged or a reviewer comments.")
|
||||
for fact in ("pull request #12", "awaits a person's merge", "end your run"):
|
||||
self.assertIn(fact, str(done))
|
||||
self.assertNotIn("chunk-pr clean", str(done))
|
||||
|
||||
def test_under_a_humans_merge_a_failed_check_leaves_the_pull_request_as_it_was(self):
|
||||
checkout = self.merged_by_a_human()
|
||||
@@ -397,8 +401,8 @@ class Merge(unittest.TestCase):
|
||||
self.assertNotIn(GH_DECISION, checkout.ran)
|
||||
|
||||
def test_merge_waits_for_no_approval_where_a_person_merges_and_for_the_configs_otherwise(self):
|
||||
self.assertEqual([awaited("gh", True, True), awaited("tea", True, True), awaited("gh", True), awaited("gh", False)], [False, False, True, False])
|
||||
self.assertIsInstance(awaited("tea", True), Failure)
|
||||
self.assertEqual([awaited("gh", True, True), awaited("tea", True, True), awaited("gh", True, False), awaited("gh", False, False)], [False, False, True, False])
|
||||
self.assertIsInstance(awaited("tea", True, False), Failure)
|
||||
|
||||
def test_under_a_humans_merge_a_pull_request_that_cannot_be_marked_ready_fails_saying_why(self):
|
||||
checkout = self.merged_by_a_human()
|
||||
|
||||
@@ -34,10 +34,15 @@ class Open:
|
||||
news: str
|
||||
|
||||
|
||||
def gate(branch: str, checkout: str, at: typing.Callable[[str], Run], by_human: bool = False) -> Gate | Open | Failure:
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Unopened(Open):
|
||||
"""An Open whose worktree stands though no pull request is open at its head: one that was merged or closed, whose chunk still has its worktree to remove."""
|
||||
|
||||
|
||||
def gate(branch: str, checkout: str, at: typing.Callable[[str], Run], by_human: bool) -> Gate | Open | Failure:
|
||||
"""What the chunk on branch waits on, in a worktree of checkout; at gives the runner of commands in a folder, and by_human says the project's config leaves the merge to a person (`merge = "human"`). A Failure where git or the forge cannot be read, which doesn't say anything about the gate.
|
||||
|
||||
A draft never waits on a gate: its worker still works on it. On Gitea only the checks are a gate, since chunk-pr reads approvals on GitHub only (`chunk_pr.approval.awaited`). Changes a reviewer requested are news until the worker answered them (`forge.reviews.answered`); from then on the pull request awaits a new review. Where a person merges, a pull request with nothing else to wait on awaits that merge, and the chunk has news again once it is merged, when it is no longer open.
|
||||
A draft never waits on a gate: its worker still works on it. On Gitea only the checks are a gate, since chunk-pr reads approvals on GitHub only (`chunk_pr.approval.awaited`). Changes a reviewer requested are news until the worker answered them (`forge.reviews.answered`); from then on the pull request awaits a new review. Where a person merges, a pull request with nothing else to wait on awaits that merge, and the chunk has news again once the pull request is no longer open.
|
||||
"""
|
||||
worktree = worktree_of(branch, at(checkout))
|
||||
if not isinstance(worktree, str):
|
||||
@@ -51,7 +56,7 @@ def gate(branch: str, checkout: str, at: typing.Callable[[str], Run], by_human:
|
||||
forge = forge_of(origin)
|
||||
pull = open_pull(forge, branch, head, run)
|
||||
if not isinstance(pull, str):
|
||||
return pull or Open(f"no pull request from origin's {branch} is open at {head[:12]}; it may be merged or closed already")
|
||||
return pull or Unopened(f"no pull request from origin's {branch} is open at {head[:12]}; it may be merged or closed already")
|
||||
decision = review_decision(forge, pull, head, run)
|
||||
if not isinstance(decision, str):
|
||||
return decision or Open(f"pull request #{pull} is a draft")
|
||||
|
||||
+22
-9
@@ -56,8 +56,8 @@ A repo takes as many chunks as its `parallel-chunks`, and none while loop-claude
|
||||
A chunk whose worker ends its run while its pull request waits on its checks, an approval or a new review
|
||||
is parked: it frees its place for the next chunk, and its window's name says what it awaits. Its worker goes
|
||||
on once the checks pass, the approval comes or a reviewer comments, and a place is free; until one is, the
|
||||
name says `awaits a slot`. In a repo whose config sets `merge = "human"`, a chunk never merges: its pull
|
||||
request, ready and with nothing else to wait on, `awaits your merge`, and its worker goes on once you merged it. A parked chunk survives a reboot: run do-epic <EPIC-KEY> again to go on polling.
|
||||
name says `awaits a slot`. In a repo whose config sets `merge = "human"`, a chunk never merges: once its pull
|
||||
request is ready, with nothing else to wait on, the window's name says `awaits your merge`, and its worker goes on once you merged it. A parked chunk survives a reboot: run do-epic <EPIC-KEY> again to go on polling.
|
||||
--status doesn't start any chunk. It prints a line per open issue: that its chunk runs or asks you a question, or why it waits, such as the gate a parked chunk awaits and since when.
|
||||
{findings.HELP}
|
||||
{finish.HELP}
|
||||
@@ -258,7 +258,7 @@ def chunk_run(key: str, epic: EpicRun) -> Stop:
|
||||
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()
|
||||
# What a chunk that was parked is told as it resumes; empty for a chunk that wasn't.
|
||||
news = parked_through(repo, loop, epic, starts=True) if repo is not None else ""
|
||||
news = parked_through(repo, loop, epic, told=None) if repo is not None else ""
|
||||
while True:
|
||||
if isinstance(news, Stop):
|
||||
return news
|
||||
@@ -276,14 +276,16 @@ def chunk_run(key: str, epic: EpicRun) -> Stop:
|
||||
if isinstance(closed, Stop):
|
||||
return closed
|
||||
run = closed
|
||||
news = parked_through(repo, loop, epic, starts=False) if repo is not None else ""
|
||||
news = parked_through(repo, loop, epic, told=news) if repo is not None else ""
|
||||
# A chunk that was parked has work again, whatever the judge ruled before its pull request passed the gate.
|
||||
if isinstance(concluded.verdict, Finished) and news == "":
|
||||
return handed_on(key, epic)
|
||||
|
||||
|
||||
def parked_through(repo: str, loop: Loop, epic: EpicRun, starts: bool) -> str | Stop:
|
||||
"""Keeps the chunk in loop's window parked. Its work is in the repo called repo. It stays parked for as long as its pull request waits on a gate, and returns once its worker has something to do: what to tell that worker, or empty where the chunk was never parked. starts says the window just started, where the chunk is parked only if its file says so: the forge isn't read for a chunk that starts afresh.
|
||||
def parked_through(repo: str, loop: Loop, epic: EpicRun, told: str | None) -> str | Stop:
|
||||
"""Keeps the chunk in loop's window parked. Its work is in the repo called repo. It stays parked for as long as its pull request waits on a gate, and returns once its worker has something to do: what to tell that worker, or empty where the chunk was never parked. told is the news its last cycle's worker got, None where the window just started. A window that just started parks the chunk only if its file says so: the forge isn't read for a chunk that starts afresh.
|
||||
|
||||
Where a person merges, a worker ends its run with the pull request open, so the judge may rule the chunk finished before it is. There a gate that cannot be read is read again until it can, and a pull request no longer open, in a worktree that still stands, is news the worker hasn't been told: the worker removes the worktree.
|
||||
|
||||
A chunk parks in three steps: its file is written, its window is shown as parked, and the epic's next chunks start in the slot it frees. It resumes in the reverse order: `scheduler.resume` gives it a running slot, then its file is removed. So a window that ends in between finds the chunk parked when it starts again.
|
||||
"""
|
||||
@@ -297,11 +299,12 @@ def parked_through(repo: str, loop: Loop, epic: EpicRun, starts: bool) -> str |
|
||||
poll = Poll(key, repo, config.merge == "human", folder, loop, epic)
|
||||
if key in recorded_as:
|
||||
return resumed_news(poll, recorded_as[key].on, shown=None)
|
||||
entered = None if starts else poll.gate()
|
||||
entered = None if told is None else poll.first_gate()
|
||||
if not isinstance(entered, gates.Gate):
|
||||
if isinstance(entered, Failure):
|
||||
say(f"cannot tell whether the chunk's pull request waits on a gate, so the chunk isn't parked: {entered.reason}", epic.effects, stdout=True)
|
||||
return ""
|
||||
uncleaned = f"{chunk_prompt.DRIVER} keeps the chunk open while its worktree stands: {entered.news}." if poll.by_human and isinstance(entered, gates.Unopened) else ""
|
||||
return "" if uncleaned in (told or "") else uncleaned
|
||||
if failed := poll.record(entered):
|
||||
return Stop(1, failed.reason)
|
||||
tmux.park(loop.window, entered.on, epic.effects.tmux)
|
||||
@@ -326,6 +329,16 @@ class Poll:
|
||||
def gate(self) -> gates.Gate | gates.Open | Failure:
|
||||
return gates.gate(self.key, self.loop.root, self.epic.forge_at, self.by_human)
|
||||
|
||||
def first_gate(self) -> gates.Gate | gates.Open | Failure:
|
||||
"""The gate as a cycle ends. Where a person merges, one that cannot be read is read again every POLL_SECONDS until it can."""
|
||||
now = self.gate()
|
||||
if self.by_human and isinstance(now, Failure):
|
||||
say(f"cannot read the gate of a pull request a person merges: {now.reason}; trying again every {POLL_SECONDS} seconds", self.epic.effects, stdout=True)
|
||||
while self.by_human and isinstance(now, Failure):
|
||||
self.epic.effects.sleep(POLL_SECONDS)
|
||||
now = self.gate()
|
||||
return now
|
||||
|
||||
def record(self, gate: gates.Gate) -> Failure | None:
|
||||
"""Writes the chunk's file as parked on gate, and says so."""
|
||||
failed = parked.park(self.folder, parked.Parked(self.key, gate.worktree, gate.pull, str(self.loop.session.id), gate.on))
|
||||
@@ -352,7 +365,7 @@ def resumed_news(poll: Poll, on: str, shown: str | None) -> str | Stop:
|
||||
full = resumed(poll.repo, poll.loop, poll.epic)
|
||||
if full is None:
|
||||
failed = parked.unpark(poll.folder, poll.key)
|
||||
return Stop(1, failed.reason) if failed is not None else f"{DRIVER_PARKED} its pull request awaited {on}. It resumes now: {now.news}."
|
||||
return Stop(1, failed.reason) if failed is not None else f"{DRIVER_PARKED} its pull request awaited {"a person's merge" if on == gates.MERGE else on}. It resumes now: {now.news}."
|
||||
awaits, stays = parked.SLOT, f"{now.news}, but the chunk stays parked: {full}"
|
||||
if awaits != shown:
|
||||
tmux.park(poll.loop.window, awaits, poll.epic.effects.tmux)
|
||||
|
||||
@@ -5,7 +5,7 @@ import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from do_epic.gates import APPROVAL, CHECKS, gate, Gate, MERGE, NEW_REVIEW, Open
|
||||
from do_epic.gates import APPROVAL, CHECKS, gate, Gate, MERGE, NEW_REVIEW, Open, Unopened
|
||||
from failure import Failure
|
||||
|
||||
WORKTREES = "worktree /code/billing\nHEAD aaa\nbranch refs/heads/main\n\nworktree /code/billing-ABC-21\nHEAD abc\nbranch refs/heads/ABC-21\n"
|
||||
@@ -77,8 +77,7 @@ class GateOfAChunk(unittest.TestCase):
|
||||
for forge in (Forge(decision="APPROVED"), Forge(decision=""), Forge(gitea)):
|
||||
with self.subTest(forge.answers["git remote"]):
|
||||
self.assertEqual(forge.gate(by_human=True), Gate("/code/billing-ABC-21", "7", MERGE))
|
||||
self.assertEqual(MERGE, "your merge")
|
||||
self.assertEqual(gate("ABC-21", "/code/billing", Forge(decision="APPROVED").at), Open("pull request #7 passed its checks and is approved"))
|
||||
self.assertEqual(Forge(decision="APPROVED").gate(by_human=False), Open("pull request #7 passed its checks and is approved"))
|
||||
|
||||
def test_where_a_person_merges_every_other_gate_and_all_news_stay_as_they_are(self):
|
||||
same = (Forge(), Forge(buckets=("pending",)), Forge(draft=True), Forge(decision="CHANGES_REQUESTED"), Forge(threads=(thread(False, "reviewer"),)), Forge(buckets=("fail",)), Forge(pulls=""))
|
||||
@@ -142,12 +141,12 @@ class GateOfAChunk(unittest.TestCase):
|
||||
"a check on pull request 7 failed; fix it and push": Forge(buckets=("fail",)),
|
||||
"a reviewer requested changes on pull request #7": Forge(decision="CHANGES_REQUESTED"),
|
||||
"a reviewer's comment on pull request #7 waits for an answer, in a.py, b.py": Forge(threads=(thread(False, "reviewer", "b.py"), thread(False, "reviewer"), thread(True, "reviewer", "c.py"), thread(False, "worker", "d.py"))),
|
||||
"no pull request from origin's ABC-21 is open at abcabcabcabc; it may be merged or closed already": Forge(pulls=""),
|
||||
"no worktree of /code/billing has the branch ABC-21 checked out": Forge(worktrees="worktree /code/billing\nHEAD aaa\nbranch refs/heads/main\n"),
|
||||
}
|
||||
for news, forge in cases.items():
|
||||
with self.subTest(news=news):
|
||||
self.assertEqual(forge.gate(), Open(news))
|
||||
self.assertEqual(Forge(pulls="").gate(), Unopened("no pull request from origin's ABC-21 is open at abcabcabcabc; it may be merged or closed already"))
|
||||
|
||||
def test_a_read_that_fails_is_a_failure_and_says_nothing_of_the_gate(self):
|
||||
for command in ("git worktree", "git remote", "gh pr list", "gh pr view", "gh pr checks", "gh api graphql"):
|
||||
|
||||
@@ -652,6 +652,10 @@ def awaiting(**answers: object) -> Forge:
|
||||
return Forge(worktrees=WORKTREE, **answers) # type: ignore[arg-type]
|
||||
|
||||
|
||||
# A forge whose checkout no longer has ABC-20's worktree, as after `chunk-pr clean`.
|
||||
CLEANED = Forge(worktrees="worktree /code/api\nHEAD aaa\nbranch refs/heads/main\n")
|
||||
|
||||
|
||||
class AChunkWhosePullRequestWaitsOnAGate(DoEpicTest):
|
||||
def setUp(self) -> None:
|
||||
super().setUp()
|
||||
@@ -687,15 +691,15 @@ class AChunkWhosePullRequestWaitsOnAGate(DoEpicTest):
|
||||
|
||||
def test_where_a_person_merges_it_parks_on_that_merge_and_works_again_once_merged(self) -> None:
|
||||
self.repo_config.write_text(self.repo_config.read_text(encoding="utf-8") + 'merge = "human"\n', encoding="utf-8")
|
||||
self.forges = [awaiting(), awaiting(decision="APPROVED"), awaiting(pulls="")]
|
||||
self.forges = [awaiting(), awaiting(decision="APPROVED"), awaiting(pulls=""), CLEANED]
|
||||
fake = FakeEffects(streams=[self.worker(), self.worker()], claude=[judged("unfinished"), judged("finished")], git=UNREAD, windows=PARKED_WINDOW)
|
||||
code, out, err, prompts = self.parked_run(fake)
|
||||
self.assertEqual(code, 0, err)
|
||||
self.assertIn("parked: pull request #7 awaits an approval\nstarted ABC-22\nparked: pull request #7 awaits your merge\n", out)
|
||||
self.assertEqual(out.count("parked: "), 2)
|
||||
self.assertIn("so run `chunk-pr merge` without `--finish`. The repo's team merges its pull requests itself, so `chunk-pr merge` leaves the pull request ready for a person to merge: end your run when it says so. Where the repo publishes", prompts[0])
|
||||
self.assertTrue(prompts[1].startswith(f"do-epic parked the chunk while its pull request awaited your merge. It resumes now: no pull request from origin's ABC-20 is open at abcabcabcabc; it may be merged or closed already. {chunk_prompt.FEEDBACK}\n\n"), prompts[1])
|
||||
self.assertIn("Where the pull request is merged, run `chunk-pr clean`", chunk_prompt.FEEDBACK)
|
||||
self.assertIn("leaves the pull request ready for a person to merge", prompts[0])
|
||||
for fact in ("awaited a person's merge", "no pull request from origin's ABC-20 is open", "chunk-pr clean"):
|
||||
self.assertIn(fact, prompts[1].split("\n\n")[0])
|
||||
self.assertEqual([args[3] for args in fake.tmux_calls if args[0] == "rename-window"], ["ABC-20 awaits an approval", "ABC-20 awaits your merge", "ABC-20"])
|
||||
self.assertFalse(self.file.exists())
|
||||
|
||||
@@ -719,6 +723,31 @@ class AChunkWhosePullRequestWaitsOnAGate(DoEpicTest):
|
||||
self.assertEqual((code, len(prompts), out.count("parked: ")), (1, 1, 1))
|
||||
self.assertIn("Permission denied", err)
|
||||
|
||||
def test_where_a_person_merges_a_finished_chunk_waits_for_a_gate_it_cannot_read(self) -> None:
|
||||
self.repo_config.write_text(self.repo_config.read_text(encoding="utf-8") + 'merge = "human"\n', encoding="utf-8")
|
||||
self.forges = [awaiting(decision="APPROVED", fails="gh pr checks"), awaiting(decision="APPROVED"), CLEANED]
|
||||
fake = FakeEffects(streams=[self.worker(), self.worker()], claude=[judged("finished"), judged("finished")], git=UNREAD, windows=PARKED_WINDOW)
|
||||
code, out, err, prompts = self.parked_run(fake)
|
||||
self.assertEqual((code, len(prompts)), (0, 2), err)
|
||||
self.assertIn("cannot read the gate of a pull request a person merges: gh pr checks failed", out)
|
||||
self.assertIn("parked: pull request #7 awaits your merge", out)
|
||||
|
||||
def test_where_a_person_merged_before_the_cycle_closed_the_worker_is_told_once_to_remove_its_worktree(self) -> None:
|
||||
self.repo_config.write_text(self.repo_config.read_text(encoding="utf-8") + 'merge = "human"\n', encoding="utf-8")
|
||||
self.forges = [awaiting(pulls=""), awaiting(pulls="")]
|
||||
fake = FakeEffects(streams=[self.worker(), self.worker()], claude=[judged("finished"), judged("finished")], git=UNREAD, windows=PARKED_WINDOW)
|
||||
code, out, err, prompts = self.parked_run(fake)
|
||||
self.assertEqual((code, len(prompts)), (0, 2), err)
|
||||
for fact in ("keeps the chunk open while its worktree stands", "no pull request from origin's ABC-20 is open", "chunk-pr clean"):
|
||||
self.assertIn(fact, prompts[1].split("\n\n")[0])
|
||||
self.assertNotIn("parked: ", out)
|
||||
|
||||
def test_where_the_chunk_merges_a_finished_chunk_whose_pull_request_is_no_longer_open_is_handed_on(self) -> None:
|
||||
self.forges = [awaiting(pulls="")]
|
||||
fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD, windows=PARKED_WINDOW)
|
||||
code, _, err, prompts = self.parked_run(fake)
|
||||
self.assertEqual((code, len(prompts)), (0, 1), err)
|
||||
|
||||
def test_where_the_chunk_merges_an_approved_pull_request_parks_no_chunk(self) -> None:
|
||||
self.forges = [awaiting(decision="APPROVED")]
|
||||
fake = FakeEffects(streams=[self.worker()], claude=[judged("finished")], git=UNREAD, windows=PARKED_WINDOW)
|
||||
|
||||
@@ -404,12 +404,12 @@ class LoadTest(ConfigCase):
|
||||
|
||||
def test_a_merge_that_is_neither_chunk_nor_human_fails_naming_it(self) -> None:
|
||||
folder = self.write("acme", CLIENT)
|
||||
for spelled in ('"person"', "true"):
|
||||
for spelled, named in (('"person"', "'person'"), ("true", "True")):
|
||||
with self.subTest(spelled):
|
||||
(folder / "config.toml").write_text(CLIENT + f"merge = {spelled}\n")
|
||||
found = load(self.checkout, self.checkout, self.home)
|
||||
assert isinstance(found, Failure), found
|
||||
self.assertIn(f'`merge` is {spelled.strip(chr(34)) if spelled == "true" else repr(spelled.strip(chr(34)))}, not "chunk" or "human"'.replace("true", "True"), found.reason)
|
||||
self.assertIn(f'`merge` is {named}, not "chunk" or "human"', found.reason)
|
||||
|
||||
def test_wait_for_approval_is_an_optional_boolean_that_is_false_where_left_out(self) -> None:
|
||||
folder = self.write("acme", CLIENT)
|
||||
|
||||
Reference in New Issue
Block a user