Have chunk-pr merge wait for the required checks, and name sync, ready's title and wait-for in the docs
This commit is contained in:
@@ -66,7 +66,7 @@ The rules only reviewers apply, for quality, comments, READMEs and prose, live i
|
||||
- Run a project's language runtime, package manager, and task runner through its container/tooling setup, never directly on the host unless a decision puts them there. Example: `docker compose run --rm app <tool> …`.
|
||||
- Tear down test containers after a run.
|
||||
- Give every container you start a memory limit and a swap limit, as large as its work needs: `--memory 4g --memory-swap 4g` on `docker run`, or `mem_limit` and `memswap_limit` in a compose file, scripts included. rule-hook checks only the `docker run` and `docker create` in your Bash commands.
|
||||
- A heavy command loads the machine for minutes: a full gate, mutation tests, an e2e run, a `docker build`. Run each one under `~/.claude/bin/run-heavy`, as in `~/.claude/bin/run-heavy ./ci.sh`. run-heavy waits for one of the heavy slots that every session on the machine shares. It also caps each container the command makes at the slot's share of memory, where the container sets no limits; give a container that needs more its own. Run it in the background, since the wait can outlast the Bash tool's timeout.
|
||||
- A heavy command loads the machine for minutes: a full gate, mutation tests, an e2e run, a `docker build`. Run each one under `~/.claude/bin/run-heavy`, as in `~/.claude/bin/run-heavy ./ci.sh`. run-heavy waits for one of the heavy slots that every session on the machine shares. It also caps each container the command makes at the slot's share of memory, where the container sets no limits; give a container that needs more its own. Run it in the background, since the wait can outlast the Bash tool's timeout; `~/.claude/bin/wait-for <file> [<pattern>]` waits for a line in a log it writes.
|
||||
- Delegate a task to a subagent only when you need just its conclusion: a search or read across many files, or work independent enough to run in parallel. Keep edits, and whatever you must check line by line, in your own thread: you would read a delegated diff again to check it. Score the task's L as for a `todo.md` item; a task that changes no file, such as a search, is L 1. `<model>` below is the project's model id, such as `claude-opus-5-5`: the one loop-claude's prompt names as the project's, or else your own. Launch the subagent with the model and effort of the first case that fits:
|
||||
1. A reviewer, a comprehension seat or the security pass: those loop-claude's prompt gives it. Given none, pass no model or effort, so it runs on your model.
|
||||
2. An escalated task, below: the rung loop-claude's prompt names for escalation, or case 3's rung where the subagent files or scores `todo.md` items and that rung is higher.
|
||||
|
||||
@@ -97,7 +97,7 @@ It renames `## Unreleased` in `CHANGELOG.md` to the version and merges that thro
|
||||
|
||||
Install puts only `loop-claude` and `loop-inbox` 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|ready|merge|clean` opens a chunk's pull request as a draft, marks it ready and merges it, 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 the required 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-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.
|
||||
@@ -113,11 +113,13 @@ Install puts only `loop-claude` and `loop-inbox` on `PATH`; call the others by t
|
||||
- `review-replay <pass> <model>` replays a review pass's archived rounds from the projects run on the model, on the code each reviewed, and prints the lowest rung below the project's that, like each rung above it, finds every 🔴 and 🟡 the project's rung finds again; `review-replay --help` states the replay. With `--omit-claude-md` it tests instead whether the pass's reviewer may start without `CLAUDE.md`: it replays each round twice as archived and once without the instruction files, and prints each finding the last replay missed that both of the others found. Each replayed reviewer skips every permission prompt, stability-reviewer has Bash, and an archived prompt may name paths on the host.
|
||||
- `rule-hook [overrides]` blocks a tool call that breaks a rule a program can check, unless the call overrides the rule; `settings.json` → `hooks` runs it before each Agent, Bash, Edit, MultiEdit, Read, Skill and Write call, and `rule-hook --help` states the rules and the override.
|
||||
- `run-heavy <command>` runs a heavy command once it holds one of the machine's heavy slots, one per 4 CPUs, which every session shares; `run-heavy --help` states the slots, and the memory cap it gives a container that sets no limit.
|
||||
- `run-tests [<pytest args>...]` runs this repo's test suite, as Test says.
|
||||
- `score-outcomes [L E I S]` shows what each finished item's chunk measured beside the scores the item was guessed at, to score a new item by, and code health's two counter-signals per chunk, misread findings and later fixes; `score-outcomes --help` states the report.
|
||||
- `settings_filter.py` is git's clean filter for `settings.json`: it drops `"model"` and sorts the keys. `.gitattributes` sets the filter `settings` on `settings.json`, and Install's `git config` line makes this script that filter.
|
||||
- `statusline.py` renders Claude Code's status line; `settings.json` → `statusLine` runs it.
|
||||
- `subagent-rung [--plan] <model> <L>` prints the Agent tool's model and effort for a subagent's task, picked by its L from the project's model, and with `--plan` never below the project's rung; `subagent-rung --help` states the rule.
|
||||
- `todo-item add …` files an item in a project's `todo.md`, taking `Next ID` as the item's ID, and `todo-item finish <ID>` removes a finished item and adds the bullet passed with `--changelog` to `CHANGELOG.md`; both rank the file. `todo-item show <ID>` prints an item's row and detail. `todo-item --help` states the flags.
|
||||
- `wait-for <file> [<pattern>] [--timeout <seconds>]` waits until a file a background job writes holds a line matching the pattern, and prints it.
|
||||
|
||||
`bin/` is the import root: each launcher puts it on `sys.path`, so a module imports another by its path under `bin/`, such as `from claude_code.entries import parse_entry`. Each tool's package holds its tests. Beside the packages, `bin/`'s root holds only the launchers, the tools of one file with their tests, `test_env.py`, `failure.py` and `setup.cfg`. `failure.py`'s `Failure`, which modules across `bin/` return for a failed step, belongs to no single package. `branch_chunks/`, `claude_code/`, `command_lines/`, `git_cli/`, `loop_effects/`, `loop_state/`, `machine_load/`, `mattermost_dm/`, `model_routing/`, `records/`, `release_plan/`, `review_rules/`, `rung_replay/` and `transcript_archive/` serve more than one tool.
|
||||
|
||||
|
||||
+66
-13
@@ -3,7 +3,7 @@
|
||||
usage: chunk-pr open <title> [<body>]
|
||||
chunk-pr sync
|
||||
chunk-pr ready [<title>]
|
||||
chunk-pr merge --gate-passed
|
||||
chunk-pr merge
|
||||
chunk-pr clean
|
||||
|
||||
Run it in the chunk's worktree, on the chunk's branch. ready and merge act on the branch's open
|
||||
@@ -21,13 +21,16 @@ sync fetches origin and merges its default branch into the branch checked ou
|
||||
ready marks the pull request ready for review. On Gitea a draft is a pull request whose title
|
||||
starts with `WIP: `, so there it drops that prefix. Given <title>, one line, it sets that
|
||||
as the pull request's title first; where that fails, the pull request stays a draft.
|
||||
merge merges the pull request, and only while its head is still the commit checked out, so a
|
||||
push after the gate is never merged. It takes the first method the repository allows of:
|
||||
a merge commit, fast-forward only, a rebase followed by a merge commit, a rebase, a squash.
|
||||
GitHub offers only the merge commit, the rebase and the squash. --gate-passed says the
|
||||
merge gate passed on that commit; without it, chunk-pr refuses. It also refuses where
|
||||
`larv-review scoring-run-owed` exits 1, because the chunk owes a scoring run it has not
|
||||
recorded; no flag waives that.
|
||||
merge waits for the checks 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. It refuses where a required check fails. On Gitea it also refuses
|
||||
where one still runs after 9 minutes, so a foreground call of the Bash tool can hold the
|
||||
wait; run it again then. On GitHub, gh waits as long as the checks run.
|
||||
It takes the first merge method the repository allows of: a merge commit, fast-forward
|
||||
only, a rebase followed by a merge commit, a rebase, a squash. GitHub offers only the
|
||||
merge commit, the rebase and the squash. It also refuses where `larv-review
|
||||
scoring-run-owed` exits 1, because the chunk owes a scoring run it has not recorded; no
|
||||
flag waives that.
|
||||
clean acts once the forge reports the branch's pull request merged at the commit checked out,
|
||||
by any merge method. It fetches origin, fast-forwards the main checkout to origin's
|
||||
default branch, removes the chunk's worktree, then deletes the local branch; origin's
|
||||
@@ -39,10 +42,12 @@ 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 dataclasses
|
||||
import fnmatch
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import sys
|
||||
import time
|
||||
import typing
|
||||
|
||||
from failure import Failure
|
||||
@@ -51,7 +56,9 @@ from chunk_preflight.choices import forge_of
|
||||
from deploy_release.forge import gitea, merged_pull, open_pull, Run, runner
|
||||
|
||||
BIN = pathlib.Path(__file__).resolve().parents[1]
|
||||
USAGE = "usage: chunk-pr open <title> [<body>] | chunk-pr sync | chunk-pr ready [<title>] | chunk-pr merge --gate-passed | chunk-pr clean"
|
||||
POLL_SECONDS = 10
|
||||
CHECKS_TIMEOUT_SECONDS = 540
|
||||
USAGE = "usage: chunk-pr open <title> [<body>] | chunk-pr sync | chunk-pr ready [<title>] | chunk-pr merge | 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], ...]] = {
|
||||
@@ -81,10 +88,8 @@ def step(argv: list[str], run: Run) -> str | Failure:
|
||||
return synced(run)
|
||||
case ["ready", *title] if len(title) <= 1:
|
||||
return Failure("give a title of one line") if title and not one_line(title[0]) else marked_ready(run, title[0] if title else None)
|
||||
case ["merge", "--gate-passed"]:
|
||||
return merged(run)
|
||||
case ["merge"]:
|
||||
return Failure("merge only once the gate has passed, and say so with --gate-passed")
|
||||
return merged(run)
|
||||
case ["clean"]:
|
||||
return cleaned(run)
|
||||
return Failure(USAGE)
|
||||
@@ -211,7 +216,12 @@ 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) -> str | Failure:
|
||||
class Clock(typing.Protocol):
|
||||
def monotonic(self) -> float: ...
|
||||
def sleep(self, seconds: float) -> None: ...
|
||||
|
||||
|
||||
def merged(run: Run, clock: Clock = time) -> str | Failure:
|
||||
found = pull(run)
|
||||
if isinstance(found, Failure):
|
||||
return found
|
||||
@@ -222,6 +232,9 @@ def merged(run: Run) -> str | Failure:
|
||||
method = merge_method(forge, run)
|
||||
if isinstance(method, Failure):
|
||||
return method
|
||||
checked = checks_passed(forge, number, head, run, clock)
|
||||
if isinstance(checked, Failure):
|
||||
return checked
|
||||
if forge == "gh":
|
||||
done = run(["gh", "pr", "merge", number, method, "--match-head-commit", head])
|
||||
else:
|
||||
@@ -229,6 +242,46 @@ def merged(run: Run) -> str | Failure:
|
||||
return done if isinstance(done, Failure) else f"Merged pull request #{number} ({method.removeprefix('--')})."
|
||||
|
||||
|
||||
def checks_passed(forge: Forge, number: str, head: str, run: Run, clock: Clock) -> None | Failure:
|
||||
"""None once every check origin's default branch requires has passed at head, or a Failure where one failed or still runs at CHECKS_TIMEOUT_SECONDS."""
|
||||
if forge == "gh":
|
||||
watched = run(["gh", "pr", "checks", number, "--required", "--watch", "--interval", str(POLL_SECONDS)])
|
||||
# gh fails where the branch requires no checks; then nothing is to wait for.
|
||||
return None if not isinstance(watched, Failure) or "no required checks" in watched.reason else watched
|
||||
required = required_contexts(run)
|
||||
if isinstance(required, Failure) or not required:
|
||||
return required or None
|
||||
deadline = clock.monotonic() + CHECKS_TIMEOUT_SECONDS
|
||||
while True:
|
||||
combined = gitea(run, f"repos/{{owner}}/{{repo}}/commits/{head}/status")
|
||||
if isinstance(combined, Failure):
|
||||
return combined
|
||||
statuses = combined.get("statuses") or [] if isinstance(combined, dict) else []
|
||||
matching = {pattern: [status for status in statuses if fnmatch.fnmatchcase(str(status.get("context")), pattern)] for pattern in required}
|
||||
failed = next((status for found in matching.values() for status in found if status.get("status") in ("failure", "error")), None)
|
||||
if failed is not None:
|
||||
return Failure(f"the required check {failed.get('context')} failed at {head[:12]}: {failed.get('target_url')}")
|
||||
waiting = [pattern for pattern, found in matching.items() if not found or any(status.get("status") != "success" for status in found)]
|
||||
if not waiting:
|
||||
return None
|
||||
left = deadline - clock.monotonic()
|
||||
if left <= 0:
|
||||
return Failure(f"the required checks {', '.join(waiting)} still run at {head[:12]} after {CHECKS_TIMEOUT_SECONDS} s; run chunk-pr merge again")
|
||||
clock.sleep(min(POLL_SECONDS, left))
|
||||
|
||||
|
||||
def required_contexts(run: Run) -> list[str] | Failure:
|
||||
"""The status contexts, as Gitea's glob patterns, that the protection rule for origin's default branch requires; [] where none is required."""
|
||||
base = default_branch(run)
|
||||
if isinstance(base, Failure):
|
||||
return base
|
||||
rules = gitea(run, "repos/{owner}/{repo}/branch_protections")
|
||||
if isinstance(rules, Failure):
|
||||
return rules
|
||||
rule = next((rule for rule in rules if isinstance(rule, dict) and fnmatch.fnmatchcase(base, str(rule.get("rule_name") or rule.get("branch_name")))), None) if isinstance(rules, list) else None
|
||||
return list(rule.get("status_check_contexts") or []) if rule and rule.get("enable_status_check") else []
|
||||
|
||||
|
||||
def merge_method(forge: Forge, run: Run) -> str | Failure:
|
||||
"""The first of METHODS[forge] that the repository's settings allow."""
|
||||
if forge == "gh":
|
||||
|
||||
@@ -7,7 +7,7 @@ import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from chunk_pr.main import cleaned, step
|
||||
from chunk_pr.main import CHECKS_TIMEOUT_SECONDS, POLL_SECONDS, cleaned, merged, step
|
||||
from failure import Failure
|
||||
from test_env import isolated_env
|
||||
from deploy_release.forge import Run
|
||||
@@ -21,9 +21,25 @@ GH_LIST = ["gh", "pr", "list", "--head", "item-7", "--json", "number,headRefOid,
|
||||
TEA_LIST = ["tea", "api", "repos/{owner}/{repo}/pulls?state=open&limit=50"]
|
||||
GH_SETTINGS = ["gh", "repo", "view", "--json", "mergeCommitAllowed,rebaseMergeAllowed,squashMergeAllowed"]
|
||||
TEA_SETTINGS = ["tea", "api", "repos/{owner}/{repo}"]
|
||||
GH_CHECKS = ["gh", "pr", "checks", "12", "--required", "--watch", "--interval", "10"]
|
||||
TEA_PROTECTIONS = ["tea", "api", "repos/{owner}/{repo}/branch_protections"]
|
||||
TEA_STATUS = ["tea", "api", f"repos/{{owner}}/{{repo}}/commits/{HEAD}/status"]
|
||||
OWED = [str(pathlib.Path(__file__).resolve().parents[1] / "larv-review"), "scoring-run-owed"]
|
||||
|
||||
|
||||
class Clock:
|
||||
"""A fake clock whose sleep only advances its time."""
|
||||
|
||||
def __init__(self):
|
||||
self.now = 0.0
|
||||
|
||||
def monotonic(self) -> float:
|
||||
return self.now
|
||||
|
||||
def sleep(self, seconds: float):
|
||||
self.now += seconds
|
||||
|
||||
|
||||
class Checkout:
|
||||
"""A fake run in a checkout of branch item-7 at commit HEAD, cloned from the GitHub or Gitea origin it is given, with main as origin's default branch.
|
||||
|
||||
@@ -33,6 +49,7 @@ class Checkout:
|
||||
self.github = origin == GITHUB
|
||||
self.open = open
|
||||
self.allowed = allowed
|
||||
self.statuses: list[str] = []
|
||||
self.ran: list[list[str]] = []
|
||||
self.answers: dict[tuple[str, ...], str | Failure] = {
|
||||
("git", "remote", "get-url", "origin"): f"{origin}\n",
|
||||
@@ -53,13 +70,15 @@ class Checkout:
|
||||
return f"12\t{HEAD}\tfalse\n" if self.open else ""
|
||||
if command == TEA_LIST:
|
||||
return json.dumps([{"number": 12, "head": {"ref": "item-7", "label": "item-7", "sha": HEAD, "repo": {"full_name": "me/project"}}, "base": {"repo": {"full_name": "me/project"}}}] if self.open else [])
|
||||
if command == TEA_STATUS and self.statuses:
|
||||
return self.statuses.pop(0)
|
||||
if command in (GH_SETTINGS, TEA_SETTINGS):
|
||||
return json.dumps({setting: True for setting in self.allowed})
|
||||
return ""
|
||||
|
||||
def acted(self) -> list[list[str]]:
|
||||
"""What it ran beyond reading the checkout, the pull requests and the repository's settings."""
|
||||
reads = [GH_LIST, TEA_LIST, GH_SETTINGS, TEA_SETTINGS, OWED]
|
||||
reads = [GH_LIST, TEA_LIST, GH_SETTINGS, TEA_SETTINGS, OWED, GH_CHECKS, TEA_PROTECTIONS, TEA_STATUS]
|
||||
return [command for command in self.ran if tuple(command) not in self.answers and command not in reads]
|
||||
|
||||
|
||||
@@ -221,53 +240,103 @@ class Sync(unittest.TestCase):
|
||||
|
||||
|
||||
class Merge(unittest.TestCase):
|
||||
def test_without_the_gate_passed_it_refuses_before_anything_runs(self):
|
||||
def test_the_gate_passed_flag_it_no_longer_takes_is_refused_before_anything_runs(self):
|
||||
checkout = Checkout(GITHUB, open=True)
|
||||
self.assertIsInstance(step(["merge"], checkout), Failure)
|
||||
self.assertIsInstance(step(["merge", "--gate-passed"], checkout), Failure)
|
||||
self.assertEqual(checkout.ran, [])
|
||||
|
||||
def test_github_waits_for_the_required_checks_before_merging(self):
|
||||
checkout = Checkout(GITHUB, open=True)
|
||||
self.assertEqual(step(["merge"], checkout), "Merged pull request #12 (merge).")
|
||||
self.assertEqual(checkout.ran[-2:], [GH_CHECKS, ["gh", "pr", "merge", "12", "--merge", "--match-head-commit", HEAD]])
|
||||
|
||||
def test_a_failed_required_check_on_github_leaves_it_unmerged(self):
|
||||
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(), [])
|
||||
|
||||
def test_a_github_repository_requiring_no_checks_merges(self):
|
||||
checkout = Checkout(GITHUB, open=True)
|
||||
checkout.answers[tuple(GH_CHECKS)] = Failure("gh pr checks 12: no required checks reported on the 'item-7' branch")
|
||||
self.assertEqual(step(["merge"], checkout), "Merged pull request #12 (merge).")
|
||||
|
||||
def protected(self, *statuses: list[tuple[str, str]], rule: str = "main") -> Checkout:
|
||||
"""A Gitea Checkout whose rule for branch rule requires CI / tests, its status at HEAD reading each of statuses in turn."""
|
||||
checkout = Checkout(GITEA, open=True)
|
||||
checkout.answers[tuple(TEA_PROTECTIONS)] = json.dumps([{"rule_name": rule, "enable_status_check": True, "status_check_contexts": ["CI / tests*"]}])
|
||||
checkout.statuses = [json.dumps({"statuses": [{"context": context, "status": state, "target_url": "https://ci/1"} for context, state in read]}) for read in statuses]
|
||||
return checkout
|
||||
|
||||
def test_gitea_waits_until_every_required_check_passes_then_merges(self):
|
||||
checkout = self.protected([], [("CI / tests (pull_request)", "pending"), ("lint", "failure")], [("CI / tests (pull_request)", "success"), ("lint", "failure")])
|
||||
clock = Clock()
|
||||
self.assertEqual(merged(checkout, clock), "Merged pull request #12 (merge).")
|
||||
self.assertEqual(clock.now, 2 * POLL_SECONDS)
|
||||
self.assertEqual(checkout.ran.count(TEA_STATUS), 3)
|
||||
|
||||
def test_a_failed_required_check_on_gitea_leaves_it_unmerged_naming_it(self):
|
||||
checkout = self.protected([("CI / tests (pull_request)", "pending")], [("CI / tests (pull_request)", "failure")])
|
||||
self.assertEqual(merged(checkout, Clock()), Failure(f"the required check CI / tests (pull_request) failed at {HEAD}: https://ci/1"))
|
||||
self.assertEqual(checkout.acted(), [])
|
||||
|
||||
def test_gitea_checks_still_running_at_the_timeout_leave_it_unmerged(self):
|
||||
checkout = self.protected(*[[("CI / tests (pull_request)", "pending")]] * 1000)
|
||||
clock = Clock()
|
||||
failed = merged(checkout, clock)
|
||||
self.assertIsInstance(failed, Failure)
|
||||
self.assertIn("CI / tests*", failed.reason)
|
||||
self.assertIn("run chunk-pr merge again", failed.reason)
|
||||
self.assertLessEqual(clock.now, CHECKS_TIMEOUT_SECONDS)
|
||||
self.assertEqual(checkout.acted(), [])
|
||||
|
||||
def test_gitea_without_a_rule_for_the_default_branch_merges_without_reading_the_status(self):
|
||||
checkout = self.protected(rule="release/*")
|
||||
self.assertEqual(step(["merge"], checkout), "Merged pull request #12 (merge).")
|
||||
self.assertNotIn(TEA_STATUS, checkout.ran)
|
||||
|
||||
def test_a_scoring_run_the_chunk_owes_and_has_not_recorded_refuses_the_merge(self):
|
||||
for origin in (GITHUB, GITEA):
|
||||
with self.subTest(origin=origin):
|
||||
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", "--gate-passed"], checkout), 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(), [])
|
||||
|
||||
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", "--gate-passed"], checkout), "Merged pull request #12 (merge).")
|
||||
self.assertEqual(step(["merge"], checkout), "Merged pull request #12 (merge).")
|
||||
self.assertEqual(checkout.acted(), [["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", "--gate-passed"], checkout)
|
||||
step(["merge"], checkout)
|
||||
self.assertEqual(checkout.acted(), [["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", "--gate-passed"], checkout), "Merged pull request #12 (fast-forward-only).")
|
||||
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"]])
|
||||
|
||||
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", "--gate-passed"], checkout), Failure)
|
||||
self.assertIsInstance(step(["merge"], checkout), Failure)
|
||||
self.assertEqual(checkout.acted(), [])
|
||||
|
||||
def test_a_forge_failure_is_returned(self):
|
||||
checkout = Checkout(GITHUB, open=True)
|
||||
checkout.answers[("gh", "pr", "merge", "12", "--merge", "--match-head-commit", HEAD)] = Failure("gh pr merge: head moved")
|
||||
self.assertEqual(step(["merge", "--gate-passed"], checkout), Failure("gh pr merge: head moved"))
|
||||
self.assertEqual(step(["merge"], checkout), Failure("gh pr merge: head moved"))
|
||||
checkout = Checkout(GITHUB, open=True)
|
||||
checkout.answers[tuple(GH_SETTINGS)] = "not json"
|
||||
self.assertIsInstance(step(["merge", "--gate-passed"], checkout), Failure)
|
||||
self.assertIsInstance(step(["merge"], checkout), Failure)
|
||||
|
||||
def test_a_failed_settings_read_is_returned_unmerged(self):
|
||||
for origin, settings in ((GITHUB, GH_SETTINGS), (GITEA, TEA_SETTINGS)):
|
||||
with self.subTest(origin):
|
||||
checkout = Checkout(origin, open=True)
|
||||
checkout.answers[tuple(settings)] = Failure("settings: denied")
|
||||
self.assertEqual(step(["merge", "--gate-passed"], checkout), Failure("settings: denied"))
|
||||
self.assertEqual(step(["merge"], checkout), Failure("settings: denied"))
|
||||
self.assertEqual(checkout.acted(), [])
|
||||
|
||||
|
||||
|
||||
@@ -186,20 +186,19 @@ Launch prose-reviewer with what the diff touched and every section this review c
|
||||
|
||||
## 4. Gate
|
||||
|
||||
1. Merge `origin/<default branch>` into this branch unless the head already holds it.
|
||||
2. Run `~/.claude/bin/rank_todo.py --check todo.md`; a failure is a finding.
|
||||
3. Run the project's test suite locally unless a run at the head, §2's or a stability round's, left it verified green.
|
||||
4. Watch the forge's checks until every one passes. A red check is a finding.
|
||||
5. No CI configured → the gate is local tests only; note it in the summary.
|
||||
6. Everything green → mark the PR ready with `~/.claude/bin/chunk-pr ready`.
|
||||
7. **External auto-reviewer**, when the repo has one — its config file (`.coderabbit.yaml` and the like), or its comments on earlier PRs; none → skip it, say so. Marking the PR ready is what summons it. Wait up to **10 minutes** for its first review, checking about once a minute; nothing by then → note it in the summary and carry on, never waiting twice. Its rounds, §3 → "Round cap". Once it has reviewed, each later return here before its cap, after a fix re-entered per §3, waits up to **5 minutes** for its re-review of the new commit.
|
||||
1. Run `~/.claude/bin/chunk-pr sync`: it merges `origin/<default branch>` into this branch unless the head already holds it, then runs `rank_todo.py --check` on `todo.md`. A rank failure is a finding.
|
||||
2. Run the project's test suite locally unless a run at the head, §2's or a stability round's, left it verified green.
|
||||
3. The forge's checks: `chunk-pr merge` waits for those the default branch requires (§5 step 4). A red check is a finding.
|
||||
4. No CI configured → the gate is local tests only; note it in the summary.
|
||||
5. Everything green → mark the PR ready with `~/.claude/bin/chunk-pr ready '<final title>'`, which sets the title as it marks the PR ready.
|
||||
6. **External auto-reviewer**, when the repo has one — its config file (`.coderabbit.yaml` and the like), or its comments on earlier PRs; none → skip it, say so. Marking the PR ready is what summons it. Wait up to **10 minutes** for its first review, checking about once a minute; nothing by then → note it in the summary and carry on, never waiting twice. Its rounds, §3 → "Round cap". Once it has reviewed, each later return here before its cap, after a fix re-entered per §3, waits up to **5 minutes** for its re-review of the new commit.
|
||||
|
||||
## 5. Goal alignment, then merge
|
||||
|
||||
1. Read the finished PR against the README goals and code health, unless the README 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. Remove the chunk's items from `todo.md` per `~/.claude/CLAUDE.md` → "Working loop" in the branch, commit and push that, and wait for the forge's checks (§4 step 4); the commit re-enters no pass.
|
||||
4. Aligned, every pass done and everything green → **merge** with `~/.claude/bin/chunk-pr merge --gate-passed`, which 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, after `~/.claude/bin/larv-review scoring-run-owed` exits 0. A repo withholds this in its `AGENTS.md` → leave the PR ready and unmerged, and say which line withheld it.
|
||||
3. Remove the chunk's items from `todo.md` per `~/.claude/CLAUDE.md` → "Working loop" in the branch, commit and push that; the commit re-enters no pass.
|
||||
4. Aligned, every pass done and everything green → **merge** with `~/.claude/bin/chunk-pr merge`, which waits for the checks the default branch requires, 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, after `~/.claude/bin/larv-review scoring-run-owed` exits 0. 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