From 6f861b5ff158514c20481b905a533efcb1b78123 Mon Sep 17 00:00:00 2001 From: Brian O'Kelley Date: Mon, 9 Nov 2026 18:18:22 +0000 Subject: [PATCH 1/2] chore(release): derive the RC promotion line from package.json `npm run promote:rc` refused anything but 3.2.0. It now promotes the current line's final beta, `X.Y.0-beta.N` from package.json, to `X.Y.0-rc.0`, so the 3.3 candidate can use the same guarded path. The marker check and the intermediate-beta guard derive the target and line from the package version instead of literals. The safety properties are unchanged: one-way, beta pre mode required, the exact changeset pool snapshotted by SHA-256, any changed, added or removed changeset refused, and no intermediate beta. `--check` and `--prepare` now list the pending changesets that fold into rc.0. RELEASING's RC section is version-neutral and records the open beta Version Packages PR handling, the marker invalidation and main freeze, the docs-snapshot label, and the hosted training agent preview bump. Co-Authored-By: Claude Opus 5.5 --- RELEASING.md | 58 ++-- scripts/promote-release-candidate.mjs | 37 ++- scripts/version-packages.mjs | 4 +- tests/promote-release-candidate.test.cjs | 351 +++++++++++++---------- 4 files changed, 268 insertions(+), 182 deletions(-) diff --git a/RELEASING.md b/RELEASING.md index f18f21dac66..3f207acf237 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -133,39 +133,52 @@ Version Packages PRs that resolve to `3.2.0-beta.N`. Keep pre mode and its changeset pool on `main`; neither belongs on `3.1.x`. Exiting pre mode for 3.2 GA is a separate, explicitly reviewed release operation. -## Cutting a 3.2 release candidate +## Cutting a release candidate -The first candidate is `3.2.0-rc.0`. Treat that promotion as a reviewed release +A minor (or major) line's first candidate is `X.Y.0-rc.0`, promoted from the +line's final accepted beta: `3.2.0-beta.11` became `3.2.0-rc.0`, and 3.3 goes +from `3.3.0-beta.N` to `3.3.0-rc.0`. Treat that promotion as a reviewed release operation, not as an ordinary Changesets tag switch. Changesets increments the existing beta ordinal when its prerelease tag changes, which would turn `beta.10` into `rc.11`. The repository's guarded promotion script uses semver's phase-change behavior instead. It can fold a reviewed pending changeset pool directly into RC.0 without publishing another beta. -After verifying the latest beta's immutable assets, close any superseded beta -Version Packages PR. Then, from a clean branch based on the resulting `main`: +After verifying the latest beta's immutable assets, deal with the open beta +Version Packages PR on `changeset-release/main`. Either leave it open, and the +release workflow regenerates it in place at `X.Y.0-rc.0` once the marker lands +(3.2's #7196 was), or close it with `gh pr close --delete-branch`. Closing +it but leaving the branch stops the next release run ("PR and release ref +disagree"). Then, from a clean branch based on the resulting `main`: ```bash -git switch main -git pull --ff-only origin main +git fetch origin +git switch -c chore/prepare-rc0 origin/main npm run promote:rc -- --check npm run promote:rc -- --prepare git diff --check git add .changeset/rc-promotion.json -git commit -m "chore(release): prepare 3.2.0-rc.0" +git commit -m "chore(release): prepare X.Y.0-rc.0" ``` -Open and merge that state-only commit as its own PR. The release workflow sees -the marker, creates the Version Packages PR at `3.2.0-rc.0`, and generates and +`--check` and `--prepare` print the target version and the pending changesets +that fold into it. Open and merge that state-only commit as its own PR. Any +changeset that reaches `main` after `--prepare`, including one in the same PR, +invalidates the marker: delete it and run `--prepare` again on the new head. +From the marker PR's merge until the RC release finishes publishing, merge +nothing else into `main`. The release workflow sees +the marker, creates the Version Packages PR at `X.Y.0-rc.0`, and generates and signs the normal schema, compliance, and protocol artifacts in GitHub Actions. That generated PR must receive human approval on its final head SHA. Do not run `changeset version` for this one phase-transition, and do not hand-edit the package version, lockfile, prerelease state, marker, or generated artifacts. -The script is intentionally one-way and 3.2-specific: it requires `beta.N` and -beta pre mode, computes `3.2.0-rc.0`, and records the exact pending changeset -filenames and SHA-256 digests in the reviewed marker. The Version Packages -workflow refuses any changed or additional changeset, consumes the reviewed +The script is intentionally one-way: it reads the line from `package.json`, +requires an `X.Y.0-beta.N` version and beta pre mode, computes `X.Y.0-rc.0`, and +records the exact pending changeset filenames and SHA-256 digests in the +reviewed marker. The Version Packages +workflow refuses any changed, added or removed changeset, and any marker that +does not name the current beta and its rc.0. It consumes the reviewed pool through Changesets, retitles that generated changelog section to RC.0, updates the package and lockfile through `npm version`, and switches pre mode to `rc` before building the release artifacts. With an empty pool it adds the @@ -174,7 +187,7 @@ and the normal Version Packages flow to produce `rc.1`, `rc.2`, and so on. Before merging the RC Version Packages PR, confirm: -- the package and lockfile resolve to `3.2.0-rc.N`, and `.changeset/pre.json` +- the package and lockfile resolve to `X.Y.0-rc.N`, and `.changeset/pre.json` still has `"mode": "pre"` and `"tag": "rc"`; - the changelog contains only changes intended for the candidate; - versioned schemas, compliance bundles, protocol tarball, checksum, @@ -182,13 +195,13 @@ Before merging the RC Version Packages PR, confirm: - the compact lifecycle storyboards and training-agent profile tests pass; - the TypeScript, Python, Go, and Java SDK disposition is recorded, with any unsupported SDK called out rather than silently implied ready; and -- open 3.2 milestone items are either closed or explicitly moved out of the +- open `X.Y.0` milestone items are either closed or explicitly moved out of the release by their decision owner. After merge, verify the exact immutable release rather than a moving alias: ```bash -VERSION=3.2.0-rc.0 +VERSION=3.3.0-rc.0 git fetch origin --tags git rev-parse "v$VERSION^{}" @@ -199,18 +212,23 @@ curl -fsSI "https://adcontextprotocol.org/protocol/$VERSION.tgz" ``` Also confirm the release is marked prerelease, has exactly the tarball and -three sidecars, the `3.2-rc` docs snapshot lands, and the public training agent -advertises and executes the exact RC version. Subsequent fixes get ordinary +three sidecars, the `X.Y-rc` docs snapshot lands (`release-docs.yml` derives +the label from the tag, so `v3.3.0-rc.0` adds a `3.3-rc` selector), and the +public training agent advertises and executes the exact RC version. The hosted +agent serves one pinned preview, `TRAINING_AGENT_HOSTED_PREVIEW` in +`server/src/training-agent/candidate-version.ts`, and it must be the +prerelease the installed `@adcp/sdk` negotiates. Move it to `X.Y-rc.N` in the +PR that adopts an SDK that negotiates that RC. Subsequent fixes get ordinary changesets and advance to the next `rc.N` through the Version Packages PR. -For 3.2 stable, use a separate reviewed state change: +For the line's stable release, use a separate reviewed state change: ```bash npx changeset pre exit ``` The resulting Version Packages PR removes the prerelease suffix. Do not -re-enter another tag before that stable versioning step. 3.2 GA ships as +re-enter another tag before that stable versioning step. 3.2 GA shipped as **`3.2.1`**, not `3.2.0` (see the next section). Follow the ordered GA runbook in [`.agents/shortcuts/cut-minor-ga.md`](.agents/shortcuts/cut-minor-ga.md): freeze gates, pre-exit PR contents, the Version Packages audit, CDN worker diff --git a/scripts/promote-release-candidate.mjs b/scripts/promote-release-candidate.mjs index 3dcb5722a60..33533338ed0 100644 --- a/scripts/promote-release-candidate.mjs +++ b/scripts/promote-release-candidate.mjs @@ -1,7 +1,8 @@ #!/usr/bin/env node /** - * Promote the final 3.2 beta to rc.0 without publishing an intermediate + * Promote the current line's final beta (`X.Y.0-beta.N`, read from + * package.json) to `X.Y.0-rc.0` without publishing an intermediate beta or * stable release. Changesets increments the numeric suffix across tag changes, * so its default beta -> rc path would turn beta.N into rc.(N+1). * @@ -23,19 +24,30 @@ const { inc, parse } = semver; const repoRoot = resolve(fileURLToPath(new URL('..', import.meta.url))); const markerRelativePath = '.changeset/rc-promotion.json'; +// `X.Y.Z` of a parsed version: the release line its prereleases belong to. +function releaseLine({ major, minor, patch }) { + return `${major}.${minor}.${patch}`; +} + export function planRcPromotion({ packageVersion, preState, pendingChangesets }) { const parsed = parse(packageVersion); - if (!parsed || parsed.prerelease[0] !== 'beta' || typeof parsed.prerelease[1] !== 'number') { + if ( + !parsed + || parsed.prerelease.length !== 2 + || parsed.prerelease[0] !== 'beta' + || typeof parsed.prerelease[1] !== 'number' + ) { throw new Error(`Expected the final beta version, received ${JSON.stringify(packageVersion)}.`); } - if (parsed.major !== 3 || parsed.minor !== 2 || parsed.patch !== 0) { - throw new Error(`RC promotion is restricted to the 3.2.0 release line, received ${JSON.stringify(packageVersion)}.`); + // Candidates exist only for a new minor or major line; patches ship stable. + if (parsed.patch !== 0) { + throw new Error(`RC promotion requires an X.Y.0 beta, received ${JSON.stringify(packageVersion)}.`); } if (preState?.mode !== 'pre' || preState?.tag !== 'beta') { throw new Error('Expected .changeset/pre.json to remain in beta pre mode.'); } const targetVersion = inc(packageVersion, 'prerelease', 'rc'); - if (targetVersion !== `${parsed.major}.${parsed.minor}.${parsed.patch}-rc.0`) { + if (targetVersion !== `${releaseLine(parsed)}-rc.0`) { throw new Error(`Refusing unexpected RC target ${JSON.stringify(targetVersion)}.`); } @@ -101,7 +113,12 @@ export function readPreparedRcPromotion(root = repoRoot) { if (preState?.mode !== 'pre' || preState?.tag !== 'beta') { throw new Error('Prepared RC promotion requires beta pre mode until versioning.'); } - if (marker?.from !== packageJson.version || marker?.to !== '3.2.0-rc.0') { + const { targetVersion } = planRcPromotion({ + packageVersion: packageJson.version, + preState, + pendingChangesets: [], + }); + if (marker?.from !== packageJson.version || marker?.to !== targetVersion) { throw new Error('RC promotion marker does not match the current package version and rc.0 target.'); } if (!Array.isArray(marker?.pendingChangesets)) { @@ -186,7 +203,7 @@ export function versionPreparedRc(root = repoRoot, options = {}) { let intermediateVersion = null; if (plan.pendingChangesets.length > 0) { intermediateVersion = inc(plan.currentVersion, 'prerelease', 'beta'); - if (!intermediateVersion?.startsWith('3.2.0-beta.')) { + if (!intermediateVersion?.startsWith(`${releaseLine(parse(plan.currentVersion))}-beta.`)) { throw new Error(`Refusing unexpected intermediate version ${JSON.stringify(intermediateVersion)}.`); } (options.runChangesetVersion ?? runChangesetVersion)(root); @@ -232,6 +249,12 @@ if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1] console.log( `${checkOnly ? 'Ready to prepare' : prepare ? 'Prepared' : 'Versioned'} ${plan.currentVersion} -> ${plan.targetVersion}.`, ); + console.log( + plan.pendingChangesets.length === 0 + ? `No pending changesets: ${plan.targetVersion} is a phase-only promotion.` + : `Pending changesets folded into ${plan.targetVersion} (${plan.pendingChangesets.length}):`, + ); + for (const file of plan.pendingChangesets) console.log(` ${file}`); } catch (error) { console.error(error instanceof Error ? error.message : error); process.exitCode = 1; diff --git a/scripts/version-packages.mjs b/scripts/version-packages.mjs index 34861e0f659..0b713f3136e 100644 --- a/scripts/version-packages.mjs +++ b/scripts/version-packages.mjs @@ -1,7 +1,9 @@ #!/usr/bin/env node /** - * Select the one exceptional 3.2 beta -> rc.0 versioning path, otherwise + * Select the exceptional final-beta -> rc.0 versioning path when a reviewed + * .changeset/rc-promotion.json marker is present (promote-release-candidate.mjs + * derives the line from package.json), otherwise * delegate to Changesets. A reviewed withdrawn-release marker lets the * pre-exit cut skip a permanently withdrawn version number. Artifact * generation and signing remain in the package `version` script so every path diff --git a/tests/promote-release-candidate.test.cjs b/tests/promote-release-candidate.test.cjs index 9984e80e2a3..6843c1743af 100644 --- a/tests/promote-release-candidate.test.cjs +++ b/tests/promote-release-candidate.test.cjs @@ -29,191 +29,234 @@ const path = require('node:path'); assert.match(versionWrapper, /\.changeset\/release-supersession\.json/); assert.match(versionWrapper, /check-release-supersession\.cjs/); assert.match(versionWrapper, /changeset', 'version'/); + // The release line comes from package.json, never from a literal. + assert.doesNotMatch( + fs.readFileSync(path.join(repoRoot, 'scripts', 'promote-release-candidate.mjs'), 'utf8'), + /\d+\.\d+\.\d+-(?:beta|rc)\b/, + ); - const plan = planRcPromotion({ - packageVersion: '3.2.0-beta.10', - preState: { mode: 'pre', tag: 'beta' }, - pendingChangesets: [], - }); - assert.deepEqual(plan, { - currentVersion: '3.2.0-beta.10', - targetVersion: '3.2.0-rc.0', - nextPreState: { mode: 'pre', tag: 'rc' }, - pendingChangesets: [], - }); + const beta = { mode: 'pre', tag: 'beta' }; + for (const [finalBeta, target] of [ + ['3.2.0-beta.10', '3.2.0-rc.0'], + ['3.3.0-beta.5', '3.3.0-rc.0'], + ['4.0.0-beta.0', '4.0.0-rc.0'], + ]) { + assert.deepEqual( + planRcPromotion({ packageVersion: finalBeta, preState: beta, pendingChangesets: [] }), + { + currentVersion: finalBeta, + targetVersion: target, + nextPreState: { mode: 'pre', tag: 'rc' }, + pendingChangesets: [], + }, + ); + } assert.deepEqual( planRcPromotion({ - packageVersion: '3.2.0-beta.10', - preState: { mode: 'pre', tag: 'beta' }, + packageVersion: '3.3.0-beta.5', + preState: beta, pendingChangesets: ['z-last.md', 'a-first.md'], }).pendingChangesets, ['a-first.md', 'z-last.md'], ); assert.throws( () => planRcPromotion({ - packageVersion: '3.2.0-beta.10', + packageVersion: '3.3.0-beta.5', preState: { mode: 'pre', tag: 'rc' }, pendingChangesets: [], }), /remain in beta pre mode/, ); assert.throws( - () => planRcPromotion({ - packageVersion: '3.2.0-rc.0', - preState: { mode: 'pre', tag: 'beta' }, - pendingChangesets: [], - }), - /Expected the final beta version/, + () => planRcPromotion({ packageVersion: '3.3.0-beta.5', preState: null, pendingChangesets: [] }), + /remain in beta pre mode/, ); + // One-way: an RC, a stable release, or any other prerelease shape is refused. + for (const packageVersion of ['3.3.0-rc.0', '3.3.0', '3.3.0-alpha.1', '3.3.0-beta', '3.3.0-beta.5.1']) { + assert.throws( + () => planRcPromotion({ packageVersion, preState: beta, pendingChangesets: [] }), + /Expected the final beta version/, + packageVersion, + ); + } assert.throws( - () => planRcPromotion({ - packageVersion: '3.3.0-beta.1', - preState: { mode: 'pre', tag: 'beta' }, - pendingChangesets: [], - }), - /restricted to the 3\.2\.0 release line/, + () => planRcPromotion({ packageVersion: '3.2.10-beta.0', preState: beta, pendingChangesets: [] }), + /requires an X\.Y\.0 beta/, ); assert.match( rcChangelogContent( - '# Changelog\n\n## 3.2.0-beta.10\n\n- Final beta.\n', - { currentVersion: '3.2.0-beta.10', targetVersion: '3.2.0-rc.0' }, + '# Changelog\n\n## 3.3.0-beta.5\n\n- Final beta.\n', + { currentVersion: '3.3.0-beta.5', targetVersion: '3.3.0-rc.0' }, ), - /^# Changelog\n\n## 3\.2\.0-rc\.0\n\nPromoted from `3\.2\.0-beta\.10`/, + /^# Changelog\n\n## 3\.3\.0-rc\.0\n\nPromoted from `3\.3\.0-beta\.5`/, ); - const root = fs.mkdtempSync(path.join(os.tmpdir(), 'adcp-rc-promotion-')); - try { - fs.mkdirSync(path.join(root, '.changeset')); - fs.writeFileSync( - path.join(root, 'package.json'), - `${JSON.stringify({ name: 'adcontextprotocol', version: '3.2.0-beta.10' }, null, 2)}\n`, - ); - fs.writeFileSync( - path.join(root, '.changeset', 'pre.json'), - `${JSON.stringify({ mode: 'pre', tag: 'beta' }, null, 2)}\n`, - ); - fs.writeFileSync( - path.join(root, 'CHANGELOG.md'), - '# Changelog\n\n## 3.2.0-beta.10\n\n### Patch Changes\n\n- Final beta.\n', - ); - fs.writeFileSync( - path.join(root, '.changeset', 'candidate-fix.md'), - '---\n"adcontextprotocol": patch\n---\n\nCandidate fix.\n', - ); + for (const finalBeta of ['3.3.0-beta.5', '3.2.0-beta.10']) { + exercisePromotion(finalBeta); + } - prepareRcPromotion(root); - assert.deepEqual( - JSON.parse(fs.readFileSync(path.join(root, '.changeset', 'pre.json'), 'utf8')), - { mode: 'pre', tag: 'beta' }, - ); - const marker = JSON.parse( - fs.readFileSync(path.join(root, '.changeset', 'rc-promotion.json'), 'utf8'), - ); - assert.equal(marker.from, '3.2.0-beta.10'); - assert.equal(marker.to, '3.2.0-rc.0'); - assert.equal(marker.pendingChangesets[0].file, 'candidate-fix.md'); - assert.match(marker.pendingChangesets[0].sha256, /^[a-f0-9]{64}$/); - const prepared = readPreparedRcPromotion(root); - assert.deepEqual({ - ...prepared, - reviewedChangesets: prepared.reviewedChangesets.map(({ file }) => file), - }, { - currentVersion: '3.2.0-beta.10', - targetVersion: '3.2.0-rc.0', - nextPreState: { mode: 'pre', tag: 'rc' }, - pendingChangesets: ['candidate-fix.md'], - reviewedChangesets: ['candidate-fix.md'], - }); + function exercisePromotion(finalBeta) { + const line = finalBeta.replace(/-beta\.\d+$/, ''); + const target = `${line}-rc.0`; + const nextBeta = `${line}-beta.${Number(finalBeta.split('.').pop()) + 1}`; + const escape = (value) => value.replace(/\./g, '\\.'); + const root = fs.mkdtempSync(path.join(os.tmpdir(), 'adcp-rc-promotion-')); + try { + fs.mkdirSync(path.join(root, '.changeset')); + const writePackageVersion = (version) => { + fs.writeFileSync( + path.join(root, 'package.json'), + `${JSON.stringify({ name: 'adcontextprotocol', version }, null, 2)}\n`, + ); + }; + writePackageVersion(finalBeta); + fs.writeFileSync( + path.join(root, '.changeset', 'pre.json'), + `${JSON.stringify(beta, null, 2)}\n`, + ); + fs.writeFileSync( + path.join(root, 'CHANGELOG.md'), + `# Changelog\n\n## ${finalBeta}\n\n### Patch Changes\n\n- Final beta.\n`, + ); + const changesetPath = path.join(root, '.changeset', 'candidate-fix.md'); + const reviewedChangeset = '---\n"adcontextprotocol": patch\n---\n\nCandidate fix.\n'; + fs.writeFileSync(changesetPath, reviewedChangeset); - const changesetPath = path.join(root, '.changeset', 'candidate-fix.md'); - const reviewedChangeset = fs.readFileSync(changesetPath, 'utf8'); - fs.writeFileSync(changesetPath, `${reviewedChangeset}\nTampered.\n`); - assert.throws( - () => readPreparedRcPromotion(root), - /do not match the reviewed RC promotion marker/, - ); - fs.writeFileSync(changesetPath, reviewedChangeset); + prepareRcPromotion(root); + assert.deepEqual( + JSON.parse(fs.readFileSync(path.join(root, '.changeset', 'pre.json'), 'utf8')), + beta, + ); + const markerPath = path.join(root, '.changeset', 'rc-promotion.json'); + const markerText = fs.readFileSync(markerPath, 'utf8'); + const marker = JSON.parse(markerText); + assert.equal(marker.from, finalBeta); + assert.equal(marker.to, target); + assert.equal(marker.pendingChangesets[0].file, 'candidate-fix.md'); + assert.match(marker.pendingChangesets[0].sha256, /^[a-f0-9]{64}$/); + assert.throws(() => prepareRcPromotion(root), /rc-promotion\.json already exists/); + const prepared = readPreparedRcPromotion(root); + assert.deepEqual({ + ...prepared, + reviewedChangesets: prepared.reviewedChangesets.map(({ file }) => file), + }, { + currentVersion: finalBeta, + targetVersion: target, + nextPreState: { mode: 'pre', tag: 'rc' }, + pendingChangesets: ['candidate-fix.md'], + reviewedChangesets: ['candidate-fix.md'], + }); - const writePackageVersion = (version) => { - const generatedPackage = JSON.parse( - fs.readFileSync(path.join(root, 'package.json'), 'utf8'), + // The reviewed pool is exact: a changed, added, or removed changeset is refused. + fs.writeFileSync(changesetPath, `${reviewedChangeset}\nTampered.\n`); + assert.throws( + () => readPreparedRcPromotion(root), + /do not match the reviewed RC promotion marker/, ); - generatedPackage.version = version; - fs.writeFileSync( - path.join(root, 'package.json'), - `${JSON.stringify(generatedPackage, null, 2)}\n`, + fs.writeFileSync(changesetPath, reviewedChangeset); + const addedPath = path.join(root, '.changeset', 'late-arrival.md'); + fs.writeFileSync(addedPath, '---\n"adcontextprotocol": patch\n---\n\nLate.\n'); + assert.throws( + () => readPreparedRcPromotion(root), + /do not match the reviewed RC promotion marker/, ); - }; - writePackageVersion('3.2.0-beta.99'); - assert.throws( - () => validateChangesetConsumption(root, prepared, '3.2.0-beta.11'), - /generated "3\.2\.0-beta\.99" instead of "3\.2\.0-beta\.11"/, - ); - writePackageVersion('3.2.0-beta.11'); - assert.throws( - () => validateChangesetConsumption(root, prepared, '3.2.0-beta.11'), - /did not consume the reviewed RC changeset pool/, - ); - fs.unlinkSync(changesetPath); - fs.mkdirSync(path.join(root, '.changeset', 'pre'), { recursive: true }); - fs.writeFileSync( - path.join(root, '.changeset', 'pre', 'candidate-fix.md'), - `${reviewedChangeset}\nTampered after consumption.\n`, - ); - assert.throws( - () => validateChangesetConsumption(root, prepared, '3.2.0-beta.11'), - /did not preserve reviewed content for candidate-fix\.md/, - ); - fs.rmSync(path.join(root, '.changeset', 'pre'), { recursive: true }); - fs.writeFileSync(changesetPath, reviewedChangeset); - writePackageVersion('3.2.0-beta.10'); + fs.unlinkSync(addedPath); + fs.unlinkSync(changesetPath); + assert.throws( + () => readPreparedRcPromotion(root), + /do not match the reviewed RC promotion marker/, + ); + fs.writeFileSync(changesetPath, reviewedChangeset); - let consumed = false; - versionPreparedRc(root, { - runChangesetVersion: () => { - consumed = true; - fs.unlinkSync(changesetPath); - fs.mkdirSync(path.join(root, '.changeset', 'pre'), { recursive: true }); - fs.writeFileSync( - path.join(root, '.changeset', 'pre', 'candidate-fix.md'), - reviewedChangeset, - ); - writePackageVersion('3.2.0-beta.11'); - const changelogPath = path.join(root, 'CHANGELOG.md'); - const changelog = fs.readFileSync(changelogPath, 'utf8'); - fs.writeFileSync( - changelogPath, - changelog.replace( - '# Changelog\n\n', - '# Changelog\n\n## 3.2.0-beta.11\n\n### Patch Changes\n\n- Candidate fix.\n\n', - ), + // The marker must name this line's rc.0 from the current package version. + for (const tampered of [ + { ...marker, to: '3.1.0-rc.0' }, + { ...marker, to: `${line}-rc.1` }, + { ...marker, from: `${line}-beta.0` }, + ]) { + fs.writeFileSync(markerPath, `${JSON.stringify(tampered, null, 2)}\n`); + assert.throws( + () => readPreparedRcPromotion(root), + /does not match the current package version and rc\.0 target/, ); - }, - }); - assert.equal(consumed, true); - assert.equal( - JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8')).version, - '3.2.0-rc.0', - ); - assert.deepEqual( - JSON.parse(fs.readFileSync(path.join(root, '.changeset', 'pre.json'), 'utf8')), - { mode: 'pre', tag: 'rc' }, - ); - assert.match( - fs.readFileSync(path.join(root, 'CHANGELOG.md'), 'utf8'), - /^# Changelog\n\n## 3\.2\.0-rc\.0\n\n### Patch Changes\n\n- Candidate fix\./, - ); - assert.doesNotMatch( - fs.readFileSync(path.join(root, 'CHANGELOG.md'), 'utf8'), - /## 3\.2\.0-beta\.11\n/, - ); - assert.equal( - fs.existsSync(path.join(root, '.changeset', 'rc-promotion.json')), - false, - ); - } finally { - fs.rmSync(root, { recursive: true, force: true }); + } + fs.writeFileSync(markerPath, markerText); + fs.writeFileSync( + path.join(root, '.changeset', 'pre.json'), + `${JSON.stringify({ mode: 'pre', tag: 'rc' }, null, 2)}\n`, + ); + assert.throws(() => readPreparedRcPromotion(root), /requires beta pre mode/); + fs.writeFileSync( + path.join(root, '.changeset', 'pre.json'), + `${JSON.stringify(beta, null, 2)}\n`, + ); + + writePackageVersion(`${line}-beta.99`); + assert.throws( + () => validateChangesetConsumption(root, prepared, nextBeta), + new RegExp(`generated "${escape(line)}-beta\\.99" instead of "${escape(nextBeta)}"`), + ); + writePackageVersion(nextBeta); + assert.throws( + () => validateChangesetConsumption(root, prepared, nextBeta), + /did not consume the reviewed RC changeset pool/, + ); + fs.unlinkSync(changesetPath); + fs.mkdirSync(path.join(root, '.changeset', 'pre'), { recursive: true }); + fs.writeFileSync( + path.join(root, '.changeset', 'pre', 'candidate-fix.md'), + `${reviewedChangeset}\nTampered after consumption.\n`, + ); + assert.throws( + () => validateChangesetConsumption(root, prepared, nextBeta), + /did not preserve reviewed content for candidate-fix\.md/, + ); + fs.rmSync(path.join(root, '.changeset', 'pre'), { recursive: true }); + fs.writeFileSync(changesetPath, reviewedChangeset); + writePackageVersion(finalBeta); + + let consumed = false; + versionPreparedRc(root, { + runChangesetVersion: () => { + consumed = true; + fs.unlinkSync(changesetPath); + fs.mkdirSync(path.join(root, '.changeset', 'pre'), { recursive: true }); + fs.writeFileSync( + path.join(root, '.changeset', 'pre', 'candidate-fix.md'), + reviewedChangeset, + ); + writePackageVersion(nextBeta); + const changelogPath = path.join(root, 'CHANGELOG.md'); + const changelog = fs.readFileSync(changelogPath, 'utf8'); + fs.writeFileSync( + changelogPath, + changelog.replace( + '# Changelog\n\n', + `# Changelog\n\n## ${nextBeta}\n\n### Patch Changes\n\n- Candidate fix.\n\n`, + ), + ); + }, + }); + assert.equal(consumed, true); + assert.equal( + JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8')).version, + target, + ); + assert.deepEqual( + JSON.parse(fs.readFileSync(path.join(root, '.changeset', 'pre.json'), 'utf8')), + { mode: 'pre', tag: 'rc' }, + ); + const changelog = fs.readFileSync(path.join(root, 'CHANGELOG.md'), 'utf8'); + assert.match( + changelog, + new RegExp(`^# Changelog\\n\\n## ${escape(target)}\\n\\n### Patch Changes\\n\\n- Candidate fix\\.`), + ); + assert.doesNotMatch(changelog, new RegExp(`## ${escape(nextBeta)}\\n`)); + assert.equal(fs.existsSync(markerPath), false); + } finally { + fs.rmSync(root, { recursive: true, force: true }); + } } console.log('Release-candidate promotion checks passed.'); From 90ef730cad8c054ff3068252e75156895ed64e40 Mon Sep 17 00:00:00 2001 From: Brian O'Kelley Date: Mon, 9 Nov 2026 18:55:40 +0000 Subject: [PATCH 2/2] test(release): escape every regex metacharacter in RC promotion checks CodeQL flagged the version-escaping helper for escaping only dots. Co-Authored-By: Claude Opus 5.5 --- tests/promote-release-candidate.test.cjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/promote-release-candidate.test.cjs b/tests/promote-release-candidate.test.cjs index 6843c1743af..8aea3cfee9a 100644 --- a/tests/promote-release-candidate.test.cjs +++ b/tests/promote-release-candidate.test.cjs @@ -100,7 +100,7 @@ const path = require('node:path'); const line = finalBeta.replace(/-beta\.\d+$/, ''); const target = `${line}-rc.0`; const nextBeta = `${line}-beta.${Number(finalBeta.split('.').pop()) + 1}`; - const escape = (value) => value.replace(/\./g, '\\.'); + const escape = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); const root = fs.mkdtempSync(path.join(os.tmpdir(), 'adcp-rc-promotion-')); try { fs.mkdirSync(path.join(root, '.changeset'));