Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .agents/shortcuts/cut-beta.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<version>` branch
that touches only `.changeset/*.md`, so the changeset scope check accepts text
edits and bump escalations.

### Publish

Expand Down
35 changes: 33 additions & 2 deletions scripts/check-changeset-protocol-scope.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 = [];

Expand Down Expand Up @@ -292,6 +308,19 @@ 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;
}
// 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) {
return [
'Non-protocol changeset detected:',
Expand Down Expand Up @@ -346,7 +375,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) {
Expand Down Expand Up @@ -376,6 +406,7 @@ module.exports = {
isChangesetEditOnlyMaintenance,
isChangesetStatusExemptMaintenance,
isProtocolScopedPath,
isReleaseAuditChangesetMaintenance,
parseNameStatus,
run,
};
74 changes: 74 additions & 0 deletions tests/changeset-protocol-scope.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
isChangesetEditOnlyMaintenance,
isChangesetStatusExemptMaintenance,
isProtocolScopedPath,
isReleaseAuditChangesetMaintenance,
isStoryboardBranchRegistrationOnly,
parseNameStatus,
} = require('../scripts/check-changeset-protocol-scope.cjs');
Expand Down Expand Up @@ -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] || '';
}
Expand Down Expand Up @@ -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'] }],
Expand Down
Loading