Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix: refuse a changelog fragment that asks for a bump other than patch

garrytan2c9253f50ca5
diff --git a/scripts/build-behavior-changes.ts b/scripts/build-behavior-changes.ts
index 8f35801e7e..84458c62aa 100644
--- a/scripts/build-behavior-changes.ts
+++ b/scripts/build-behavior-changes.ts
@@ -15,6 +15,7 @@
* Unreleased markers (changelog.d, `## [Unreleased]`) count only while a release is being stamped: VERSION is
* newer than the CHANGELOG's top release heading (gstack-restamp --release runs this before it folds the
* fragments). On every other tree they are pending and generate nothing, so a PR never changes the generated file.
+ * A changelog.d fragment whose front matter says `bump:` anything but `patch` is refused: releases are PATCH only.
* Dependency-free and history-free: gstack's release check reruns it in a bare worktree of the release head.
*
* Exit: 0 written or fresh, 1 stale or invalid (FAIL/Why/Fix printed), 2 usage.
@@ -72,6 +73,11 @@ export function build(root: string): Built {
const stamping = !!version && (!top || cmp(version, top) > 0);
const pendingFiles = existsSync(join(root, CHANGELOG_FRAGMENT_DIR))
? readdirSync(join(root, CHANGELOG_FRAGMENT_DIR)).filter(f => f.endsWith('.md') && f !== 'README.md').sort() : [];
+ for (const f of pendingFiles) {
+ const front = /^---\r?\n([\s\S]*?)\r?\n---\s*(\n|$)/.exec(read(root, join(CHANGELOG_FRAGMENT_DIR, f)))?.[1] ?? '';
+ const bump = /^\s*bump\s*:\s*['"]?([^'"\s]*)['"]?\s*$/m.exec(front)?.[1];
+ if (bump !== undefined && bump !== 'patch') problems.push(`${CHANGELOG_FRAGMENT_DIR}/${f} says bump: ${bump}; gbrain releases are PATCH only and the release takes the highest bump in the batch, so delete the bump: line (or write bump: patch)`);
+ }
const pending = [...pendingFiles.flatMap(f => markers(read(root, join(CHANGELOG_FRAGMENT_DIR, f)))), ...releases.filter(r => !r.version).flatMap(r => r.ids)];
const sinceOf = new Map<string, string>();
const order: string[] = [];
diff --git a/test/scripts/build-behavior-changes.test.ts b/test/scripts/build-behavior-changes.test.ts
index f20c7290ee..f0e7a6a0c4 100644
--- a/test/scripts/build-behavior-changes.test.ts
+++ b/test/scripts/build-behavior-changes.test.ts
@@ -193,6 +193,16 @@ describe('build()', () => {
expect(remarked.problems).toEqual(['old_row_abc is marked again after release 0.1.0.0; a released id is never marked again']);
});
+ test('a changelog.d fragment whose front matter bumps anything but patch is refused, naming the file and the fix', () => {
+ const base = { VERSION: '0.1.0.0\n', 'CHANGELOG.md': changelog(section('0.1.0.0', 'First.')) };
+ for (const bump of ['minor', 'major', "'micro'"]) {
+ const { problems } = build(tree({ ...base, 'changelog.d/feature-x.md': `---\nbump: ${bump}\nimportant: security\n---\n**Faster sync.**\n` }));
+ expect(problems).toEqual([`changelog.d/feature-x.md says bump: ${bump.replace(/'/g, '')}; gbrain releases are PATCH only and the release takes the highest bump in the batch, so delete the bump: line (or write bump: patch)`]);
+ }
+ expect(build(tree({ ...base, 'changelog.d/feature-x.md': '---\nbump: patch\n---\n**Faster sync.**\n' })).problems).toEqual([]);
+ expect(build(tree({ ...base, 'changelog.d/feature-x.md': '**Faster sync.**\n\nbump: minor appears in prose here.\n' })).problems).toEqual([]);
+ });
+
test('an id starting with a digit is refused, so the generated map never holds an unquoted numeric key', () => {
const root = tree({
VERSION: '0.1.0.0\n',