From f58689123246c9c67eb537cef7f7b1c8360ea061 Mon Sep 17 00:00:00 2001 From: Synaeve Date: Tue, 10 Nov 2026 11:52:48 +0100 Subject: [PATCH 1/2] fix(ci): let release-audit branches edit changeset text Changeset-only PRs from release-audit/ branches may reword or escalate existing changesets, matching the cut-beta audit runbook. Other PRs keep the existing delete and downgrade guards. Closes #8371. --- .agents/shortcuts/cut-beta.md | 4 +- scripts/check-changeset-protocol-scope.cjs | 30 ++++++++- tests/changeset-protocol-scope.test.cjs | 74 ++++++++++++++++++++++ 3 files changed, 105 insertions(+), 3 deletions(-) diff --git a/.agents/shortcuts/cut-beta.md b/.agents/shortcuts/cut-beta.md index 6dcd83a4d4b..0263a11e9f5 100644 --- a/.agents/shortcuts/cut-beta.md +++ b/.agents/shortcuts/cut-beta.md @@ -97,7 +97,9 @@ or other operational work. Empty changesets do not belong in the beta cut. Do not hand-edit `CHANGELOG.md`; changesets owns it. Correct or remove the source `.changeset/*.md` file on `main`, then wait for the release branch to -regenerate. +regenerate. Open that correction PR from a `release-audit/` branch +that touches only `.changeset/*.md`, so the changeset scope check accepts text +edits and bump escalations. ### Publish diff --git a/scripts/check-changeset-protocol-scope.cjs b/scripts/check-changeset-protocol-scope.cjs index d0456965341..1248cfdc2a8 100644 --- a/scripts/check-changeset-protocol-scope.cjs +++ b/scripts/check-changeset-protocol-scope.cjs @@ -3,6 +3,7 @@ const { execFileSync } = require('child_process'); const CHANGESET_FILE_RE = /^\.changeset\/[^/]+[.]md$/; +const RELEASE_AUDIT_BRANCH_PREFIX = 'release-audit/'; const PROTOCOL_CHANGESET_RE = /^["']adcontextprotocol["']\s*:\s*(major|minor|patch)\s*$/m; const PROTOCOL_BUMP_RANK = new Map([ [null, 0], @@ -205,6 +206,19 @@ function isChangesetDeleteOnlyCleanup(changes) { return deletedChangeset; } +// Release managers correct pending changesets on main before each cut +// (.agents/shortcuts/cut-beta.md), which can mean rewording text or escalating a +// misclassified bump. Allow that only from release-audit/ branches whose diff +// edits or deletes existing changesets and nothing else. +function isReleaseAuditChangesetMaintenance(changes, headRef) { + if (!String(headRef || '').startsWith(RELEASE_AUDIT_BRANCH_PREFIX)) return false; + if (changes.length === 0) return false; + + return changes.every(change => (change.status === 'M' || change.status === 'D') + && (change.paths || []).length > 0 + && change.paths.every(isChangesetFile)); +} + function isChangesetStatusExemptMaintenance(changes) { let exemptChange = false; @@ -235,7 +249,9 @@ function changedPathForHead(change) { return change.paths[change.paths.length - 1] || null; } -function findChangesetProtocolScopeViolations(changes, readFileAtHead, readFileAtBase = () => '') { +function findChangesetProtocolScopeViolations(changes, readFileAtHead, readFileAtBase = () => '', { headRef = '' } = {}) { + if (isReleaseAuditChangesetMaintenance(changes, headRef)) return []; + const changesetFiles = []; const protocolScopedFiles = []; @@ -292,6 +308,14 @@ function defaultBaseRef() { return 'origin/main'; } +function defaultHeadRef() { + if (process.env.CHANGESET_SCOPE_HEAD_REF) return process.env.CHANGESET_SCOPE_HEAD_REF; + if (process.env.GITHUB_EVENT_NAME === 'pull_request' && process.env.GITHUB_HEAD_REF) { + return process.env.GITHUB_HEAD_REF; + } + return ''; +} + function formatViolationMessage(violations) { return [ 'Non-protocol changeset detected:', @@ -346,7 +370,8 @@ function run(argv = process.argv.slice(2)) { const violations = findChangesetProtocolScopeViolations( changes, readFileAtHead, - filePath => readFileAtRef(baseRef, filePath) + filePath => readFileAtRef(baseRef, filePath), + { headRef: defaultHeadRef() } ); if (violations.length > 0) { @@ -376,6 +401,7 @@ module.exports = { isChangesetEditOnlyMaintenance, isChangesetStatusExemptMaintenance, isProtocolScopedPath, + isReleaseAuditChangesetMaintenance, parseNameStatus, run, }; diff --git a/tests/changeset-protocol-scope.test.cjs b/tests/changeset-protocol-scope.test.cjs index 191be5c1a4d..9cfe287ae2c 100644 --- a/tests/changeset-protocol-scope.test.cjs +++ b/tests/changeset-protocol-scope.test.cjs @@ -13,6 +13,7 @@ const { isChangesetEditOnlyMaintenance, isChangesetStatusExemptMaintenance, isProtocolScopedPath, + isReleaseAuditChangesetMaintenance, isStoryboardBranchRegistrationOnly, parseNameStatus, } = require('../scripts/check-changeset-protocol-scope.cjs'); @@ -44,6 +45,9 @@ const emptyChangeset = `--- No package release. `; +const rewordedProtocolChangeset = protocolChangeset.replace('Update the protocol.', 'Clarify the protocol.'); +const releaseAudit = { headRef: 'release-audit/3.3.0-beta.1' }; + function readFiles(files) { return filePath => files[filePath] || ''; } @@ -243,6 +247,76 @@ violations = findChangesetProtocolScopeViolations( ); assert.strictEqual(violations.length, 1, 'Editing protocol changeset prose without a classification downgrade still fails'); +violations = findChangesetProtocolScopeViolations( + [{ status: 'M', paths: ['.changeset/existing-protocol-fix.md'] }], + readFiles({ '.changeset/existing-protocol-fix.md': rewordedProtocolChangeset }), + readFiles({ '.changeset/existing-protocol-fix.md': protocolChangeset }), + releaseAudit +); +assert.deepStrictEqual(violations, [], 'Release-audit branches can edit protocol changeset text'); + +violations = findChangesetProtocolScopeViolations( + [ + { status: 'M', paths: ['.changeset/existing-protocol-fix.md'] }, + { status: 'D', paths: ['.changeset/old-app-fix.md'] }, + ], + readFiles({ '.changeset/existing-protocol-fix.md': majorProtocolChangeset }), + readFiles({ '.changeset/existing-protocol-fix.md': protocolChangeset }), + releaseAudit +); +assert.deepStrictEqual(violations, [], 'Release-audit branches can escalate a misclassified changeset bump'); + +violations = findChangesetProtocolScopeViolations( + [{ status: 'M', paths: ['.changeset/existing-protocol-fix.md'] }], + readFiles({ '.changeset/existing-protocol-fix.md': majorProtocolChangeset }), + readFiles({ '.changeset/existing-protocol-fix.md': protocolChangeset }), + { headRef: 'fix/release-audit/escalate' } +); +assert.strictEqual(violations.length, 1, 'Only the release-audit/ head-branch prefix relaxes changeset edits'); + +violations = findChangesetProtocolScopeViolations( + [ + { status: 'M', paths: ['.changeset/existing-protocol-fix.md'] }, + { status: 'M', paths: ['server/src/billing/subscription-sync.ts'] }, + ], + readFiles({ '.changeset/existing-protocol-fix.md': majorProtocolChangeset }), + readFiles({ '.changeset/existing-protocol-fix.md': protocolChangeset }), + releaseAudit +); +assert.strictEqual(violations.length, 1, 'Release-audit branches that touch non-changeset files are checked normally'); + +violations = findChangesetProtocolScopeViolations( + [{ status: 'A', paths: ['.changeset/new-protocol-fix.md'] }], + readFiles({ '.changeset/new-protocol-fix.md': protocolChangeset }), + readFiles({}), + releaseAudit +); +assert.strictEqual(violations.length, 1, 'Release-audit branches cannot add new protocol changesets'); + +assert.strictEqual( + isReleaseAuditChangesetMaintenance( + [{ status: 'M', paths: ['.changeset/existing-protocol-fix.md'] }], + 'main' + ), + false, + 'Changeset edits from other branches are not release-audit maintenance' +); + +assert.strictEqual( + isReleaseAuditChangesetMaintenance( + [{ status: 'R090', paths: ['.changeset/old-name.md', '.changeset/new-name.md'] }], + releaseAudit.headRef + ), + false, + 'Release-audit maintenance does not cover renamed changesets' +); + +assert.strictEqual( + isReleaseAuditChangesetMaintenance([], releaseAudit.headRef), + false, + 'An empty diff is not release-audit maintenance' +); + assert.strictEqual( isChangesetClassificationMaintenance( [{ status: 'M', paths: ['.changeset/existing-protocol-fix.md'] }], From 65a472ef5361807b8096949477ee5720b055ca74 Mon Sep 17 00:00:00 2001 From: Synaeve Date: Tue, 10 Nov 2026 13:45:18 +0100 Subject: [PATCH 2/2] fix(ci): resolve the head branch locally in the changeset scope check --- scripts/check-changeset-protocol-scope.cjs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/check-changeset-protocol-scope.cjs b/scripts/check-changeset-protocol-scope.cjs index 1248cfdc2a8..66273189360 100644 --- a/scripts/check-changeset-protocol-scope.cjs +++ b/scripts/check-changeset-protocol-scope.cjs @@ -313,7 +313,12 @@ function defaultHeadRef() { if (process.env.GITHUB_EVENT_NAME === 'pull_request' && process.env.GITHUB_HEAD_REF) { return process.env.GITHUB_HEAD_REF; } - return ''; + // Local runs (prep-for-pr) should grade a release-audit branch the way CI will. + try { + return git(['rev-parse', '--abbrev-ref', 'HEAD']).trim(); + } catch { + return ''; + } } function formatViolationMessage(violations) {