Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
ci(release): refuse a CHANGELOG.md that drops a release heading origin/master has
garrytan95fa11f94987
diff --git a/docs/RELEASING.md b/docs/RELEASING.mdindex 964205f79e..021f2e45de 100644--- a/docs/RELEASING.md+++ b/docs/RELEASING.md@@ -227,7 +227,8 @@ and the commit it would make, and changes nothing.with `--continue` when a line means the published migration.8. Runs the drift checks (version stamps and CHANGELOG agree, bootstrapstamp, plugin tree, template repo, migration registry and order, no- `since: 'TBD'` row left: `bun scripts/check-behavior-since.ts --stamped`), commits+ `since: 'TBD'` row left: `bun scripts/check-behavior-since.ts --stamped`, and every+ master release heading still in CHANGELOG.md: `bun scripts/check-changelog-headings.ts`), commitsonce as `v<new> chore(release): restamp onto master v<master>`, and printsthe old-to-new migration mapping with the collision-recovery steps, thegolden-regeneration reason for the PR body, the PR title anddiff --git a/package.json b/package.jsonindex 2e74545c66..22797ebd1b 100644--- a/package.json+++ b/package.json@@ -175,6 +175,7 @@"check:bash32": "bash scripts/check-bash32.sh","check:schema-migration-order": "bun scripts/check-schema-migration-order.ts","check:behavior-since": "bun scripts/check-behavior-since.ts",+ "check:changelog-headings": "bun scripts/check-changelog-headings.ts","check:compile-autoload": "bash scripts/check-compile-autoload.sh","check:structural-manifest": "bash scripts/check-structural-manifest.sh","regen:all": "bun scripts/regen-all.ts",diff --git a/scripts/check-changelog-headings.ts b/scripts/check-changelog-headings.tsnew file mode 100644index 0000000000..acca053d14--- /dev/null+++ b/scripts/check-changelog-headings.ts@@ -0,0 +1,50 @@+#!/usr/bin/env bun+/**+ * check:changelog-headings — CHANGELOG.md keeps every release heading origin/master has.+ *+ * A tool or agent that rewrites CHANGELOG.md from a partial read can cut the file+ * (a 42k-line changelog written back as its first few hundred lines). Every+ * `## [X]` heading on the base ref must still be in the working tree's file.+ * Base ref: $GBRAIN_CHANGELOG_BASE_REF, default origin/master; unavailable: fails+ * under CI=true, skips locally. Exit 0 ok or skipped, 1 refused.+ * Docs: docs/RELEASING.md#release-restamp+ */+import { spawnSync } from 'node:child_process';+import { existsSync, readFileSync } from 'node:fs';+import { join } from 'node:path';++export function releaseHeadings(text: string): string[] {+ return text.split('\n').filter((line) => line.startsWith('## ['));+}++export function main(opts: { cwd?: string; env?: Record<string, string | undefined>; log?: (line: string) => void } = {}): number {+ const root = opts.cwd ?? process.cwd();+ const env = opts.env ?? process.env;+ const log = opts.log ?? ((line: string) => console.log(line));+ const ref = env.GBRAIN_CHANGELOG_BASE_REF || 'origin/master';+ const base = spawnSync('git', ['show', `${ref}:CHANGELOG.md`], { cwd: root, encoding: 'utf8', maxBuffer: 256 * 1024 * 1024 });+ if (base.status !== 0) {+ if (env.CI === 'true') {+ log(`FAIL: check-changelog-headings: cannot read ${ref}:CHANGELOG.md`);+ log('Fix: fetch the base ref (git fetch --no-tags --depth=1 origin +refs/heads/master:refs/remotes/origin/master)');+ return 1;+ }+ log(`skip: check-changelog-headings: ${ref} is not available`);+ log(`GBRAIN_CHECK_SKIPPED: base ref ${ref} unavailable`);+ return 0;+ }+ const file = join(root, 'CHANGELOG.md');+ const have = new Set(existsSync(file) ? releaseHeadings(readFileSync(file, 'utf8')) : []);+ const missing = releaseHeadings(base.stdout).filter((heading) => !have.has(heading));+ if (missing.length === 0) {+ log(`check-changelog-headings: ok (every release heading on ${ref} is present)`);+ return 0;+ }+ log(`FAIL: CHANGELOG.md is missing ${missing.length} release heading(s) that ${ref} has (first: ${missing[0]}).`);+ log('Why: release history never leaves the changelog; a missing heading means the file was cut or an entry was deleted.');+ log(`Fix: restore it from the base (git show ${ref}:CHANGELOG.md > CHANGELOG.md), put this branch\'s entry back on top, then rerun bun run check:changelog-headings.`);+ log('See: docs/RELEASING.md#release-restamp');+ return 1;+}++if (import.meta.main) process.exit(main());diff --git a/scripts/guards-manifest.tsv b/scripts/guards-manifest.tsvindex e4d304135e..b103c96b16 100644--- a/scripts/guards-manifest.tsv+++ b/scripts/guards-manifest.tsv@@ -82,6 +82,7 @@ check-shared-tree-git.sh scanner yes #6530: unsafe shared-checkout git (pull --rcheck-bash32.sh scanner todo #5810: every tracked *.sh parses under bash 3.2 (real parser: GBRAIN_BASH32, stock macOS /bin/bash, or the digest-pinned bash:3.2 image); not in verify CHECKS or this self-test, which must not need Docker; its bad/good fixtures run in test/scripts/check-bash32.test.ts, mandatory in the test.yml verify-job step (GBRAIN_TEST_BASH32_REQUIRE=1)check-schema-migration-order.ts repostate exempt EO10: a migration origin/master lacks must be numbered above its latest version; reads the base ref from git (unit: test/scripts/build-schema-migrations.test.ts)check-behavior-since.ts repostate exempt A since: 'TBD' BEHAVIOR_CHANGES row never ships: refused on a stamped tree, on master and with --stamped (restamp, Release); reads the base ref from git (unit: test/scripts/check-behavior-since.test.ts)+check-changelog-headings.ts repostate exempt CHANGELOG.md keeps every release heading origin/master has; reads the base ref from git (unit: test/scripts/check-changelog-headings.test.ts)check-structural-manifest.sh buildfresh exempt regenerate+diff of structural-suites.tsv (classify-tests.ts); the diff IS the self-testcheck-opencode-pin.sh repostate exempt pin-stamp drift check (OPENCODE-CLI-PIN.md stamps vs heavy-tests opencode-door env); own bun guard tests in test/check-bootstrap-guards.test.tscheck-pin-doc-privacy.sh repostate exempt PIN-doc placeholder discipline (no operator paths/key material/emails in docs/mcp/*-CLI-PIN.md); own bun guard tests in test/check-bootstrap-guards.test.tsdiff --git a/scripts/release-restamp.ts b/scripts/release-restamp.tsindex 629a413564..d43d8407af 100644--- a/scripts/release-restamp.ts+++ b/scripts/release-restamp.ts@@ -73,6 +73,7 @@ export const DEFAULT_CHECKS: Step[] = [{ name: 'schema migration registry fresh', argv: ['bash', 'scripts/check-schema-migrations-fresh.sh'] },{ name: 'schema migration order', argv: ['bun', 'scripts/check-schema-migration-order.ts'] },{ name: "no since: 'TBD' BEHAVIOR_CHANGES row", argv: ['bun', 'scripts/check-behavior-since.ts', '--stamped'] },+ { name: 'CHANGELOG keeps every master release heading', argv: ['bun', 'scripts/check-changelog-headings.ts'] },];interface State {diff --git a/scripts/run-verify-parallel.sh b/scripts/run-verify-parallel.shindex 0d7b52648b..b5441c90bf 100755--- a/scripts/run-verify-parallel.sh+++ b/scripts/run-verify-parallel.sh@@ -215,6 +215,8 @@ CHECKS=(# A since: 'TBD' BEHAVIOR_CHANGES row never ships: refused on a stamped tree# (VERSION has a CHANGELOG header and differs from origin/master's) and on master."check:behavior-since"+ # CHANGELOG.md keeps every release heading origin/master has (a cut file is refused).+ "check:changelog-headings""check:structural-manifest"# Every generated artifact's freshness in one place (GBRA-47 B8); its Fix# line is `bun run regen:all`, the same code path that regenerates them.diff --git a/test/scripts/check-changelog-headings.test.ts b/test/scripts/check-changelog-headings.test.tsnew file mode 100644index 0000000000..8a347725e7--- /dev/null+++ b/test/scripts/check-changelog-headings.test.ts@@ -0,0 +1,65 @@+/**+ * check:changelog-headings (scripts/check-changelog-headings.ts): a CHANGELOG.md+ * that drops any release heading origin/master has is refused; one that only adds+ * an entry on top passes. Fixtures are throwaway git repos.+ */+import { afterAll, describe, expect, test } from 'bun:test';+import { execFileSync } from 'node:child_process';+import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';+import { main } from '../../scripts/check-changelog-headings.ts';+import { DEFAULT_CHECKS } from '../../scripts/release-restamp.ts';++const roots: string[] = [];+afterAll(() => { for (const root of roots) rmSync(root, { recursive: true, force: true }); });+const git = (cwd: string, ...args: string[]) => execFileSync('git', args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] });+const changelog = (...versions: string[]) => '# Changelog\n\n' + versions.map((v) => '## [' + v + '] - 2026-10-20\n\nEntry ' + v + '.\n').join('\n');++function repo(): string {+ const root = mkdtempSync(join(tmpdir(), 'gbrain-changelog-headings-'));+ roots.push(root);+ git(root, 'init', '-q', '-b', 'master');+ git(root, 'config', 'user.email', '[email protected]');+ git(root, 'config', 'user.name', 't');+ writeFileSync(join(root, 'CHANGELOG.md'), changelog('0.60.322.0', '0.60.321.0', '0.60.46.0'));+ git(root, 'add', '-A');+ git(root, 'commit', '-q', '-m', 'master');+ git(root, 'update-ref', 'refs/remotes/origin/master', 'HEAD');+ return root;+}++function run(root: string, env: Record<string, string> = {}): { code: number; out: string } {+ const lines: string[] = [];+ const code = main({ cwd: root, env, log: (line) => lines.push(line) });+ return { code, out: lines.join('\n') };+}++describe('check:changelog-headings', () => {+ test('a new entry on top of every master heading passes', () => {+ const root = repo();+ writeFileSync(join(root, 'CHANGELOG.md'), changelog('0.60.323.0', '0.60.322.0', '0.60.321.0', '0.60.46.0'));+ expect(run(root).code).toBe(0);+ });++ test('a truncated changelog (the old entries cut off) is refused with a fix line', () => {+ const root = repo();+ writeFileSync(join(root, 'CHANGELOG.md'), changelog('0.60.323.0', '0.60.322.0'));+ const r = run(root);+ expect(r.code).toBe(1);+ expect(r.out).toContain('missing 2 release heading(s)');+ expect(r.out).toContain('## [0.60.321.0]');+ expect(r.out).toContain('Fix: restore it from the base');+ });++ test('without the base ref: refused under CI, skipped locally', () => {+ const root = repo();+ git(root, 'update-ref', '-d', 'refs/remotes/origin/master');+ expect(run(root, { CI: 'true' }).code).toBe(1);+ expect(run(root).out).toContain('GBRAIN_CHECK_SKIPPED');+ });++ test("release:restamp's drift checks run it", () => {+ expect(DEFAULT_CHECKS.map((c) => c.argv.join(' '))).toContain('bun scripts/check-changelog-headings.ts');+ });+});