Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

release:restamp moves a stamped branch's own BEHAVIOR_CHANGES rows to the new version

garrytane7c327e9af3a
diff --git a/docs/RELEASING.md b/docs/RELEASING.md
index 021f2e45de..9649b6a2f6 100644
--- a/docs/RELEASING.md
+++ b/docs/RELEASING.md
@@ -208,7 +208,7 @@ and the commit it would make, and changes nothing.
date), branch-added TODOS lines naming the old version, and every
`since: 'TBD'` row in `src/core/behavior-change-notice.ts` (development
branches write their BEHAVIOR_CHANGES rows as TBD; the stamp gives them the
- new version).
+ new version, and a restamp moves the branch's own rows from the old version).
5. Renumbers the branch's own schema migrations (files `origin/master` does
not have) consecutively from master's latest + 1, in their original order.
It changes only the filename, the `export const v<NNN>` name and the
diff --git a/scripts/lib/restamp.ts b/scripts/lib/restamp.ts
index 47cc37cca2..02452459bf 100644
--- a/scripts/lib/restamp.ts
+++ b/scripts/lib/restamp.ts
@@ -179,6 +179,12 @@ export function restampTodoLines(text: string, addedLines: Set<number>, oldVersi
return text.split('\n').map((l, i) => (addedLines.has(i + 1) ? l.split(`v${oldVersion}`).join(`v${newVersion}`) : l)).join('\n');
}
+/** Rewrite `since: 'OLD'` to `since: 'NEW'` on branch-added lines (1-based): a stamped branch's own BEHAVIOR_CHANGES rows follow a restamp. */
+export function restampSinceLines(text: string, addedLines: Set<number>, oldVersion: string, newVersion: string): string {
+ if (oldVersion === newVersion) return text;
+ return text.split('\n').map((l, i) => (addedLines.has(i + 1) ? l.split(`since: '${oldVersion}'`).join(`since: '${newVersion}'`) : l)).join('\n');
+}
+
// ---------------------------------------------------------------- migrations
export const MIGRATIONS_DIR = 'src/core/schema-migrations';
diff --git a/scripts/release-restamp.ts b/scripts/release-restamp.ts
index d43d8407af..00b5242bb6 100644
--- a/scripts/release-restamp.ts
+++ b/scripts/release-restamp.ts
@@ -37,7 +37,7 @@ import { join, resolve } from 'node:path';
import {
BEHAVIOR_NOTICE_FILE, COLLISION_DOCS, MIGRATION_FILE_RE, MIGRATIONS_DIR, RESTAMP_DOCS, RestampError, STAMPS,
branchEntrySections, fail, findLeftoverRefs, isGenerated, migrationPayloadKey, nextPatchVersion, parseAddedLines,
- isVersionToken, planRenumber, rebuildChangelog, renumberMigrationText, resolveVersionOnlyHunks, restampTodoLines, stampTbdSince, versionOfHeader,
+ isVersionToken, planRenumber, rebuildChangelog, renumberMigrationText, resolveVersionOnlyHunks, restampSinceLines, restampTodoLines, stampTbdSince, versionOfHeader,
type BranchMigration, type ChangelogSection, type LeftoverRef, type Renumber,
} from './lib/restamp.ts';
import { offlineEnv } from './regen-all.ts';
@@ -346,12 +346,14 @@ function restampTree(ctx: Ctx, state: State, opts: { acceptRefs: boolean; date:
const text = ctx.read(stamp.file);
if (stamp.read(text) !== version) ctx.write(stamp.file, stamp.write(text, version));
}
+ const olds = new Set([state.branchVersion, state.entry ? versionOfHeader(state.entry.header) ?? '' : ''].filter((v) => v && v !== version && isVersionToken(v)));
if (existsSync(join(ctx.root, BEHAVIOR_NOTICE_FILE))) {
const notice = ctx.read(BEHAVIOR_NOTICE_FILE);
- const stamped = stampTbdSince(notice, version);
+ const lines = new Set(addedLines(ctx, state.masterRef, ['--', BEHAVIOR_NOTICE_FILE]).map((l) => l.line));
+ let stamped = stampTbdSince(notice, version);
+ for (const old of olds) stamped = restampSinceLines(stamped, lines, old, version);
if (stamped !== notice) ctx.write(BEHAVIOR_NOTICE_FILE, stamped);
}
- const olds = new Set([state.branchVersion, state.entry ? versionOfHeader(state.entry.header) ?? '' : ''].filter((v) => v && v !== version && isVersionToken(v)));
if (state.entry) {
const old = versionOfHeader(state.entry.header) ?? state.branchVersion;
ctx.write('CHANGELOG.md', rebuildChangelog(ctx.read('CHANGELOG.md'), state.entry, old, version, opts.date));
diff --git a/test/scripts/check-behavior-since.test.ts b/test/scripts/check-behavior-since.test.ts
index df52e7aba4..da8b89c05c 100644
--- a/test/scripts/check-behavior-since.test.ts
+++ b/test/scripts/check-behavior-since.test.ts
@@ -13,7 +13,7 @@ import { tmpdir } from 'node:os';
import { dirname, join } from 'node:path';
import { main, NOTICE_FILE, tbdLines } from '../../scripts/check-behavior-since.ts';
import { DEFAULT_CHECKS } from '../../scripts/release-restamp.ts';
-import { BEHAVIOR_NOTICE_FILE, stampTbdSince } from '../../scripts/lib/restamp.ts';
+import { BEHAVIOR_NOTICE_FILE, restampSinceLines, stampTbdSince } from '../../scripts/lib/restamp.ts';
const roots: string[] = [];
afterAll(() => { for (const root of roots) rmSync(root, { recursive: true, force: true }); });
@@ -150,6 +150,12 @@ describe('release:restamp and the TBD rows', () => {
expect(BEHAVIOR_NOTICE_FILE).toBe(NOTICE_FILE);
});
+ test('restampSinceLines moves only branch-added rows from the old version to the new one', () => {
+ const text = notice('0.60.323.0', '0.60.323.0', '0.60.323.0');
+ expect(restampSinceLines(text, new Set([3, 4]), '0.60.323.0', '0.60.324.0')).toBe(notice('0.60.323.0', '0.60.324.0', '0.60.324.0'));
+ expect(restampSinceLines(text, new Set([3]), '0.60.324.0', '0.60.324.0')).toBe(text);
+ });
+
test("restamp's drift checks run the guard with --stamped", () => {
expect(DEFAULT_CHECKS.map((c) => c.argv.join(' '))).toContain('bun scripts/check-behavior-since.ts --stamped');
});