Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
release:unstamp keeps reading notice-row ownership from the merge base's ids
garrytan7ba398070031
diff --git a/scripts/release-restamp.ts b/scripts/release-restamp.tsindex cad945964b..a3491d665b 100644--- a/scripts/release-restamp.ts+++ b/scripts/release-restamp.ts@@ -282,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 (the ids on the lines it added since the merge base), read from the evaluated table at+ * The BEHAVIOR_CHANGES rows this branch appended (ids its merge base does not hold), 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).*/@@ -297,15 +297,14 @@ function branchNoticeRows(ctx: Ctx, masterRef: string, mergeBase: string): Arrayconst close = head.findIndex((l, i) => i >= open && l === '];') + 1;const outside = added.filter((l) => l.line <= open || l.line >= close);if (removed !== '0' || outside.length > 0) fail(`this branch changes ${BEHAVIOR_NOTICE_FILE} beyond appending BEHAVIOR_CHANGES rows${outside.length ? ` (line ${outside.slice(0, 5).map((l) => l.line).join(', ')})` : ''}`, why, how);- const quotedId = /\bid:\s*(['"`])([^'"`]+)\1/g;- const noId = added.filter((l) => /\{ since:|\bid\s*:/.test(l.text) && !l.text.match(quotedId));+ const noId = added.filter((l) => /\{ since:/.test(l.text) && !/\bid: '/.test(l.text));if (noId.length > 0) fail(`${noId.length} BEHAVIOR_CHANGES row(s) this branch added have no id (line ${noId.map((l) => l.line).join(', ')})`, 'a moved row is named behavior-changes.d/<id>.md and dated by its id.', 'give each row an id (lowercase letters, digits and _), commit, then rerun: bun run release:unstamp');const r = ctx.run(['bun', '-e', ROW_DUMP]);const 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(quotedId)].map((m) => m[2]!));- 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 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 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 cc57488ebb..1822b887bf 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 16 readFileSync-test/scripts/release-restamp.test.ts release:unstamp and merge: direct 9 readFileSync+test/scripts/release-restamp.test.ts release:unstamp and merge: direct 7 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 60aee5fe89..cd68e367ef 100644--- a/test/scripts/release-restamp.test.ts+++ b/test/scripts/release-restamp.test.ts@@ -704,39 +704,6 @@ describe('release:unstamp and merge: direct', () => {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('a row whose id is double-quoted moves to its fragment instead of vanishing with the table', () => {- const fx = noticeFixture();- branchWork(fx, '0.1.1.0', { [NOTICE]: noticeFile(BRANCH_ROW, " { id: \"quoted_row_abc\", since: '0.1.1.0', text: 'Quoted id.' },") });- landOnMaster(fx, '0.1.1.0', null, POLICY_DIRECT);- const r = restamp(fx.work, ['--unstamp'], QUIET);- expect(r.code).toBe(0);- expect(read(fx.work, 'behavior-changes.d/quoted_row_abc.md')).toContain('Quoted id.');- expect(read(fx.work, 'behavior-changes.d/faster_sync_abc.md')).toContain('Sync is faster now.');- }, 120_000);-test('plain restamp is refused when origin/master says merge: direct', () => {const fx = noticeFixture();branchWork(fx, '0.1.1.0', {});