From 2310b92cab47a1132d49ac55cb0ab0195f3cf6db Mon Sep 17 00:00:00 2001 From: leemour Date: Tue, 24 Nov 2026 02:36:13 +0100 Subject: [PATCH] fix(release): keep a published section and collect changes/ fragments (#706) When npm already had the version in package.json, bin/release renamed that version's CHANGELOG section to the next number, so the published section lost its heading. Now a published section keeps it: the new version takes the Unreleased section, or a new section that the changes/ fragments fill. With neither (or an empty Unreleased section), the release stops. - Fragments are collected with `cli-dev changelog fragments --collect` and the version is raised with `cli-dev changelog level`, as in the CLIs. - A version npm has starts from its next patch; the entries decide the level, so 1.0.0 plus a fix is 1.0.1, not 2.0.0. - A published pre-release with fragments stops: raise the version first. - package.json and the CHANGELOG are both checked before either is written, and a refusal restores the tree. - --major is checked before any version lands on main. - Fragments merged while the release pull request waited are collected by a second run. - scripts/release.test.ts runs bin/release against a local origin with fake npm and gh. Fixes #706 Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 4 +- bin/release | 148 ++++++++++++++++---- changes/fix-release-fold-fragments.md | 9 ++ docs/dev/CONVENTIONS.md | 5 +- docs/dev/RELEASING.md | 21 ++- scripts/release.test.ts | 190 ++++++++++++++++++++++++++ 6 files changed, 338 insertions(+), 39 deletions(-) create mode 100644 changes/fix-release-fold-fragments.md create mode 100644 scripts/release.test.ts diff --git a/CLAUDE.md b/CLAUDE.md index 42ad5832..a39e9cb4 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -32,8 +32,8 @@ Sparse, and only *why*. The global rule in `~/.claude/CLAUDE.md` applies. Conventional commits, a branch off `main` in a worktree, a pull request. The pre-commit hook checks staged lint and secrets; no other local checks are required by default. -A change a caller can see gets a `CHANGELOG.md` entry under `## Unreleased`. Releasing is -`bin/release` on `main` — [README](README.md#releasing). +A change a caller can see gets a `CHANGELOG.md` entry under `## Unreleased`, or in a `changes/.md` fragment. +Releasing is `bin/release` on `main` — [README](README.md#releasing). ## Development check budget diff --git a/bin/release b/bin/release index ebe2c41c..73a29fc2 100755 --- a/bin/release +++ b/bin/release @@ -1,9 +1,10 @@ #!/usr/bin/env sh # Publishes the version in package.json and tags it. Run on a clean `main`. When npm already has that -# version, or a higher one, it lands the next free version on `main` through a pull request, with the -# CHANGELOG heading renamed to match, and publishes that. An Unreleased section left above the dated, -# unpublished version is folded into it first, through a pull request too, after the last release's section is -# put back to its tag. +# version, or a higher one, it lands the next free version on `main` through a pull request and publishes that: an +# unpublished section is renamed to it, while a published one keeps its heading and the new version gets the +# Unreleased section, or a new one. The `changes/` fragments are collected into the version's section, which may then +# need a higher level. An Unreleased section left above the dated, unpublished version is folded into it first, +# through a pull request too, after the last release's section is put back to its tag. # # bin/release # publishes from GitHub Actions (.github/workflows/release.yml) # bin/release --local # publishes from this machine: the keyring entry NPM_KEYRING_ACCOUNT names, else npm's login @@ -52,24 +53,19 @@ version=$(node -p 'require("./package.json").version') published() { npm view "@wirecat/cli-base@$version" version --prefer-online >/dev/null 2>&1 } +dev() { node dist/dev/bin.js "$@"; } # A pull request checked before the last release and merged after it put its entry in that release's section; # restore moves it to Unreleased, so the fold below brings it into this version. -restored=$(pnpm build >/dev/null && node dist/dev/bin.js changelog restore --land) +restored=$(pnpm build >/dev/null && dev changelog restore --land) [ -z "$restored" ] || echo "$restored" rerun_if_changed "$@" # A session that merges after the version was dated, but before it was published, adds Unreleased above it. # --land folds on a fresh main through its own pull request, and folds again once if main moves under it. if ! published; then - folded=$(pnpm build >/dev/null && node dist/dev/bin.js changelog fold --land --version "$version") + folded=$(pnpm build >/dev/null && dev changelog fold --land --version "$version") [ -z "$folded" ] || echo "$folded" fi rerun_if_changed "$@" -# Only the top section: the rename below must never touch one that is already published. -top=$(grep -m1 '^## ' CHANGELOG.md || true) -case "$top" in - "## $version — "*) ;; - *) echo "CHANGELOG.md's top section is \"$top\" — date it as $version first" >&2; exit 1 ;; -esac # main takes changes only through a pull request (the repository's ruleset). land() { @@ -99,34 +95,128 @@ land() { git merge -q --ff-only origin/main } -# Two sessions preparing the same number is normal; the second takes the next free one (2026-09-29). +# Raises the version from $1 to $2 in package.json and the CHANGELOG heading. With $3 set, npm has $1: its section +# stays as published, and the unreleased one becomes $2 (#706). Both files are checked before either is written. +renumber() { + node -e 'const fs = require("fs"); const [o, n, taken] = process.argv.slice(1) + const swap = (file, text, from, to) => { + if (!text.includes(from)) throw new Error(`${file} has no ${JSON.stringify(from.trim())} to raise ${o} to ${n}`) + return text.replace(from, to) + } + const today = new Date().toLocaleDateString("en-GB").replaceAll("/", ".") + const pkg = swap("package.json", fs.readFileSync("package.json", "utf8"), `"version": "${o}"`, `"version": "${n}"`) + const log = fs.readFileSync("CHANGELOG.md", "utf8") + const top = log.match(/^## .*$/m)?.[0] ?? "" + const heading = `\n## ${n} — ${today}\n` + let next + if (taken && log.includes("\n## Unreleased\n")) next = swap("CHANGELOG.md", log, "\n## Unreleased\n", heading) + // With only changes/ fragments there is no Unreleased section: the new version gets an empty one they fill. + else if (taken) next = swap("CHANGELOG.md", log, "\n## ", `${heading}\n## `) + else if (top.startsWith(`## ${o} — `)) next = swap("CHANGELOG.md", log, `\n## ${o} — `, `\n## ${n} — `) + else throw new Error(`CHANGELOG.md top section is ${JSON.stringify(top)} — date it as ${o} first`) + fs.writeFileSync("package.json", pkg) + fs.writeFileSync("CHANGELOG.md", next)' "$1" "$2" "$3" +} + +# A major breaks every caller of the stable API, so it ships only when the owner chose to (WC-REL-7). Checked before +# a version lands on main, so a refused major leaves main as it was. +allow_major() { + if [ "${1%%.*}" != "${latest%%.*}" ] && [ -n "$latest" ] && [ -z "$major" ]; then + echo "$1 raises the major version over npm's $latest — run bin/release --major if that is meant" >&2 + exit 1 + fi +} + +# An Unreleased section with at least one line under it, before the next version's heading. +unreleased() { + awk '/^## /{if (u) exit; u = ($0 == "## Unreleased"); next} u && NF {found = 1; exit} END {exit !found}' CHANGELOG.md +} +fragments() { + find changes -maxdepth 1 -type f -name '*.md' ! -name README.md 2>/dev/null | wc -l +} +# The tree was clean at the start; a refusal before a version lands puts it back, so the next run is not refused. +undo() { + git checkout -q HEAD -- . +} +# land() pulls main, which may bring fragments merged while its pull request waited: they belong to this version. +rerun_if_fragments() { + [ "$(fragments)" -gt 0 ] || return 0 + echo "changes/ fragments merged while releasing — running bin/release again to collect them" + exec ./bin/release "$@" +} + +# Two sessions preparing the same number is normal; the second takes the next free one (2026-09-29). A version npm +# has starts again from its patch: the entries after it, not its own section, decide the level below. latest=$(npm view @wirecat/cli-base version --prefer-online 2>/dev/null || true) versions=$(npm view @wirecat/cli-base versions --json --prefer-online 2>/dev/null || true) -next=$(node scripts/next-version.mjs "$version" "$latest" "$versions") +taken="" +want=$version +if published; then + taken=1 + case "$version" in + *-*) ;; + *) want=$(node -p 'const [a, b, c] = process.argv[1].split(".").map(Number); `${a}.${b}.${c + 1}`' "$version") ;; + esac +fi +next=$(node scripts/next-version.mjs "$want" "$latest" "$versions") +count=$(fragments) if [ "$next" != "$version" ]; then - if published; then why="$version is already on npm"; else why="$version is not above npm's latest $latest"; fi + if [ -n "$taken" ]; then why="$version is already on npm"; else why="$version is not above npm's latest $latest"; fi + if [ -n "$taken" ] && [ "$count" -eq 0 ] && ! unreleased; then + echo "$why and nothing is unreleased — add an Unreleased section or a changes/ fragment first" >&2 + exit 1 + fi + trap undo EXIT + renumber "$version" "$next" "$taken" + [ "$count" -eq 0 ] || dev changelog fragments --collect "$next" + # The section, with the fragments now in it, may need more than the number npm left free: an Added is a minor. + levelled=$(dev changelog level --next "$next") + if [ "$levelled" != "$next" ]; then + levelled=$(node scripts/next-version.mjs "$levelled" "$latest" "$versions") + renumber "$next" "$levelled" "" + next=$levelled + fi + allow_major "$next" + trap - EXIT echo "$why — publishing $next instead" - node -e 'const fs = require("fs"); const [o, n] = process.argv.slice(1) - const swaps = [["package.json", `"version": "${o}"`, `"version": "${n}"`], ["CHANGELOG.md", `\n## ${o} — `, `\n## ${n} — `]] - const texts = swaps.map(([file, from]) => { - const text = fs.readFileSync(file, "utf8") - if (!text.includes(from)) { console.error(`${file} has no ${from.trim()}`); process.exit(1) } - return text - }) - swaps.forEach(([file, from, to], i) => fs.writeFileSync(file, texts[i].replace(from, to)))' "$version" "$next" - land "release/$next" "chore(release): $next" "bin/release: $why. Only package.json and the CHANGELOG heading change." + land "release/$next" "chore(release): $next" "bin/release: $why. Only the number changes, to the level the changelog +needs: package.json, the CHANGELOG heading, and the changes/ fragments collected under it." rerun_if_changed "$@" version=$next + rerun_if_fragments "$@" +elif [ "$count" -gt 0 ] && [ -z "$taken" ]; then + # The version was dated by hand; fragments merged since then still belong to it, and may need a higher level. + allow_major "$version" + trap undo EXIT + dev changelog fragments --collect "$version" + levelled=$(dev changelog level --next "$version") + if [ "$levelled" != "$version" ]; then + levelled=$(node scripts/next-version.mjs "$levelled" "$latest" "$versions") + renumber "$version" "$levelled" "" + allow_major "$levelled" + trap - EXIT + echo "the changes/ fragments need $levelled — publishing it instead of $version" + land "release/$levelled" "chore(release): $levelled" \ + "bin/release: the changes/ fragments merged since $version was dated need $levelled, collected into its section." + version=$levelled + else + trap - EXIT + land "release/$version-changes" "chore(changelog): collect changes/ into $version" \ + "bin/release: the changes/ fragments merged since $version was dated, collected into its section." + fi + rerun_if_changed "$@" + rerun_if_fragments "$@" fi if published; then echo "$version is already on npm — raise the version first" >&2 exit 1 fi -# A major breaks every caller of the stable API, so it ships only when the owner chose to (WC-REL-7). -if [ "${version%%.*}" != "${latest%%.*}" ] && [ -n "$latest" ] && [ -z "$major" ]; then - echo "$version raises the major version over npm's $latest — run bin/release --major if that is meant" >&2 - exit 1 -fi +allow_major "$version" +top=$(sed -n '/^## /{p;q;}' CHANGELOG.md) +case "$top" in + "## $version — "*) ;; + *) echo "CHANGELOG.md's top section is \"$top\" — date it as $version first" >&2; exit 1 ;; +esac if [ "$mode" = ci ]; then last_run() { diff --git a/changes/fix-release-fold-fragments.md b/changes/fix-release-fold-fragments.md new file mode 100644 index 00000000..82f6e048 --- /dev/null +++ b/changes/fix-release-fold-fragments.md @@ -0,0 +1,9 @@ +### Fixed + +- **`bin/release` collects the `changes/` fragments and never renames a published section.** When npm already had + the version in `package.json` and only fragments had merged, it renamed that version's heading (`## 0.131.0` to + `## 0.132.0`), moved the published entries under the new number and left the fragments out (#706). Now a published + section keeps its heading: the new version takes the Unreleased section, or a new section the fragments fill, and + the release stops when there is neither. The fragments are collected into the version's section, which may raise + it to the level they need (an Added is a minor), as the CLIs' `bin/release` does. See + [RELEASING.md](../docs/dev/RELEASING.md). diff --git a/docs/dev/CONVENTIONS.md b/docs/dev/CONVENTIONS.md index ac5ad190..bb889e63 100644 --- a/docs/dev/CONVENTIONS.md +++ b/docs/dev/CONVENTIONS.md @@ -36,8 +36,9 @@ mark, and git keeps the old text. A finished plan is deleted. ## The changelog `CHANGELOG.md`, newest first. The top section is `## Unreleased` while work is merged; a release -dates it as `## — DD.MM.YYYY`. Headings, each at most once per version: `Added`, -`Changed — may break callers`, `Fixed`, `Security`, `Removed`. +dates it as `## — DD.MM.YYYY`. A pull request may put its entries in `changes/.md` instead, under +the same headings; `bin/release` collects them into the version's section. Headings, each at most once per version: +`Added`, `Changed — may break callers`, `Fixed`, `Security`, `Removed`. Every entry answers, in this order: **what changed, as a caller sees it** — the bold lead, a whole sentence; **why**, unless it is obvious; **what to watch for** — who is affected and what to do. No diff --git a/docs/dev/RELEASING.md b/docs/dev/RELEASING.md index 4a295e63..ffb718bd 100644 --- a/docs/dev/RELEASING.md +++ b/docs/dev/RELEASING.md @@ -1,18 +1,27 @@ # Releasing -Raise `version` in `package.json` and date the `## Unreleased` section of -[`CHANGELOG.md`](../../CHANGELOG.md) as that version, through a pull request. Before 1.0.0, a section with an Added, -"Changed — may break callers" or Removed entry raises the minor; only fixes and document changes raise the patch +A pull request adds its changelog entries under `## Unreleased`, or in a fragment, `changes/.md`, under the +changelog's `###` headings; fragments of open pull requests do not conflict with each other. +An Added, Deprecated or "Changed — experimental" entry raises the minor; "Changed — may break callers" or Removed +raises the major from 1.0.0 on and the minor before it; only fixes and document changes raise the patch ([Releases](../standards/releases.md#wc-rel-7--versions-are-xyz-a-break-of-the-stable-api-raises-the-major-from-100-on-and-the-minor-before-it)). -Merge it, then on `main`: +No version pull request is needed: on `main`, run ```sh bin/release ``` It refuses a dirty tree, a branch other than `main` and a `main` that is not pushed. When npm already -has the version, or a higher one, it commits the next free version to `main` — the next minor for -`x.y.0`, the next patch otherwise — renames the changelog heading to match, and publishes that. Then it starts +has the version, or a higher one, it lands the next free version on `main` through a pull request and publishes +that. After a version npm has, that is its next patch, raised to the level the new entries need: 1.0.0 with only a +fix is followed by 1.0.1, with an Added by 1.1.0. A version npm does not have but that is not above its latest keeps +its level: the next free major for `x.0.0` from 1.0.0 on, the next minor for `x.y.0`, the next patch otherwise. +A section npm already has keeps its heading: the new version takes the `## Unreleased` section, or a new section, +and the release stops when there is neither an Unreleased entry nor a fragment. +The fragments are collected into the version's section and deleted; when they need a higher level than the number +npm left free, the version is raised to it. A version dated by hand in `package.json` and the +changelog is released as it is, with the fragments merged since collected into it. A pre-release (`1.0.0-rc.1`) is +numbered by hand: when npm has it, the release stops. Then it starts [`release.yml`](../../.github/workflows/release.yml) and follows it. The workflow runs every check, publishes through npm's [trusted publishing](https://docs.npmjs.com/trusted-publishers/) — no npm token in GitHub, and npm attaches provenance — and tags `v` only once npm shows the new version. diff --git a/scripts/release.test.ts b/scripts/release.test.ts new file mode 100644 index 00000000..eef3c627 --- /dev/null +++ b/scripts/release.test.ts @@ -0,0 +1,190 @@ +import { execFileSync, spawnSync } from "node:child_process" +import { chmodSync, cpSync, mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from "node:fs" +import { tmpdir } from "node:os" +import { join } from "node:path" +import { build } from "esbuild" +import { afterAll, beforeAll, describe, expect, it } from "vitest" + +const root = join(import.meta.dirname, "..") +const dirs: string[] = [] +let dist = "" + +// bin/release runs cli-dev from dist/, and the test shards do not build: the dev bin is bundled from src/ instead, +// inside the worktree so its packages resolve from node_modules. +beforeAll(async () => { + mkdirSync(join(root, "node_modules/.cache"), { recursive: true }) + dist = mkdtempSync(join(root, "node_modules/.cache/release-dist-")) + dirs.push(dist) + await build({ + entryPoints: [join(root, "src/dev/bin.ts")], + outfile: join(dist, "dev/bin.js"), + bundle: true, + platform: "node", + format: "esm", + packages: "external", + logLevel: "silent", + }) +}, 60_000) +afterAll(() => { + for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true }) +}) + +const git = (cwd: string, ...args: string[]) => execFileSync("git", args, { cwd, encoding: "utf8" }) + +const stub = (dir: string, name: string, body: string) => { + writeFileSync(join(dir, name), `#!/bin/sh\n${body}\n`) + chmodSync(join(dir, name), 0o755) +} + +type Repo = { version: string; published: string[]; changelog: string; fragment?: string } + +// gh refuses to open the release pull request, which stops the run right after the release branch is pushed, before +// anything could publish. +const release = ({ version, published, changelog, fragment }: Repo) => { + const work = mkdtempSync(join(tmpdir(), "release-")) + dirs.push(work) + const origin = join(work, "origin.git") + const repo = join(work, "repo") + const stubs = join(work, "stubs") + mkdirSync(stubs) + git(work, "init", "-q", "--bare", "-b", "main", origin) + git(work, "clone", "-q", origin, repo) + for (const file of ["bin/release", "scripts/next-version.mjs", "config/wirecat/release-lock.sh"]) { + mkdirSync(join(repo, file, ".."), { recursive: true }) + cpSync(join(root, file), join(repo, file)) + } + cpSync(join(root, "config/wirecat/release-lock-info.mjs"), join(repo, "config/wirecat/release-lock-info.mjs")) + symlinkSync(dist, join(repo, "dist")) + writeFileSync(join(repo, ".gitignore"), "dist\n") + writeFileSync(join(repo, "package.json"), `${JSON.stringify({ name: "@wirecat/cli-base", version }, null, 2)}\n`) + writeFileSync(join(repo, "CHANGELOG.md"), changelog) + if (fragment) { + mkdirSync(join(repo, "changes")) + writeFileSync(join(repo, "changes/feat-x.md"), fragment) + } + git(repo, "add", "-A") + git(repo, "-c", "user.name=t", "-c", "user.email=t@example.com", "commit", "-q", "-m", "init") + for (const tag of published) git(repo, "tag", `v${tag}`) + git(repo, "push", "-q", "--tags", "origin", "main") + + const latest = published.at(-1) ?? "" + const views = published.map((one) => `"view @wirecat/cli-base@${one} version "*`).join("|") + stub(stubs, "pnpm", '[ "$1" = build ] && exit 0\nexit 1') + stub( + stubs, + "npm", + [ + 'case "$*" in', + ` *" versions "*) echo '${JSON.stringify(published)}' ;;`, + ` "view @wirecat/cli-base version "*) echo ${latest} ;;`, + ...(views ? [` ${views}) echo yes ;;`] : []), + " *) exit 1 ;;", + "esac", + ].join("\n"), + ) + stub(stubs, "gh", "exit 1") + const run = spawnSync("sh", ["bin/release"], { + cwd: repo, + encoding: "utf8", + env: { + ...process.env, + PATH: `${stubs}:${process.env.PATH}`, + XDG_RUNTIME_DIR: work, + GIT_AUTHOR_NAME: "t", + GIT_AUTHOR_EMAIL: "t@example.com", + GIT_COMMITTER_NAME: "t", + GIT_COMMITTER_EMAIL: "t@example.com", + }, + }) + const branches = git(origin, "branch", "--format=%(refname:short)").split("\n").filter(Boolean) + const show = (branch: string, file: string) => git(origin, "show", `${branch}:${file}`) + const files = (branch: string) => git(origin, "ls-tree", "-r", "--name-only", branch) + return { run, branches, show, files } +} + +const PUBLISHED = "# Changelog\n\n## 0.131.0 — 22.11.2026\n\n### Fixed\n\n- **Old.** Shipped in 0.131.0.\n" +const above = (section: string) => PUBLISHED.replace("## 0.131.0", `${section}\n\n## 0.131.0`) + +// bin/release takes the release lock with flock, which macOS does not ship. +// Each run starts node several times; a loaded machine takes seconds for each. +describe.skipIf(spawnSync("sh", ["-c", "command -v flock"]).status !== 0)("bin/release", { timeout: 60_000 }, () => { + it("gives fragments a new section and leaves the published one as npm has it", () => { + const { run, branches, show, files } = release({ + version: "0.131.0", + published: ["0.131.0"], + changelog: PUBLISHED, + fragment: "### Fixed\n\n- **New.** Merged after 0.131.0.\n", + }) + expect(run.stdout).toContain("0.131.0 is already on npm — publishing 0.131.1 instead") + expect(branches).toContain("release/0.131.1") + expect(JSON.parse(show("release/0.131.1", "package.json")).version).toBe("0.131.1") + const log = show("release/0.131.1", "CHANGELOG.md") + expect(log).toMatch(/## 0\.131\.1 — [\d.]+\n\n### Fixed\n\n- \*\*New\.\*\*/) + expect(log).toContain("## 0.131.0 — 22.11.2026\n\n### Fixed\n\n- **Old.** Shipped in 0.131.0.\n") + expect(log.split("\n## 0.131.0")[0]).not.toContain("Old") + expect(files("release/0.131.1")).not.toContain("changes/feat-x.md") + }) + + it("follows a published 1.0.0 with a patch when only a fix is unreleased", () => { + const { run, branches, show } = release({ + version: "1.0.0", + published: ["0.131.0", "1.0.0"], + changelog: above( + "## Unreleased\n\n### Fixed\n\n- **Fix.** After 1.0.0.\n\n## 1.0.0 — 23.11.2026\n\n### Added\n\n- **One.** A.", + ), + }) + expect(run.stdout).toContain("1.0.0 is already on npm — publishing 1.0.1 instead") + expect(branches).toContain("release/1.0.1") + expect(show("release/1.0.1", "CHANGELOG.md")).toMatch(/## 1\.0\.1 — [\d.]+\n\n### Fixed\n\n- \*\*Fix\.\*\*/) + }) + + it("refuses an empty Unreleased section on a published version", () => { + const { run, branches } = release({ version: "0.131.0", published: ["0.131.0"], changelog: above("## Unreleased") }) + expect(run.status).toBe(1) + expect(run.stderr).toContain("0.131.0 is already on npm and nothing is unreleased") + expect(branches).toEqual(["main"]) + }) + + it("raises to the level the fragments need: an Added is a minor", () => { + const { run, branches, show } = release({ + version: "0.131.1", + published: ["0.131.0", "0.131.1"], + changelog: above("## 0.131.1 — 23.11.2026\n\n### Fixed\n\n- **One.** A fix."), + fragment: "### Added\n\n- **Pages.** Pages are written.\n", + }) + expect(run.stdout).toContain("0.131.1 is already on npm — publishing 0.132.0 instead") + expect(show("release/0.132.0", "CHANGELOG.md")).toMatch(/## 0\.132\.0 — [\d.]+\n\n### Added\n\n- \*\*Pages\.\*\*/) + expect(branches).not.toContain("release/0.131.2") + }) + + it("refuses a published version with nothing unreleased instead of renaming its section", () => { + const { run, branches } = release({ version: "0.131.0", published: ["0.131.0"], changelog: PUBLISHED }) + expect(run.status).toBe(1) + expect(run.stderr).toContain("0.131.0 is already on npm and nothing is unreleased") + expect(branches).toEqual(["main"]) + }) + + it("does not collect fragments into a published pre-release", () => { + const { run, branches } = release({ + version: "1.0.0-rc.0", + published: ["0.131.0", "1.0.0-rc.0"], + changelog: above("## 1.0.0-rc.0 — 23.11.2026\n\n### Added\n\n- **Rc.** A."), + fragment: "### Fixed\n\n- **New.** After the rc.\n", + }) + expect(run.status).toBe(1) + expect(run.stderr).toContain("1.0.0-rc.0 is already on npm — raise the version first") + expect(branches).toEqual(["main"]) + }) + + it("stops a major the fragments need before anything lands, without --major", () => { + const { run, branches } = release({ + version: "1.0.0", + published: ["0.131.0", "1.0.0"], + changelog: above("## 1.0.0 — 23.11.2026\n\n### Added\n\n- **One.** A."), + fragment: "### Removed\n\n- **Gone.** A stable name is removed.\n", + }) + expect(run.status).toBe(1) + expect(run.stderr).toContain("2.0.0 raises the major version over npm's 1.0.0") + expect(branches).toEqual(["main"]) + }) +})