Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
release:unstamp no longer refuses a branch for changes master made after it
garrytan2005509d18a2
diff --git a/scripts/release-restamp.ts b/scripts/release-restamp.tsindex 163298a443..a46a095374 100644--- a/scripts/release-restamp.ts+++ b/scripts/release-restamp.ts@@ -209,19 +209,23 @@ interface MigrationAnalysis { masterMax: number; branch: BranchMigration[]; plan/*** Split `head` migrations into published (on the master ref) and branch-only,* with the payload identity rules: a published file must keep master's- * payload, and a branch file must not be a copy of a published one.+ * payload unless only master changed it since the merge base, and a branch+ * file must not be a copy of a published one.*/function analyzeMigrations(ctx: Ctx, masterRef: string, head: Map<string, string>): MigrationAnalysis {const masterFiles = migrationPaths(ctx.git('ls-tree', '--name-only', `${masterRef}:${MIGRATIONS_DIR}`).split('\n'));const masterText = catFiles(ctx, masterRef, masterFiles.map((m) => m.path));const masterMax = Math.max(...masterFiles.map((m) => m.version));const masterKeys = new Map(masterFiles.map((m) => [migrationPayloadKey(masterText.get(m.path)!, m.path), m.path]));+ const mergeBase = ctx.git('merge-base', 'HEAD', masterRef).trim();+ const baseText = catFiles(ctx, mergeBase, migrationPaths(ctx.git('ls-tree', '--name-only', `${mergeBase}:${MIGRATIONS_DIR}`).split('\n')).map((m) => m.path));+ const changes = (from: string | undefined, to: string, path: string) => from === undefined || (from !== to && migrationPayloadKey(from, path) !== migrationPayloadKey(to, path));const branch: BranchMigration[] = [];for (const m of migrationPaths([...head.keys()].map((p) => p.slice(MIGRATIONS_DIR.length + 1)))) {const text = head.get(m.path)!;const published = masterText.get(m.path);if (published !== undefined) {- if (published !== text && migrationPayloadKey(published, m.path) !== migrationPayloadKey(text, m.path)) {+ if (changes(published, text, m.path) && changes(baseText.get(m.path), text, m.path)) {fail(`${m.path} is published on ${masterRef} but this branch changes its payload`,'brains that already applied it never run it again, so an edit to a published migration silently never lands; restamp never renumbers or edits published migrations.',[`put the change in a new migration (bun run new:migration <name>) and restore the file: git checkout ${masterRef} -- ${m.path}`, 'commit, then rerun: bun run release:restamp'], COLLISION_DOCS);@@ -278,7 +282,7 @@ const ROW_DUMP = `import { BEHAVIOR_CHANGES } from './${BEHAVIOR_NOTICE_FILE}';console.log(JSON.stringify(BEHAVIOR_CHANGES.map((r) => ({ id: r.id ?? null, text: typeof r.text === 'string' ? r.text : null }))));`;/**- * The BEHAVIOR_CHANGES rows this branch appended (ids its merge base does not hold), read from the evaluated table at+ * The BEHAVIOR_CHANGES rows this branch appended (the ids on the lines it added since the merge base), read from the evaluated table at* HEAD. release:unstamp moves them to behavior-changes.d/, so it refuses a branch whose notice-file diff is anything* but appended table lines, a row without an id, and a row whose text is a function (convert that one by hand).*/@@ -299,8 +303,8 @@ function branchNoticeRows(ctx: Ctx, masterRef: string, mergeBase: string): Arrayconst rows = (() => { try { return JSON.parse(r.out.trim().split('\n').at(-1) ?? '') as Array<{ id: string | null; text: string | null }>; } catch { return null; } })();if (r.code !== 0 || !rows) fail(`could not read the BEHAVIOR_CHANGES table at HEAD (exit ${r.code}): ${r.out.trim().split('\n').slice(-3).join(' ')}`, 'release:unstamp reads each appended row\'s text from the evaluated table.', 'fix the table so bun can import it, then rerun: bun run release:unstamp');const ids = (text: string) => new Set([...text.matchAll(/\bid: '([^']+)'/g)].map((m) => m[1]!));- const baseIds = ids(ctx.git('show', `${mergeBase}:${BEHAVIOR_NOTICE_FILE}`));- const mine = rows.filter((row): row is { id: string; text: string | null } => !!row.id && !baseIds.has(row.id));+ const appended = ids(added.map((l) => l.text).join('\n'));+ const mine = rows.filter((row): row is { id: string; text: string | null } => !!row.id && appended.has(row.id));const fn = mine.filter((row) => row.text === null).map((row) => row.id);if (fn.length > 0) fail(`${fn.length} appended row(s) compute their text (${fn.join(', ')})`, 'a function row stays in the table, dated since: releasedIn(\'<id>\'), which release:unstamp does not write for you.', ["change each to { since: releasedIn('<id>'), id: '<id>', ... }, name <!-- behavior-change: <id> --> in changelog.d/<slug>.md, commit,", 'then rerun: bun run release:unstamp']);const taken = [...ids(ctx.git('show', `${masterRef}:${BEHAVIOR_NOTICE_FILE}`))].filter((id) => mine.some((row) => row.id === id));diff --git a/scripts/structural-suites.tsv b/scripts/structural-suites.tsvindex 53ecf51227..4a72c55433 100644--- a/scripts/structural-suites.tsv+++ b/scripts/structural-suites.tsv@@ -357,7 +357,7 @@ test/scripts/promote-stable.test.ts promote-stable.yml 2 readFileSynctest/scripts/regen-all.test.ts regen:all 5 readFileSynctest/scripts/release-restamp.test.ts release-restamp --stamp-only 2 readFileSynctest/scripts/release-restamp.test.ts release:restamp end to end 15 readFileSync-test/scripts/release-restamp.test.ts release:unstamp and merge: direct 6 readFileSync+test/scripts/release-restamp.test.ts release:unstamp and merge: direct 8 readFileSynctest/scripts/require-executed-tests.test.ts require-executed-tests 9 readFileSynctest/scripts/run-verify-parallel.test.ts guard registration ⇒ execution coverage 1 readFileSynctest/scripts/run-verify-parallel.test.ts run-verify-parallel.sh — no-timeout-binary fallback rc capture (regression) 7 readFileSyncdiff --git a/test/scripts/release-restamp.test.ts b/test/scripts/release-restamp.test.tsindex e8ca39d5fe..18d583d308 100644--- a/test/scripts/release-restamp.test.ts+++ b/test/scripts/release-restamp.test.ts@@ -679,6 +679,40 @@ describe('release:unstamp and merge: direct', () => {expect(read(fx.work, 'changelog.d/feature.md')).toBe('Another PR.\n');}, 120_000);+ test('a published migration that only master changed after the merge base does not refuse the branch', () => {+ const fx = noticeFixture();+ branchWork(fx, '0.1.1.0', { 'src/widgets.ts': 'export const W = 1;\n' });+ landOnMaster(fx, '0.1.1.0', null, { ...POLICY_DIRECT, [migrationFile(208, 'seed_two')]: migration(208, 'seed_two', 'CREATE TABLE IF NOT EXISTS seed_two (id BIGINT);') });+ const r = restamp(fx.work, ['--unstamp'], QUIET);+ expect(r.out).not.toContain('is published on origin/master but this branch changes its payload');+ expect(r.code).toBe(0);+ expect(read(fx.work, migrationFile(208, 'seed_two'))).toBe(git(fx.work, 'show', `origin/master:${migrationFile(208, 'seed_two')}`));+ expect(read(fx.work, 'changelog.d/feature.md')).toContain('Widgets now sync twice as fast.');+ }, 120_000);++ test('rows the table pulls in from released fragments are master\'s, not the branch\'s', () => {+ const fx = noticeFixture();+ const RELEASED = 'src/core/released-rows.ts';+ const table = (...rows: string[]) => [`import { RELEASED_ROWS } from './released-rows.ts';`, ...noticeFile(...rows).split('\n').slice(0, 2), ' ...RELEASED_ROWS,', ...rows, '];', ''].join('\n');+ put(fx.master, {+ [NOTICE]: table(),+ [RELEASED]: "export const RELEASED_ROWS = [{ since: '0.1.0.0', id: 'released_row_abc', text: 'Released.' }];\n",+ 'behavior-changes.d/released_row_abc.md': 'Released.\n',+ });+ commit(fx.master, 'released rows');+ git(fx.master, 'push', '-q', 'origin', 'master');+ git(fx.work, 'fetch', '-q', 'origin');+ git(fx.work, 'merge', '-q', '--ff-only', 'origin/master');+ branchWork(fx, '0.1.1.0', { [NOTICE]: table(BRANCH_ROW) });+ landOnMaster(fx, '0.1.1.0', null, POLICY_DIRECT);+ const r = restamp(fx.work, ['--unstamp'], QUIET);+ expect(r.out).not.toContain('already name a row');+ expect(r.code).toBe(0);+ expect(r.out).toContain('1 row(s) in behavior-changes.d/ (faster_sync_abc)');+ expect(read(fx.work, NOTICE)).toBe(git(fx.work, 'show', `origin/master:${NOTICE}`));+ expect(read(fx.work, 'behavior-changes.d/released_row_abc.md')).toBe('Released.\n');+ }, 120_000);+test('plain restamp is refused when origin/master says merge: direct', () => {const fx = noticeFixture();branchWork(fx, '0.1.1.0', {});