Use Garry Tan's exact Claude Code setup: 23 opinionated tools that serve as CEO, Designer, Eng Manager, Release Manager, Doc Engineer, and QA
TypeScript
Release notes keep quoted versions, count only real changes and print each heading once (GST-3686) (#4803)
Garry Tan47b464a0d4a9
diff --git a/changelog.d/release-notes-keep-versions-and-headings.md b/changelog.d/release-notes-keep-versions-and-headings.mdnew file mode 100644index 000000000..ecfc3e7c2--- /dev/null+++ b/changelog.d/release-notes-keep-versions-and-headings.md@@ -0,0 +1,3 @@+### For contributors++- **A release no longer rewrites version numbers inside changelog entries, counts subsection headings as changes, or prints a subsection heading twice.** `gstack-restamp --release` copies each `changelog.d/` entry as written, even where the CHANGELOG is one of the policy's `stamp_files`, so a note that quotes the version being released from keeps pointing at it. The release PR lists one line per change, and entries that share a heading such as `### For contributors` sit under one copy of it. To correct an entry already on main, land a small PR before the release that deletes it and adds the fixed text under a new file name.diff --git a/docs/ship-policy.md b/docs/ship-policy.mdindex 68b617cf8..c2225d589 100644--- a/docs/ship-policy.md+++ b/docs/ship-policy.md@@ -2803,10 +2803,15 @@ writes no version in Step 12 and writes Step 13's entry as**The fold.** `gstack-restamp` (and so `land`) concatenates the fragmentbodies in path order above any legacy `[Unreleased]` section, re-heads both asone `## [<version>] - <date>` section at the top, and deletes the fragment-files, in one stamp. The tree receipt, and so `gstack-pregate clear`'s+files, in one stamp. Same-named `### ` subsections of the fragments merge into+one: their unheaded entries come first, then each subsection once, in the order+it first appears, with its entries in fold order, then the legacy text. A+`### ` line inside a fenced block is text. Every other line is copied+as written, and no version in it is rewritten, even when the CHANGELOG is one+of the policy's `stamp_files`. The tree receipt, and so `gstack-pregate clear`'sstamp-only substitution, calls a deleted fragment a stamp (rule-`changelog_fragments`) only when the new CHANGELOG section is exactly the-deleted fragments' bodies in path order above any legacy `[Unreleased]` text+`changelog_fragments`) only when the new CHANGELOG section is exactly what the+fold makes of the deleted fragments' bodies and any legacy `[Unreleased]` text(rule `changelog-fragments`); an edited fold, or a fragment deleted withoutits text, is a change.@@ -3349,7 +3354,9 @@ bump any fragment declares (the policy `bump` when none does). It reruns therelease tool, and it moves a tentative `stamp_paths` mention (a `*_KEY_VERSION`a PR wrote ahead of its release) on lines added since the last version change.With no fragment on main it refuses with-[`RELEASE_STAMP_EMPTY`](troubleshooting.md#release-stamp-empty).+[`RELEASE_STAMP_EMPTY`](troubleshooting.md#release-stamp-empty). The release+PR's body lists one line per change, never a subsection heading.+To correct a fragment already on main, land a small PR before the stamp that deletes it and adds the corrected text under a new file name (an edit in place is `CHANGELOG_FRAGMENT_INVALID`): `--release` refuses any head but a clean `origin/main`, so the release itself never carries the fix.When the release PR's checks are green, the Captain lands it like any other PR:`gstack-ship-queue land --pr <n> --pin <head>`. On a `release/<version>`diff --git a/lib/changelog-fragments.ts b/lib/changelog-fragments.tsindex 903cd4275..cddbb9fe1 100644--- a/lib/changelog-fragments.ts+++ b/lib/changelog-fragments.ts@@ -85,8 +85,10 @@ export function readFragments(cwd: string, treeish: string | null, dir: string,const shown = exclude && changelog ? readHistoryFile(cwd, exclude, changelog) : null;const released = shown !== null ? parseChangelog(shown.replace(/\r\n/g, '\n')).sections.filter(s => !s.unreleased).map(s => s.lines) : [];const isReleased = (body: string) => {- const want = body.split('\n');- return released.some(lines => lines.some((_, i) => want.every((w, k) => lines[i + k] === w)));+ const at = (lines: string[], want: string[]) => lines.some((_, i) => want.every((w, k) => lines[i + k] === w));+ const parts = subsections(body.split('\n')).map(p => ({ name: p.name, run: trimBlank(p.run, true) })).filter(p => p.run.length);+ if (!parts.length) return released.some(lines => at(lines, body.split('\n')));+ return released.some(lines => { const own = subsections(lines); return parts.every(({ name, run }) => (name ? own.filter(p => p.name === name).some(p => at(p.run, run)) : at(lines, run))); });};const fragments: Fragment[] = [];const errors: FragmentError[] = [];@@ -117,26 +119,62 @@ export function effectiveBump(level: Bump, fragments: readonly Fragment[]): Bumpreturn fragments.reduce<Bump>((acc, f) => (f.bump && BUMP_RANK[f.bump] > BUMP_RANK[acc] ? f.bump : acc), level);}+/** Lines with blank lines dropped from the end, and from the start too when `start` is set. */+function trimBlank(lines: string[], start: boolean): string[] {+ const out = [...lines];+ while (out.length && !out[out.length - 1]!.trim()) out.pop();+ while (start && out.length && !out[0]!.trim()) out.shift();+ return out;+}++/** A fragment body cut at its `### ` subsection headings, never inside a fenced block: each part's heading ('' before the first) and its lines as written. */+function subsections(lines: readonly string[]): Array<{ name: string; run: string[] }> {+ const parts: Array<{ name: string; run: string[] }> = [{ name: '', run: [] }];+ let fence: string | null = null;+ for (const line of lines) {+ const open = /^\s*(`{3,}|~{3,})/.exec(line)?.[1];+ const close = /^\s*(`{3,}|~{3,})\s*$/.exec(line)?.[1];+ if (fence === null && open) fence = open;+ else if (fence !== null && close && close[0] === fence[0] && close.length >= fence.length) fence = null;+ else if (fence === null && /^###\s+\S/.test(line)) { parts.push({ name: line.trim(), run: [] }); continue; }+ parts[parts.length - 1]!.run.push(line);+ }+ return parts;+}+/*** Put the fragment bodies, in path order, into the CHANGELOG's `[Unreleased]` section (created at the* top when absent), so the existing re-heading moves fragments and a legacy entry together under one- * version. Returns the text unchanged when there are no fragments.+ * version. Same-named `### ` subsections merge into one (#4785: two fragments each brought+ * "### For contributors"): the fragments' unheaded entries come first, then each subsection once in the+ * order it first appears, its entries in fold order, then any legacy `[Unreleased]` text as it stood+ * (crew/scripts/release-notes.ts reads the fragments' changes first). Every other line is copied as+ * written. Returns the text unchanged when there are no fragments.*/export function foldIntoUnreleased(text: string, fragments: readonly Fragment[]): string {if (!fragments.length) return text;const parsed = parseChangelog(text);- const bodies = fragments.map(f => f.body).join('\n\n');const unreleased = parsed.sections.find(s => s.unreleased);const lines = text.replace(/\r\n/g, '\n').split('\n');- if (unreleased) {- const own = lines.slice(unreleased.start + 1, unreleased.end);- while (own.length && !own[0]!.trim()) own.shift();- while (own.length && !own[own.length - 1]!.trim()) own.pop();- const merged = [lines[unreleased.start]!, '', ...bodies.split('\n'), ...(own.length ? ['', ...own] : []), ''];- return [...lines.slice(0, unreleased.start), ...merged, ...lines.slice(unreleased.end)].join('\n');+ const own = trimBlank(unreleased ? lines.slice(unreleased.start + 1, unreleased.end) : [], true);+ const groups = new Map<string, string[][]>([['', []]]);+ for (const f of fragments) for (const { name, run } of subsections(f.body.split('\n'))) {+ if (!groups.has(name)) groups.set(name, []);+ const runs = groups.get(name)!;+ const kept = trimBlank(run, !name || runs.length > 0);+ if (kept.some(l => l.trim())) runs.push(kept);+ }+ const section: string[] = [];+ for (const [name, runs] of groups) {+ if (!name && !runs.length) continue;+ if (section.length) section.push('');+ if (name) section.push(name);+ runs.forEach((r, i) => section.push(...(i ? ['', ...r] : r)));}+ if (own.length) section.push('', ...own);+ if (unreleased) return [...lines.slice(0, unreleased.start), lines[unreleased.start]!, '', ...section, '', ...lines.slice(unreleased.end)].join('\n');const at = parsed.sections[0]?.start ?? lines.length;const head = lines.slice(0, at);while (head.length && !head[head.length - 1]!.trim()) head.pop();- return [...head, ...(head.length ? [''] : []), '## [Unreleased]', '', ...bodies.split('\n'), '', ...lines.slice(at)].join('\n');+ return [...head, ...(head.length ? [''] : []), '## [Unreleased]', '', ...section, '', ...lines.slice(at)].join('\n');}diff --git a/lib/release-stamp.ts b/lib/release-stamp.tsindex 6dccde13f..8e13bae89 100644--- a/lib/release-stamp.ts+++ b/lib/release-stamp.ts@@ -26,12 +26,13 @@ export const RELEASE_BRANCH = /^release\/(\d+(?:\.\d+){2,3})$/;/*** The release notes (R76): one plain line per change the release folds, from each changelog fragment's entries (a* fragment may hold several `- ` entries): the bold lead sentence, or else the first sentence, with the pull request- * whose squash commit added the fragment (`(#n)` at the end of its subject) when git finds one.+ * whose squash commit added the fragment (`(#n)` at the end of its subject) when git finds one. A heading such as+ * `### For contributors` groups entries and is never a change of its own (#4785).*/export function releaseNoteLines(root: string, ref: string, fragments: readonly string[]): string[] {return fragments.flatMap(file => {const pr = /\(#(\d+)\)\s*$/.exec(git(root, ['log', '-1', '--diff-filter=A', '--format=%s', ref, '--', file]).out)?.[1];- const text = git(root, ['show', `${ref}:${file}`]).out.replace(/^---\n[\s\S]*?\n---\n/, '').trim();+ const text = git(root, ['show', `${ref}:${file}`]).out.replace(/^---\n[\s\S]*?\n---\n/, '').replace(/^#{1,6}(?:[ \t].*)?$/gm, '').trim();return text.split(/\n(?=- )/).map(entry => {const first = entry.replace(/^- +/, '').replace(/\s+/g, ' ').trim();const lead = (/^\*\*(.+?)\*\*/.exec(first)?.[1] ?? first.split(/(?<=[.!?])\s/)[0] ?? '').replace(/\*\*/g, '').trim();diff --git a/lib/restamp.ts b/lib/restamp.tsindex 0266cec37..038fc798e 100644--- a/lib/restamp.ts+++ b/lib/restamp.ts@@ -532,13 +532,14 @@ function runStages(o: RestampOptions, plan: Plan, staging: string, since: string* lost its slot and merged the base). Then a stamp-form mention of the base* version on a line the branch added is its own tentative stamp, stale now,* and moves; the same version on a line the base already carries is the- * base's release and stays. The detail names both counts per file.+ * base's release and stays. The detail names both counts per file. Under changelog_fragments the CHANGELOG is never+ * rewritten here, even as a stamp file: the changelog stage heads the new section, and folded prose stays as written (GBRA-784).*/function rewriteStampPaths(o: RestampOptions, plan: Plan, staging: string, since: string, sp: StageRecord): void {const stampGlobs = [...plan.policy.stamp_paths, ...plan.policy.stamp_files];const templates = plan.policy.stamp_patterns;if (stampGlobs.length === 0) { sp.status = 'skipped'; sp.detail = 'no stamp_paths in policy'; return; }- const files = git(staging, ['ls-files', '-z']).out.split('\0').filter(f => f && matchesAny(stampGlobs, f));+ const files = git(staging, ['ls-files', '-z']).out.split('\0').filter(f => f && matchesAny(stampGlobs, f) && !(plan.policy.changelog_fragments && f === plan.policy.changelog));for (const rel of files) {const why = assertInsideRoot(staging, rel);if (why) throw new Refusal('POLICY_CONTAINMENT', `${why}; nothing written`);diff --git a/test/changelog-fragments.test.ts b/test/changelog-fragments.test.tsindex 0e5509448..c4a5042d5 100644--- a/test/changelog-fragments.test.ts+++ b/test/changelog-fragments.test.ts@@ -68,6 +68,23 @@ describe('effectiveBump and the fold', () => {const r = reheadChangelog(folded, { from: null, to: '1.2.4.0', date: '2026-10-29' });expect(r.text).toBe('# Changelog\n\n## [1.2.4.0] - 2026-10-29\n\n- a\n\n- b\n\n- legacy\n\n## [1.2.3.0] - 2026-10-01\n\n- base\n');});+ // Value: protects=one copy of each subsection heading per release section, every entry's lines as written;+ // fails_when=fragments each bring "### For contributors" and the section carries it twice (#4785); seam=foldIntoUnreleased+ test('same-named subsection headings merge into one, unheaded entries first, legacy text last, and a heading inside a code fence is prose', () => {+ const cl = '# Changelog\n\n## [Unreleased]\n\n- legacy\n\n## [1.2.3.0] - 2026-10-01\n\n- base\n';+ const folded = foldIntoUnreleased(cl, [+ { path: 'changelog.d/a.md', body: '### For contributors\n\n- a', bump: null },+ { path: 'changelog.d/b.md', body: '**b lead.**\n\n### Fixed\n- b fix\n\n~~~md\n```\n### not a heading\n~~~', bump: null },+ { path: 'changelog.d/c.md', body: '- c\n\n### For contributors\n\n- c contrib', bump: null },+ ]);+ expect(folded).toBe('# Changelog\n\n## [Unreleased]\n\n**b lead.**\n\n- c\n\n### For contributors\n\n- a\n\n- c contrib\n\n### Fixed\n- b fix\n\n~~~md\n```\n### not a heading\n~~~\n\n- legacy\n\n## [1.2.3.0] - 2026-10-01\n\n- base\n');+ });+ test('a fence marker with text after it never closes a fence', () => {+ const cl = '# Changelog\n\n## [1.2.3.0] - 2026-10-01\n\n- base\n';+ const body = '### Added\n\n- a\n\n~~~md\n~~~text\n### inside\n~~~';+ const folded = foldIntoUnreleased(cl, [{ path: 'changelog.d/a.md', body, bump: null }, { path: 'changelog.d/b.md', body: '### inside\n\n- b', bump: null }]);+ expect(folded).toBe(`# Changelog\n\n## [Unreleased]\n\n${body}\n\n### inside\n\n- b\n\n## [1.2.3.0] - 2026-10-01\n\n- base\n`);+ });test('no fragments leaves the text unchanged', () => {expect(foldIntoUnreleased('# C\n', [])).toBe('# C\n');});@@ -206,4 +223,34 @@ describe('readFragments: text already released at the base', () => {expect(set.errors.map(e => e.path)).toEqual(['changelog.d/carried.md']);expect(set.errors[0]!.message).toContain('already released in CHANGELOG.md');});++ // Value: protects=a carried-back fragment whose heading the fold shared with another is still found released;+ // fails_when=the second "### For contributors" fragment of v1.103.2.0 folds again because its heading no longer sits+ // right above its body; seam=readFragments with the base CHANGELOG+ test('a released fragment whose subsection heading merged with another still refuses', () => {+ const repo = fixture();+ const dir = path.join(import.meta.dir, 'fixtures', 'release-stamp', 'v1.103.2.0');+ const frag = (name: string) => parseFragment(`changelog.d/${name}`, fs.readFileSync(path.join(dir, name), 'utf8')) as { path: string; body: string; bump: null };+ const shared = ['stable-benchmark-record-text-hardening.md', 'stable-release-reads-weekly-benchmark.md'];+ const folded = reheadChangelog(foldIntoUnreleased(readFile(repo, 'CHANGELOG.md'), shared.map(frag)), { from: null, to: '1.2.4.0', date: '2026-11-24' }).text;+ expect(folded.match(/^### For contributors$/gm)).toHaveLength(1);+ fs.writeFileSync(path.join(repo.work, 'CHANGELOG.md'), folded);+ repo.git('commit', '-qam', 'release 1.2.4.0');+ repo.git('push', '-q', 'origin', 'HEAD:main');+ repo.git('fetch', '-q', 'origin');+ fragmentPr(repo, 'feat-carry', { [shared[1]!]: fs.readFileSync(path.join(dir, shared[1]!), 'utf8') });+ const set = readFragments(repo.work, 'HEAD', 'changelog.d', 'origin/main', 'CHANGELOG.md');+ expect(set.errors.map(e => e.path)).toEqual([`changelog.d/${shared[1]}`]);+ });++ test('a new fragment whose entry was released only under another subsection is not refused', () => {+ const repo = fixture();+ fs.writeFileSync(path.join(repo.work, 'CHANGELOG.md'), readFile(repo, 'CHANGELOG.md').replace('- base release\n', '- base release\n\n### Added\n\n- older addition\n\n### Fixed\n\n- **A shared line.**\n'));+ repo.git('commit', '-qam', 'released subsections');+ repo.git('push', '-q', 'origin', 'HEAD:main');+ repo.git('fetch', '-q', 'origin');+ fragmentPr(repo, 'feat-added', { 'added.md': '### Added\n\n- **A shared line.**\n' });+ const set = readFragments(repo.work, 'HEAD', 'changelog.d', 'origin/main', 'CHANGELOG.md');+ expect([set.errors, set.fragments.map(f => f.path)]).toEqual([[], ['changelog.d/added.md']]);+ });});diff --git a/test/fixtures/release-stamp/gbrain-d7278e4c/capy-ghost-pages-move-evidence.md b/test/fixtures/release-stamp/gbrain-d7278e4c/capy-ghost-pages-move-evidence.mdnew file mode 100644index 000000000..98edb8502--- /dev/null+++ b/test/fixtures/release-stamp/gbrain-d7278e4c/capy-ghost-pages-move-evidence.md@@ -0,0 +1,13 @@+---+important: data-loss+---+**`gbrain repair ghost-pages` no longer soft-deletes a page whose file moved to another page, and `gbrain repair moved-pages` folds a file that was renamed and edited in one commit.**++### Fixed+- `gbrain repair ghost-pages` approved a page whose file a commit deleted for soft-delete even when Git shows the file moved to another live page, so the old page's links, facts and timeline were purged 72 hours later instead of carried over. The preview now lists such a page apart as `moved_to`, names the fold (`gbrain repair moved-pages --source <id> --slug <slug>`, which previews first and applies only with `--apply --expect <hash> --yes`) and never approves it. A page whose path Git renamed, or whose last committed content a file in HEAD still holds, but whose fold is not proven to lose nothing, is kept as `move_unproven`.+- A `database_ahead_of_file` ghost now carries move evidence in the preview: `matched` when a moved page holds every line of it, database edit included, with the fold to run, and `unmatched` otherwise, naming any file that looks like where it went.+- `gbrain repair moved-pages` folded only a move that kept the file byte for byte. It now also folds a file the deleting commit renamed (or the one live file with the same name that Git first added after the old file and no later than its deletion) when the moved page holds every line of the old page's body and timeline in order, its type, its tags and its frontmatter, and a strict move whose old page was edited in the database when the moved page holds that edit. A move whose lines changed stays held as before.+- `gbrain extract --stale` crashed with `TypeError: undefined is not an object` on a page stored in segments (over 1 MiB) whose saved timeline derivation named a segment the page no longer holds. The incremental timeline read now falls back to the full pass, and saved timeline derivations are re-derived once.+- Correction to the v0.60.769.0 note on `file_drift` holds: it said a plain `gbrain sync` never re-checks a hold an earlier release wrote. That release adds no automatic re-check of its own, but a hold written before screen version 3 is still re-checked by every sync, as earlier releases already did.++<!-- behavior-change: ghost_pages_moved_kept_gst3623 -->diff --git a/test/fixtures/release-stamp/v1.103.2.0/make-pdf-nul-cannot-revive-handlers.md b/test/fixtures/release-stamp/v1.103.2.0/make-pdf-nul-cannot-revive-handlers.mdnew file mode 100644index 000000000..7b21bf770--- /dev/null+++ b/test/fixtures/release-stamp/v1.103.2.0/make-pdf-nul-cannot-revive-handlers.md@@ -0,0 +1,4 @@+---+important: security+---+**make-pdf no longer lets a NUL character hide an `onerror` handler, a `javascript:` link or a `<script>` tag from its sanitizer.** The typography pass drops U+0000 after the sanitizer has run, so `on\u0000error=` became a live `onerror` in the print browser; the sanitizer now drops NUL first. Removing a handler could also join the two halves of a tag name, so `<scr onx="a"ipt>` came out as a live `<script>`; the sanitizer now repeats until its output stops changing. Removing a handler or a `javascript:` link also keeps the page's structure. Handler-looking text inside a quoted attribute no longer deletes the elements after it, and a `javascript:` value loses only its scheme instead of gaining quotes, and the scheme is also caught after leading spaces or with its colon written as an entity.diff --git a/test/fixtures/release-stamp/v1.103.2.0/round-two-is-always-a-full-review.md b/test/fixtures/release-stamp/v1.103.2.0/round-two-is-always-a-full-review.mdnew file mode 100644index 000000000..102d55230--- /dev/null+++ b/test/fixtures/release-stamp/v1.103.2.0/round-two-is-always-a-full-review.md@@ -0,0 +1 @@+**After a blocking fix, /ship's second review round is always a full review whose every reader is recorded with the pass, instead of a narrower re-check whose result could go missing.**diff --git a/test/fixtures/release-stamp/v1.103.2.0/ship-prose-matches-new-review-rules.md b/test/fixtures/release-stamp/v1.103.2.0/ship-prose-matches-new-review-rules.mdnew file mode 100644index 000000000..e9af08f06--- /dev/null+++ b/test/fixtures/release-stamp/v1.103.2.0/ship-prose-matches-new-review-rules.md@@ -0,0 +1 @@+**/ship's instructions now match how it reviews code.** A code change after the first review round gets a full second round, and a pull request past its two rounds whose code changed gets one read-only full review of its final head; the old narrow re-checks and the grants that bought them are marked deprecated and go away next release. Unattended /ship skips the test-coverage and plan-completion readers and the scope, exploratory-QA, TODOS, metrics and nudge steps, none of which caught anything in recorded runs. The documentation audit edits only README.md, docs/ and bench/README.md, a new /ship run on a pull request past its review rounds no longer lets that last review apply fixes, and the starter `.gstack/pregate.json` that gstack prints now links to its documentation on GitHub.diff --git a/test/fixtures/release-stamp/v1.103.2.0/stable-benchmark-record-text-hardening.md b/test/fixtures/release-stamp/v1.103.2.0/stable-benchmark-record-text-hardening.mdnew file mode 100644index 000000000..a8bc6692f--- /dev/null+++ b/test/fixtures/release-stamp/v1.103.2.0/stable-benchmark-record-text-hardening.md@@ -0,0 +1,3 @@+### For contributors++- **A weekly benchmark record can no longer slip text into the release job's log through its error messages, or lose a model row to an odd model name.** When the release tool can't read a record, the reason it prints is now stripped of control characters too, and model names that collide once cleaned make the record unreadable instead of silently dropping a row.diff --git a/test/fixtures/release-stamp/v1.103.2.0/stable-release-reads-weekly-benchmark.md b/test/fixtures/release-stamp/v1.103.2.0/stable-release-reads-weekly-benchmark.mdnew file mode 100644index 000000000..a81cccb93--- /dev/null+++ b/test/fixtures/release-stamp/v1.103.2.0/stable-release-reads-weekly-benchmark.md@@ -0,0 +1,3 @@+### For contributors++- **Every stable release plan now prints the weekly benchmark's result, so you can see whether this week's gstack measurably fixes more or fewer bugs than the current stable release.** The release tool reads the weekly record gstack-evals publishes, and a measured drop will hold the regular cut once holding is switched on after two weekly records. Security, data-loss and regression fixes still ship. A hand-run cut can pass a hold with the new `benchmark_waiver` input. See docs/releases.md#weekly-benchmark.diff --git a/test/helpers/free-fixtures-data.ts b/test/helpers/free-fixtures-data.tsindex 1575b82ec..1ad7e8676 100644--- a/test/helpers/free-fixtures-data.ts+++ b/test/helpers/free-fixtures-data.ts@@ -216,6 +216,7 @@ export const FREE_FIXTURES: Readonly<Record<string, readonly string[]>> = {'test/fixtures/prose-lint/**': ['test/prose-lint.test.ts'],'test/fixtures/pty-idle-turn-end.json': ['test/helpers/claude-pty-runner.runners.unit.test.ts', 'test/helpers/claude-pty-runner.screen.unit.test.ts'],'test/fixtures/redact-diagram/**': ['test/redact-context-exemptions.test.ts'],+ 'test/fixtures/release-stamp/**': ['test/changelog-fragments.test.ts', 'test/release-stamp.test.ts'],'test/fixtures/remote-identity-vectors.json': ['test/bin-context-windows-slug.test.ts', 'test/gstack-slug-parity.test.ts', 'test/remote-identity-vectors.test.ts'],'test/fixtures/review-depth/**': ['crew/test/review-dispatch-compare.test.ts'],'test/fixtures/review-depth-main/**': ['test/helpers/gst3562-replay.ts'],diff --git a/test/release-stamp.test.ts b/test/release-stamp.test.tsindex dad5acc9f..c43dae967 100644--- a/test/release-stamp.test.ts+++ b/test/release-stamp.test.ts@@ -19,8 +19,8 @@ const repos: FixtureRepo[] = [];afterEach(() => { while (repos.length) cleanup(repos.pop()!); });/** A fixture whose main carries two landed fragments (one bump: minor) and a tentative stamp_paths mention, like PRs landed unstamped under merge: direct. */-function landed(fragments: Record<string, string> = { 'a.md': '- a change\n', 'b.md': '---\nbump: minor\n---\n- b feature\n' }): FixtureRepo {- const repo = makeFixtureRepo({ policy: POLICY, prefix: 'gstack-release-stamp-fx-' });+function landed(fragments: Record<string, string> = { 'a.md': '- a change\n', 'b.md': '---\nbump: minor\n---\n- b feature\n' }, opts: { policy?: Record<string, unknown>; version?: string } = {}): FixtureRepo {+ const repo = makeFixtureRepo({ policy: opts.policy ?? POLICY, version: opts.version, prefix: 'gstack-release-stamp-fx-' });repos.push(repo);fs.mkdirSync(path.join(repo.work, 'changelog.d'), { recursive: true });for (const [name, body] of Object.entries(fragments)) fs.writeFileSync(path.join(repo.work, 'changelog.d', name), body);@@ -32,6 +32,9 @@ function landed(fragments: Record<string, string> = { 'a.md': '- a change\n', 'brepo.git('checkout', '-q', '--detach', 'origin/main');return repo;}+/** Real changelog.d fragments, byte for byte: v1.103.2.0's five (#4785) and gbrain d7278e4c's one that quotes its own VERSION (GBRA-784). */+const realFragments = (dir: string): Record<string, string> => Object.fromEntries(fs.readdirSync(path.join(import.meta.dir, 'fixtures', 'release-stamp', dir)).sort().map(f => [f, fs.readFileSync(path.join(import.meta.dir, 'fixtures', 'release-stamp', dir, f), 'utf8')]));+const sectionOf = (cl: string, version: string) => cl.slice(cl.indexOf(`## [${version}]`), cl.indexOf('\n## [', cl.indexOf(`## [${version}]`) + 1));const policyOf = (repo: FixtureRepo) => { const l = loadPolicyFromBase(repo.work, 'main'); if ('detail' in l && !('policy' in l)) throw new Error('no policy'); return (l as any).policy; };function stampRelease(repo: FixtureRepo): string {const r = runBin(repo, 'gstack-restamp', ['--release', '--base', 'main', '--allow-repo-commands']);@@ -59,6 +62,38 @@ describe('gstack-restamp --release', () => {expect(readFile(repo, 'docs/notes.md')).toContain('Previous release v1.2.3.0.');});+ // Value: protects=fragment prose that quotes the version being released from is copied byte for byte, even where the+ // CHANGELOG is a stamp file; fails_when=the stamp_paths stage moves "v0.60.769.0" in the folded prose to the new+ // version (GBRA-784, gbrain d7278e4c); seam=gstack-restamp --release on a gbrain-shaped policy+ test('a fragment quoting the current version keeps its prose byte for byte when the CHANGELOG is a stamp file', () => {+ const fragments = realFragments('gbrain-d7278e4c');+ const repo = landed(fragments, { version: '0.60.769.0', policy: { ...POLICY, stamp_files: ['VERSION', 'package.json', 'package-lock.json', 'CHANGELOG.md'] } });+ const base = repo.git('rev-parse', 'origin/main');+ const head = stampRelease(repo);+ expect(readFile(repo, 'VERSION').trim()).toBe('0.60.770.0');+ const section = sectionOf(readFile(repo, 'CHANGELOG.md'), '0.60.770.0');+ expect(section).toContain('- Correction to the v0.60.769.0 note on `file_drift` holds:');+ expect(section).not.toContain('v0.60.770.0');+ const body = fragments['capy-ghost-pages-move-evidence.md']!.replace(/^---\n[\s\S]*?\n---\n/, '').trim();+ expect(section).toContain(body);+ expect(classifyRelease({ repoRoot: repo.work, policy: policyOf(repo), mergeBase: base, head })).toMatchObject({ ok: true });+ });++ // Value: protects=a release section names each subsection once; fails_when=two fragments that each carry+ // "### For contributors" leave the heading twice in the new section (#4785); seam=gstack-restamp --release+ test('fragments that share a subsection heading fold under one copy of it, after the unheaded entries', () => {+ const repo = landed(realFragments('v1.103.2.0'));+ const base = repo.git('rev-parse', 'origin/main');+ const head = stampRelease(repo);+ const section = sectionOf(readFile(repo, 'CHANGELOG.md'), '1.2.4.0');+ expect(section.match(/^### For contributors$/gm)).toHaveLength(1);+ const at = (text: string) => section.indexOf(text);+ expect(at('**/ship\'s instructions now match how it reviews code.**')).toBeLessThan(at('### For contributors'));+ expect(at('### For contributors')).toBeLessThan(at('- **A weekly benchmark record can no longer slip text'));+ expect(at('### For contributors')).toBeLessThan(at('- **Every stable release plan now prints'));+ expect(classifyRelease({ repoRoot: repo.work, policy: policyOf(repo), mergeBase: base, head }).ok).toBe(true);+ });+test('takes its bump from the fragments: --bump with --release is a usage error', () => {const repo = landed();const r = runBin(repo, 'gstack-restamp', ['--release', '--bump', 'major', '--base', 'main', '--allow-repo-commands']);@@ -147,6 +182,31 @@ describe('gstack-release-stamp open', () => {});// GSTA-643 list: on Capy gh signs in as the owner, so open hands the release PR to the host's PR tool instead of gh pr create.+ // Value: protects=the release PR counts and lists changes, never subsection headings; fails_when=v1.103.2.0's two+ // "### For contributors" headings count as changes and the body says 7 instead of 5 (#4785); seam=openRelease with a gh stub+ test('the release notes count changes, not the subsection headings fragments carry', () => {+ const repo = landed(realFragments('v1.103.2.0'));+ const calls: string[][] = [];+ const r = openRelease({ repoRoot: repo.work, base: 'main', gh: (args) => { calls.push(args); return { ok: true, out: args[1] === 'list' ? '' : 'https://github.com/o/r/pull/45\n', err: '' }; } });+ expect(r.ok).toBe(true);+ const body = calls[1]![calls[1]!.indexOf('--body') + 1]!;+ expect(visibleOpening(body)[0]).toBe('v1.2.4.0 ships 5 user-visible changes, listed one per line under Release notes with the pull request that made each.');+ expect(sectionText(body, 'Release notes').split('\n')).toEqual([+ '- make-pdf no longer lets a NUL character hide an `onerror` handler, a `javascript:` link or a `<script>` tag from its sanitizer.',+ '- After a blocking fix, /ship\'s second review round is always a full review whose every reader is recorded with the pass, instead of a narrower re-check whose result could go missing.',+ '- /ship\'s instructions now match how it reviews code.',+ '- A weekly benchmark record can no longer slip text into the release job\'s log through its error messages, or lose a model row to an odd model name.',+ '- Every stable release plan now prints the weekly benchmark\'s result, so you can see whether this week\'s gstack measurably fixes more or fewer bugs than the current stable release.',+ ]);+ });++ test('an empty heading line drops only itself from the release notes', () => {+ const repo = landed({ 'a.md': '###\n- **The only change.** More words.\n' });+ const calls: string[][] = [];+ expect(openRelease({ repoRoot: repo.work, base: 'main', gh: (args) => { calls.push(args); return { ok: true, out: args[1] === 'list' ? '' : 'https://github.com/o/r/pull/46\n', err: '' }; } }).ok).toBe(true);+ expect(sectionText(calls[1]![calls[1]!.indexOf('--body') + 1]!, 'Release notes')).toBe('- The only change.');+ });+test('on Capy, open pushes the release branch and hands the PR to the host tool without gh pr create', () => {const repo = landed();const state = fs.mkdtempSync(path.join(repo.work, '..', 'state-'));