From 80de753b9ebb00a95d7d9b8ef292d457691a7365 Mon Sep 17 00:00:00 2001 From: Lilleman Date: Tue, 24 Nov 2026 14:05:11 +0100 Subject: [PATCH 01/13] File item 536: cut a patch release with deploy-release --cut-patch --- todo.md | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/todo.md b/todo.md index dad74be6..d6ff97a4 100644 --- a/todo.md +++ b/todo.md @@ -6,13 +6,14 @@ `Bar = 0.1` -`Next ID = 536` +`Next ID = 537` ## Items | ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score | |---|---|---|---|---|---|---|---|---|---|---|---| | 531 | 0.16.0 | | | **Bench the shipped features of a branch that landed by fast-forward: take as the feature the commits from the one after the item finished before it, up to the commit that took its item out of the plan.** | 2 | 2 | 1 | 3 | 3 | 1.1 by 3 | 1.1 | +| 536 | 0.16.0 | | owner | **Cut a patch release with `deploy-release --cut-patch `: the newest tag plus only the commits named, tested with `ci.sh`, tagged, merged back into main and deployed.** | 3 | 2 | 2 | 5 | 5 | 1.5 by 3 | 0.6 | | 524 | 0.16.0 | | owner | **Write fejkdata's first six bench features, each a spec, acceptance tests in Go and a reference patch that builds it, in the `bench-tasks` folder its config names.** | 3 | 2 | 1 | 4 | 6 | 1.1 by 3 | 0.5 | | 532 | 0.16.0 | | | **Leave out of a `task-bench` fix a change Haiku makes to a Rust test that stands in the file of the code it tests.** | 2 | 2 | 1 | 3 | 3 | 1.1 by 1 | 0.4 | | 527 | 0.16.0 | | owner | **Plant bugs for `task-bench` in TypeScript, from the mutants Stryker kills.** | 3 | 2 | 1 | 4 | 4 | 1.1 by 1 | 0.3 | @@ -123,6 +124,27 @@ Touches: - `bin/task_bench/main.py`: `(module)` (small) - `README.md`: `## Tools` (small) +### 536. Cut a patch release with `deploy-release --cut-patch `: the newest tag plus only the commits named, tested with `ci.sh`, tagged, merged back into main and deployed. + +Today a fix that must ship before `main`'s other unreleased work is cut by hand, as 0.15.1 was: branch off the newest tag, apply only the fix's code, write the changelog section, commit `Cut release `, tag and push, then merge the tag back into `main` with `-s ours` through a pull request, so the tag is an ancestor of `main`, and run a bare `deploy-release`. `deploy-release --cut` can't, since it cuts all of `main`. + +`deploy-release --cut-patch []`, run in the development clone, does those steps. A reader panel picked the spelling over `--cut --patch` and `--hotfix`: one flag that names the action and can't be read as a plain `--cut`. + +- **Version:** the newest tag's next patch, such as 0.15.2 after v0.15.1. The plan must name that release, and it must hold no item, as `--cut` checks. A patch skips the release review: it holds only fixes, and the review is of the whole project. +- **Commits:** one revision as `git log` reads it, such as `794ce37..1aa2367`, which follows git's `..` and leaves out the first commit, or one commit. Each must be on `origin/main` and not on the tag. Merge commits are skipped. +- **Patch:** in a worktree of its own, at the tag, it applies each commit's changes except to `todo.md`, `CHANGELOG.md` and the records every chunk writes. The changelog section is the bullets the commits add under `## Unreleased`. It commits `Cut release `, runs `ci.sh` on it, and stops where that fails. Then it tags and pushes the tag. +- **Merge-back:** a branch `release-` off `origin/main` merges the tag with `-s ours` and moves those bullets under `## `, and goes through a pull request as `--cut`'s branch does. +- **Rerun:** a step an earlier run finished is skipped: a tag on origin, a tag `main` holds. +- **Plain `--cut`** refuses a patch release and names `--cut-patch`, since it would ship all of `main` under a patch number. + +Touches: +- `bin/deploy_release/main.py`: `main` +- `bin/deploy_release/cut.py`: `cut`, `ready_release`, `land`, `push_cut_commit` +- `bin/deploy_release/patch.py` +- `bin/deploy_release/release_pull.py`: `create_pull` (small) +- `bin/deploy_release/test_deploy_release.py`: `Cut` +- `README.md`: `## Release`, `## Tools` (small) + ### 524. Write fejkdata's first six bench features, each a spec, acceptance tests in Go and a reference patch that builds it, in the `bench-tasks` folder its config names. The second part of item 504, which says what a bench feature is and when a run counts. A stronger model than the project's writes the six, once. Each breaks one of fejkdata's goals while it would suit another audience: -- 2.52.0 From 9c2587b5cab8e90d8e2137d453e33ce68528d128 Mon Sep 17 00:00:00 2001 From: Lilleman Date: Tue, 24 Nov 2026 14:09:56 +0100 Subject: [PATCH 02/13] Cut a patch release of only the commits named with deploy-release --cut-patch --- README.md | 10 +- bin/deploy_release/cut.py | 41 +++-- bin/deploy_release/main.py | 39 ++++- bin/deploy_release/patch.py | 192 ++++++++++++++++++++++ bin/deploy_release/release_pull.py | 6 +- bin/deploy_release/test_deploy_release.py | 125 +++++++++++++- 6 files changed, 389 insertions(+), 24 deletions(-) create mode 100644 bin/deploy_release/patch.py diff --git a/README.md b/README.md index 2124de54..c3ecb654 100644 --- a/README.md +++ b/README.md @@ -198,6 +198,14 @@ bin/deploy-release --cut It renames `## Unreleased` in `CHANGELOG.md` to the version and merges that through a pull request, since nobody can push to `main`. Then it tags the merged commit `v`, pushes the tag, and moves this machine's `~/.claude` to it. Where a step fails it stops with the reason, and a rerun continues where it stopped. `deploy-release --help` lists the steps. Each other machine takes the release with Update. +A fix that must ship before `main`'s other unreleased work goes out as a patch release, such as 0.15.2 after v0.15.1. File its item under that release, merge its chunk, then cut it with the commits the chunk merged, as a range or one commit: + +```sh +bin/deploy-release --cut-patch 794ce37..1aa2367 +``` + +It applies only those commits on the newest tag, tests them with `ci.sh`, tags and pushes the release, then merges the tag back into `main` through a pull request and moves `~/.claude` to it. A patch skips the release review. `deploy-release --help` lists the steps. + ## Tools 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`. The tools are listed in alphabetical order, and the packages under `bin/` follow under their own heading. @@ -206,7 +214,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a - `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 [] [--calls ]` 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 ` saves each call as a JSON line; `command-patterns --help` states the columns and the line's keys. - `compress-archives` gzips each transcript in loop-claude's archive and each file in the review folders 30 days after it last changed, keeping all of them; Install's crontab line runs it daily. -- `deploy-release [--cut] []` 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. +- `deploy-release [--cut | --cut-patch ] []` 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, and with `--cut-patch`, a patch release of only the commits named, as Release says. - `do-epic ` runs the chunks of one Jira epic whose items span repos, or have none, each in its own window of the tmux session `epic-`, on the same cycle, judge and interrupt as loop-claude. The epic's description is its record: goals, audience, scoring and decisions. Before it starts chunks, do-epic plans each open issue that no label places yet, as "Set up a project" says. It files a sub-task per repo where the issue changes several repos. Otherwise it labels the issue with where it is worked, and asks you where that is unclear. It plans no issue your team filed a sub-task under: those sub-tasks run instead, each under a label of its own, and your team closes the issue. Then, where two or more issues may start, it scores each of them that holds no scores, and moves the issues that do-epic itself filed into order of score on the board. An open issue runs once a label names its repo or marks it as Claude's, in order of score, as many at once as a line such as `**Max parallel chunks:** 2` in the epic's description allows, 1 without it, and as each repo's `parallel-chunks` allows. A chunk whose pull request waits on a gate parks. An open task of yours that blocks another issue gets a window that DMs you once and reads the epic every minute; once you close the task, the issues it blocked may start. `do-epic --dry-run` prints what `do-epic ` would write to Jira and which chunks it would start, and does neither; run it before the first real run on a team's epic. `--help` lists what it prints and leaves out. do-epic closes the epic only once you confirm every goal. Install → "Set up a project" says how to set it up; `do-epic --help` states the flags and the contract. - `do-epic-e2e` runs `do-epic` against a sandbox epic on a real Jira site, as Test says. - `judge-replay [--offline]` replays loop-claude's judge on archived verdicts of the projects run on the model. It prints what each rung a review climbs to misses, and the lowest rung below those that returns every verdict, as each candidate above it does. With `--offline` it doesn't call a judge: it counts what a "?" rule, a decision table and a classifier trained on the archive decide of each verdict's kind from the worker's final message, and how many interrupts each misses. `judge-replay --help` states both replays. diff --git a/bin/deploy_release/cut.py b/bin/deploy_release/cut.py index 9245079b..04330f08 100644 --- a/bin/deploy_release/cut.py +++ b/bin/deploy_release/cut.py @@ -16,12 +16,15 @@ from failure import Failure from plan_store.todo_md import FilePlan from record_store.stores import FileStore from forge.commands import forge_of, runner -from plan.release import newest_tag, Release, UNRELEASED_HEADING, version +from plan.release import newest_tag, Release, tagged, UNRELEASED_HEADING, version from forge import pulls from deploy_release import release_pull from project_config import templates +CUT_BODY = "Rename ## Unreleased in CHANGELOG.md to the version." + + def cut(clone: str, checkout: str, sleep: typing.Callable[[float], None]) -> str | Failure: """What the cut did, as the tool prints it; a Failure with git's, the forge's or the tool's reason where a step stopped.""" if isinstance(same := same_origin(clone, checkout), Failure): @@ -37,10 +40,13 @@ def cut(clone: str, checkout: str, sleep: typing.Callable[[float], None]) -> str if isinstance(release, Failure): return release named = version(release) - title, tag = f"Cut release {named}", f"v{named}" + if isinstance(patched := patch_refusal(clone, ref, release), Failure): + return patched + title, tag, branch = f"Cut release {named}", f"v{named}", f"release-{named}" merged = commit_titled(title, ref, clone) if merged is None: - landed = land(clone, ref, named, title, sleep) + build = lambda replacing: push_cut_commit(clone, ref, branch, named, title, replacing) + landed = land(clone, ref, branch, title, CUT_BODY, build, sleep) if isinstance(landed, Failure): return landed if isinstance(fetched := git("fetch", "--quiet", "origin", cwd=clone), Failure): @@ -58,13 +64,24 @@ def cut(clone: str, checkout: str, sleep: typing.Callable[[float], None]) -> str git("tag", "--delete", tag, cwd=clone) return pushed said(f"pushed the tag {tag}") - delete_release_branch(clone, f"release-{named}") + delete_release_branch(clone, branch) moved = deploy(checkout) if isinstance(moved, Failure): return Failure(f"cut and pushed {tag}, but moving {checkout} stopped: {moved.reason}. Fix that, then run a bare deploy-release.") return f"{moved}\n\nDone: {tag} is cut and pushed, and {checkout} is on it." +def patch_refusal(clone: str, ref: str, release: Release) -> Failure | None: + """A Failure where release is a patch of the newest tag ref holds: a cut of all of ref would ship its other work under a patch number.""" + tag = newest_tag(clone, merged_into=ref) + if isinstance(tag, Failure): + return tag + cut_release = tagged(tag) + if cut_release is not None and release[:2] == cut_release[:2]: + return Failure(f"{version(release)} is a patch of {tag}: cut it with --cut-patch , so it holds only the fix and not all of {ref}") + return None + + def said(step: str) -> None: """Say on stderr that step finished, so the human sees how far the cut got before the changelog fills the screen.""" print(f"deploy-release: {step}", file=sys.stderr) @@ -116,8 +133,8 @@ def clone_plan(clone: str) -> FilePlan: return FilePlan(pathlib.Path(clone, "todo.md"), "todo.md", goals, decisions, history, DEFAULT_FLOOR) -def ready_release(clone: str, ref: str) -> Release | Failure: - """The next release, as chunk-preflight works it out, where it is ready to cut: it holds no item in todo.md, its release review has landed and changes are unreleased.""" +def ready_release(clone: str, ref: str, review: bool = True) -> Release | Failure: + """The next release, as chunk-preflight works it out, where it is ready to cut: it holds no item in todo.md, its release review has landed, unless review is False, and changes are unreleased.""" # No project's config names the clone, so its changelog is read at the fixed path, on ref like the plan, and its titles as they stand. plan = default_plan(clone, ref, clone_plan(clone), FileStore(pathlib.Path(clone, "CHANGELOG.md"), "CHANGELOG.md"), templates.BARE) if isinstance(plan.plan, Failure): @@ -129,6 +146,8 @@ def ready_release(clone: str, ref: str) -> Release | Failure: return Failure("todo.md names no release after the last one cut") case Next(release=release) if release is not None: return Failure(f"release {version(release)} still holds items in todo.md") + case ReviewDue(release=release) if not review and release is not None: + return release case ReviewDue(release=release): return Failure(f"the release review of {version(release) if release else 'the next release'} hasn't landed") case Unplanned(): @@ -150,12 +169,12 @@ def commit_titled(title: str, ref: str, clone: str) -> str | None | Failure: return next((line.split(" ", 1)[0] for line in log.splitlines() if line.split(" ", 1)[1:] == [title]), None) -def land(clone: str, ref: str, named: str, title: str, sleep: typing.Callable[[float], None]) -> Failure | None: - """Push the branch release- with the cut commit and open its pull request, where an earlier run hasn't; then wait for its checks and merge it.""" +def land(clone: str, ref: str, branch: str, title: str, body: str, build: typing.Callable[[str | None], Failure | None], sleep: typing.Callable[[float], None]) -> Failure | None: + """Push branch with build and open its pull request, titled title with body, where an earlier run hasn't; then wait for its checks and merge it. build pushes the branch's commit on ref: a new branch, or in place of the commit it names, origin's branch's head.""" url = git("config", "--get", "remote.origin.url", cwd=clone) if isinstance(url, Failure): return url - on, run, branch, base = forge_of(url), runner(clone), f"release-{named}", ref.removeprefix("origin/") + on, run, base = forge_of(url), runner(clone), ref.removeprefix("origin/") head = branch_head(branch, clone) if isinstance(head, Failure): return head @@ -164,7 +183,7 @@ def land(clone: str, ref: str, named: str, title: str, sleep: typing.Callable[[f return behind if head is None or behind: # Where main moved on, such as to fix a failed check, the branch could no longer merge fast-forward, so it is rebuilt on main. - if isinstance(pushed := push_cut_commit(clone, ref, branch, named, title, head), Failure): + if isinstance(pushed := build(head), Failure): return pushed said(f"pushed the branch {branch}") head = branch_head(branch, clone) or Failure(f"pushed {branch}, but origin holds no such branch") @@ -172,7 +191,7 @@ def land(clone: str, ref: str, named: str, title: str, sleep: typing.Callable[[f return head number = pulls.open_pull(on, branch, head, run) if number is None: - if isinstance(created := release_pull.create_pull(on, branch, base, title, run), Failure): + if isinstance(created := release_pull.create_pull(on, branch, base, title, body, run), Failure): return created number = pulls.open_pull(on, branch, head, run) or Failure(f"opened a pull request for {branch}, but the forge lists none from origin at {head[:12]}") if isinstance(number, str): diff --git a/bin/deploy_release/main.py b/bin/deploy_release/main.py index c9a827e5..ec856427 100644 --- a/bin/deploy_release/main.py +++ b/bin/deploy_release/main.py @@ -1,6 +1,6 @@ -"""Move the checkout Claude Code reads its configuration from to this repo's newest release; with --cut, first cut the next release. +"""Move the checkout Claude Code reads its configuration from to this repo's newest release; with --cut, first cut the next release, and with --cut-patch, a patch release of only the commits named. -usage: deploy-release [--cut] [] +usage: deploy-release [--cut | --cut-patch ] [] defaults to ~/.claude. The tool fetches origin's tags and checks out the newest v* tag, detached, so the checkout holds only what a release holds. Development happens in another clone, @@ -34,7 +34,25 @@ It says on stderr as each step finishes, and ends stdout, after the changelog, w Where a step fails it stops, exit 1, with git's or the forge's reason, and leaves the pull request and the branch as they are. A rerun continues: it takes the branch's open pull request and a cut commit already merged, and drops a cut tag an earlier run made but never pushed. Once the tag is pushed, the release is cut: where only the -move stopped, fix what it names and run a bare deploy-release. +move stopped, fix what it names and run a bare deploy-release. --cut refuses a release that is a patch of the newest tag, +such as 0.15.2 after v0.15.1, since it would ship all of main: cut that with --cut-patch. + +--cut-patch runs in the development clone too, for a fix that must ship before main's other unreleased work. It +cuts the newest tag's next patch release, such as 0.15.2 after v0.15.1, holding only on top of the tag. +is one revision as git log reads it: a range such as 794ce37..1aa2367, which leaves out 794ce37 as git's `..` does, or one +commit. Each must be on origin's main and not in the tag; merge commits are left out. Name the commit that finished the +fix's item too: its entries under ## Unreleased in CHANGELOG.md become the release's. todo.md must name the release and file +no item under it; a patch skips the release review. It refuses without changing anything where any of that doesn't hold. +1. In a worktree of its own at the tag, it applies each commit's changes, except to todo.md, CHANGELOG.md and the records + every chunk appends to, heads CHANGELOG.md with the release's section, and commits that titled `Cut release `. + Where a commit doesn't apply, it stops and names it: cut that patch by hand. +2. It runs ci.sh on that commit, and stops where it fails, before anything is tagged. +3. It tags the commit v, annotated `Cut release `, and pushes only the tag. +4. On a fresh origin/main it merges the tag keeping main's files, moves the release's entries from ## Unreleased to a + ## section, commits that titled `Merge release into main`, and lands it through the branch + release- and a pull request as --cut does, so the tag is in main's history. +5. It moves to the tag as above, and ends stdout as --cut does. +A rerun skips a tag origin holds already and a merge main holds already. """ import os import pathlib @@ -43,6 +61,7 @@ import time from deploy_release.cut import cut from deploy_release.deploy import deploy +from deploy_release.patch import cut_patch from failure import Failure @@ -50,13 +69,17 @@ def main(argv: list[str]) -> int: if argv[:1] in (["-h"], ["--help"]): print(__doc__.strip()) return 0 - cutting = argv[:1] == ["--cut"] - rest = argv[1:] if cutting else argv - if len(rest) > 1 or rest[:1] and rest[0].startswith("-"): - print("deploy-release: usage: deploy-release [--cut] []", file=sys.stderr) + cutting, patching = argv[:1] == ["--cut"], argv[:1] == ["--cut-patch"] + commits = argv[1] if patching and len(argv) > 1 else None + rest = argv[2:] if patching else argv[1:] if cutting else argv + if len(rest) > 1 or rest[:1] and rest[0].startswith("-") or patching and (commits is None or commits.startswith("-")): + print("deploy-release: usage: deploy-release [--cut | --cut-patch ] []", file=sys.stderr) return 1 checkout = rest[0] if rest else str(pathlib.Path.home() / ".claude") - moved = cut(os.getcwd(), checkout, time.sleep) if cutting else deploy(checkout) + if commits is not None: + moved = cut_patch(os.getcwd(), checkout, commits, time.sleep) + else: + moved = cut(os.getcwd(), checkout, time.sleep) if cutting else deploy(checkout) if isinstance(moved, Failure): print(f"deploy-release: {moved.reason}", file=sys.stderr) return 1 diff --git a/bin/deploy_release/patch.py b/bin/deploy_release/patch.py new file mode 100644 index 00000000..83972eba --- /dev/null +++ b/bin/deploy_release/patch.py @@ -0,0 +1,192 @@ +"""`deploy-release --cut-patch `: cut the newest tag's next patch release holding only the commits named, test it with ci.sh, tag it, merge the tag back into main through a pull request, then move ~/.claude to it. + +Each step first checks whether an earlier run did it, so a rerun continues where the last run stopped. +""" +import pathlib +import re +import shutil +import subprocess +import tempfile +import typing + +from deploy_release.cut import delete_release_branch, drop_unpushed_cut_tags, land, ready_release, said, same_origin +from deploy_release.deploy import deploy +from failure import Failure +from git_cli.git_repo import default_ref, git +from plan.release import newest_tag, Release, tagged, UNRELEASED_TITLE, version +from text_files.markdown_text import section + +# The files a patch leaves as the tag holds them: the plan, the changelog the cut writes itself, and the records every chunk appends to, which seldom apply on an older tag. +LEFT_AS_TAGGED = ("todo.md", "CHANGELOG.md", "docs/reading-cost.md", "docs/comprehension-history.md") +MERGE_BACK_BODY = "Merge the patch release's tag into main, keeping main's files, and list its changelog entries under its version." + + +def cut_patch(clone: str, checkout: str, commits: str, sleep: typing.Callable[[float], None]) -> str | Failure: + """What the patch cut did, as the tool prints it; a Failure with git's, the forge's, ci.sh's or the tool's reason where a step stopped. commits is one revision as git log reads it, or one commit.""" + if isinstance(same := same_origin(clone, checkout), Failure): + return same + if isinstance(fetched := git("fetch", "--quiet", "--tags", "origin", cwd=clone), Failure): + return fetched + if isinstance(dropped := drop_unpushed_cut_tags(clone), Failure): + return dropped + ref = default_ref(cwd=clone) + if isinstance(ref, Failure): + return ref + base = newest_tag(clone, merged_into=ref) + if isinstance(base, Failure): + return base + cut_release = tagged(base) + if base is None or cut_release is None: + return Failure(f"{ref} holds no v* tag to cut a patch of") + named = version((cut_release[0], cut_release[1], cut_release[2] + 1)) + # A patch holds only fixes, and the release review reads the whole project, so a patch is cut without one. + release = ready_release(clone, ref, review=False) + if isinstance(release, Failure): + return release + if version(release) != named: + return Failure(f"the next release in todo.md is {version(release)}, not {named}, the patch of {base}: file the fix under {named}") + picked = patch_commits(clone, ref, base, commits) + if isinstance(picked, Failure): + return picked + entries = changelog_entries(clone, ref, picked) + if isinstance(entries, Failure): + return entries + title, tag = f"Cut release {named}", f"v{named}" + pushed = git("ls-remote", "--tags", "--refs", "origin", f"refs/tags/{tag}", cwd=clone) + if isinstance(pushed, Failure): + return pushed + if not pushed.strip(): + if isinstance(made := tag_patch(clone, base, picked, entries, named, title), Failure): + return made + if isinstance(git("merge-base", "--is-ancestor", tag, ref, cwd=clone), Failure): + branch = f"release-{named}" + build = lambda replacing: push_merge_back(clone, ref, branch, tag, named, entries, replacing) + if isinstance(landed := land(clone, ref, branch, f"Merge release {named} into main", MERGE_BACK_BODY, build, sleep), Failure): + return landed + delete_release_branch(clone, branch) + moved = deploy(checkout) + if isinstance(moved, Failure): + return Failure(f"cut and pushed {tag}, but moving {checkout} stopped: {moved.reason}. Fix that, then run a bare deploy-release.") + return f"{moved}\n\nDone: {tag} is cut and pushed, and {checkout} is on it." + + +def patch_commits(clone: str, ref: str, base: str, commits: str) -> list[str] | Failure: + """The commits commits names, oldest first, merge commits left out; a Failure where one is missing from ref or the tag base already holds it.""" + listed = git("rev-list", "--reverse", "--no-merges", commits if ".." in commits else f"{commits}^!", "--", cwd=clone) + if isinstance(listed, Failure): + return listed + picked = listed.split() + if not picked: + return Failure(f"{commits} names no commit but merges") + for commit in picked: + if isinstance(git("merge-base", "--is-ancestor", commit, ref, cwd=clone), Failure): + return Failure(f"{commit[:12]} isn't on {ref}: merge it there first") + if not isinstance(git("merge-base", "--is-ancestor", commit, base, cwd=clone), Failure): + return Failure(f"{commit[:12]} is in {base} already") + return picked + + +def changelog_entries(clone: str, ref: str, commits: list[str]) -> list[str] | Failure: + """The entries under ref's ## Unreleased in CHANGELOG.md that commits added, in the order ref lists them; a Failure where they added none.""" + added: set[str] = set() + for commit in commits: + diff = git("diff", f"{commit}^", commit, "--", "CHANGELOG.md", cwd=clone) + if isinstance(diff, Failure): + return diff + added |= {line[1:] for line in diff.splitlines() if line.startswith("+- ")} + changelog = git("show", f"{ref}:CHANGELOG.md", cwd=clone) + if isinstance(changelog, Failure): + return changelog + entries = [line for line in section(changelog, UNRELEASED_TITLE) or [] if line in added] + return entries or Failure(f"the commits add no entry under ## Unreleased in CHANGELOG.md on {ref}: name the commit that finished the fix's item too") + + +def tag_patch(clone: str, base: str, commits: list[str], entries: list[str], named: str, title: str) -> Failure | None: + """In a worktree at the tag base, apply commits but for LEFT_AS_TAGGED, head CHANGELOG.md with entries under ## named, commit that titled title, test it with ci.sh, then tag it v and push the tag.""" + tag = f"v{named}" + worktree = pathlib.Path(tempfile.mkdtemp(prefix="deploy-release-")) / "patch" + try: + if isinstance(added := git("worktree", "add", "--quiet", "--detach", str(worktree), base, cwd=clone), Failure): + return added + for commit in commits: + if isinstance(applied := apply_commit(clone, worktree, commit, base), Failure): + return applied + changelog = worktree / "CHANGELOG.md" + text = changelog.read_text() if changelog.exists() else "# Changelog\n" + section_text = f"## {named}\n\n" + "\n".join(entries) + "\n\n" + headed, count = re.subn(r"^## ", lambda _: section_text + "## ", text, count=1, flags=re.M) + changelog.write_text(headed if count else text.rstrip("\n") + "\n\n" + section_text.rstrip("\n") + "\n") + if isinstance(committed := git("commit", "--quiet", "--all", "--message", title, cwd=str(worktree)), Failure): + return committed + said(f"applied {len(commits)} commit(s) on {base}; testing them with ci.sh") + if isinstance(tested := run_ci(worktree), Failure): + return tested + said("ci.sh passed") + if isinstance(made := git("tag", "--annotate", "--message", title, tag, "HEAD", cwd=str(worktree)), Failure): + return made + if isinstance(pushed := git("push", "--quiet", "origin", f"refs/tags/{tag}", cwd=clone), Failure): + # Until a rerun, chunk-preflight would read a tag only the clone holds as cut. + git("tag", "--delete", tag, cwd=clone) + return pushed + said(f"pushed the tag {tag}") + return None + finally: + git("worktree", "remove", "--force", str(worktree), cwd=clone) + shutil.rmtree(worktree.parent, ignore_errors=True) + + +def apply_commit(clone: str, worktree: pathlib.Path, commit: str, base: str) -> Failure | None: + """Apply commit's change, but for LEFT_AS_TAGGED, to worktree's index and files, merging three ways where the tag base's files differ from commit's parent.""" + diff = git("diff", "--binary", f"{commit}^", commit, "--", ".", *(f":(exclude){path}" for path in LEFT_AS_TAGGED), cwd=clone) + if isinstance(diff, Failure): + return diff + if not diff: + return None + patch = worktree.parent / "commit.patch" + patch.write_text(diff) + if isinstance(applied := git("apply", "--3way", "--index", str(patch), cwd=str(worktree)), Failure): + subject = git("log", "-1", "--format=%s", commit, cwd=clone) + return Failure(f"{commit[:12]} ({'' if isinstance(subject, Failure) else subject.strip()}) doesn't apply on {base}: {applied.reason}. Cut this patch by hand.") + return None + + +def run_ci(worktree: pathlib.Path) -> Failure | None: + """None where the patch's ci.sh passes on its committed head; a Failure with the end of its output where it fails.""" + if not (worktree / "ci.sh").exists(): + return Failure("the patch holds no ci.sh to test it with") + ran = subprocess.run(["sh", "ci.sh"], capture_output=True, cwd=worktree, text=True, errors="replace") + if ran.returncode == 0: + return None + tail = "\n".join((ran.stdout + ran.stderr).strip().splitlines()[-30:]) + return Failure(f"ci.sh failed on the patch, so nothing is tagged:\n{tail}") + + +def push_merge_back(clone: str, ref: str, branch: str, tag: str, named: str, entries: list[str], replacing: str | None) -> Failure | None: + """On ref, merge tag keeping ref's files, with entries moved from ## Unreleased to a ## named section after it, in a worktree of its own; push that as branch: a new one, or in place of replacing, the commit origin's branch points at.""" + worktree = pathlib.Path(tempfile.mkdtemp(prefix="deploy-release-")) / "merge-back" + try: + if isinstance(added := git("worktree", "add", "--quiet", "--detach", str(worktree), ref, cwd=clone), Failure): + return added + if isinstance(merged := git("merge", "--quiet", "--no-ff", "--no-commit", "--strategy", "ours", tag, cwd=str(worktree)), Failure): + return merged + changelog = worktree / "CHANGELOG.md" + changelog.write_text(moved_entries(changelog.read_text(), entries, named)) + if isinstance(committed := git("commit", "--quiet", "--all", "--message", f"Merge release {named} into main", cwd=str(worktree)), Failure): + return committed + lease = [f"--force-with-lease=refs/heads/{branch}:{replacing}"] if replacing else [] + pushed = git("push", "--quiet", *lease, "origin", f"HEAD:refs/heads/{branch}", cwd=str(worktree)) + return pushed if isinstance(pushed, Failure) else None + finally: + git("worktree", "remove", "--force", str(worktree), cwd=clone) + shutil.rmtree(worktree.parent, ignore_errors=True) + + +def moved_entries(changelog: str, entries: list[str], named: str) -> str: + """changelog with entries taken out of its ## Unreleased section and put in a ## named section right after it.""" + lines = changelog.split("\n") + start = next(index for index, line in enumerate(lines) if re.fullmatch(f"## {UNRELEASED_TITLE}", line)) + end = next((index for index in range(start + 1, len(lines)) if lines[index].startswith("## ")), len(lines)) + kept = [line for line in lines[start + 1:end] if line not in entries] + while kept and not kept[-1].strip(): + kept.pop() + return "\n".join([*lines[:start + 1], *kept, "", f"## {named}", "", *entries, "", *lines[end:]]) diff --git a/bin/deploy_release/release_pull.py b/bin/deploy_release/release_pull.py index 5d919e01..31bf0e3b 100644 --- a/bin/deploy_release/release_pull.py +++ b/bin/deploy_release/release_pull.py @@ -6,10 +6,10 @@ from failure import Failure from forge.commands import Forge, gitea, Run -def create_pull(forge: Forge, branch: str, base: str, title: str, run: Run) -> Failure | None: - body = ["--body" if forge == "gh" else "--description", "Rename ## Unreleased in CHANGELOG.md to the version."] +def create_pull(forge: Forge, branch: str, base: str, title: str, body: str, run: Run) -> Failure | None: + described = ["--body" if forge == "gh" else "--description", body] command = ["gh", "pr"] if forge == "gh" else ["tea", "pulls"] - created = run([*command, "create", "--head", branch, "--base", base, "--title", title, *body]) + created = run([*command, "create", "--head", branch, "--base", base, "--title", title, *described]) return created if isinstance(created, Failure) else None diff --git a/bin/deploy_release/test_deploy_release.py b/bin/deploy_release/test_deploy_release.py index 851a1487..25a830cb 100644 --- a/bin/deploy_release/test_deploy_release.py +++ b/bin/deploy_release/test_deploy_release.py @@ -248,7 +248,7 @@ class Cut(unittest.TestCase): self.git(self.temp, "init", "-q", "--bare", "-b", "main", str(self.origin)) self.clone = self.temp / "claude-config" self.git(self.temp, "clone", "-q", str(self.origin), str(self.clone)) - self.commit({"CHANGELOG.md": "# Changelog\n\n## 0.1.0\n\n- First.\n", "todo.md": TODO + ROW.format(id=1, release="0.2.0") + ROW.format(id=2, release="0.3.0")}, "Start") + self.commit({"CHANGELOG.md": "# Changelog\n\n## 0.1.0\n\n- First.\n", "todo.md": TODO + ROW.format(id=1, release="0.2.0") + ROW.format(id=2, release="0.3.0"), "tool.txt": "broken\n", "ci.sh": "exit 0\n"}, "Start") self.git(self.clone, "tag", "-a", "v0.1.0", "-m", "Cut release 0.1.0") self.commit({"CHANGELOG.md": "# Changelog\n\n## Unreleased\n\n- Second.\n\n## 0.1.0\n\n- First.\n", "todo.md": TODO + ROW.format(id=2, release="0.3.0")}, "Ship item 1") self.git(self.clone, "commit", "-q", "--allow-empty", "-m", "Release review of 0.2.0") @@ -469,6 +469,129 @@ class Cut(unittest.TestCase): self.assertEqual(self.cut().returncode, 1, "0.2.0 is cut, so a second run refuses") self.assertEqual(self.git(self.clone, "tag", "-l", "v0.2.0", "v9.9.9").split(), ["v0.2.0", "v9.9.9"]) + def plan_patch(self, fix: dict[str, str] | None = None) -> str: + """On top of setUp's main: a feature no patch may ship, item 3 filed under 0.1.1, then the commit that fixes tool.txt and finishes item 3, pushed. The revision range that names only the fix.""" + self.commit({"feature.txt": "new\n"}, "Add a feature") + self.commit({"todo.md": TODO + ROW.format(id=2, release="0.3.0") + ROW.format(id=3, release="0.1.1")}, "File item 3") + base = self.git(self.clone, "rev-parse", "HEAD").strip() + self.commit({"tool.txt": "fixed\n", "todo.md": TODO + ROW.format(id=2, release="0.3.0"), "CHANGELOG.md": "# Changelog\n\n## Unreleased\n\n- Second.\n- Fixed.\n\n## 0.1.0\n\n- First.\n", **(fix or {})}, "Fix item 3") + head = self.git(self.clone, "rev-parse", "HEAD").strip() + self.git(self.clone, "push", "-q", "origin", "main") + return f"{base}..{head}" + + def cut_patch(self, *commits: str) -> subprocess.CompletedProcess[str]: + return subprocess.run([sys.executable, str(TOOL), "--cut-patch", *commits, str(self.target)], capture_output=True, cwd=self.clone, env=self.env, text=True) + + def test_cuts_a_patch_of_the_newest_tag_holding_only_the_named_commits_then_merges_the_tag_back_and_deploys_it(self): + ran = self.cut_patch(self.plan_patch()) + self.assertEqual(ran.returncode, 0, ran.stderr) + self.assertEqual(self.origin_git("cat-file", "-t", "v0.1.1").strip(), "tag", "the tag is annotated") + self.assertEqual(self.origin_git("tag", "-l", "--format=%(contents:subject)", "v0.1.1").strip(), "Cut release 0.1.1") + self.assertEqual(self.origin_git("log", "-1", "--format=%s", "v0.1.1").strip(), "Cut release 0.1.1") + self.assertEqual(self.origin_git("rev-parse", "v0.1.1^{commit}~1"), self.origin_git("rev-parse", "v0.1.0^{commit}")) + self.assertEqual(self.origin_git("show", "v0.1.1:tool.txt"), "fixed\n") + self.assertEqual(self.origin_git("show", "v0.1.1:CHANGELOG.md"), "# Changelog\n\n## 0.1.1\n\n- Fixed.\n\n## 0.1.0\n\n- First.\n") + self.assertEqual(self.origin_git("show", "v0.1.1:todo.md"), self.origin_git("show", "v0.1.0:todo.md")) + self.assertNotIn("feature.txt", self.origin_git("ls-tree", "--name-only", "v0.1.1")) + self.origin_git("merge-base", "--is-ancestor", "v0.1.1", "main") + self.assertEqual(self.origin_git("log", "-1", "--format=%s", "main").strip(), "Merge release 0.1.1 into main") + self.assertEqual(self.origin_git("show", "main:CHANGELOG.md"), "# Changelog\n\n## Unreleased\n\n- Second.\n\n## 0.1.1\n\n- Fixed.\n\n## 0.1.0\n\n- First.\n") + self.assertEqual(self.origin_git("show", "main:feature.txt"), "new\n") + self.assertIn(["tea", "pulls", "create", "--head", "release-0.1.1", "--base", "main"], [call[:7] for call in self.forge_state()["calls"]]) + self.assertEqual(self.git(self.target, "describe", "--tags", "--exact-match", "HEAD").strip(), "v0.1.1") + self.assertIn("Done: v0.1.1 is cut and pushed", ran.stdout) + + def test_takes_one_commit_as_the_patch(self): + head = self.plan_patch().split("..")[1] + ran = self.cut_patch(head) + self.assertEqual(ran.returncode, 0, ran.stderr) + self.assertEqual(self.origin_git("show", "v0.1.1:tool.txt"), "fixed\n") + + def test_refuses_changing_nothing_where_the_plan_names_no_patch_release(self): + self.commit({"tool.txt": "fixed\n", "CHANGELOG.md": "# Changelog\n\n## Unreleased\n\n- Second.\n- Fixed.\n\n## 0.1.0\n\n- First.\n"}, "Fix tool.txt") + self.git(self.clone, "push", "-q", "origin", "main") + ran = self.cut_patch("HEAD") + self.assertEqual(ran.returncode, 1) + self.assertIn("0.1.1", ran.stderr) + self.assertEqual(self.origin_git("tag", "-l", "v0.1.1"), "") + self.assertEqual(self.forge_state()["pulls"], []) + + def test_refuses_changing_nothing_while_the_patch_release_holds_an_item(self): + self.plan_patch() + self.commit({"todo.md": TODO + ROW.format(id=2, release="0.3.0") + ROW.format(id=4, release="0.1.1")}, "File item 4") + self.git(self.clone, "push", "-q", "origin", "main") + ran = self.cut_patch("HEAD~1") + self.assertEqual(ran.returncode, 1) + self.assertIn("still holds items", ran.stderr) + self.assertEqual(self.origin_git("tag", "-l", "v0.1.1"), "") + + def test_skips_the_release_review_a_patch_would_otherwise_wait_for(self): + self.git(self.clone, "reset", "-q", "--hard", "HEAD~1") + self.git(self.clone, "push", "-q", "--force", "origin", "main") + ran = self.cut_patch(self.plan_patch()) + self.assertEqual(ran.returncode, 0, ran.stderr) + + def test_refuses_a_commit_the_tag_holds_or_origins_main_doesnt(self): + self.plan_patch() + for commit in ("v0.1.0", "HEAD"): + if commit == "HEAD": + self.commit({"tool.txt": "local\n"}, "Unpushed") + ran = self.cut_patch(commit) + self.assertEqual(ran.returncode, 1, commit) + self.assertIn(self.git(self.clone, "rev-parse", "--short", f"{commit}^{{commit}}").strip()[:7], ran.stderr) + self.assertEqual(self.origin_git("tag", "-l", "v0.1.1"), "") + + def test_refuses_commits_that_add_no_changelog_entry_under_unreleased(self): + self.plan_patch() + self.commit({"tool.txt": "fixed again\n"}, "Fix more") + self.git(self.clone, "push", "-q", "origin", "main") + ran = self.cut_patch("HEAD") + self.assertEqual(ran.returncode, 1) + self.assertIn("## Unreleased", ran.stderr) + self.assertEqual(self.origin_git("tag", "-l", "v0.1.1"), "") + + def test_stops_before_tagging_where_ci_fails_on_the_patch(self): + ran = self.cut_patch(self.plan_patch({"ci.sh": "echo the suite failed >&2\nexit 1\n"})) + self.assertEqual(ran.returncode, 1) + self.assertIn("ci.sh", ran.stderr) + self.assertIn("the suite failed", ran.stderr) + self.assertEqual(self.origin_git("tag", "-l", "v0.1.1"), "") + self.assertEqual(self.git(self.clone, "tag", "-l", "v0.1.1"), "") + self.assertEqual(self.forge_state()["pulls"], []) + + def test_stops_naming_the_commit_that_does_not_apply_on_the_tag(self): + self.commit({"tool.txt": "half fixed\n"}, "Change tool.txt on main") + ran = self.cut_patch(self.plan_patch()) + self.assertEqual(ran.returncode, 1) + self.assertIn("Fix item 3", ran.stderr) + self.assertIn("v0.1.0", ran.stderr) + self.assertEqual(self.origin_git("tag", "-l", "v0.1.1"), "") + + def test_a_rerun_after_a_failed_merge_back_check_keeps_the_pushed_tag_and_merges_back(self): + self.set_checks("failure") + commits = self.plan_patch() + ran = self.cut_patch(commits) + self.assertEqual(ran.returncode, 1) + tagged = self.origin_git("rev-parse", "v0.1.1^{commit}") + self.set_checks("success") + ran = self.cut_patch(commits) + self.assertEqual(ran.returncode, 0, ran.stderr) + self.assertEqual(self.origin_git("rev-parse", "v0.1.1^{commit}"), tagged) + self.origin_git("merge-base", "--is-ancestor", "v0.1.1", "main") + + def test_plain_cut_refuses_a_patch_release_and_names_cut_patch(self): + self.plan_patch() + ran = self.cut() + self.assertEqual(ran.returncode, 1) + self.assertIn("--cut-patch", ran.stderr) + self.assertEqual(self.forge_state()["pulls"], []) + + def test_cut_patch_needs_its_commits(self): + ran = subprocess.run([sys.executable, str(TOOL), "--cut-patch"], capture_output=True, cwd=self.clone, env=self.env, text=True) + self.assertEqual(ran.returncode, 1) + self.assertIn("usage", ran.stderr) + self.assertEqual(self.forge_state()["calls"], []) + def test_takes_no_option_but_cut(self): ran = subprocess.run([sys.executable, str(TOOL), "--cut", "--force"], capture_output=True, cwd=self.clone, env=self.env, text=True) self.assertEqual(ran.returncode, 1) -- 2.52.0 From 2cdd3460601aeb5ca73c95133d64aa80e9d1d964 Mon Sep 17 00:00:00 2001 From: Lilleman Date: Tue, 24 Nov 2026 14:10:29 +0100 Subject: [PATCH 03/13] Record the patch cut in the deploy decision --- docs/decisions.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/decisions.md b/docs/decisions.md index fec9ae62..17e09a93 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -154,6 +154,8 @@ Valid while `~/.claude` is a checkout of this repo. 2026-11-08, lilleman, todo item 271. Serves goal 1.5 and goal 2. Nobody can push to `main` on the remote, and it merges only by fast-forward, so a cut that commits on `main` and pushes no longer works. The tool cuts only the release `chunk-preflight` would call ready to cut, through `bin/release_plan/release_standing.py`, so the two never disagree on which release is next or whether it is ready; the version is that release's, never the tool's choice. It builds the cut commit in a worktree of its own, so the clone's checkout stays as it is. It finds the merged commit on `main` by its title, `Cut release `, since GitHub's nearest merge, a rebase merge, may give the commit a new hash. It takes only a pull request from origin's own branch whose head is the commit that branch points at, and has the forge merge it only while its head is still that commit, so a fork's pull request from a branch of the same name, or a push after the checks passed, is never merged and deployed. Each step first checks whether an earlier run did it, so a rerun continues. Releases stay the human's, so the human runs it, and the forge credentials stay theirs. Valid while `main` takes changes only through a pull request. +2026-11-24, todo item 536. `deploy-release --cut-patch ` cuts the newest tag's next patch release, holding only the commits named, for a fix that must ship before `main`'s other unreleased work, as 0.15.1 did by hand. Its commit sits on the tag, not on `main`, so no pull request can merge it, and CI runs only on pull requests: the tool runs `ci.sh` on it, as CI does, before it tags. Then it merges the tag back into `main` with `-s ours` through a pull request, so the tag is in `main`'s history, where the next cut and `chunk-preflight` read it. A patch skips the release review: it holds only fixes, and the review reads the whole project. `chunk-preflight` still calls that review due until the patch is cut, so cut a patch as soon as its fix merges. Plain `--cut` refuses a patch of the newest tag, since it would ship all of `main` under a patch number. + ## do-epic: drives one Jira epic whose items span repos, or have none, ranked by the epic's goals, then code health, then each repo's goals, and closes the epic only once the human confirms every goal 2026-11-18, lilleman's answers to claude's questions while planning release 0.12.0. Serves goal 1, so development scales past one repo, and goal 1.6, since the epic stays in the client's Jira. Valid while Jira is the only backend; another backend goes behind the same interface. -- 2.52.0 From 366a10cc0e2eea223c6ece12b4d75b7ab199a105 Mon Sep 17 00:00:00 2001 From: Lilleman Date: Tue, 24 Nov 2026 14:13:32 +0100 Subject: [PATCH 04/13] Sort deploy_release's imports by their first binding --- bin/deploy_release/main.py | 2 +- bin/deploy_release/patch.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/deploy_release/main.py b/bin/deploy_release/main.py index ec856427..d8ce8935 100644 --- a/bin/deploy_release/main.py +++ b/bin/deploy_release/main.py @@ -60,8 +60,8 @@ import sys import time from deploy_release.cut import cut -from deploy_release.deploy import deploy from deploy_release.patch import cut_patch +from deploy_release.deploy import deploy from failure import Failure diff --git a/bin/deploy_release/patch.py b/bin/deploy_release/patch.py index 83972eba..427ab427 100644 --- a/bin/deploy_release/patch.py +++ b/bin/deploy_release/patch.py @@ -9,10 +9,10 @@ import subprocess import tempfile import typing +from git_cli.git_repo import default_ref, git from deploy_release.cut import delete_release_branch, drop_unpushed_cut_tags, land, ready_release, said, same_origin from deploy_release.deploy import deploy from failure import Failure -from git_cli.git_repo import default_ref, git from plan.release import newest_tag, Release, tagged, UNRELEASED_TITLE, version from text_files.markdown_text import section -- 2.52.0 From 459a3d5f54dc403cbc5d022e1e79681aa6c3177d Mon Sep 17 00:00:00 2001 From: Lilleman Date: Tue, 24 Nov 2026 14:28:55 +0100 Subject: [PATCH 05/13] Note in item 462 that deploy-release's tests fail in mutmut's copy too --- todo.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/todo.md b/todo.md index d6ff97a4..0ec382db 100644 --- a/todo.md +++ b/todo.md @@ -322,6 +322,8 @@ Name the entry and the Dockerfile line. Source the secret-name list from a widel Found while shipping item 461: `mutate-changes` printed `23 mutants on changed lines, 18 not killed. Left out the tests that fail without a mutant, in do_epic/test_main.py, larv_review/test_larv_review.py, larv_review/test_scoring_setup.py, plan/test_ranking.py, repo_checks/…, review_rules/test_review_passes.py, review_rules/test_reviewer_context.py, rule_hook/test_rule_hook.py, test_settings_filter.py`. All 18 survivors were in `bin/larv_review/scoring_setup.py`: `prepare_scoring`, whose tests are among those left out, so the chunk checked four of them by hand and left 14 unchecked. Find why each left-out test fails in mutmut's copy, such as a path to `skills/` or a git checkout it expects, and make it pass there, or report under the count which changed lines no remaining test covers. +Item 536 met it too: `deploy_release/test_deploy_release.py`, which runs `deploy-release` as a subprocess, fails there, so none of 597 mutants of `bin/deploy_release/` was checked. + Touches `bin/mutate_changes/`, and the tests named above. ### 77. Teach `bin/metric-bench` Go and TypeScript, rerun it once two projects' comprehension histories name places, and bring into review only a metric that tracks the panel. -- 2.52.0 From 39cb2f4d9e3e5da6081a9ccdc93b1120254ba3f2 Mon Sep 17 00:00:00 2001 From: Lilleman Date: Tue, 24 Nov 2026 14:29:51 +0100 Subject: [PATCH 06/13] Unit-test the patch cut's changelog edits in-process --- bin/deploy_release/patch.py | 14 ++++++++++---- bin/deploy_release/test_deploy_release.py | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/bin/deploy_release/patch.py b/bin/deploy_release/patch.py index 427ab427..e0addadf 100644 --- a/bin/deploy_release/patch.py +++ b/bin/deploy_release/patch.py @@ -112,10 +112,7 @@ def tag_patch(clone: str, base: str, commits: list[str], entries: list[str], nam if isinstance(applied := apply_commit(clone, worktree, commit, base), Failure): return applied changelog = worktree / "CHANGELOG.md" - text = changelog.read_text() if changelog.exists() else "# Changelog\n" - section_text = f"## {named}\n\n" + "\n".join(entries) + "\n\n" - headed, count = re.subn(r"^## ", lambda _: section_text + "## ", text, count=1, flags=re.M) - changelog.write_text(headed if count else text.rstrip("\n") + "\n\n" + section_text.rstrip("\n") + "\n") + changelog.write_text(headed(changelog.read_text() if changelog.exists() else "# Changelog\n", entries, named)) if isinstance(committed := git("commit", "--quiet", "--all", "--message", title, cwd=str(worktree)), Failure): return committed said(f"applied {len(commits)} commit(s) on {base}; testing them with ci.sh") @@ -135,6 +132,15 @@ def tag_patch(clone: str, base: str, commits: list[str], entries: list[str], nam shutil.rmtree(worktree.parent, ignore_errors=True) +def headed(changelog: str, entries: list[str], named: str) -> str: + """changelog with a ## named section holding entries before its first ## section, or at its end where it has none.""" + added = f"## {named}\n\n" + "\n".join(entries) + "\n" + first = re.search(r"^## ", changelog, flags=re.M) + if first is None: + return changelog.rstrip("\n") + "\n\n" + added + return changelog[:first.start()] + added + "\n" + changelog[first.start():] + + def apply_commit(clone: str, worktree: pathlib.Path, commit: str, base: str) -> Failure | None: """Apply commit's change, but for LEFT_AS_TAGGED, to worktree's index and files, merging three ways where the tag base's files differ from commit's parent.""" diff = git("diff", "--binary", f"{commit}^", commit, "--", ".", *(f":(exclude){path}" for path in LEFT_AS_TAGGED), cwd=clone) diff --git a/bin/deploy_release/test_deploy_release.py b/bin/deploy_release/test_deploy_release.py index 25a830cb..d9012a33 100644 --- a/bin/deploy_release/test_deploy_release.py +++ b/bin/deploy_release/test_deploy_release.py @@ -10,6 +10,7 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) from failure import Failure from test_env import isolated_env +from deploy_release import patch TOOL = pathlib.Path(__file__).resolve().parents[1] / "deploy-release" @@ -611,5 +612,26 @@ class Cut(unittest.TestCase): +class PatchChangelog(unittest.TestCase): + """The changelog edits of a patch cut, read in-process, so a mutation tester reaches them.""" + + def test_heads_the_tags_changelog_with_the_patchs_section(self): + self.assertEqual(patch.headed("# Changelog\n\n## 0.1.0\n\n- First.\n", ["- Fixed.", "- Also."], "0.1.1"), "# Changelog\n\n## 0.1.1\n\n- Fixed.\n- Also.\n\n## 0.1.0\n\n- First.\n") + + def test_ends_a_changelog_with_no_section_with_the_patchs_section(self): + self.assertEqual(patch.headed("# Changelog\n\n", ["- Fixed."], "0.1.1"), "# Changelog\n\n## 0.1.1\n\n- Fixed.\n") + + def test_moves_the_patchs_entries_from_unreleased_to_a_section_after_it(self): + changelog = "# Changelog\n\n## Unreleased\n\n- Second.\n- Fixed.\n\n## 0.1.0\n\n- First.\n" + self.assertEqual(patch.moved_entries(changelog, ["- Fixed."], "0.1.1"), "# Changelog\n\n## Unreleased\n\n- Second.\n\n## 0.1.1\n\n- Fixed.\n\n## 0.1.0\n\n- First.\n") + + def test_leaves_an_older_section_entry_that_reads_the_same(self): + changelog = "# Changelog\n\n## Unreleased\n\n- Fixed.\n\n## 0.1.0\n\n- Fixed.\n" + self.assertEqual(patch.moved_entries(changelog, ["- Fixed."], "0.1.1"), "# Changelog\n\n## Unreleased\n\n## 0.1.1\n\n- Fixed.\n\n## 0.1.0\n\n- Fixed.\n") + + def test_puts_the_section_last_where_unreleased_is_the_last_section(self): + self.assertEqual(patch.moved_entries("# Changelog\n\n## Unreleased\n\n- Fixed.\n", ["- Fixed."], "0.1.1"), "# Changelog\n\n## Unreleased\n\n## 0.1.1\n\n- Fixed.\n") + + if __name__ == "__main__": unittest.main() -- 2.52.0 From 3f74d32caedb273c571f26074439aae8855d3e96 Mon Sep 17 00:00:00 2001 From: Lilleman Date: Tue, 24 Nov 2026 14:48:06 +0100 Subject: [PATCH 07/13] Kill the mutant that strips more than blank lines off a changelog with no section --- bin/deploy_release/patch.py | 2 +- bin/deploy_release/test_deploy_release.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/deploy_release/patch.py b/bin/deploy_release/patch.py index e0addadf..bb74dd86 100644 --- a/bin/deploy_release/patch.py +++ b/bin/deploy_release/patch.py @@ -137,7 +137,7 @@ def headed(changelog: str, entries: list[str], named: str) -> str: added = f"## {named}\n\n" + "\n".join(entries) + "\n" first = re.search(r"^## ", changelog, flags=re.M) if first is None: - return changelog.rstrip("\n") + "\n\n" + added + return changelog.rstrip() + "\n\n" + added return changelog[:first.start()] + added + "\n" + changelog[first.start():] diff --git a/bin/deploy_release/test_deploy_release.py b/bin/deploy_release/test_deploy_release.py index d9012a33..e10e8e04 100644 --- a/bin/deploy_release/test_deploy_release.py +++ b/bin/deploy_release/test_deploy_release.py @@ -619,7 +619,7 @@ class PatchChangelog(unittest.TestCase): self.assertEqual(patch.headed("# Changelog\n\n## 0.1.0\n\n- First.\n", ["- Fixed.", "- Also."], "0.1.1"), "# Changelog\n\n## 0.1.1\n\n- Fixed.\n- Also.\n\n## 0.1.0\n\n- First.\n") def test_ends_a_changelog_with_no_section_with_the_patchs_section(self): - self.assertEqual(patch.headed("# Changelog\n\n", ["- Fixed."], "0.1.1"), "# Changelog\n\n## 0.1.1\n\n- Fixed.\n") + self.assertEqual(patch.headed("# Changelog\n\nFor Linux and macOS X\n\n", ["- Fixed."], "0.1.1"), "# Changelog\n\nFor Linux and macOS X\n\n## 0.1.1\n\n- Fixed.\n") def test_moves_the_patchs_entries_from_unreleased_to_a_section_after_it(self): changelog = "# Changelog\n\n## Unreleased\n\n- Second.\n- Fixed.\n\n## 0.1.0\n\n- First.\n" -- 2.52.0 From ec497aa9892ff0809e84363255b7fa49c25ec5b2 Mon Sep 17 00:00:00 2001 From: Lilleman Date: Tue, 24 Nov 2026 14:48:11 +0100 Subject: [PATCH 08/13] =?UTF-8?q?Answer=20security=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=200=20=F0=9F=9F=A1=20(0=20misread);=20no=20findin?= =?UTF-8?q?gs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From db32e4ef59b5fb9c1a570e7a3b426f4665255d90 Mon Sep 17 00:00:00 2001 From: Lilleman Date: Tue, 24 Nov 2026 15:12:17 +0100 Subject: [PATCH 09/13] =?UTF-8?q?Answer=20stability=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=205=20=F0=9F=9F=A1=20(0=20misread);=20share=20the?= =?UTF-8?q?=20scratch=20worktree,=20check=20a=20reused=20tag=20and=20main'?= =?UTF-8?q?s=20merge-back,=20refuse=20GitHub,=20split=20the=20looped=20tes?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +- bin/deploy_release/cut.py | 38 +++-- bin/deploy_release/main.py | 42 ++--- bin/deploy_release/patch.py | 182 +++++++++++++--------- bin/deploy_release/test_deploy_release.py | 70 +++++++-- bin/release_plan/release_standing.py | 5 +- bin/release_plan/test_release_standing.py | 18 +++ docs/decisions.md | 4 +- todo.md | 10 +- 9 files changed, 249 insertions(+), 124 deletions(-) diff --git a/README.md b/README.md index c3ecb654..cc7f636d 100644 --- a/README.md +++ b/README.md @@ -198,13 +198,13 @@ bin/deploy-release --cut It renames `## Unreleased` in `CHANGELOG.md` to the version and merges that through a pull request, since nobody can push to `main`. Then it tags the merged commit `v`, pushes the tag, and moves this machine's `~/.claude` to it. Where a step fails it stops with the reason, and a rerun continues where it stopped. `deploy-release --help` lists the steps. Each other machine takes the release with Update. -A fix that must ship before `main`'s other unreleased work goes out as a patch release, such as 0.15.2 after v0.15.1. File its item under that release, merge its chunk, then cut it with the commits the chunk merged, as a range or one commit: +A fix that must ship before `main`'s other unreleased work goes out as a patch release, such as 0.15.2 after v0.15.1. File its item under that release, merge its chunk, then cut it at once with the commits the chunk merged, as a range or one commit. A range leaves out its first commit, as git's `..` does, so start it at the commit before the chunk's first: ```sh bin/deploy-release --cut-patch 794ce37..1aa2367 ``` -It applies only those commits on the newest tag, tests them with `ci.sh`, tags and pushes the release, then merges the tag back into `main` through a pull request and moves `~/.claude` to it. A patch skips the release review. `deploy-release --help` lists the steps. +It applies only those commits on the newest tag, tests them with `ci.sh`, tags and pushes the release, then merges the tag back into `main` through a pull request and moves `~/.claude` to it. A patch skips the release review. Until it is cut, `chunk-preflight` calls the patch's release review due, and loop-claude would run it. `deploy-release --help` lists the steps. ## Tools diff --git a/bin/deploy_release/cut.py b/bin/deploy_release/cut.py index 04330f08..b6f795af 100644 --- a/bin/deploy_release/cut.py +++ b/bin/deploy_release/cut.py @@ -2,6 +2,7 @@ Each step first checks whether an earlier run did it, so a rerun continues where the last run stopped. """ +import contextlib import pathlib import shutil import sys @@ -117,13 +118,13 @@ def drop_unpushed_cut_tags(clone: str) -> Failure | None: def same_origin(clone: str, checkout: str) -> Failure | None: - """A Failure unless clone is a clone of the origin checkout takes its releases from, so --cut never cuts another project.""" + """A Failure unless clone is a clone of the origin checkout takes its releases from, so a cut never cuts another project.""" urls = [git("ls-remote", "--get-url", "origin", cwd=where) for where in (clone, checkout)] failed = next((url for url in urls if isinstance(url, Failure)), None) if failed is not None: return failed if urls[0] != urls[1]: - return Failure(f"run --cut in a clone of {checkout}'s origin, {str(urls[1]).strip()}; this directory's origin is {str(urls[0]).strip()}") + return Failure(f"run deploy-release in a clone of {checkout}'s origin, {str(urls[1]).strip()}; this directory's origin is {str(urls[0]).strip()}") return None @@ -170,7 +171,9 @@ def commit_titled(title: str, ref: str, clone: str) -> str | None | Failure: def land(clone: str, ref: str, branch: str, title: str, body: str, build: typing.Callable[[str | None], Failure | None], sleep: typing.Callable[[float], None]) -> Failure | None: - """Push branch with build and open its pull request, titled title with body, where an earlier run hasn't; then wait for its checks and merge it. build pushes the branch's commit on ref: a new branch, or in place of the commit it names, origin's branch's head.""" + """Push branch and open its pull request, titled title with body, where an earlier run hasn't; then wait for its checks and merge it. + + build pushes branch's commit, made on ref. It takes the commit origin's branch points at, which the push replaces, or None where origin has no such branch yet.""" url = git("config", "--get", "remote.origin.url", cwd=clone) if isinstance(url, Failure): return url @@ -225,11 +228,10 @@ def behind_main(branch: str, head: str, ref: str, clone: str) -> bool | Failure: def push_cut_commit(clone: str, ref: str, branch: str, named: str, title: str, replacing: str | None) -> Failure | None: - """Commit ref's CHANGELOG.md with ## Unreleased renamed to named, in a worktree of its own so the clone's checkout stays as it is, and push it as branch: a new one, or in place of replacing, the commit origin's branch points at.""" - worktree = pathlib.Path(tempfile.mkdtemp(prefix="deploy-release-")) / "cut" - try: - if isinstance(added := git("worktree", "add", "--quiet", "--detach", str(worktree), ref, cwd=clone), Failure): - return added + """Commit ref's CHANGELOG.md with ## Unreleased renamed to named, in a worktree of its own, and push it as branch, replacing the commit origin's branch points at, where there is one.""" + with scratch_worktree(clone, ref) as worktree: + if isinstance(worktree, Failure): + return worktree changelog = worktree / "CHANGELOG.md" renamed, count = UNRELEASED_HEADING.subn(f"## {named}", changelog.read_text() if changelog.exists() else "", count=1) if not count: @@ -237,9 +239,23 @@ def push_cut_commit(clone: str, ref: str, branch: str, named: str, title: str, r changelog.write_text(renamed) if isinstance(committed := git("commit", "--quiet", "-am", title, cwd=str(worktree)), Failure): return committed - lease = [f"--force-with-lease=refs/heads/{branch}:{replacing}"] if replacing else [] - pushed = git("push", "--quiet", *lease, "origin", f"HEAD:refs/heads/{branch}", cwd=str(worktree)) - return pushed if isinstance(pushed, Failure) else None + return push_branch(worktree, branch, replacing) + + +@contextlib.contextmanager +def scratch_worktree(clone: str, at: str) -> typing.Iterator[pathlib.Path | Failure]: + """A worktree of clone, detached at at, in a folder of its own that is removed afterwards, so the clone's checkout stays as it is; a Failure where git can't add it.""" + worktree = pathlib.Path(tempfile.mkdtemp(prefix="deploy-release-")) / "worktree" + try: + added = git("worktree", "add", "--quiet", "--detach", str(worktree), at, cwd=clone) + yield added if isinstance(added, Failure) else worktree finally: git("worktree", "remove", "--force", str(worktree), cwd=clone) shutil.rmtree(worktree.parent, ignore_errors=True) + + +def push_branch(worktree: pathlib.Path, branch: str, replacing: str | None) -> Failure | None: + """Push worktree's HEAD to origin as branch: a new one, or in place of replacing, only while origin's branch still points at it.""" + lease = [f"--force-with-lease=refs/heads/{branch}:{replacing}"] if replacing else [] + pushed = git("push", "--quiet", *lease, "origin", f"HEAD:refs/heads/{branch}", cwd=str(worktree)) + return pushed if isinstance(pushed, Failure) else None diff --git a/bin/deploy_release/main.py b/bin/deploy_release/main.py index d8ce8935..ff665415 100644 --- a/bin/deploy_release/main.py +++ b/bin/deploy_release/main.py @@ -18,7 +18,9 @@ memory, stay as they are. --cut runs in the development clone, and refuses where that clone's origin isn't 's. It cuts the next release, as chunk-preflight works it out, and refuses without changing anything, unless that release holds no item in todo.md, its release review has -landed and changes are unreleased. The release names the version; the tool doesn't choose one. +landed and changes are unreleased. The release names the version; the tool doesn't choose one. It also refuses a +release that is a patch of the newest tag, such as 0.15.2 after v0.15.1, since it would ship all of main: cut that +with --cut-patch. 1. On a fresh origin/main, it renames ## Unreleased in CHANGELOG.md to the version, commits that titled `Cut release `, and pushes it as the branch release-. The clone's own checkout stays as it is. Where main has moved past the branch, it rebuilds the branch on main. @@ -34,25 +36,29 @@ It says on stderr as each step finishes, and ends stdout, after the changelog, w Where a step fails it stops, exit 1, with git's or the forge's reason, and leaves the pull request and the branch as they are. A rerun continues: it takes the branch's open pull request and a cut commit already merged, and drops a cut tag an earlier run made but never pushed. Once the tag is pushed, the release is cut: where only the -move stopped, fix what it names and run a bare deploy-release. --cut refuses a release that is a patch of the newest tag, -such as 0.15.2 after v0.15.1, since it would ship all of main: cut that with --cut-patch. +move stopped, fix what it names and run a bare deploy-release. --cut-patch runs in the development clone too, for a fix that must ship before main's other unreleased work. It -cuts the newest tag's next patch release, such as 0.15.2 after v0.15.1, holding only on top of the tag. -is one revision as git log reads it: a range such as 794ce37..1aa2367, which leaves out 794ce37 as git's `..` does, or one -commit. Each must be on origin's main and not in the tag; merge commits are left out. Name the commit that finished the -fix's item too: its entries under ## Unreleased in CHANGELOG.md become the release's. todo.md must name the release and file -no item under it; a patch skips the release review. It refuses without changing anything where any of that doesn't hold. -1. In a worktree of its own at the tag, it applies each commit's changes, except to todo.md, CHANGELOG.md and the records - every chunk appends to, heads CHANGELOG.md with the release's section, and commits that titled `Cut release `. - Where a commit doesn't apply, it stops and names it: cut that patch by hand. -2. It runs ci.sh on that commit, and stops where it fails, before anything is tagged. -3. It tags the commit v, annotated `Cut release `, and pushes only the tag. -4. On a fresh origin/main it merges the tag keeping main's files, moves the release's entries from ## Unreleased to a - ## section, commits that titled `Merge release into main`, and lands it through the branch - release- and a pull request as --cut does, so the tag is in main's history. -5. It moves to the tag as above, and ends stdout as --cut does. -A rerun skips a tag origin holds already and a merge main holds already. +cuts the newest tag's next patch release, holding only on top of the tag. is a range as git log reads +it, such as 794ce37..1aa2367, which leaves out 794ce37 as git's `..` does, or one commit, which it reads as that commit +alone. Name the commits the fix's chunk merged, including the one that finished its item: the entries that commit added +under ## Unreleased in CHANGELOG.md become the release's. Each commit must be on origin's main and not in the tag. Merge +commits are left out, and so are the commits a merge of main brought into the range. todo.md must name the release and +file no item under it; a patch skips the release review. Cut it as soon as the fix merges: until then chunk-preflight calls +the patch's release review due, and loop-claude would run it. It refuses without changing anything where any of that +doesn't hold, and on a GitHub origin, whose rebase merge would drop the tag from main's history. +1. It says on stderr which commits the release ships. +2. In a worktree of its own at the tag, it applies each commit's changes, except to CHANGELOG.md, todo.md, + docs/comprehension-history.md and docs/reading-cost.md, heads CHANGELOG.md with the release's section, and commits that + titled `Cut release `. Where a commit doesn't apply, it stops, names it, and says how to cut the patch by hand. +3. It runs ci.sh on that commit, and stops where it fails, before anything is tagged. +4. It tags the commit v, annotated `Cut release `, and pushes only the tag. +5. On a fresh origin/main it merges the tag keeping main's files, moves the release's entries from ## Unreleased to a + ## section below it, commits that titled `Merge release into main`, and lands it through the branch + release- and a pull request as --cut does. Then it checks main holds the tag. +6. It moves to the tag as above, and ends stdout as --cut does. +A rerun takes a tag origin holds already, once it checks the tag lists the same changelog entries, and the merge-back's open +pull request. Once the merge-back has merged, the release is cut: where only the move stopped, run a bare deploy-release. """ import os import pathlib diff --git a/bin/deploy_release/patch.py b/bin/deploy_release/patch.py index bb74dd86..5e31b394 100644 --- a/bin/deploy_release/patch.py +++ b/bin/deploy_release/patch.py @@ -1,30 +1,79 @@ """`deploy-release --cut-patch `: cut the newest tag's next patch release holding only the commits named, test it with ci.sh, tag it, merge the tag back into main through a pull request, then move ~/.claude to it. -Each step first checks whether an earlier run did it, so a rerun continues where the last run stopped. +A rerun takes the tag an earlier run pushed, once it checks the tag lists the same changelog entries, and the merge-back's open pull request. """ +import dataclasses import pathlib import re -import shutil import subprocess -import tempfile import typing from git_cli.git_repo import default_ref, git -from deploy_release.cut import delete_release_branch, drop_unpushed_cut_tags, land, ready_release, said, same_origin +from deploy_release.cut import delete_release_branch, drop_unpushed_cut_tags, land, push_branch, ready_release, said, same_origin, scratch_worktree from deploy_release.deploy import deploy from failure import Failure -from plan.release import newest_tag, Release, tagged, UNRELEASED_TITLE, version +from forge.commands import forge_of +from plan.release import newest_tag, tagged, UNRELEASED_TITLE, version from text_files.markdown_text import section -# The files a patch leaves as the tag holds them: the plan, the changelog the cut writes itself, and the records every chunk appends to, which seldom apply on an older tag. -LEFT_AS_TAGGED = ("todo.md", "CHANGELOG.md", "docs/reading-cost.md", "docs/comprehension-history.md") +# The files a patch leaves as the tag holds them: the changelog, whose section the cut writes itself; the plan; and the records each chunk appends to, which seldom apply on an older tag. +LEFT_AS_TAGGED = ("CHANGELOG.md", "docs/comprehension-history.md", "docs/reading-cost.md", "todo.md") MERGE_BACK_BODY = "Merge the patch release's tag into main, keeping main's files, and list its changelog entries under its version." +@dataclasses.dataclass(frozen=True) +class Patch: + """A patch release ready to cut.""" + # origin's default branch, as default_ref names it. + ref: str + # The newest tag ref holds, which the patch goes on top of. + base: str + # The patch's version, the base's next patch. + named: str + # The commits the patch ships, oldest first. + commits: list[str] + # The CHANGELOG.md entries the commits added under ref's ## Unreleased, in ref's order. + entries: list[str] + + def cut_patch(clone: str, checkout: str, commits: str, sleep: typing.Callable[[float], None]) -> str | Failure: - """What the patch cut did, as the tool prints it; a Failure with git's, the forge's, ci.sh's or the tool's reason where a step stopped. commits is one revision as git log reads it, or one commit.""" + """What the patch cut did, as the tool prints it; a Failure with git's, the forge's, ci.sh's or the tool's reason where a step stopped. commits is a range as git log reads it, or one commit.""" + patch = planned(clone, checkout, commits) + if isinstance(patch, Failure): + return patch + for commit in patch.commits: + subject = git("log", "-1", "--format=%h %s", commit, cwd=clone) + said(f"ships {'' if isinstance(subject, Failure) else subject.strip()}") + tag, branch = f"v{patch.named}", f"release-{patch.named}" + pushed = git("ls-remote", "--tags", "--refs", "origin", f"refs/tags/{tag}", cwd=clone) + if isinstance(pushed, Failure): + return pushed + made = tagged_entries(clone, patch) if pushed.strip() else tag_patch(clone, patch) + if isinstance(made, Failure): + return made + build = lambda replacing: push_merge_back(clone, patch, replacing) + if isinstance(landed := land(clone, patch.ref, branch, f"Merge release {patch.named} into main", MERGE_BACK_BODY, build, sleep), Failure): + return landed + if isinstance(fetched := git("fetch", "--quiet", "origin", cwd=clone), Failure): + return fetched + if isinstance(git("merge-base", "--is-ancestor", tag, patch.ref, cwd=clone), Failure): + return Failure(f"the merge-back merged, but {patch.ref} doesn't hold {tag}, so the next cut can't read it as cut") + delete_release_branch(clone, branch) + moved = deploy(checkout) + if isinstance(moved, Failure): + return Failure(f"cut and pushed {tag}, but moving {checkout} stopped: {moved.reason}. Fix that, then run a bare deploy-release.") + return f"{moved}\n\nDone: {tag} is cut and pushed, and {checkout} is on it." + + +def planned(clone: str, checkout: str, commits: str) -> Patch | Failure: + """The patch commits names, once the clone, the plan and the commits allow it; a Failure saying why not, before anything changes on origin.""" if isinstance(same := same_origin(clone, checkout), Failure): return same + url = git("config", "--get", "remote.origin.url", cwd=clone) + if isinstance(url, Failure): + return url + if forge_of(url) == "gh": + return Failure("--cut-patch merges the tag back fast-forward, which GitHub can't, since its rebase merge drops the merge commit: cut the patch by hand there") if isinstance(fetched := git("fetch", "--quiet", "--tags", "origin", cwd=clone), Failure): return fetched if isinstance(dropped := drop_unpushed_cut_tags(clone), Failure): @@ -35,10 +84,10 @@ def cut_patch(clone: str, checkout: str, commits: str, sleep: typing.Callable[[f base = newest_tag(clone, merged_into=ref) if isinstance(base, Failure): return base - cut_release = tagged(base) - if base is None or cut_release is None: - return Failure(f"{ref} holds no v* tag to cut a patch of") - named = version((cut_release[0], cut_release[1], cut_release[2] + 1)) + cut = tagged(base) + if base is None or cut is None: + return Failure(f"{ref}'s newest tag, {base}, names no release x.y.z to cut a patch of" if base else f"{ref} holds no v* tag to cut a patch of") + named = version((cut[0], cut[1], cut[2] + 1)) # A patch holds only fixes, and the release review reads the whole project, so a patch is cut without one. release = ready_release(clone, ref, review=False) if isinstance(release, Failure): @@ -49,35 +98,17 @@ def cut_patch(clone: str, checkout: str, commits: str, sleep: typing.Callable[[f if isinstance(picked, Failure): return picked entries = changelog_entries(clone, ref, picked) - if isinstance(entries, Failure): - return entries - title, tag = f"Cut release {named}", f"v{named}" - pushed = git("ls-remote", "--tags", "--refs", "origin", f"refs/tags/{tag}", cwd=clone) - if isinstance(pushed, Failure): - return pushed - if not pushed.strip(): - if isinstance(made := tag_patch(clone, base, picked, entries, named, title), Failure): - return made - if isinstance(git("merge-base", "--is-ancestor", tag, ref, cwd=clone), Failure): - branch = f"release-{named}" - build = lambda replacing: push_merge_back(clone, ref, branch, tag, named, entries, replacing) - if isinstance(landed := land(clone, ref, branch, f"Merge release {named} into main", MERGE_BACK_BODY, build, sleep), Failure): - return landed - delete_release_branch(clone, branch) - moved = deploy(checkout) - if isinstance(moved, Failure): - return Failure(f"cut and pushed {tag}, but moving {checkout} stopped: {moved.reason}. Fix that, then run a bare deploy-release.") - return f"{moved}\n\nDone: {tag} is cut and pushed, and {checkout} is on it." + return entries if isinstance(entries, Failure) else Patch(ref, base, named, picked, entries) def patch_commits(clone: str, ref: str, base: str, commits: str) -> list[str] | Failure: - """The commits commits names, oldest first, merge commits left out; a Failure where one is missing from ref or the tag base already holds it.""" - listed = git("rev-list", "--reverse", "--no-merges", commits if ".." in commits else f"{commits}^!", "--", cwd=clone) + """The commits commits names, oldest first: merge commits, and the commits a merge brought into a range, are left out. A Failure where one is missing from ref or the tag base already holds it.""" + listed = git("rev-list", "--reverse", "--no-merges", "--first-parent", commits if ".." in commits else f"{commits}^!", "--", cwd=clone) if isinstance(listed, Failure): return listed picked = listed.split() if not picked: - return Failure(f"{commits} names no commit but merges") + return Failure(f"{commits} names no commit that isn't a merge: write a range as ..") for commit in picked: if isinstance(git("merge-base", "--is-ancestor", commit, ref, cwd=clone), Failure): return Failure(f"{commit[:12]} isn't on {ref}: merge it there first") @@ -101,22 +132,32 @@ def changelog_entries(clone: str, ref: str, commits: list[str]) -> list[str] | F return entries or Failure(f"the commits add no entry under ## Unreleased in CHANGELOG.md on {ref}: name the commit that finished the fix's item too") -def tag_patch(clone: str, base: str, commits: list[str], entries: list[str], named: str, title: str) -> Failure | None: - """In a worktree at the tag base, apply commits but for LEFT_AS_TAGGED, head CHANGELOG.md with entries under ## named, commit that titled title, test it with ci.sh, then tag it v and push the tag.""" - tag = f"v{named}" - worktree = pathlib.Path(tempfile.mkdtemp(prefix="deploy-release-")) / "patch" - try: - if isinstance(added := git("worktree", "add", "--quiet", "--detach", str(worktree), base, cwd=clone), Failure): - return added - for commit in commits: - if isinstance(applied := apply_commit(clone, worktree, commit, base), Failure): +def tagged_entries(clone: str, patch: Patch) -> Failure | None: + """A Failure unless the tag an earlier run pushed lists patch's entries under its version, so a rerun with other commits doesn't merge back entries the tag doesn't ship.""" + changelog = git("show", f"v{patch.named}:CHANGELOG.md", cwd=clone) + if isinstance(changelog, Failure): + return changelog + listed = [line for line in section(changelog, re.escape(patch.named)) or [] if line.strip()] + if listed != patch.entries: + return Failure(f"origin's v{patch.named} lists other changelog entries than the commits named: name the commits it was cut from") + return None + + +def tag_patch(clone: str, patch: Patch) -> Failure | None: + """In a worktree at the base tag, apply patch's commits but for LEFT_AS_TAGGED, head CHANGELOG.md with its section, commit that titled `Cut release `, test it with ci.sh, then tag it and push the tag.""" + title, tag = f"Cut release {patch.named}", f"v{patch.named}" + with scratch_worktree(clone, patch.base) as worktree: + if isinstance(worktree, Failure): + return worktree + for commit in patch.commits: + if isinstance(applied := apply_commit(clone, worktree, commit, patch), Failure): return applied changelog = worktree / "CHANGELOG.md" - changelog.write_text(headed(changelog.read_text() if changelog.exists() else "# Changelog\n", entries, named)) + changelog.write_text(headed(changelog.read_text() if changelog.exists() else "# Changelog\n", patch.entries, patch.named)) if isinstance(committed := git("commit", "--quiet", "--all", "--message", title, cwd=str(worktree)), Failure): return committed - said(f"applied {len(commits)} commit(s) on {base}; testing them with ci.sh") - if isinstance(tested := run_ci(worktree), Failure): + said(f"applied the commits on {patch.base}; testing them with ci.sh") + if isinstance(tested := run_ci(worktree, patch.ref), Failure): return tested said("ci.sh passed") if isinstance(made := git("tag", "--annotate", "--message", title, tag, "HEAD", cwd=str(worktree)), Failure): @@ -127,9 +168,6 @@ def tag_patch(clone: str, base: str, commits: list[str], entries: list[str], nam return pushed said(f"pushed the tag {tag}") return None - finally: - git("worktree", "remove", "--force", str(worktree), cwd=clone) - shutil.rmtree(worktree.parent, ignore_errors=True) def headed(changelog: str, entries: list[str], named: str) -> str: @@ -141,22 +179,26 @@ def headed(changelog: str, entries: list[str], named: str) -> str: return changelog[:first.start()] + added + "\n" + changelog[first.start():] -def apply_commit(clone: str, worktree: pathlib.Path, commit: str, base: str) -> Failure | None: - """Apply commit's change, but for LEFT_AS_TAGGED, to worktree's index and files, merging three ways where the tag base's files differ from commit's parent.""" +def apply_commit(clone: str, worktree: pathlib.Path, commit: str, patch: Patch) -> Failure | None: + """Apply commit's change, but for LEFT_AS_TAGGED, to worktree's index and files, merging three ways where the base tag's files differ from commit's parent.""" diff = git("diff", "--binary", f"{commit}^", commit, "--", ".", *(f":(exclude){path}" for path in LEFT_AS_TAGGED), cwd=clone) if isinstance(diff, Failure): return diff if not diff: return None - patch = worktree.parent / "commit.patch" - patch.write_text(diff) - if isinstance(applied := git("apply", "--3way", "--index", str(patch), cwd=str(worktree)), Failure): + patch_file = worktree.parent / "commit.patch" + patch_file.write_text(diff) + if isinstance(applied := git("apply", "--3way", "--index", str(patch_file), cwd=str(worktree)), Failure): subject = git("log", "-1", "--format=%s", commit, cwd=clone) - return Failure(f"{commit[:12]} ({'' if isinstance(subject, Failure) else subject.strip()}) doesn't apply on {base}: {applied.reason}. Cut this patch by hand.") + return Failure( + f"{commit[:12]} ({'' if isinstance(subject, Failure) else subject.strip()}) doesn't apply on {patch.base}: {applied.reason}. " + f"Cut the patch by hand: on {patch.base}, apply the fix and add CHANGELOG.md's ## {patch.named} section, commit that titled `Cut release {patch.named}`, " + f"tag it v{patch.named}, annotated with that title, and push the tag. A rerun then merges it back and deploys it." + ) return None -def run_ci(worktree: pathlib.Path) -> Failure | None: +def run_ci(worktree: pathlib.Path, ref: str) -> Failure | None: """None where the patch's ci.sh passes on its committed head; a Failure with the end of its output where it fails.""" if not (worktree / "ci.sh").exists(): return Failure("the patch holds no ci.sh to test it with") @@ -164,31 +206,25 @@ def run_ci(worktree: pathlib.Path) -> Failure | None: if ran.returncode == 0: return None tail = "\n".join((ran.stdout + ran.stderr).strip().splitlines()[-30:]) - return Failure(f"ci.sh failed on the patch, so nothing is tagged:\n{tail}") + return Failure(f"ci.sh failed on the patch, so nothing is tagged. Fix it on {ref}, then rerun naming the fix's commits too. The end of its output:\n{tail}") -def push_merge_back(clone: str, ref: str, branch: str, tag: str, named: str, entries: list[str], replacing: str | None) -> Failure | None: - """On ref, merge tag keeping ref's files, with entries moved from ## Unreleased to a ## named section after it, in a worktree of its own; push that as branch: a new one, or in place of replacing, the commit origin's branch points at.""" - worktree = pathlib.Path(tempfile.mkdtemp(prefix="deploy-release-")) / "merge-back" - try: - if isinstance(added := git("worktree", "add", "--quiet", "--detach", str(worktree), ref, cwd=clone), Failure): - return added - if isinstance(merged := git("merge", "--quiet", "--no-ff", "--no-commit", "--strategy", "ours", tag, cwd=str(worktree)), Failure): +def push_merge_back(clone: str, patch: Patch, replacing: str | None) -> Failure | None: + """On origin's main, merge the patch's tag keeping main's files, move its entries from ## Unreleased to a ## section below ## Unreleased, and push that as the branch release-, replacing the commit origin's branch points at, where there is one.""" + with scratch_worktree(clone, patch.ref) as worktree: + if isinstance(worktree, Failure): + return worktree + if isinstance(merged := git("merge", "--quiet", "--no-ff", "--no-commit", "--strategy", "ours", f"v{patch.named}", cwd=str(worktree)), Failure): return merged changelog = worktree / "CHANGELOG.md" - changelog.write_text(moved_entries(changelog.read_text(), entries, named)) - if isinstance(committed := git("commit", "--quiet", "--all", "--message", f"Merge release {named} into main", cwd=str(worktree)), Failure): + changelog.write_text(moved_entries(changelog.read_text(), patch.entries, patch.named)) + if isinstance(committed := git("commit", "--quiet", "--all", "--message", f"Merge release {patch.named} into main", cwd=str(worktree)), Failure): return committed - lease = [f"--force-with-lease=refs/heads/{branch}:{replacing}"] if replacing else [] - pushed = git("push", "--quiet", *lease, "origin", f"HEAD:refs/heads/{branch}", cwd=str(worktree)) - return pushed if isinstance(pushed, Failure) else None - finally: - git("worktree", "remove", "--force", str(worktree), cwd=clone) - shutil.rmtree(worktree.parent, ignore_errors=True) + return push_branch(worktree, f"release-{patch.named}", replacing) def moved_entries(changelog: str, entries: list[str], named: str) -> str: - """changelog with entries taken out of its ## Unreleased section and put in a ## named section right after it.""" + """changelog with entries taken out of its ## Unreleased section and put in a ## named section right below that section.""" lines = changelog.split("\n") start = next(index for index, line in enumerate(lines) if re.fullmatch(f"## {UNRELEASED_TITLE}", line)) end = next((index for index in range(start + 1, len(lines)) if lines[index].startswith("## ")), len(lines)) diff --git a/bin/deploy_release/test_deploy_release.py b/bin/deploy_release/test_deploy_release.py index e10e8e04..8ed6f5d8 100644 --- a/bin/deploy_release/test_deploy_release.py +++ b/bin/deploy_release/test_deploy_release.py @@ -508,7 +508,7 @@ class Cut(unittest.TestCase): self.assertEqual(ran.returncode, 0, ran.stderr) self.assertEqual(self.origin_git("show", "v0.1.1:tool.txt"), "fixed\n") - def test_refuses_changing_nothing_where_the_plan_names_no_patch_release(self): + def test_refuses_before_any_change_where_the_plan_names_no_patch_release(self): self.commit({"tool.txt": "fixed\n", "CHANGELOG.md": "# Changelog\n\n## Unreleased\n\n- Second.\n- Fixed.\n\n## 0.1.0\n\n- First.\n"}, "Fix tool.txt") self.git(self.clone, "push", "-q", "origin", "main") ran = self.cut_patch("HEAD") @@ -517,7 +517,7 @@ class Cut(unittest.TestCase): self.assertEqual(self.origin_git("tag", "-l", "v0.1.1"), "") self.assertEqual(self.forge_state()["pulls"], []) - def test_refuses_changing_nothing_while_the_patch_release_holds_an_item(self): + def test_refuses_before_any_change_while_the_patch_release_holds_an_item(self): self.plan_patch() self.commit({"todo.md": TODO + ROW.format(id=2, release="0.3.0") + ROW.format(id=4, release="0.1.1")}, "File item 4") self.git(self.clone, "push", "-q", "origin", "main") @@ -532,16 +532,64 @@ class Cut(unittest.TestCase): ran = self.cut_patch(self.plan_patch()) self.assertEqual(ran.returncode, 0, ran.stderr) - def test_refuses_a_commit_the_tag_holds_or_origins_main_doesnt(self): + def test_refuses_a_commit_the_tag_holds(self): self.plan_patch() - for commit in ("v0.1.0", "HEAD"): - if commit == "HEAD": - self.commit({"tool.txt": "local\n"}, "Unpushed") - ran = self.cut_patch(commit) - self.assertEqual(ran.returncode, 1, commit) - self.assertIn(self.git(self.clone, "rev-parse", "--short", f"{commit}^{{commit}}").strip()[:7], ran.stderr) + ran = self.cut_patch("v0.1.0") + self.assertEqual(ran.returncode, 1) + self.assertIn(self.git(self.clone, "rev-parse", "v0.1.0^{commit}")[:12] + " is in v0.1.0 already", ran.stderr) self.assertEqual(self.origin_git("tag", "-l", "v0.1.1"), "") + def test_refuses_a_commit_origins_main_doesnt_hold(self): + self.plan_patch() + self.commit({"tool.txt": "local\n"}, "Unpushed") + ran = self.cut_patch("HEAD") + self.assertEqual(ran.returncode, 1) + self.assertIn(self.git(self.clone, "rev-parse", "HEAD")[:12] + " isn't on origin/main", ran.stderr) + self.assertEqual(self.origin_git("tag", "-l", "v0.1.1"), "") + + def test_leaves_out_the_commits_a_merge_of_main_brought_into_the_chunk(self): + self.commit({"todo.md": TODO + ROW.format(id=2, release="0.3.0") + ROW.format(id=3, release="0.1.1")}, "File item 3") + base = self.git(self.clone, "rev-parse", "HEAD").strip() + self.commit({"feature.txt": "new\n"}, "Add a feature") + self.git(self.clone, "switch", "-q", "-c", "chunk", base) + self.git(self.clone, "merge", "-q", "--no-ff", "-m", "Sync with main", "main") + self.commit({"tool.txt": "fixed\n", "todo.md": TODO + ROW.format(id=2, release="0.3.0"), "CHANGELOG.md": "# Changelog\n\n## Unreleased\n\n- Second.\n- Fixed.\n\n## 0.1.0\n\n- First.\n"}, "Fix item 3") + head = self.git(self.clone, "rev-parse", "HEAD").strip() + self.git(self.clone, "switch", "-q", "main") + self.git(self.clone, "merge", "-q", "--ff-only", "chunk") + self.git(self.clone, "push", "-q", "origin", "main") + ran = self.cut_patch(f"{base}..{head}") + self.assertEqual(ran.returncode, 0, ran.stderr) + self.assertNotIn("feature.txt", self.origin_git("ls-tree", "--name-only", "v0.1.1")) + self.assertEqual(self.origin_git("show", "v0.1.1:tool.txt"), "fixed\n") + + def test_says_which_commits_the_patch_ships_before_it_applies_them(self): + ran = self.cut_patch(self.plan_patch()) + self.assertEqual(ran.returncode, 0, ran.stderr) + self.assertIn("deploy-release: ships " + self.git(self.clone, "log", "-1", "--format=%h %s", "HEAD").strip(), ran.stderr) + self.assertNotIn("Add a feature", ran.stderr) + + def test_refuses_on_a_github_origin_whose_merge_would_drop_the_tag_from_main(self): + commits = self.plan_patch() + self.use_github() + ran = self.cut_patch(commits) + self.assertEqual(ran.returncode, 1) + self.assertIn("GitHub", ran.stderr) + self.assertEqual(self.forge_state()["calls"], []) + self.assertEqual(self.origin_git("tag", "-l", "v0.1.1"), "") + + def test_a_rerun_refuses_a_pushed_tag_cut_from_other_commits(self): + self.set_checks("failure") + commits = self.plan_patch() + self.assertEqual(self.cut_patch(commits).returncode, 1) + self.commit({"tool.txt": "fixed twice\n", "CHANGELOG.md": "# Changelog\n\n## Unreleased\n\n- Second.\n- Fixed.\n- Fixed twice.\n\n## 0.1.0\n\n- First.\n"}, "Fix item 3 again") + self.git(self.clone, "push", "-q", "origin", "main") + self.set_checks("success") + ran = self.cut_patch("HEAD") + self.assertEqual(ran.returncode, 1) + self.assertIn("other changelog entries", ran.stderr) + self.assertNotIn("Fixed twice", self.origin_git("show", "main:CHANGELOG.md").split("## 0.1.0")[0].split("## Unreleased")[0]) + def test_refuses_commits_that_add_no_changelog_entry_under_unreleased(self): self.plan_patch() self.commit({"tool.txt": "fixed again\n"}, "Fix more") @@ -593,7 +641,7 @@ class Cut(unittest.TestCase): self.assertIn("usage", ran.stderr) self.assertEqual(self.forge_state()["calls"], []) - def test_takes_no_option_but_cut(self): + def test_refuses_an_option_it_does_not_know(self): ran = subprocess.run([sys.executable, str(TOOL), "--cut", "--force"], capture_output=True, cwd=self.clone, env=self.env, text=True) self.assertEqual(ran.returncode, 1) self.assertIn("usage", ran.stderr) @@ -618,7 +666,7 @@ class PatchChangelog(unittest.TestCase): def test_heads_the_tags_changelog_with_the_patchs_section(self): self.assertEqual(patch.headed("# Changelog\n\n## 0.1.0\n\n- First.\n", ["- Fixed.", "- Also."], "0.1.1"), "# Changelog\n\n## 0.1.1\n\n- Fixed.\n- Also.\n\n## 0.1.0\n\n- First.\n") - def test_ends_a_changelog_with_no_section_with_the_patchs_section(self): + def test_appends_the_patchs_section_to_a_changelog_without_sections(self): self.assertEqual(patch.headed("# Changelog\n\nFor Linux and macOS X\n\n", ["- Fixed."], "0.1.1"), "# Changelog\n\nFor Linux and macOS X\n\n## 0.1.1\n\n- Fixed.\n") def test_moves_the_patchs_entries_from_unreleased_to_a_section_after_it(self): diff --git a/bin/release_plan/release_standing.py b/bin/release_plan/release_standing.py index 427b5371..e4ef5bc8 100644 --- a/bin/release_plan/release_standing.py +++ b/bin/release_plan/release_standing.py @@ -138,14 +138,15 @@ def heading_commit(release: Release, ref: str, changelog: stores.RecordStore, cw def release_reviewed(tag: str | None, ref: str, cwd: str, titles: templates.Titles, after: Release | None = None, run: Git = git) -> bool | Failure: """Whether ref holds a commit titled as a release review opens, `Release review of `: after tag, or anywhere where tag is None. A title that names no version, such as an epic's `Release review of ABC-12` (do_epic/finish.py), reviews no release. - titles holds the project's title templates, and each commit title is read as the summary they give. after is the version a branch with no tag counts as cut, or None. Where it is given, a title counts only where its release is later than after. + titles holds the project's title templates, and each commit title is read as the summary they give. after is the version a branch with no tag counts as cut, or None. A title counts only where its release is later than after, or than tag's version where after is None. A patch release cut beside the default branch and merged back leaves on ref, after its tag, the review of that patch, which reviews no later release. """ log = run("log", "--format=%s", f"{tag}..{ref}" if tag else ref, cwd=cwd) if isinstance(log, Failure): return log summaries = [titles.summary(line) for line in log.splitlines()] reviews = [summary.removeprefix("Release review of ") for summary in summaries if summary.startswith("Release review of ")] - return any((named := parsed(review)) is not None and (after is None or named > after) for review in reviews) + floor = after if after is not None else tagged(tag) + return any((named := parsed(review)) is not None and (floor is None or named > floor) for review in reviews) def todos_since(tag: str | None | Failure, ref: str, plan: str | None, cwd: str, run: Git = git) -> list[str] | Failure: diff --git a/bin/release_plan/test_release_standing.py b/bin/release_plan/test_release_standing.py index 36c52749..349f5854 100644 --- a/bin/release_plan/test_release_standing.py +++ b/bin/release_plan/test_release_standing.py @@ -236,6 +236,24 @@ class ChunkItem(unittest.TestCase): self.assertIs(release_standing.project_plan(dataclasses.replace(config, commit_title="PAY-{id} - {summary}"), "main", repo).cut.reviewed, True) self.assertIs(release_standing.project_plan(dataclasses.replace(config, pull_request_title="PAY-{id} - {summary}"), "main", repo).cut.reviewed, True) + def test_counts_no_release_review_of_the_patch_release_cut_beside_main_as_a_review_of_the_next(self): + repo = tempfile.mkdtemp() + self.addCleanup(subprocess.run, ["rm", "-rf", repo]) + run = lambda *args: subprocess.run(["git", "-c", "user.name=t", "-c", "user.email=t@t", *args], capture_output=True, check=True, cwd=repo, env=isolated_env(), text=True) + run("init", "-q", "-b", "main") + run("commit", "-q", "--allow-empty", "-m", "Cut release 0.15.1") + run("tag", "v0.15.1") + run("commit", "-q", "--allow-empty", "-m", "Release review of 0.15.2") + run("switch", "-q", "--detach", "v0.15.1") + run("commit", "-q", "--allow-empty", "-m", "Cut release 0.15.2") + run("tag", "v0.15.2") + run("switch", "-q", "main") + run("merge", "-q", "--strategy", "ours", "--no-ff", "-m", "Merge release 0.15.2 into main", "v0.15.2") + # v0.15.2..main holds the review, which reviewed 0.15.2 itself, so 0.16.0 still waits for its own. + self.assertIs(release_standing.release_reviewed("v0.15.2", "main", repo, BARE), False) + run("commit", "-q", "--allow-empty", "-m", "Release review of 0.16.0") + self.assertIs(release_standing.release_reviewed("v0.15.2", "main", repo, BARE), True) + def test_counts_no_release_review_of_a_release_cut_under_a_dated_heading_on_a_branch_with_no_tag(self): repo = tempfile.mkdtemp() self.addCleanup(subprocess.run, ["rm", "-rf", repo]) diff --git a/docs/decisions.md b/docs/decisions.md index 17e09a93..2442b5a4 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -150,11 +150,11 @@ The cap is 5, `bin/plan/todo_table.py`'s `BUNDLE_MAX_R`, from the same chunks: b Valid while `~/.claude` is a checkout of this repo. -## deploy: `deploy-release --cut` cuts a release through a pull request merged fast-forward only, then tags the merged commit and moves `~/.claude` to it; the human runs it +## deploy: `deploy-release --cut` cuts a release through a pull request merged fast-forward only, then tags the merged commit and moves `~/.claude` to it, and `--cut-patch` tags a patch of the newest tag beside `main`, then merges the tag back; the human runs both 2026-11-08, lilleman, todo item 271. Serves goal 1.5 and goal 2. Nobody can push to `main` on the remote, and it merges only by fast-forward, so a cut that commits on `main` and pushes no longer works. The tool cuts only the release `chunk-preflight` would call ready to cut, through `bin/release_plan/release_standing.py`, so the two never disagree on which release is next or whether it is ready; the version is that release's, never the tool's choice. It builds the cut commit in a worktree of its own, so the clone's checkout stays as it is. It finds the merged commit on `main` by its title, `Cut release `, since GitHub's nearest merge, a rebase merge, may give the commit a new hash. It takes only a pull request from origin's own branch whose head is the commit that branch points at, and has the forge merge it only while its head is still that commit, so a fork's pull request from a branch of the same name, or a push after the checks passed, is never merged and deployed. Each step first checks whether an earlier run did it, so a rerun continues. Releases stay the human's, so the human runs it, and the forge credentials stay theirs. Valid while `main` takes changes only through a pull request. -2026-11-24, todo item 536. `deploy-release --cut-patch ` cuts the newest tag's next patch release, holding only the commits named, for a fix that must ship before `main`'s other unreleased work, as 0.15.1 did by hand. Its commit sits on the tag, not on `main`, so no pull request can merge it, and CI runs only on pull requests: the tool runs `ci.sh` on it, as CI does, before it tags. Then it merges the tag back into `main` with `-s ours` through a pull request, so the tag is in `main`'s history, where the next cut and `chunk-preflight` read it. A patch skips the release review: it holds only fixes, and the review reads the whole project. `chunk-preflight` still calls that review due until the patch is cut, so cut a patch as soon as its fix merges. Plain `--cut` refuses a patch of the newest tag, since it would ship all of `main` under a patch number. +2026-11-24, lilleman, todo item 536. `deploy-release --cut-patch ` cuts the newest tag's next patch release, holding only the commits named, for a fix that must ship before `main`'s other unreleased work. Before it, 0.15.1 was cut by those steps by hand. The patch's commit has the tag as its parent, not `main`'s head, so no pull request into `main` can merge it, and CI runs only on pull requests: the tool runs `ci.sh` on it, as CI does, before it tags. Then it merges the tag back into `main` with `-s ours` through a pull request, so the tag is in `main`'s history, where the next cut and `chunk-preflight` read it, and a release review on `main` counts only for a release later than the last cut. GitHub's rebase merge would drop that merge commit, so the tool refuses a GitHub origin. A patch skips the release review: `chunk-preflight` still calls it due until the patch is cut, so cut a patch as soon as its fix merges. Plain `--cut` refuses a patch of the newest tag, since it would ship all of `main` under a patch number. A panel of three readers seated as the owner picked the spelling `--cut-patch` over `--cut --patch` and `--hotfix`: one flag that names the action, which can't be read as a plain `--cut`. ## do-epic: drives one Jira epic whose items span repos, or have none, ranked by the epic's goals, then code health, then each repo's goals, and closes the epic only once the human confirms every goal diff --git a/todo.md b/todo.md index 0ec382db..bb1fd1cc 100644 --- a/todo.md +++ b/todo.md @@ -128,22 +128,22 @@ Touches: Today a fix that must ship before `main`'s other unreleased work is cut by hand, as 0.15.1 was: branch off the newest tag, apply only the fix's code, write the changelog section, commit `Cut release `, tag and push, then merge the tag back into `main` with `-s ours` through a pull request, so the tag is an ancestor of `main`, and run a bare `deploy-release`. `deploy-release --cut` can't, since it cuts all of `main`. -`deploy-release --cut-patch []`, run in the development clone, does those steps. A reader panel picked the spelling over `--cut --patch` and `--hotfix`: one flag that names the action and can't be read as a plain `--cut`. +`deploy-release --cut-patch []`, run in the development clone, does those steps; `docs/decisions.md` → "deploy: `deploy-release --cut` cuts a release …" says why it is spelled so. - **Version:** the newest tag's next patch, such as 0.15.2 after v0.15.1. The plan must name that release, and it must hold no item, as `--cut` checks. A patch skips the release review: it holds only fixes, and the review is of the whole project. - **Commits:** one revision as `git log` reads it, such as `794ce37..1aa2367`, which follows git's `..` and leaves out the first commit, or one commit. Each must be on `origin/main` and not on the tag. Merge commits are skipped. - **Patch:** in a worktree of its own, at the tag, it applies each commit's changes except to `todo.md`, `CHANGELOG.md` and the records every chunk writes. The changelog section is the bullets the commits add under `## Unreleased`. It commits `Cut release `, runs `ci.sh` on it, and stops where that fails. Then it tags and pushes the tag. - **Merge-back:** a branch `release-` off `origin/main` merges the tag with `-s ours` and moves those bullets under `## `, and goes through a pull request as `--cut`'s branch does. -- **Rerun:** a step an earlier run finished is skipped: a tag on origin, a tag `main` holds. +- **Rerun:** it takes a tag origin holds, once the tag lists the same changelog entries, and the merge-back's open pull request. - **Plain `--cut`** refuses a patch release and names `--cut-patch`, since it would ship all of `main` under a patch number. Touches: +- `README.md`: `## Release`, `## Tools` (small) +- `bin/deploy_release/cut.py`: `cut`, `land`, `push_cut_commit`, `ready_release` - `bin/deploy_release/main.py`: `main` -- `bin/deploy_release/cut.py`: `cut`, `ready_release`, `land`, `push_cut_commit` - `bin/deploy_release/patch.py` - `bin/deploy_release/release_pull.py`: `create_pull` (small) - `bin/deploy_release/test_deploy_release.py`: `Cut` -- `README.md`: `## Release`, `## Tools` (small) ### 524. Write fejkdata's first six bench features, each a spec, acceptance tests in Go and a reference patch that builds it, in the `bench-tasks` folder its config names. @@ -322,7 +322,7 @@ Name the entry and the Dockerfile line. Source the secret-name list from a widel Found while shipping item 461: `mutate-changes` printed `23 mutants on changed lines, 18 not killed. Left out the tests that fail without a mutant, in do_epic/test_main.py, larv_review/test_larv_review.py, larv_review/test_scoring_setup.py, plan/test_ranking.py, repo_checks/…, review_rules/test_review_passes.py, review_rules/test_reviewer_context.py, rule_hook/test_rule_hook.py, test_settings_filter.py`. All 18 survivors were in `bin/larv_review/scoring_setup.py`: `prepare_scoring`, whose tests are among those left out, so the chunk checked four of them by hand and left 14 unchecked. Find why each left-out test fails in mutmut's copy, such as a path to `skills/` or a git checkout it expects, and make it pass there, or report under the count which changed lines no remaining test covers. -Item 536 met it too: `deploy_release/test_deploy_release.py`, which runs `deploy-release` as a subprocess, fails there, so none of 597 mutants of `bin/deploy_release/` was checked. +Item 536 met the same gap: `deploy_release/test_deploy_release.py` runs `deploy-release` as a subprocess, and those tests fail in mutmut's copy, so only its in-process tests ran, and 530 of 590 mutants of `bin/deploy_release/` went unchecked. Touches `bin/mutate_changes/`, and the tests named above. -- 2.52.0 From 010be0c9e75c9a0dffe9830500be0544eac5f04d Mon Sep 17 00:00:00 2001 From: Lilleman Date: Tue, 24 Nov 2026 15:12:17 +0100 Subject: [PATCH 10/13] =?UTF-8?q?Answer=20product-owner=20round=201:=200?= =?UTF-8?q?=20=F0=9F=94=B4,=203=20=F0=9F=9F=A1=20(0=20misread);=20a=20patc?= =?UTF-8?q?h's=20review=20no=20longer=20counts=20for=20the=20next=20releas?= =?UTF-8?q?e,=20the=20help=20says=20what=20a=20rerun=20does,=20and=20the?= =?UTF-8?q?=20cut=20lists=20the=20commits=20it=20ships,=20in=20the=20stabi?= =?UTF-8?q?lity=20answer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From 0a38f99a8d79888270ddab9ba470508e2d4ab1e9 Mon Sep 17 00:00:00 2001 From: Lilleman Date: Tue, 24 Nov 2026 15:12:17 +0100 Subject: [PATCH 11/13] =?UTF-8?q?Answer=20prose=20round=201:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=207=20=F0=9F=9F=A1=20(0=20misread);=20true=20reru?= =?UTF-8?q?n=20and=20range=20text,=20clearer=20refusals=20and=20test=20nam?= =?UTF-8?q?es,=20and=20the=20decision=20names=20its=20choices,=20in=20the?= =?UTF-8?q?=20stability=20answer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From a1e6791cdb59cc0cca2fcfc0e67d1c2b657ce93c Mon Sep 17 00:00:00 2001 From: Lilleman Date: Tue, 24 Nov 2026 15:35:08 +0100 Subject: [PATCH 12/13] =?UTF-8?q?Answer=20stability=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1=20(0=20misread);=20the=20hand-?= =?UTF-8?q?cut=20steps=20and=20the=20reused=20tag's=20refusal=20list=20the?= =?UTF-8?q?=20exact=20entries,=20and=20a=20hand=20cut=20reruns=20to=20the?= =?UTF-8?q?=20end?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/deploy_release/patch.py | 7 ++++--- bin/deploy_release/test_deploy_release.py | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/bin/deploy_release/patch.py b/bin/deploy_release/patch.py index 5e31b394..4f349905 100644 --- a/bin/deploy_release/patch.py +++ b/bin/deploy_release/patch.py @@ -139,7 +139,7 @@ def tagged_entries(clone: str, patch: Patch) -> Failure | None: return changelog listed = [line for line in section(changelog, re.escape(patch.named)) or [] if line.strip()] if listed != patch.entries: - return Failure(f"origin's v{patch.named} lists other changelog entries than the commits named: name the commits it was cut from") + return Failure(f"origin's v{patch.named} lists other changelog entries under ## {patch.named} than the commits named added under ## Unreleased. The tag lists:\n" + "\n".join(listed) + "\nThe commits added:\n" + "\n".join(patch.entries)) return None @@ -192,8 +192,9 @@ def apply_commit(clone: str, worktree: pathlib.Path, commit: str, patch: Patch) subject = git("log", "-1", "--format=%s", commit, cwd=clone) return Failure( f"{commit[:12]} ({'' if isinstance(subject, Failure) else subject.strip()}) doesn't apply on {patch.base}: {applied.reason}. " - f"Cut the patch by hand: on {patch.base}, apply the fix and add CHANGELOG.md's ## {patch.named} section, commit that titled `Cut release {patch.named}`, " - f"tag it v{patch.named}, annotated with that title, and push the tag. A rerun then merges it back and deploys it." + f"Cut the patch by hand: on {patch.base}, apply the fix and add a ## {patch.named} section to CHANGELOG.md, commit that titled `Cut release {patch.named}`, " + f"tag it v{patch.named}, annotated with that title, and push the tag. A rerun with the same commits then merges it back and deploys it, " + f"where the section holds exactly these lines:\n" + "\n".join(patch.entries) ) return None diff --git a/bin/deploy_release/test_deploy_release.py b/bin/deploy_release/test_deploy_release.py index 8ed6f5d8..c8d2499e 100644 --- a/bin/deploy_release/test_deploy_release.py +++ b/bin/deploy_release/test_deploy_release.py @@ -578,6 +578,24 @@ class Cut(unittest.TestCase): self.assertEqual(self.forge_state()["calls"], []) self.assertEqual(self.origin_git("tag", "-l", "v0.1.1"), "") + def test_a_rerun_merges_back_and_deploys_a_patch_cut_by_hand_as_the_refusal_says(self): + self.commit({"tool.txt": "half fixed\n"}, "Change tool.txt on main") + commits = self.plan_patch() + refused = self.cut_patch(commits) + self.assertEqual(refused.returncode, 1) + self.assertIn("exactly these lines:\n- Fixed.", refused.stderr) + self.git(self.clone, "switch", "-q", "--detach", "v0.1.0") + self.commit({"tool.txt": "fixed\n", "CHANGELOG.md": "# Changelog\n\n## 0.1.1\n\n- Fixed.\n\n## 0.1.0\n\n- First.\n"}, "Cut release 0.1.1") + self.git(self.clone, "tag", "-a", "v0.1.1", "-m", "Cut release 0.1.1") + self.git(self.clone, "push", "-q", "origin", "v0.1.1") + self.git(self.clone, "switch", "-q", "main") + tagged = self.origin_git("rev-parse", "v0.1.1^{commit}") + ran = self.cut_patch(commits) + self.assertEqual(ran.returncode, 0, ran.stderr) + self.assertEqual(self.origin_git("rev-parse", "v0.1.1^{commit}"), tagged) + self.origin_git("merge-base", "--is-ancestor", "v0.1.1", "main") + self.assertEqual(self.git(self.target, "describe", "--tags", "--exact-match", "HEAD").strip(), "v0.1.1") + def test_a_rerun_refuses_a_pushed_tag_cut_from_other_commits(self): self.set_checks("failure") commits = self.plan_patch() @@ -587,7 +605,7 @@ class Cut(unittest.TestCase): self.set_checks("success") ran = self.cut_patch("HEAD") self.assertEqual(ran.returncode, 1) - self.assertIn("other changelog entries", ran.stderr) + self.assertIn("The tag lists:\n- Fixed.\nThe commits added:\n- Fixed twice.", ran.stderr) self.assertNotIn("Fixed twice", self.origin_git("show", "main:CHANGELOG.md").split("## 0.1.0")[0].split("## Unreleased")[0]) def test_refuses_commits_that_add_no_changelog_entry_under_unreleased(self): -- 2.52.0 From a38dad4a6cfe0408fbbcf1f35b14654a54f80e21 Mon Sep 17 00:00:00 2001 From: Lilleman Date: Tue, 24 Nov 2026 15:38:23 +0100 Subject: [PATCH 13/13] Finish item 536 in the plan --- CHANGELOG.md | 1 + todo.md | 22 ---------------------- 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b405a0b3..6475fcf4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- `deploy-release --cut-patch ` cuts the newest tag's next patch release, such as 0.15.2 after v0.15.1, holding only the commits named, for a fix that must ship before main's other unreleased work. It runs `ci.sh` on the patch, tags and pushes it, merges the tag back into main through a pull request, and moves `~/.claude` to it. Plain `--cut` now refuses a patch release, and a release review counts only for a release later than the last cut. - `task-bench` plants bugs in Rust files too, from the mutants cargo-mutants catches, and tells Haiku the panic message `cargo test` prints. - `task-bench --tasks shipped-features` benches rebuilding features the project shipped: it takes each one's change out of the code, tells Haiku the tagline of its plan item, and checks the build with the tests that change holds. `--shipped ` sets how many it takes, and a feature whose branch landed by fast-forward is passed over. - `task-bench` plants a Python mutant in a file whose lines end in CRLF, which it could not re-apply before, and a Go mutant there keeps applying. diff --git a/todo.md b/todo.md index bb1fd1cc..21640c83 100644 --- a/todo.md +++ b/todo.md @@ -13,7 +13,6 @@ | ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score | |---|---|---|---|---|---|---|---|---|---|---|---| | 531 | 0.16.0 | | | **Bench the shipped features of a branch that landed by fast-forward: take as the feature the commits from the one after the item finished before it, up to the commit that took its item out of the plan.** | 2 | 2 | 1 | 3 | 3 | 1.1 by 3 | 1.1 | -| 536 | 0.16.0 | | owner | **Cut a patch release with `deploy-release --cut-patch `: the newest tag plus only the commits named, tested with `ci.sh`, tagged, merged back into main and deployed.** | 3 | 2 | 2 | 5 | 5 | 1.5 by 3 | 0.6 | | 524 | 0.16.0 | | owner | **Write fejkdata's first six bench features, each a spec, acceptance tests in Go and a reference patch that builds it, in the `bench-tasks` folder its config names.** | 3 | 2 | 1 | 4 | 6 | 1.1 by 3 | 0.5 | | 532 | 0.16.0 | | | **Leave out of a `task-bench` fix a change Haiku makes to a Rust test that stands in the file of the code it tests.** | 2 | 2 | 1 | 3 | 3 | 1.1 by 1 | 0.4 | | 527 | 0.16.0 | | owner | **Plant bugs for `task-bench` in TypeScript, from the mutants Stryker kills.** | 3 | 2 | 1 | 4 | 4 | 1.1 by 1 | 0.3 | @@ -124,27 +123,6 @@ Touches: - `bin/task_bench/main.py`: `(module)` (small) - `README.md`: `## Tools` (small) -### 536. Cut a patch release with `deploy-release --cut-patch `: the newest tag plus only the commits named, tested with `ci.sh`, tagged, merged back into main and deployed. - -Today a fix that must ship before `main`'s other unreleased work is cut by hand, as 0.15.1 was: branch off the newest tag, apply only the fix's code, write the changelog section, commit `Cut release `, tag and push, then merge the tag back into `main` with `-s ours` through a pull request, so the tag is an ancestor of `main`, and run a bare `deploy-release`. `deploy-release --cut` can't, since it cuts all of `main`. - -`deploy-release --cut-patch []`, run in the development clone, does those steps; `docs/decisions.md` → "deploy: `deploy-release --cut` cuts a release …" says why it is spelled so. - -- **Version:** the newest tag's next patch, such as 0.15.2 after v0.15.1. The plan must name that release, and it must hold no item, as `--cut` checks. A patch skips the release review: it holds only fixes, and the review is of the whole project. -- **Commits:** one revision as `git log` reads it, such as `794ce37..1aa2367`, which follows git's `..` and leaves out the first commit, or one commit. Each must be on `origin/main` and not on the tag. Merge commits are skipped. -- **Patch:** in a worktree of its own, at the tag, it applies each commit's changes except to `todo.md`, `CHANGELOG.md` and the records every chunk writes. The changelog section is the bullets the commits add under `## Unreleased`. It commits `Cut release `, runs `ci.sh` on it, and stops where that fails. Then it tags and pushes the tag. -- **Merge-back:** a branch `release-` off `origin/main` merges the tag with `-s ours` and moves those bullets under `## `, and goes through a pull request as `--cut`'s branch does. -- **Rerun:** it takes a tag origin holds, once the tag lists the same changelog entries, and the merge-back's open pull request. -- **Plain `--cut`** refuses a patch release and names `--cut-patch`, since it would ship all of `main` under a patch number. - -Touches: -- `README.md`: `## Release`, `## Tools` (small) -- `bin/deploy_release/cut.py`: `cut`, `land`, `push_cut_commit`, `ready_release` -- `bin/deploy_release/main.py`: `main` -- `bin/deploy_release/patch.py` -- `bin/deploy_release/release_pull.py`: `create_pull` (small) -- `bin/deploy_release/test_deploy_release.py`: `Cut` - ### 524. Write fejkdata's first six bench features, each a spec, acceptance tests in Go and a reference patch that builds it, in the `bench-tasks` folder its config names. The second part of item 504, which says what a bench feature is and when a run counts. A stronger model than the project's writes the six, once. Each breaks one of fejkdata's goals while it would suit another audience: -- 2.52.0