Merge a project's chunks one at a time, finishing each one's plan items in its turn
CI / tests (pull_request) Successful in 2m9s
CI / tests (pull_request) Successful in 2m9s
This commit is contained in:
@@ -17,7 +17,7 @@ How work proceeds in any repo, unless the repo's `AGENTS.md` says otherwise. The
|
||||
- **Ask, don't guess.** Three choices are always the human's: a goal; a release, meaning the items planned into it and when it is cut; and a change to loop-claude's routing ladder, its rungs included. Any other rule that asks the human's approval reserves that choice too. Ask about a reserved choice. For any other choice, first check whether the goals already answer it. If they nearly do, propose a change to the goals and show how it answers this case: an answer settles one question, a goal settles every question like it. Otherwise take the option you would recommend, and record it with its reason: in the item's detail, or, where it governs later work, as the next sentence says. A recommendation you can give a reason for is not a guess. Ask only where you have no recommendation. Write every answer once, where it belongs, never only in chat: a goal in the goals file, a working rule in `AGENTS.md`, a standing choice in a comment at the one place it governs, or in `docs/decisions.md` once made in more than one place. When an answer holds a goal and a choice, write the goal in the goals file, and record as a choice only what the goal leaves open.
|
||||
- **Bench a syntax with the people who write it.** Before a new or changed spelling of something users read or write ships — markdown, HTML, a config key, a CLI flag — a panel of fresh-context readers, seated as those users from the goals file's `## Audience`, picks it.
|
||||
- **Implement the simplest change that solves the item, and ship it with `/larv-review`.** Whenever a test can check the change, write that test first and see it fail. Take its expected values from the item, never from the code. larv-review's reviewers hold the change to the technical principles, and a finding against one names it. Read a file in the principles folder the project's config sets (`~/.claude/bin/project-config principles` prints it) only when the item changes it, a finding or a record you write names it, or you decline a finding.
|
||||
- **Remove a finished item from the plan, and revise any decision that cites it.** If the repo publishes something others consume — a package, an image, an API — reword the item for them and move it to `CHANGELOG.md` under `## Unreleased`. A changelog is for the public, never for the next agent. Otherwise delete it; git history is the record. `~/.claude/bin/todo-item finish <ID>` removes the item with its detail, and adds the bullet you pass with `--changelog <bullet>`; it refuses while a decision cites the item.
|
||||
- **Remove a finished item from the plan, and revise any decision that cites it.** If the repo publishes something others consume — a package, an image, an API — reword the item for them and move it to `CHANGELOG.md` under `## Unreleased`. A changelog is for the public, never for the next agent. Otherwise delete it; git history is the record. `~/.claude/bin/todo-item finish <ID>` removes the item with its detail, and adds the bullet you pass with `--changelog <bullet>`; it refuses while a decision cites the item. A chunk finishes its items as it merges, through `chunk-pr merge --finish <ID>`, which takes the same flags (`larv-review` §5).
|
||||
- **Releases are the human's.** The version bump and the publishing credentials are theirs, whatever another rule says. Prepare everything else, so cutting a release is one decision.
|
||||
- **Open each plan item or ticket with a bold one-sentence tagline**, so the taglines alone say what a release holds. The tagline states the target state, checkable when done: an imperative verb plus what holds afterwards. A present-tense fact reads as the current state and doesn't say anything about what to do. Add "today X" only where the direction is otherwise ambiguous. GOOD: `**Accept undefined in MetadataValue and drop such keys on output.**` BANNED: `MetadataValue accepts undefined; such keys are dropped on output`.
|
||||
- **File a security finding the moment it is found.** A security finding — a leaked credential, secret or PII, an auth bypass, an injection — goes under the next release, marked `security`, naming the exposure and the path it reaches. `~/.claude/bin/rank_todo.py` ranks it first in its release, after only the open questions, which wait for me. Never among additive or nice-to-have items, never only in a chunk's summary, and never as a question about where it belongs: file it, say you did, and I will unmark it if I disagree. Fixing it inside an unrelated change is a separate call — say whether it is in the blast radius.
|
||||
|
||||
@@ -107,7 +107,7 @@ A project's config may set four more things, each optional, as `project-config -
|
||||
|
||||
A legacy project with no container setup sets `tooling-on-host = true`, so the loop runs its language runtime, package manager, tests and task runner directly on the host. One whose code the comprehension panel scores low may lower `readability-floor` from 7.0: under it, the ranking weighs code health 4 times as much, and a scoring run asks for a floor item.
|
||||
|
||||
A project whose pull requests need a human's approval sets `wait-for-approval = true` in its config. `chunk-pr merge` then waits, once the checks have passed, until GitHub reports the pull request approved as its branch protection requires, and merges it. It refuses on Gitea, where a reviewer requested changes and where the protection requires no review. It gives up after 90 minutes without an approval; run it again once the pull request is approved. Left out, the setting is false.
|
||||
A project whose pull requests need a human's approval sets `wait-for-approval = true` in its config. `chunk-pr merge` then waits, once the checks have passed, until GitHub reports the pull request approved as its branch protection requires, and merges it. It refuses on Gitea, where a reviewer requested changes and where the protection requires no review. While it waits, other chunks merge. It stops where a reviewer's comment waits for an answer; answer it and run it again. It gives up after 90 minutes without an approval; run it again once the pull request is approved. Left out, the setting is false.
|
||||
|
||||
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.
|
||||
|
||||
@@ -162,7 +162,7 @@ It renames `## Unreleased` in `CHANGELOG.md` to the version and merges that thro
|
||||
|
||||
Install puts only `loop-claude` on `PATH`; call the others by their path, such as `~/.claude/bin/metric-bench`, from the project's checkout. Those under `~/.claude` are the release's; test a change to one from `~/code/claude-config/bin`.
|
||||
|
||||
- `chunk-pr open|sync|ready|merge|clean` opens a chunk's pull request as a draft, brings its branch level with origin's default branch, marks it ready and merges it once its checks pass, with `gh` on a GitHub origin and `tea` elsewhere; once it is merged, `clean` removes the chunk's worktree and branch and fast-forwards the main checkout. `chunk-pr --help` states the steps.
|
||||
- `chunk-pr open|sync|ready|merge|clean` opens a chunk's pull request as a draft, brings its branch level with origin's default branch, marks it ready and merges it once its checks pass, with `gh` on a GitHub origin and `tea` elsewhere. The chunks of one project merge one at a time: in its turn, `merge` brings the branch level again, finishes the plan items its `--finish` flags name, and waits for the checks; once it is merged, `clean` removes the chunk's worktree and branch and fast-forwards the main checkout. `chunk-pr --help` states the steps.
|
||||
- `chunk-preflight` finds the mechanical facts a chunk starts from, and with `--worktree` makes its worktree; `loop-claude` runs it with `--worktree` before it routes each chunk, and `chunk-preflight --help` lists the facts.
|
||||
- `command-patterns [<version>] [--calls <file>]` prints a table of the shell command patterns a release's archived chunks ran, such as `tea pr create`, for an audit of the release, and with `--calls <file>` saves each call as a JSON line; `command-patterns --help` states the columns and the line's keys.
|
||||
- `deploy-release [--cut] [<checkout>]` moves `~/.claude`, or the checkout named, to the newest release, as Update says; with `--cut`, run in the development clone, it first cuts the next release, as Release says.
|
||||
|
||||
+48
-16
@@ -26,24 +26,56 @@ def awaited(forge: Forge, run: Run) -> bool | Failure:
|
||||
return answer.strip() == "true"
|
||||
|
||||
|
||||
# Each review thread nobody resolved, with who wrote its last comment, beside who opened the pull request. gh fills {owner} and {repo} from the checkout.
|
||||
THREADS = """query($owner: String!, $repo: String!, $number: Int!) { repository(owner: $owner, name: $repo) { pullRequest(number: $number) {
|
||||
author { login }
|
||||
reviewThreads(first: 100) { nodes { isResolved path comments(last: 1) { nodes { author { login } } } } }
|
||||
} } }"""
|
||||
|
||||
|
||||
def approval(number: str, run: Run) -> bool | Failure:
|
||||
"""Whether GitHub reports pull request number approved, as its branch protection asks, read once: False while it still wants a review. A Failure where a reviewer requested changes, or where the protection asks for no review."""
|
||||
viewed = run(["gh", "pr", "view", number, "--json", "reviewDecision"])
|
||||
try:
|
||||
decision = viewed if isinstance(viewed, Failure) else json.loads(viewed)["reviewDecision"]
|
||||
except (ValueError, KeyError, TypeError):
|
||||
return Failure(f"gh pr view printed no review decision: {str(viewed).strip()[:200]}")
|
||||
if isinstance(decision, Failure):
|
||||
return decision
|
||||
if decision == "CHANGES_REQUESTED":
|
||||
return Failure(f"a reviewer requested changes on pull request {number}")
|
||||
if not decision:
|
||||
return Failure("wait-for-approval is set, but the branch protection requires no review, so GitHub reports no decision; ask the human to require a review in the protection or to set wait-for-approval to false")
|
||||
if decision not in ("APPROVED", "REVIEW_REQUIRED"):
|
||||
return Failure(f"GitHub reports the review decision {decision!r} on pull request {number}, and chunk-pr doesn't know that decision")
|
||||
return decision == "APPROVED"
|
||||
|
||||
|
||||
def approved(number: str, run: Run, sleep: typing.Callable[[float], None] = time.sleep) -> Failure | None:
|
||||
"""None once GitHub reports pull request number approved, as its branch protection asks; a Failure where a reviewer requested changes, where the protection asks for no review, or where no approval came within WAIT_SECONDS."""
|
||||
"""None once GitHub reports pull request number approved; a Failure where `approval` fails, where a reviewer's comment waits for an answer, or where no approval came within WAIT_SECONDS."""
|
||||
for waited in range(0, WAIT_SECONDS + 1, POLL_SECONDS):
|
||||
viewed = run(["gh", "pr", "view", number, "--json", "reviewDecision"])
|
||||
try:
|
||||
decision = viewed if isinstance(viewed, Failure) else json.loads(viewed)["reviewDecision"]
|
||||
except (ValueError, KeyError, TypeError):
|
||||
return Failure(f"gh pr view printed no review decision: {str(viewed).strip()[:200]}")
|
||||
if isinstance(decision, Failure):
|
||||
return decision
|
||||
if decision == "APPROVED":
|
||||
return None
|
||||
if decision == "CHANGES_REQUESTED":
|
||||
return Failure(f"a reviewer requested changes on pull request {number}")
|
||||
if not decision:
|
||||
return Failure("wait-for-approval is set, but the branch protection requires no review, so GitHub reports no decision; ask the human to require a review in the protection or to set wait-for-approval to false")
|
||||
if decision != "REVIEW_REQUIRED":
|
||||
return Failure(f"GitHub reports the review decision {decision!r} on pull request {number}, and chunk-pr doesn't know that decision")
|
||||
read = approval(number, run)
|
||||
if read is True or isinstance(read, Failure):
|
||||
return None if read is True else read
|
||||
asked = unanswered(number, run)
|
||||
if asked is not None:
|
||||
return asked
|
||||
if waited < WAIT_SECONDS:
|
||||
sleep(POLL_SECONDS)
|
||||
return Failure(f"pull request {number} wasn't approved within {WAIT_SECONDS // 60} minutes; run chunk-pr merge again once it is")
|
||||
|
||||
|
||||
def unanswered(number: str, run: Run) -> Failure | None:
|
||||
"""A Failure naming the files where a reviewer's comment waits for an answer on pull request number: a review thread nobody resolved, whose last comment someone other than the pull request's author wrote. So a thread the worker answered, as that author, waits for the reviewer again. None where no thread waits."""
|
||||
read = run(["gh", "api", "graphql", "-f", f"query={THREADS}", "-F", "owner={owner}", "-F", "repo={repo}", "-F", f"number={number}"])
|
||||
try:
|
||||
pull = read if isinstance(read, Failure) else json.loads(read)["data"]["repository"]["pullRequest"]
|
||||
if isinstance(pull, Failure):
|
||||
return pull
|
||||
author = pull["author"]["login"]
|
||||
waiting = sorted({thread["path"] for thread in pull["reviewThreads"]["nodes"] if not thread["isResolved"] and any(comment["author"]["login"] != author for comment in thread["comments"]["nodes"])})
|
||||
except (ValueError, KeyError, TypeError):
|
||||
return Failure(f"gh api graphql printed no review threads: {str(read).strip()[:200]}")
|
||||
if not waiting:
|
||||
return None
|
||||
return Failure(f"a reviewer's comment on pull request {number} waits for an answer, in {', '.join(waiting)}; answer it in its thread, push any fix, and run chunk-pr merge again")
|
||||
|
||||
+167
-37
@@ -3,7 +3,7 @@
|
||||
usage: chunk-pr open <title> [<body>]
|
||||
chunk-pr sync
|
||||
chunk-pr ready [<title>]
|
||||
chunk-pr merge
|
||||
chunk-pr merge [--finish <ID> [--changelog <bullet> | --no-changelog]]...
|
||||
chunk-pr clean
|
||||
|
||||
Run it in the chunk's worktree, on the chunk's branch. ready and merge act on the branch's open
|
||||
@@ -25,7 +25,18 @@ ready marks the pull request ready for review. On Gitea a draft is a pull req
|
||||
starts with `WIP: `, so there it drops that prefix. Given <title>, one line, which it holds
|
||||
to the template as open does, it sets that
|
||||
as the pull request's title first; where that fails, the pull request stays a draft.
|
||||
merge waits for the pull request's checks, and those origin's default branch requires, to pass
|
||||
merge merges the pull request in its turn: the chunks of one project on this machine merge one
|
||||
at a time, each waiting until the one before it has merged or failed. In its turn it
|
||||
fetches origin and merges its default branch into the branch, as sync does; finishes each
|
||||
plan item a --finish names with `todo-item finish`, passing on --changelog or
|
||||
--no-changelog, and commits what that changed in the plan and the changelog; and pushes.
|
||||
So the plan and the changelog change only at merge time, on top of every chunk merged
|
||||
before. An item the plan no longer holds was finished by an earlier run, and stays so.
|
||||
On a merge conflict it names the conflicted files and leaves the merge in progress:
|
||||
resolve them, commit, push, and run it again. Where the default branch brought changes in
|
||||
and the branch has recorded a comprehension check, it pushes and stops, since a paired
|
||||
ruling read the head before them: run the ruling again, then merge again.
|
||||
Then it waits for the pull request's checks, and those origin's default branch requires, to pass
|
||||
on the head, then merges the pull request, and only while its head is still the commit
|
||||
checked out, so a push after the gate is never merged. Where no check reports within a
|
||||
minute, it takes the pull request as having none. It refuses where a check fails, or, on
|
||||
@@ -37,8 +48,12 @@ merge waits for the pull request's checks, and those origin's default branch
|
||||
scoring-run-owed` exits 1, because the chunk owes a scoring run it has not recorded.
|
||||
Where the project's config sets `wait-for-approval = true` (`project-config --help`), it
|
||||
also waits, once the checks have passed, until GitHub reports the pull request approved
|
||||
as its branch protection requires. It refuses at once where a reviewer requested changes,
|
||||
as its branch protection requires. It waits outside its turn, so other chunks merge
|
||||
meanwhile, and takes a new turn once approved. It refuses at once where a reviewer requested changes,
|
||||
where the protection requires no review, on Gitea, and where it cannot read the config.
|
||||
It stops too where a reviewer's comment waits for an answer: a review thread nobody
|
||||
resolved whose last comment is not the pull request author's. Answer it in its thread,
|
||||
push any fix, and run merge again to go on waiting.
|
||||
After 90 minutes without an approval it refuses too; run it again once the pull request
|
||||
is approved.
|
||||
clean acts once the forge reports the branch's pull request merged at the commit checked out,
|
||||
@@ -51,7 +66,9 @@ clean acts once the forge reports the branch's pull request merged at the com
|
||||
|
||||
It prints what it did, exit 0, or why it failed, exit 1.
|
||||
"""
|
||||
import contextlib
|
||||
import dataclasses
|
||||
import fcntl
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
@@ -59,7 +76,7 @@ import sys
|
||||
import time
|
||||
import typing
|
||||
|
||||
from chunk_pr.approval import approved, awaited
|
||||
from chunk_pr.approval import approval, approved, awaited
|
||||
from deploy_release.forge import checks_passed, gitea, merged_pull, open_pull, required_checks, Run, runner
|
||||
from failure import Failure
|
||||
from chunk_preflight.gathered import Forge
|
||||
@@ -69,7 +86,9 @@ from project_config import templates
|
||||
BIN = pathlib.Path(__file__).resolve().parents[1]
|
||||
# How long merge waits for a check to report before it takes a pull request without any as passed: CI queues its checks within seconds of a push, and merge may run right after one.
|
||||
NO_CHECKS_SECONDS = 60
|
||||
USAGE = "usage: chunk-pr open <title> [<body>] | chunk-pr sync | chunk-pr ready [<title>] | chunk-pr merge | chunk-pr clean"
|
||||
# The file, in the git folder that every worktree of the checkout shares, that a merge keeps locked with flock for its turn: so every chunk of the project on this machine queues on it.
|
||||
QUEUE = "chunk-pr-merge-queue"
|
||||
USAGE = "usage: chunk-pr open <title> [<body>] | chunk-pr sync | chunk-pr ready [<title>] | chunk-pr merge [--finish <ID> [--changelog <bullet> | --no-changelog]]... | chunk-pr clean"
|
||||
|
||||
# Each forge's merge methods in the order merge prefers them, as the repository setting that allows the method and the method's name in the forge's merge call. A merge commit and a fast-forward keep the branch's commits as they are; a rebase or a squash rewrites them.
|
||||
METHODS: dict[Forge, tuple[tuple[str, str], ...]] = {
|
||||
@@ -99,8 +118,9 @@ def step(argv: list[str], run: Run) -> str | Failure:
|
||||
return synced(run)
|
||||
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) if title else None) or marked_ready(run, title[0] if title else None)
|
||||
case ["merge"]:
|
||||
return merged(run)
|
||||
case ["merge", *given]:
|
||||
finishes = finishes_of(given)
|
||||
return Failure(USAGE) if finishes is None else merged(run, finishes=finishes)
|
||||
case ["clean"]:
|
||||
return cleaned(run)
|
||||
return Failure(USAGE)
|
||||
@@ -195,23 +215,10 @@ def synced(run: Run) -> str | Failure:
|
||||
return base
|
||||
if branch == base:
|
||||
return Failure(f"{branch} is origin's default branch; sync the chunk's branch")
|
||||
fetched = run(["git", "fetch", "--quiet", "origin"])
|
||||
if isinstance(fetched, Failure):
|
||||
return fetched
|
||||
behind = answers(run, ["rev-list", "--count", f"HEAD..origin/{base}"], ["rev-parse", "--show-toplevel"])
|
||||
if isinstance(behind, Failure):
|
||||
return behind
|
||||
count, root = behind
|
||||
if count == "0":
|
||||
done = f"{branch} already holds origin/{base}."
|
||||
else:
|
||||
merged = run(["git", "merge", "--quiet", "--no-edit", f"origin/{base}"])
|
||||
if isinstance(merged, Failure):
|
||||
conflicted = answers(run, ["diff", "--name-only", "--diff-filter=U"])
|
||||
if isinstance(conflicted, Failure) or not conflicted[0]:
|
||||
return merged
|
||||
return Failure(f"merging origin/{base} into {branch} conflicts in {', '.join(conflicted[0].splitlines())}; the merge stays in progress: resolve them and commit")
|
||||
done = f"Merged origin/{base} into {branch}."
|
||||
level = levelled(run, branch, base)
|
||||
if isinstance(level, Failure):
|
||||
return level
|
||||
done = f"Merged origin/{base} into {branch}." if level else f"{branch} already holds origin/{base}."
|
||||
plan = run([str(BIN / "project-config"), "plan"])
|
||||
if isinstance(plan, Failure):
|
||||
return Failure(f"{done.removesuffix('.')}, but the plan to check cannot be found: {plan.reason}")
|
||||
@@ -224,6 +231,25 @@ def synced(run: Run) -> str | Failure:
|
||||
return f"{done}\nrank_todo.py --check todo.md passed."
|
||||
|
||||
|
||||
def levelled(run: Run, branch: str, base: str) -> bool | Failure:
|
||||
"""Fetch origin and merge its base into branch, the one checked out: whether that brought anything in. On a conflict the merge stays in progress, and the Failure names the conflicted files."""
|
||||
fetched = run(["git", "fetch", "--quiet", "origin"])
|
||||
if isinstance(fetched, Failure):
|
||||
return fetched
|
||||
behind = answers(run, ["rev-list", "--count", f"HEAD..origin/{base}"])
|
||||
if isinstance(behind, Failure):
|
||||
return behind
|
||||
if behind[0] == "0":
|
||||
return False
|
||||
merged = run(["git", "merge", "--quiet", "--no-edit", f"origin/{base}"])
|
||||
if isinstance(merged, Failure):
|
||||
conflicted = answers(run, ["diff", "--name-only", "--diff-filter=U"])
|
||||
if isinstance(conflicted, Failure) or not conflicted[0]:
|
||||
return merged
|
||||
return Failure(f"merging origin/{base} into {branch} conflicts in {', '.join(conflicted[0].splitlines())}; the merge stays in progress: resolve them and commit")
|
||||
return True
|
||||
|
||||
|
||||
def marked_ready(run: Run, title: str | None) -> str | Failure:
|
||||
found = pull(run)
|
||||
if isinstance(found, Failure):
|
||||
@@ -241,11 +267,28 @@ def marked_ready(run: Run, title: str | None) -> str | Failure:
|
||||
return f"Marked pull request #{number} ready, titled “{title}”." if title is not None else f"Marked pull request #{number} ready."
|
||||
|
||||
|
||||
def merged(run: Run, sleep: typing.Callable[[float], None] = time.sleep) -> str | Failure:
|
||||
def finishes_of(given: list[str]) -> list[list[str]] | None:
|
||||
"""`todo-item finish`'s arguments for each item that merge's flags name, in their order; None where the flags are malformed."""
|
||||
finishes, rest = [], given
|
||||
while rest:
|
||||
match rest:
|
||||
case ["--finish", item, "--changelog", bullet, *rest] if not item.startswith("-"):
|
||||
finishes.append([item, "--changelog", bullet])
|
||||
case ["--finish", item, "--no-changelog", *rest] if not item.startswith("-"):
|
||||
finishes.append([item, "--no-changelog"])
|
||||
case ["--finish", item, *rest] if not item.startswith("-"):
|
||||
finishes.append([item])
|
||||
case _:
|
||||
return None
|
||||
return finishes
|
||||
|
||||
|
||||
def merged(run: Run, sleep: typing.Callable[[float], None] = time.sleep, finishes: typing.Sequence[list[str]] = ()) -> str | Failure:
|
||||
"""Merge the branch's pull request in the project's merge queue. Each pass of the loop is one turn in the queue; a pull request that still wants its approval leaves the queue while it waits, so the next chunk merges meanwhile, and takes a new turn once approved."""
|
||||
found = pull(run)
|
||||
if isinstance(found, Failure):
|
||||
return found
|
||||
forge, number, head = found
|
||||
forge, number, _ = found
|
||||
waits = awaited(forge, run)
|
||||
if isinstance(waits, Failure):
|
||||
return waits
|
||||
@@ -257,17 +300,104 @@ def merged(run: Run, sleep: typing.Callable[[float], None] = time.sleep) -> str
|
||||
return method
|
||||
base = default_branch(run)
|
||||
required = base if isinstance(base, Failure) else required_checks(forge, base, run)
|
||||
checked = required if isinstance(required, Failure) else checks_passed(forge, number, head, required, run, sleep, NO_CHECKS_SECONDS)
|
||||
if isinstance(checked, Failure):
|
||||
return checked
|
||||
approval = approved(number, run, sleep) if waits else None
|
||||
if isinstance(approval, Failure):
|
||||
return approval
|
||||
if forge == "gh":
|
||||
done = run(["gh", "pr", "merge", number, method, "--match-head-commit", head])
|
||||
else:
|
||||
done = gitea(run, f"repos/{{owner}}/{{repo}}/pulls/{number}/merge", f"Do={method}", f"head_commit_id={head}")
|
||||
return done if isinstance(done, Failure) else f"Merged pull request #{number} ({method.removeprefix('--')})."
|
||||
if isinstance(required, Failure):
|
||||
return required
|
||||
queue = answers(run, ["rev-parse", "--path-format=absolute", "--git-common-dir"])
|
||||
if isinstance(queue, Failure):
|
||||
return queue
|
||||
while True:
|
||||
try:
|
||||
with turn(pathlib.Path(queue[0]) / QUEUE):
|
||||
head = levelled_and_finished(run, str(base), finishes)
|
||||
checked = head if isinstance(head, Failure) else checks_passed(forge, number, head, required, run, sleep, NO_CHECKS_SECONDS)
|
||||
if isinstance(checked, Failure):
|
||||
return checked
|
||||
ready = approval(number, run) if waits else True
|
||||
if isinstance(ready, Failure):
|
||||
return ready
|
||||
if ready and forge == "gh":
|
||||
done = run(["gh", "pr", "merge", number, method, "--match-head-commit", str(head)])
|
||||
elif ready:
|
||||
done = gitea(run, f"repos/{{owner}}/{{repo}}/pulls/{number}/merge", f"Do={method}", f"head_commit_id={head}")
|
||||
if ready:
|
||||
return done if isinstance(done, Failure) else f"Merged pull request #{number} ({method.removeprefix('--')})."
|
||||
except OSError as failure:
|
||||
return Failure(f"cannot take a turn in the merge queue, {failure.filename}: {failure.strerror}")
|
||||
waited = approved(number, run, sleep)
|
||||
if isinstance(waited, Failure):
|
||||
return waited
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def turn(queue: pathlib.Path) -> typing.Iterator[None]:
|
||||
"""Hold the project's merge queue: wait until no other chunk-pr merge on this machine holds it, and free it on the way out, however that is. Raises OSError where the file cannot be opened or locked."""
|
||||
fd = os.open(queue, os.O_RDWR | os.O_CREAT, 0o644)
|
||||
try:
|
||||
fcntl.flock(fd, fcntl.LOCK_EX)
|
||||
yield
|
||||
finally:
|
||||
os.close(fd)
|
||||
|
||||
|
||||
def levelled_and_finished(run: Run, base: str, finishes: typing.Sequence[list[str]]) -> str | Failure:
|
||||
"""What merge does to the branch inside its turn, before the checks: merge origin's base into it, finish the plan items, and push. The head to merge, or why the worker must act first."""
|
||||
found = checkout(run)
|
||||
if isinstance(found, Failure):
|
||||
return found
|
||||
_, branch, before = found
|
||||
moved = levelled(run, branch, base)
|
||||
failed = moved if isinstance(moved, Failure) else next((failure for finish in finishes if (failure := finished(run, branch, finish))), None)
|
||||
head = failed or answers(run, ["rev-parse", "HEAD"])
|
||||
if isinstance(head, Failure):
|
||||
return head
|
||||
pushed = run(["git", "push", "--quiet", "origin", branch]) if head[0] != before else ""
|
||||
if isinstance(pushed, Failure):
|
||||
return pushed
|
||||
return (remeasure(run, base) if moved else None) or head[0]
|
||||
|
||||
|
||||
def finished(run: Run, branch: str, finish: list[str]) -> Failure | None:
|
||||
"""Finish one plan item with `todo-item finish` and commit what that changed. An item the plan no longer holds was finished by an earlier run of merge, and stays as it is."""
|
||||
shown = run([str(BIN / "todo-item"), "show", finish[0]])
|
||||
if isinstance(shown, Failure):
|
||||
return None if f"holds no item {finish[0]}" in shown.reason else shown
|
||||
read = [run([str(BIN / "todo-item"), "finish", *finish]), run([str(BIN / "project-config"), "commit-title"]), run([str(BIN / "project-config"), "branch"]), run([str(BIN / "project-config"), "plan"]), run([str(BIN / "project-config"), "changelog"])]
|
||||
if failed := next((answer for answer in read if isinstance(answer, Failure)), None):
|
||||
return failed
|
||||
_, template, branch_template, *records = (str(answer).strip() for answer in read)
|
||||
summary = f"Finish item {finish[0]} in the plan"
|
||||
# A branch that doesn't fit the config's `branch` template has no ID for {id}, so its titles are the summary alone, as CLAUDE.md → "Git, commits, and PRs" says.
|
||||
title = template.replace(templates.ID, finish[0]).replace(templates.SUMMARY, summary) if templates.branch_fits(branch_template, branch) else summary
|
||||
return committed(run, title, [pathlib.Path(record) for record in records if pathlib.Path(record).is_file()])
|
||||
|
||||
|
||||
def committed(run: Run, title: str, files: list[pathlib.Path]) -> Failure | None:
|
||||
"""Commit what changed in files under title, each in the git repository that holds it, and only those files: a record the config keeps in its own folder is committed there, where another chunk may commit at once."""
|
||||
held: dict[str, list[str]] = {}
|
||||
for file in files:
|
||||
top = run(["git", "-C", str(file.parent), "rev-parse", "--show-toplevel"])
|
||||
if isinstance(top, Failure):
|
||||
return top
|
||||
held.setdefault(top.strip(), []).append(str(file))
|
||||
for top, paths in held.items():
|
||||
changed = run(["git", "-C", top, "status", "--porcelain", "--", *paths])
|
||||
steps = [changed] if isinstance(changed, Failure) or not changed.strip() else [run(["git", "-C", top, "add", "--", *paths]), run(["git", "-C", top, "commit", "--quiet", "-m", title, "--", *paths])]
|
||||
if failed := next((step for step in steps if isinstance(step, Failure)), None):
|
||||
return failed
|
||||
return None
|
||||
|
||||
|
||||
def remeasure(run: Run, base: str) -> Failure | None:
|
||||
"""A Failure where the branch recorded a comprehension check before origin's base, just merged in, brought in another chunk's change: the check read a head that no longer merges. None where the branch recorded none, or the history is no file in the checkout."""
|
||||
history = run([str(BIN / "project-config"), "comprehension-history"])
|
||||
if isinstance(history, Failure):
|
||||
return history
|
||||
if not pathlib.Path(history.strip()).is_file():
|
||||
return None
|
||||
recorded = answers(run, ["diff", "--name-only", f"origin/{base}...HEAD", "--", history.strip()])
|
||||
if isinstance(recorded, Failure) or not recorded[0]:
|
||||
return recorded if isinstance(recorded, Failure) else None
|
||||
return Failure(f"origin/{base} moved after the branch recorded its comprehension check, and its changes are merged in and pushed; where the chunk recorded a paired ruling, run it again at the new head, record it, and run chunk-pr merge again")
|
||||
|
||||
|
||||
def merge_method(forge: Forge, run: Run) -> str | Failure:
|
||||
|
||||
+211
-21
@@ -1,5 +1,8 @@
|
||||
import fcntl
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
@@ -7,10 +10,11 @@ import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from chunk_pr.main import cleaned, merged, step, USAGE
|
||||
from chunk_pr.main import cleaned, merged, QUEUE, step, turn, USAGE
|
||||
from failure import Failure
|
||||
from test_env import isolated_env
|
||||
from deploy_release.forge import Run
|
||||
from chunk_pr.approval import THREADS
|
||||
|
||||
TOOL = pathlib.Path(__file__).resolve().parents[1] / "chunk-pr"
|
||||
GITHUB = "git@github.com:me/project.git"
|
||||
@@ -29,6 +33,11 @@ TITLE = [str(pathlib.Path(__file__).resolve().parents[1] / "project-config"), "p
|
||||
BRANCH = [str(pathlib.Path(__file__).resolve().parents[1] / "project-config"), "branch"]
|
||||
WAITS = [str(pathlib.Path(__file__).resolve().parents[1] / "project-config"), "wait-for-approval"]
|
||||
GH_DECISION = ["gh", "pr", "view", "12", "--json", "reviewDecision"]
|
||||
GH_THREADS = ["gh", "api", "graphql", "-f", f"query={THREADS}", "-F", "owner={owner}", "-F", "repo={repo}", "-F", "number=12"]
|
||||
BEHIND = ["git", "rev-list", "--count", "HEAD..origin/main"]
|
||||
COMMON = ["git", "rev-parse", "--path-format=absolute", "--git-common-dir"]
|
||||
# The folder the fake checkouts name as their shared git folder, where merge keeps its queue's file.
|
||||
GIT_FOLDER = tempfile.TemporaryDirectory()
|
||||
|
||||
|
||||
class Checkout:
|
||||
@@ -45,6 +54,8 @@ class Checkout:
|
||||
self.decisions = ["APPROVED"]
|
||||
# Set, what GitHub prints instead of a decision's JSON.
|
||||
self.unreadable: str | Failure | None = None
|
||||
# The pull request's review threads, as GitHub's GraphQL API prints them; its author is `worker`.
|
||||
self.threads: list[dict[str, object]] = []
|
||||
self.ran: list[list[str]] = []
|
||||
self.answers: dict[tuple[str, ...], str | Failure] = {
|
||||
("git", "remote", "get-url", "origin"): f"{origin}\n",
|
||||
@@ -54,6 +65,8 @@ class Checkout:
|
||||
tuple(WAITS): "false\n",
|
||||
tuple(TITLE): "{summary}\n",
|
||||
tuple(BRANCH): "item-{id}\n",
|
||||
tuple(BEHIND): "0\n",
|
||||
tuple(COMMON): f"{GIT_FOLDER.name}\n",
|
||||
}
|
||||
|
||||
def __call__(self, command: list[str]) -> str | Failure:
|
||||
@@ -74,6 +87,8 @@ class Checkout:
|
||||
return self.unreadable
|
||||
if command == GH_DECISION:
|
||||
return json.dumps({"reviewDecision": self.decisions.pop(0) if len(self.decisions) > 1 else self.decisions[0]})
|
||||
if command == GH_THREADS:
|
||||
return json.dumps({"data": {"repository": {"pullRequest": {"author": {"login": "worker"}, "reviewThreads": {"nodes": self.threads}}}}})
|
||||
if command == TEA_BRANCH:
|
||||
return json.dumps({"enable_status_check": False})
|
||||
if command in (GH_SETTINGS, TEA_SETTINGS):
|
||||
@@ -82,7 +97,7 @@ class Checkout:
|
||||
|
||||
def acted(self) -> list[list[str]]:
|
||||
"""What it ran beyond reading the checkout, the pull requests and the repository's settings."""
|
||||
reads = [GH_LIST, GH_DECISION, TEA_LIST, GH_SETTINGS, TEA_SETTINGS, OWED, GH_CHECKS, TEA_BRANCH, TEA_STATUS]
|
||||
reads = [GH_LIST, GH_DECISION, TEA_LIST, GH_SETTINGS, TEA_SETTINGS, OWED, GH_CHECKS, TEA_BRANCH, TEA_STATUS, GH_THREADS]
|
||||
return [command for command in self.ran if tuple(command) not in self.answers and command not in reads]
|
||||
|
||||
|
||||
@@ -281,6 +296,11 @@ class Sync(unittest.TestCase):
|
||||
self.assertEqual(step(["sync"], checkout), Failure("git fetch --quiet: could not read from remote"))
|
||||
|
||||
|
||||
def changes(checkout: Checkout) -> list[list[str]]:
|
||||
"""What a merge ran beyond its reads, of the project's config too, and the fetch its turn opens with."""
|
||||
return [command for command in checkout.acted() if command != FETCH and not command[0].endswith("/project-config")]
|
||||
|
||||
|
||||
class Merge(unittest.TestCase):
|
||||
def test_the_gate_passed_flag_it_no_longer_takes_is_refused_before_anything_runs(self):
|
||||
checkout = Checkout(GITHUB, open=True)
|
||||
@@ -302,7 +322,7 @@ class Merge(unittest.TestCase):
|
||||
checkout = Checkout(GITHUB, open=True)
|
||||
checkout.answers[tuple(GH_CHECKS)] = Failure("gh pr checks 12: CI / tests\tfail")
|
||||
self.assertEqual(step(["merge"], checkout), Failure("gh pr checks 12: CI / tests\tfail"))
|
||||
self.assertEqual(checkout.acted(), [])
|
||||
self.assertEqual(changes(checkout), [])
|
||||
|
||||
def test_github_waits_a_minute_for_checks_to_report_before_taking_none_as_passed(self):
|
||||
checkout = Checkout(GITHUB, open=True)
|
||||
@@ -341,7 +361,7 @@ class Merge(unittest.TestCase):
|
||||
checkout = self.requiring_approval(GITHUB, "REVIEW_REQUIRED", "REVIEW_REQUIRED", "APPROVED")
|
||||
slept: list[float] = []
|
||||
self.assertEqual(merged(checkout, slept.append), "Merged pull request #12 (merge).")
|
||||
self.assertEqual(slept, [60, 60])
|
||||
self.assertEqual(slept, [60])
|
||||
|
||||
def test_an_approval_that_never_comes_leaves_it_unmerged_after_90_minutes(self):
|
||||
checkout = self.requiring_approval(GITHUB, "REVIEW_REQUIRED")
|
||||
@@ -350,10 +370,10 @@ class Merge(unittest.TestCase):
|
||||
self.assertIsInstance(failed, Failure)
|
||||
self.assertIn("90 minutes", failed.reason)
|
||||
self.assertEqual(sum(slept), 90 * 60)
|
||||
self.assertEqual(checkout.acted(), [])
|
||||
self.assertEqual(changes(checkout), [])
|
||||
|
||||
def test_an_approval_that_comes_in_the_last_minute_still_merges(self):
|
||||
checkout = self.requiring_approval(GITHUB, *["REVIEW_REQUIRED"] * 90, "APPROVED")
|
||||
checkout = self.requiring_approval(GITHUB, *["REVIEW_REQUIRED"] * 91, "APPROVED")
|
||||
slept: list[float] = []
|
||||
self.assertEqual(merged(checkout, slept.append), "Merged pull request #12 (merge).")
|
||||
self.assertEqual(sum(slept), 90 * 60)
|
||||
@@ -364,7 +384,7 @@ class Merge(unittest.TestCase):
|
||||
checkout = self.requiring_approval()
|
||||
checkout.unreadable = answer
|
||||
self.assertIsInstance(step(["merge"], checkout), Failure)
|
||||
self.assertEqual(checkout.acted(), [])
|
||||
self.assertEqual(changes(checkout), [])
|
||||
|
||||
def test_requested_changes_leave_it_unmerged_without_waiting(self):
|
||||
checkout = self.requiring_approval(GITHUB, "CHANGES_REQUESTED")
|
||||
@@ -372,7 +392,7 @@ class Merge(unittest.TestCase):
|
||||
failed = merged(checkout, slept.append)
|
||||
self.assertIsInstance(failed, Failure)
|
||||
self.assertIn("requested changes", failed.reason)
|
||||
self.assertEqual((slept, checkout.acted()), ([], []))
|
||||
self.assertEqual((slept, changes(checkout)), ([], []))
|
||||
|
||||
def test_a_branch_protection_that_asks_for_no_review_leaves_it_unmerged_naming_the_setting(self):
|
||||
for decision in ("", None):
|
||||
@@ -381,14 +401,14 @@ class Merge(unittest.TestCase):
|
||||
failed = step(["merge"], checkout)
|
||||
self.assertIsInstance(failed, Failure)
|
||||
self.assertIn("requires no review", failed.reason)
|
||||
self.assertEqual(checkout.acted(), [])
|
||||
self.assertEqual(changes(checkout), [])
|
||||
|
||||
def test_gitea_with_wait_for_approval_leaves_it_unmerged_since_chunk_pr_reads_approvals_on_github_only(self):
|
||||
checkout = self.requiring_approval(GITEA)
|
||||
failed = step(["merge"], checkout)
|
||||
self.assertIsInstance(failed, Failure)
|
||||
self.assertIn("GitHub", failed.reason)
|
||||
self.assertEqual(checkout.acted(), [])
|
||||
self.assertEqual(changes(checkout), [])
|
||||
|
||||
def test_a_config_it_cannot_read_or_that_prints_neither_true_nor_false_leaves_it_unmerged(self):
|
||||
for answer in (Failure("no config names the checkout"), "maybe\n", ""):
|
||||
@@ -396,7 +416,7 @@ class Merge(unittest.TestCase):
|
||||
checkout = Checkout(GITHUB, open=True)
|
||||
checkout.answers[tuple(WAITS)] = answer
|
||||
self.assertIsInstance(step(["merge"], checkout), Failure)
|
||||
self.assertEqual(checkout.acted(), [])
|
||||
self.assertEqual(changes(checkout), [])
|
||||
|
||||
def protected(self, *reads: list[tuple[str, str]]) -> Checkout:
|
||||
"""A Gitea Checkout whose main requires a check matching CI / tests*, its status at HEAD holding each of reads in turn."""
|
||||
@@ -419,28 +439,28 @@ class Merge(unittest.TestCase):
|
||||
def test_a_failed_check_on_gitea_leaves_it_unmerged(self):
|
||||
checkout = self.protected([("CI / tests (pull_request)", "pending")], [("CI / tests (pull_request)", "failure")])
|
||||
self.assertIsInstance(merged(checkout, lambda _: None), Failure)
|
||||
self.assertEqual(checkout.acted(), [])
|
||||
self.assertEqual(changes(checkout), [])
|
||||
|
||||
def test_a_branch_protection_it_cannot_read_leaves_it_unmerged(self):
|
||||
checkout = Checkout(GITEA, open=True)
|
||||
checkout.answers[tuple(TEA_BRANCH)] = Failure("tea api: 500")
|
||||
self.assertEqual(merged(checkout, self.fail), Failure("tea api: 500"))
|
||||
self.assertNotIn(TEA_STATUS, checkout.ran)
|
||||
self.assertEqual(checkout.acted(), [])
|
||||
self.assertEqual(changes(checkout), [])
|
||||
|
||||
def test_an_unknown_default_branch_leaves_it_unmerged_reading_no_checks(self):
|
||||
checkout = Checkout(GITEA, open=True)
|
||||
checkout.answers[("git", "symbolic-ref", "--short", "refs/remotes/origin/HEAD")] = Failure("no such ref")
|
||||
self.assertEqual(merged(checkout, self.fail), Failure("origin records no default branch; set it with `git remote set-head origin --auto`: no such ref"))
|
||||
self.assertNotIn(TEA_STATUS, checkout.ran)
|
||||
self.assertEqual(checkout.acted(), [])
|
||||
self.assertEqual(changes(checkout), [])
|
||||
|
||||
def test_gitea_checks_that_never_pass_leave_it_unmerged(self):
|
||||
checkout = self.protected(*[[("CI / tests (pull_request)", "pending")]] * 1000)
|
||||
failed = merged(checkout, lambda _: None)
|
||||
self.assertIsInstance(failed, Failure)
|
||||
self.assertIn("gave up on pull request 12", failed.reason)
|
||||
self.assertEqual(checkout.acted(), [])
|
||||
self.assertEqual(changes(checkout), [])
|
||||
|
||||
def test_a_scoring_run_the_chunk_owes_and_has_not_recorded_refuses_the_merge(self):
|
||||
for origin in (GITHUB, GITEA):
|
||||
@@ -448,27 +468,27 @@ class Merge(unittest.TestCase):
|
||||
checkout = Checkout(origin, open=True)
|
||||
checkout.answers[tuple(OWED)] = Failure("larv-review scoring-run-owed: the chunk owes 2 scoring runs")
|
||||
self.assertEqual(step(["merge"], checkout), Failure("larv-review scoring-run-owed: the chunk owes 2 scoring runs"))
|
||||
self.assertEqual(checkout.acted(), [])
|
||||
self.assertEqual(changes(checkout), [])
|
||||
|
||||
def test_github_merges_with_a_merge_commit_pinned_to_the_head(self):
|
||||
checkout = Checkout(GITHUB, open=True, allowed=("squashMergeAllowed", "mergeCommitAllowed"))
|
||||
self.assertEqual(step(["merge"], checkout), "Merged pull request #12 (merge).")
|
||||
self.assertEqual(checkout.acted(), [["gh", "pr", "merge", "12", "--merge", "--match-head-commit", HEAD]])
|
||||
self.assertEqual(changes(checkout), [["gh", "pr", "merge", "12", "--merge", "--match-head-commit", HEAD]])
|
||||
|
||||
def test_github_without_merge_commits_rebases(self):
|
||||
checkout = Checkout(GITHUB, open=True, allowed=("squashMergeAllowed", "rebaseMergeAllowed"))
|
||||
step(["merge"], checkout)
|
||||
self.assertEqual(checkout.acted(), [["gh", "pr", "merge", "12", "--rebase", "--match-head-commit", HEAD]])
|
||||
self.assertEqual(changes(checkout), [["gh", "pr", "merge", "12", "--rebase", "--match-head-commit", HEAD]])
|
||||
|
||||
def test_gitea_merges_fast_forward_only_where_only_that_and_squash_are_allowed(self):
|
||||
checkout = Checkout(GITEA, open=True, allowed=("allow_squash_merge", "allow_fast_forward_only_merge"))
|
||||
self.assertEqual(step(["merge"], checkout), "Merged pull request #12 (fast-forward-only).")
|
||||
self.assertEqual(checkout.acted(), [["tea", "api", "--method", "POST", "--field", "Do=fast-forward-only", "--field", f"head_commit_id={HEAD}", "repos/{owner}/{repo}/pulls/12/merge"]])
|
||||
self.assertEqual(changes(checkout), [["tea", "api", "--method", "POST", "--field", "Do=fast-forward-only", "--field", f"head_commit_id={HEAD}", "repos/{owner}/{repo}/pulls/12/merge"]])
|
||||
|
||||
def test_a_repository_allowing_no_known_method_is_refused_unmerged(self):
|
||||
checkout = Checkout(GITEA, open=True, allowed=("allow_manual_merge",))
|
||||
self.assertIsInstance(step(["merge"], checkout), Failure)
|
||||
self.assertEqual(checkout.acted(), [])
|
||||
self.assertEqual(changes(checkout), [])
|
||||
|
||||
def test_a_forge_failure_is_returned(self):
|
||||
checkout = Checkout(GITHUB, open=True)
|
||||
@@ -484,7 +504,177 @@ class Merge(unittest.TestCase):
|
||||
checkout = Checkout(origin, open=True)
|
||||
checkout.answers[tuple(settings)] = Failure("settings: denied")
|
||||
self.assertEqual(step(["merge"], checkout), Failure("settings: denied"))
|
||||
self.assertEqual(checkout.acted(), [])
|
||||
self.assertEqual(changes(checkout), [])
|
||||
|
||||
|
||||
def queue_is_free() -> bool:
|
||||
"""Whether another merge could take its turn now."""
|
||||
fd = os.open(pathlib.Path(GIT_FOLDER.name) / QUEUE, os.O_RDWR | os.O_CREAT)
|
||||
try:
|
||||
fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
except BlockingIOError:
|
||||
return False
|
||||
finally:
|
||||
os.close(fd)
|
||||
return True
|
||||
|
||||
|
||||
class MergeQueue(unittest.TestCase):
|
||||
PUSHED = ["git", "push", "--quiet", "origin", "item-7"]
|
||||
TODO_ITEM = str(pathlib.Path(__file__).resolve().parents[1] / "todo-item")
|
||||
CONFIG = str(pathlib.Path(__file__).resolve().parents[1] / "project-config")
|
||||
|
||||
def moved(self, checkout: Checkout) -> Checkout:
|
||||
"""checkout with origin's main two commits ahead of the branch, whose head is `decaf` once main is merged in."""
|
||||
checkout.answers[tuple(BEHIND)] = "2\n"
|
||||
run = checkout.__call__
|
||||
def merging(command: list[str]) -> str | Failure:
|
||||
answer = run(command)
|
||||
if command == MERGE and not isinstance(answer, Failure):
|
||||
checkout.answers[("git", "rev-parse", "HEAD")] = "decaf\n"
|
||||
return answer
|
||||
checkout.__call__ = merging # type: ignore[method-assign]
|
||||
return checkout
|
||||
|
||||
def with_plan(self, checkout: Checkout, held: bool = True) -> tuple[Checkout, str]:
|
||||
"""checkout in a project whose config names a todo.md and a CHANGELOG.md in one folder, which is returned, and titles commits `[{id}] {summary}`. The plan holds item 7 where held. A commit moves the head to `f00d`."""
|
||||
folder = tempfile.mkdtemp()
|
||||
self.addCleanup(shutil.rmtree, folder)
|
||||
for name in ("todo.md", "CHANGELOG.md"):
|
||||
(pathlib.Path(folder) / name).write_text("")
|
||||
checkout.answers.update({
|
||||
(self.TODO_ITEM, "show", "7"): "From todo.md:\n" if held else Failure("todo-item show 7: todo.md holds no item 7"),
|
||||
(self.CONFIG, "plan"): f"{folder}/todo.md\n",
|
||||
(self.CONFIG, "changelog"): f"{folder}/CHANGELOG.md\n",
|
||||
(self.CONFIG, "commit-title"): "[{id}] {summary}\n",
|
||||
("git", "-C", folder, "rev-parse", "--show-toplevel"): f"{folder}\n",
|
||||
("git", "-C", folder, "status", "--porcelain", "--", f"{folder}/todo.md", f"{folder}/CHANGELOG.md"): " M todo.md\n",
|
||||
})
|
||||
run = checkout.__call__
|
||||
def committing(command: list[str]) -> str | Failure:
|
||||
if command[3:4] == ["commit"]:
|
||||
checkout.answers[("git", "rev-parse", "HEAD")] = "f00d\n"
|
||||
return run(command)
|
||||
checkout.__call__ = committing # type: ignore[method-assign]
|
||||
return checkout, folder
|
||||
|
||||
def test_malformed_finish_flags_run_nothing(self):
|
||||
for flags in (["--finish"], ["--changelog", "Bullet."], ["12"], ["--finish", "--no-changelog"], ["--finish", "7", "--changelog"], ["--finish", "7", "--no-changelog", "--changelog", "Bullet."]):
|
||||
with self.subTest(flags):
|
||||
checkout = Checkout(GITHUB, open=True)
|
||||
self.assertEqual(step(["merge", *flags], checkout), Failure(USAGE))
|
||||
self.assertEqual(checkout.ran, [])
|
||||
|
||||
def test_a_branch_behind_the_default_branch_merges_it_in_and_pushes_before_the_checks(self):
|
||||
checkout = self.moved(Checkout(GITHUB, open=True))
|
||||
self.assertEqual(merged(checkout.__call__), "Merged pull request #12 (merge).")
|
||||
self.assertEqual(changes(checkout), [MERGE, self.PUSHED, ["gh", "pr", "merge", "12", "--merge", "--match-head-commit", "decaf"]])
|
||||
self.assertLess(checkout.ran.index(self.PUSHED), checkout.ran.index(GH_CHECKS))
|
||||
|
||||
def test_a_conflict_with_the_default_branch_leaves_it_unmerged_naming_the_files_and_frees_the_queue(self):
|
||||
checkout = self.moved(Checkout(GITHUB, open=True))
|
||||
checkout.answers[tuple(MERGE)] = Failure("git merge --quiet: CONFLICT")
|
||||
checkout.answers[("git", "diff", "--name-only", "--diff-filter=U")] = "bin/tool.py\n"
|
||||
failed = merged(checkout.__call__)
|
||||
self.assertIsInstance(failed, Failure)
|
||||
self.assertIn("conflicts in bin/tool.py", failed.reason)
|
||||
self.assertEqual((changes(checkout), MERGE in checkout.ran), ([], True))
|
||||
self.assertTrue(queue_is_free())
|
||||
|
||||
def test_a_finished_item_is_committed_under_the_configs_title_and_pushed_before_the_merge(self):
|
||||
checkout, folder = self.with_plan(Checkout(GITHUB, open=True))
|
||||
files = [f"{folder}/todo.md", f"{folder}/CHANGELOG.md"]
|
||||
self.assertEqual(merged(checkout.__call__, finishes=[["7", "--changelog", "Exports keep their order."]]), "Merged pull request #12 (merge).")
|
||||
self.assertEqual(changes(checkout)[:1], [[self.TODO_ITEM, "finish", "7", "--changelog", "Exports keep their order."]])
|
||||
self.assertEqual(changes(checkout)[-4:], [
|
||||
["git", "-C", folder, "add", "--", *files],
|
||||
["git", "-C", folder, "commit", "--quiet", "-m", "[7] Finish item 7 in the plan", "--", *files],
|
||||
self.PUSHED,
|
||||
["gh", "pr", "merge", "12", "--merge", "--match-head-commit", "f00d"],
|
||||
])
|
||||
|
||||
def test_the_flags_reach_todo_item_as_given(self):
|
||||
checkout, _ = self.with_plan(Checkout(GITHUB, open=True))
|
||||
checkout.answers[(self.TODO_ITEM, "show", "8")] = "From todo.md:\n"
|
||||
self.assertEqual(step(["merge", "--finish", "7", "--no-changelog", "--finish", "8"], checkout.__call__), "Merged pull request #12 (merge).")
|
||||
self.assertEqual([command[1:] for command in checkout.ran if command[:2] == [self.TODO_ITEM, "finish"]], [["finish", "7", "--no-changelog"], ["finish", "8"]])
|
||||
|
||||
def test_an_item_an_earlier_run_finished_stays_as_it_is(self):
|
||||
checkout, _ = self.with_plan(Checkout(GITHUB, open=True), held=False)
|
||||
self.assertEqual(merged(checkout.__call__, finishes=[["7"]]), "Merged pull request #12 (merge).")
|
||||
self.assertEqual(changes(checkout), [["gh", "pr", "merge", "12", "--merge", "--match-head-commit", HEAD]])
|
||||
|
||||
def test_a_plan_it_cannot_read_or_an_item_it_cannot_finish_leaves_it_unmerged(self):
|
||||
for failing in ("show", "finish"):
|
||||
with self.subTest(failing):
|
||||
checkout, _ = self.with_plan(Checkout(GITHUB, open=True))
|
||||
checkout.answers[(self.TODO_ITEM, failing, "7")] = Failure(f"todo-item {failing} 7: no config names the checkout")
|
||||
self.assertEqual(merged(checkout.__call__, finishes=[["7"]]), Failure(f"todo-item {failing} 7: no config names the checkout"))
|
||||
self.assertNotIn(self.PUSHED, checkout.ran)
|
||||
|
||||
def test_a_merge_holds_the_queue_through_the_checks_and_frees_it_while_it_waits_for_an_approval(self):
|
||||
checkout = Checkout(GITHUB, open=True)
|
||||
checkout.answers[tuple(WAITS)] = "true\n"
|
||||
checkout.decisions = ["REVIEW_REQUIRED", "REVIEW_REQUIRED", "APPROVED"]
|
||||
free: dict[str, bool] = {}
|
||||
def run(command: list[str]) -> str | Failure:
|
||||
if command == GH_CHECKS:
|
||||
free.setdefault("during the checks", queue_is_free())
|
||||
return checkout(command)
|
||||
self.assertEqual(merged(run, lambda seconds: free.setdefault("waiting for the approval", queue_is_free())), "Merged pull request #12 (merge).")
|
||||
self.assertEqual(free, {"during the checks": False, "waiting for the approval": True})
|
||||
self.assertEqual(checkout.ran.count(FETCH), 2)
|
||||
|
||||
def test_a_reviewers_comment_ends_the_wait_naming_its_file_until_the_author_answers_or_it_is_resolved(self):
|
||||
def thread(path: str, last: str, resolved: bool = False) -> dict[str, object]:
|
||||
return {"isResolved": resolved, "path": path, "comments": {"nodes": [{"author": {"login": last}}]}}
|
||||
checkout = Checkout(GITHUB, open=True)
|
||||
checkout.answers[tuple(WAITS)] = "true\n"
|
||||
checkout.decisions = ["REVIEW_REQUIRED"]
|
||||
checkout.threads = [thread("bin/asked.py", "reviewer"), thread("bin/answered.py", "worker"), thread("bin/resolved.py", "reviewer", resolved=True)]
|
||||
slept: list[float] = []
|
||||
failed = merged(checkout, slept.append)
|
||||
self.assertIsInstance(failed, Failure)
|
||||
self.assertIn("waits for an answer, in bin/asked.py;", failed.reason)
|
||||
self.assertEqual((slept, changes(checkout)), ([], []))
|
||||
checkout.threads = checkout.threads[1:]
|
||||
checkout.decisions = ["REVIEW_REQUIRED", "REVIEW_REQUIRED", "APPROVED"]
|
||||
self.assertEqual(merged(checkout, slept.append), "Merged pull request #12 (merge).")
|
||||
|
||||
def test_review_threads_it_cannot_read_leave_it_unmerged(self):
|
||||
for answer in (Failure("gh api graphql failed"), "not json", "{}"):
|
||||
with self.subTest(answer):
|
||||
checkout = Checkout(GITHUB, open=True)
|
||||
checkout.answers.update({tuple(WAITS): "true\n", tuple(GH_THREADS): answer})
|
||||
checkout.decisions = ["REVIEW_REQUIRED"]
|
||||
self.assertIsInstance(merged(checkout, lambda seconds: None), Failure)
|
||||
self.assertEqual(changes(checkout), [])
|
||||
|
||||
def test_a_default_branch_that_moved_after_the_branch_recorded_its_comprehension_check_stops_for_a_new_ruling(self):
|
||||
with tempfile.NamedTemporaryFile() as history:
|
||||
for recorded, expected in (("docs/comprehension-history.md\n", [MERGE, self.PUSHED]), ("", [MERGE, self.PUSHED, ["gh", "pr", "merge", "12", "--merge", "--match-head-commit", "decaf"]])):
|
||||
with self.subTest(recorded):
|
||||
checkout = self.moved(Checkout(GITHUB, open=True))
|
||||
checkout.answers[(self.CONFIG, "comprehension-history")] = f"{history.name}\n"
|
||||
checkout.answers[("git", "diff", "--name-only", "origin/main...HEAD", "--", history.name)] = recorded
|
||||
done = merged(checkout.__call__)
|
||||
self.assertEqual(changes(checkout), expected)
|
||||
self.assertEqual(isinstance(done, Failure) and "paired ruling" in done.reason, bool(recorded))
|
||||
|
||||
def test_a_turn_keeps_every_other_merge_out_until_it_ends_even_by_an_error(self):
|
||||
with self.assertRaises(ValueError):
|
||||
with turn(pathlib.Path(GIT_FOLDER.name) / QUEUE):
|
||||
self.assertFalse(queue_is_free())
|
||||
raise ValueError
|
||||
self.assertTrue(queue_is_free())
|
||||
|
||||
def test_a_queue_it_cannot_open_leaves_it_unmerged(self):
|
||||
checkout = Checkout(GITHUB, open=True)
|
||||
checkout.answers[tuple(COMMON)] = "/nonexistent/folder\n"
|
||||
failed = merged(checkout)
|
||||
self.assertIsInstance(failed, Failure)
|
||||
self.assertIn("merge queue", failed.reason)
|
||||
self.assertEqual(checkout.acted(), [])
|
||||
|
||||
|
||||
class Clean(unittest.TestCase):
|
||||
|
||||
@@ -15,6 +15,7 @@ Each project principle states one rule that the decisions below apply; their ent
|
||||
- bin/: a test parametrizes its cases with `subTest`, since pytest's `parametrize` doesn't reach a unittest `TestCase`
|
||||
- bin/: the tools run on the host's Python, with no container, and so do their tests outside CI
|
||||
- bin/: the tools support only the latest stable Python, and the tests, written in plain unittest, run on it in four pytest-xdist workers
|
||||
- chunk-pr: the chunks of a project merge one at a time on a machine, each finishing its plan items in its turn, and a pull request that waits for an approval leaves the queue while it waits
|
||||
- deploy: this repo keeps no `AGENTS.md`, since `~/.claude` is its checkout; its principles and decision titles head `docs/decisions.md`, its working rules follow them there, and its `.claude/settings.json` excludes every `.claude/CLAUDE.md`, so a session in the clone loads only the clone's `CLAUDE.md`
|
||||
- loop-claude: each verdict records the claude-config release and commit that ran it, the raw tokens each thread spent by model and kind since the previous outcome that recorded a spend, and the human's typed answer the judge quotes as reversing a choice the worker took on its own recommendation
|
||||
- loop-claude: one session per running loop of a project, named after the slot the loop holds, its id derived from that name; a chunk's commit in the config's folder takes only the file it changed
|
||||
@@ -78,6 +79,19 @@ Valid while the archive's file names, the Vocabulary and the panel keep these wo
|
||||
|
||||
2026-10-28, lilleman, through todo item 245. Serves goal 1.5: the suite gates every chunk. The suite took 198 s, 102 s of which went to rerunning it on the oldest Python README Install named, 3.11. README Install now asks for the latest stable Python as `python3`, and mypy checks every tool under `bin/` for the version Install names. README's Test line runs the tests in four pytest-xdist workers through `uvx`: 29 s on a 16-CPU machine. Four is one heavy slot's CPUs, `CPUS_PER_SLOT` in `bin/machine_load/slots.py`, so a gate under `run-heavy` loads only the slot it waits for. The line pins pytest and pytest-xdist, as `test_types.py` pins mypy, so every machine runs the gate the same way. It passes the path of `python3`, since `uvx --python python3` picks a Python uv installed itself, which may be older. The tests use stdlib `unittest` alone, and pytest only runs them, so plain `python3 -m unittest` runs the same tests one at a time and another runner can replace pytest. Valid while every machine taking the checkout gets the latest stable Python soon after its release.
|
||||
|
||||
## chunk-pr: the chunks of a project merge one at a time on a machine, each finishing its plan items in its turn, and a pull request that waits for an approval leaves the queue while it waits
|
||||
|
||||
2026-11-15, lilleman's call of 2026-11-13 in item 374, which split item 361. Serves goals 1.5 and 1.4: with several chunks open, every chunk removed its item from `todo.md` and added a bullet to `CHANGELOG.md` in its branch, so each merge left the others a conflict, a gate rerun and often a review round. `chunk-pr merge --finish <ID>` now makes those edits in the chunk's turn, on top of every chunk merged before. The worker's choices, for what the call left open:
|
||||
|
||||
- **A merge of the default branch, where the call said rebase.** A rebase rewrites commits the pull request already shows. The forge then drops the approval and the review threads' places, and the round titles rule-hook counts on the branch get new commits. `chunk-pr sync` already merges, and the turn reuses it.
|
||||
- **The queue is a file in the git folder the checkout's worktrees share**, held with flock for the turn (`bin/chunk_pr/main.py` → `QUEUE`). Every chunk of the project on the machine finds it without a config or a key. Two machines don't share it: there the forge refuses the second merge, whose head lacks the first, and its next run merges the first in.
|
||||
- **The turn holds the queue through the checks**, so what merges is what the checks ran on. A project without forge checks waits the minute `chunk-pr --help` names.
|
||||
- **The wait for an approval is outside the turn.** The first turn pushes the finished branch, so the approver reads what merges. Once approved, the pull request takes a new turn. Where the default branch moved meanwhile, that turn merges it in, and a branch protection that dismisses approvals on a push asks the approver again.
|
||||
- **A reviewer's comment ends the wait, in place of the loop watching for one.** `chunk-pr merge` runs in the worker's own session, so its failure is what resumes the worker, which answers and runs it again. A comment that waits is a review thread nobody resolved whose last comment someone other than the pull request's author wrote: the worker answers as that author, so an answered thread waits for the reviewer again. A comment outside a thread doesn't end the wait, since bots write those too.
|
||||
- **A paired ruling runs again after a turn merged the default branch in**, on the last measured commit as before: `review: the comprehension check records …` says why the base stays. `chunk-pr merge` stops once to ask for it, and its next run merges whether or not a ruling was added, since no ruling blocks a merge (project principle 2).
|
||||
|
||||
Valid while a chunk's worker runs `chunk-pr merge` itself, and one machine runs a project's loops.
|
||||
|
||||
## chunks: a chunk takes every unblocked item of its release that fires the same review passes, whatever its purpose, and an item above R 5 ships alone
|
||||
|
||||
2026-10-22, lilleman, through todo item 217. Serves goal 1.4: each review has a fixed cost, so more items per chunk cost less per item. Across the 165 finished chunks loop-claude archived up to that day, a chunk took a median of 1.30M tokens with one item and 1.33M with two, and three in four chunks shipped one item. The old rule also asked one PR title to state what the items achieve together; lilleman dropped it, since unrelated items that fire the same passes cost one review.
|
||||
@@ -388,6 +402,8 @@ The base is the last measured commit: the default branch's newest merged change
|
||||
|
||||
2026-11-11, lilleman. Serves goal 1.1. Item 296 made `chunk-pr merge` refuse while a scoring run the plan calls is unrecorded on the branch, so a missing run can block a merge. No score or ruling does, and the titles say so: "no score blocks a merge".
|
||||
|
||||
2026-11-15, the worker's choice in item 374, which lilleman's call of 2026-11-13 left open. The call asked that a ruling never charge one chunk with another's change, by reading against the new base after a rebase. Only the release review runs a paired ruling, and it measures the whole release, so its base stays the last measured commit. What another chunk's merge changes is the head: a ruling recorded before the merge came in read a head that never merges. So `chunk-pr merge` stops where its turn merged the default branch into a branch that has recorded a comprehension check, and the worker runs the ruling again at the new head.
|
||||
|
||||
## review: the premises chunk's whole review is the human's approval
|
||||
|
||||
2026-09-20, lilleman. Serves goal 1.1. A reviewer's finding on that chunk could only be declined by citing the goals the chunk exists to write. Valid while every decline must name a goal or a technical principle.
|
||||
|
||||
@@ -2249,3 +2249,20 @@ Read most (opens and searches):
|
||||
- `bin/plan_store/stores.py` 2
|
||||
- `docs/decisions.md` 2
|
||||
- `CHANGELOG.md` 1
|
||||
|
||||
## Reading cost, chunk ba82c458ad98, finished 2026-11-15T13:51:17Z
|
||||
|
||||
120652 new input tokens before the first commit.
|
||||
|
||||
Read most (opens and searches):
|
||||
|
||||
- `docs/decisions.md` 10
|
||||
- `bin/loop_claude/test_black_box.py` 8
|
||||
- `bin/loop_claude/loop/usage.py` 5
|
||||
- `CHANGELOG.md` 3
|
||||
- `CLAUDE.md` 3
|
||||
- `bin/claude_code/session.py` 2
|
||||
- `bin/command_lines/shell_command.py` 2
|
||||
- `bin/loop_claude/loop/main.py` 2
|
||||
- `rules/todo-items.md` 2
|
||||
- `README.md` 1
|
||||
|
||||
@@ -153,7 +153,7 @@ The comprehension check records how hard the project is for its contributor to r
|
||||
- **Head.** The head holds `origin/<default branch>`, merged in at §4 step 1, so it differs from the default branch only by this branch's change.
|
||||
- **Seats.** Mid A and the inherited architect. Write what they read and their replies into a votes file in the chunk's review folder, in the shape `~/.claude/bin/larv-review --help` shows, and run `~/.claude/bin/larv-review record-ruling <votes file>`. On `Split:`, launch the maintainability senior and Junior A together, add their lines, and run it again.
|
||||
|
||||
**Scoring run**, when `~/.claude/bin/larv-review needs-scoring-run <the IDs of the items the chunk ships, if any>` prints `Scoring run due:`. Run `needs-scoring-run` before removing the chunk's items from `todo.md`. `chunk-pr merge` refuses until the branch's committed history records every run the plan calls, which `larv-review scoring-run-owed` counts at merge time from the merge base; an earlier due line is only a snapshot.
|
||||
**Scoring run**, when `~/.claude/bin/larv-review needs-scoring-run <the IDs of the items the chunk ships, if any>` prints `Scoring run due:`. `chunk-pr merge` refuses until the branch's committed history records every run the plan calls, which `larv-review scoring-run-owed` counts at merge time from the merge base; an earlier due line is only a snapshot.
|
||||
|
||||
- **Seats.** Junior A, Mid A, the maintainability senior and the inherited architect each score the project at the head from 1 to 10 overall and on four dimensions: Navigation, Locality, Shape and Self-sufficiency. Run `~/.claude/bin/larv-review prepare-scoring`, adding `--preloaded <text>` only where its default list of pre-loaded files is wrong. It makes the worktree the seats read and prints each seat's prompt file; launch each seat with its file's text as its prompt. Write their lines into a scores file and run `~/.claude/bin/larv-review record-scoring <scores file> <the same item IDs>`, which appends the run to the history and prints the four seats' means.
|
||||
- **Floor item.** Where `record-scoring` prints `Floor:`, a `Next:` line follows: file one floor item, or refresh the open one. A floor item is a plan item meant to bring every mean to the project's readability floor, which `record-scoring`'s `Floor:` line names. File it as one ambitious refactor, not touch-ups. It restructures the area behind the places `larv-review places` prints for this run, chosen where they bear on the lowest dimension, sized to bring every mean to that floor, and quotes those places. Its tagline opens with `Reach the comprehension floor:`, so its own chunk runs a scoring run; while a mean stays under the floor, that run's `Next:` line asks for the next floor item. Mark it `owner`, since the human asked that such a project always hold one, so no score deletes it. Put it in the earliest release the plan names after the one the chunk ships into, or else in the next version after that one that `~/.claude/rules/todo-items.md` allows, so the floor doesn't hold up any release. While one is open, refresh its places and aim from the newest run instead of filing another; the item the chunk ships doesn't count as open. Commit it with the run, as "Record" says.
|
||||
@@ -200,9 +200,14 @@ Launch prose-reviewer with what the diff touched and every section this review c
|
||||
## 5. Goal alignment, then merge
|
||||
|
||||
1. Read the finished PR against the goals file's goals and code health, unless that file voids it: does anything in it work against one? It breaks a maintain goal → do not merge; redesign the change or drop its item. It works against an achieve goal → do not merge; ask the human, stating the conflict.
|
||||
2. Run the comprehension check (§3) where it runs; it runs once. When `origin/<default branch>` moves after that, return to §4, and keep the ruling and scoring run already recorded.
|
||||
3. Run `~/.claude/bin/touch-predictions record <ID>...` in the worktree, naming the chunk's items: it records what they were predicted to touch beside what the branch touched, where the project's config names that record. A later pass through this step, after a return to §4, skips it, since the items have left the plan. Then remove the chunk's items from `todo.md` per `~/.claude/CLAUDE.md` → "Working loop" in the branch. Commit and push both; the commit re-enters no pass.
|
||||
4. Aligned and every pass done → **merge** with `~/.claude/bin/chunk-pr merge`, run in the background with its `timeout` set to 7200000 ms, since its wait can outlast the Bash tool's default. It waits for the pull request's checks to pass, and for a human's approval where the project's config sets `wait-for-approval` (`chunk-pr --help`), then takes the first merge method the repository allows on its forge. A repo whose `AGENTS.md` names another method merges that way with the forge's CLI instead, once the pull request's checks pass, `~/.claude/bin/larv-review scoring-run-owed` exits 0 and, where `~/.claude/bin/project-config wait-for-approval` prints `true`, GitHub reports the pull request approved. A repo withholds this in its `AGENTS.md` → leave the PR ready and unmerged, and say which line withheld it.
|
||||
2. Run the comprehension check (§3) where it runs; it runs once. When `origin/<default branch>` moves after that, return to §4, and keep the scoring run already recorded. A paired ruling read the head before the other chunk's merge came in, so run it again at the new head and record it.
|
||||
3. Run `~/.claude/bin/touch-predictions record <ID>...` in the worktree, naming the chunk's items: it records what they were predicted to touch beside what the branch touched, where the project's config names that record. A later pass through this step, after a return to §4, skips it. Commit and push it; the commit re-enters no pass. Leave the chunk's items in the plan, and write no changelog bullet in the branch: step 4 does both, so that `todo.md` and `CHANGELOG.md` never conflict between chunks. Revise any decision that cites an item now, since `todo-item finish` refuses while one does.
|
||||
4. Aligned and every pass done → **merge** with `~/.claude/bin/chunk-pr merge`, run in the background with its `timeout` set to 7200000 ms, since its wait can outlast the Bash tool's default. Give it one `--finish <ID>` per item the chunk ships, each with the arguments `~/.claude/CLAUDE.md` → "Working loop" asks of `todo-item finish`, as in `chunk-pr merge --finish 12 --changelog '<bullet>' --finish 13 --no-changelog`. The project's chunks merge one at a time. In its turn, `chunk-pr merge` merges `origin/<default branch>` into the branch, finishes those items, pushes, and waits for the pull request's checks to pass; then it takes the first merge method the repository allows on its forge. Where it stops, do what it asks and run it again with the same arguments:
|
||||
- **A merge conflict.** Resolve it, commit and push. Rerun only the passes whose triggers the resolution's own lines meet (§3), each in a round of its own.
|
||||
- **A paired ruling to run again**, as step 2 says.
|
||||
- **A reviewer's comment**, where the project's config sets `wait-for-approval` (`chunk-pr --help`) and the pull request waits for a human's approval. Answer it in its thread on the forge, and fix what it asks as a finding of the chunk. The wait doesn't hold the queue, so other chunks merge meanwhile.
|
||||
|
||||
A repo whose `AGENTS.md` names another method merges that way with the forge's CLI instead, after it finishes the chunk's items with `todo-item finish` in the branch, and once the pull request's checks pass, `~/.claude/bin/larv-review scoring-run-owed` exits 0 and, where `~/.claude/bin/project-config wait-for-approval` prints `true`, GitHub reports the pull request approved. A repo withholds this in its `AGENTS.md` → leave the PR ready and unmerged, and say which line withheld it.
|
||||
5. Merged → run `~/.claude/bin/chunk-pr clean` in the chunk's worktree, and put a failure it prints in the summary.
|
||||
6. Stop. The next chunk gets a fresh session.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user