fix(#2488): strip leading terminators so changeset bullets survive re-parse (#2492)

* fix(#2488): strip leading terminators so changeset bullets survive re-parse

A fragment body beginning with a line terminator rendered as an empty
`- ` bullet followed by an orphaned paragraph. `parseChangelog` treats a
non-indented line as terminating a bullet, so `github-release-notes.cjs`
silently dropped the entry when re-parsing CHANGELOG.md to build the
GitHub Release body.

Two independent causes, both in scripts/changeset/parse.cjs:

1. `extractDocsExempt` stripped trailing terminators but not leading
   ones. `DOCS_EXEMPT_RE` is `^...$` under /m, so removing a first-line
   `<!-- docs-exempt -->` marker left the `\n` that `$` does not consume.

2. `parseFragment` preserved the post-frontmatter body verbatim, so a
   blank line between the closing `---` and the first content line
   produced the same leading `\n` with no marker involved.

8 of 256 pending fragments were affected, split 4/4 across the two
causes — including the OpenCode MCP binding, the pi extension, and the
EoS adapters, all of which would have vanished from the v1.8.0 release
notes.

Regression tests cover both causes in LF and CRLF form, plus an
end-to-end serializeChangelog -> parseChangelog round-trip that pins the
user-visible defect.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* chore(#2488): regenerate golden install fixtures for parse.cjs

scripts/ ships in the npm package and the installer, so the golden
install-parity fixtures record a content hash for every shipped file.
Editing scripts/changeset/parse.cjs drifts that hash and fails all 18
per-runtime parity tests.

Regenerated via `npm run gen:golden`. The diff is exactly one line per
fixture — the scripts/changeset/parse.cjs hash — with no unrelated drift.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Tom Boucher
2026-07-21 19:32:51 -04:00
committed by GitHub
parent c19d3d7bda
commit 9fe9da9830
20 changed files with 138 additions and 18 deletions

View File

@@ -65,10 +65,23 @@ function extractDocsExempt(body) {
// is CRLF-aware so Windows-authored fragments don't leave residual `\r`
// characters that would shift the `(#NNNN)` PR suffix to a blank line in
// the rendered CHANGELOG.md / GitHub release-notes bullet.
//
// Both leading AND trailing line terminators are stripped. `DOCS_EXEMPT_RE`
// removes the marker's own text but its `$` anchor (multiline mode) does
// not consume the `\n` that terminates the marker's line. When the marker
// is the FIRST line of the body, that leftover `\n` becomes the new first
// character of `body` — serializeChangelog then emits an empty `- ` bullet
// followed by an orphaned continuation paragraph, and parseChangelog's
// bullet-continuation check (which requires a leading `\s`) treats that
// non-indented paragraph as terminating the bullet, silently dropping the
// entry's content on re-parse. Stripping leading terminators here closes
// that gap the same way the trailing strip already does for the opposite
// (marker-last) position.
const cleaned = body
.replace(DOCS_EXEMPT_RE, '')
.replace(/[ \t\r]+$/gm, '') // strip trailing \r/spaces on each line
.replace(/(?:\r?\n){3,}/g, '\n\n') // collapse 3+ blank lines (CRLF-aware)
.replace(/^[\r\n]+/, '') // strip terminators left by a first-line marker
.replace(/[\r\n]+$/, ''); // strip every trailing line terminator
return { docsExempt: reason, body: cleaned };
}
@@ -105,6 +118,19 @@ function parseFragment(src) {
if (body.endsWith('\r\n')) verbatimBody = body.slice(0, -2);
else if (body.endsWith('\n')) verbatimBody = body.slice(0, -1);
else verbatimBody = body;
// Some fragments have a blank line between the closing frontmatter `---`
// and the first line of actual content (purely a stylistic authoring
// choice — the blank line carries no significant content, unlike
// indentation inside a code block). Strip any such leading blank line(s)
// here, mirroring the trailing-terminator strip above. Without this,
// `body` starts with `\n`/`\r\n`, serializeChangelog emits an empty `- `
// bullet followed by an orphaned paragraph, and parseChangelog's
// continuation check (requires a leading `\s` on the line) treats that
// non-indented paragraph as terminating the bullet — silently dropping
// the fragment's content on re-parse. This is the same downstream failure
// mode as a first-line docs-exempt marker (see extractDocsExempt below);
// it just arises from plain authoring whitespace instead of a marker.
verbatimBody = verbatimBody.replace(/^(?:[ \t]*\r?\n)+/, '');
const { docsExempt, body: visibleBody } = extractDocsExempt(verbatimBody);
if (!visibleBody.trim()) return { ok: false, reason: FRAGMENT_ERROR.EMPTY_BODY };

View File

@@ -27,6 +27,48 @@ describe('changeset parse: fragment file → typed record (#2975)', () => {
assert.equal(r.fragment.body, '```js\nlet x = 1;\n```');
});
test('strips a blank line between the frontmatter close and the body content (no marker involved)', () => {
// Same downstream failure mode as a first-line docs-exempt marker, but
// triggered purely by authoring whitespace (a blank line right after the
// closing `---`) with no docs-exempt marker present at all — a distinct
// root cause than extractDocsExempt's marker-stripping path, discovered
// via the .changeset/ fleet scan while regression-testing #1929.
const src = '---\ntype: Changed\npr: 2036\n---\n\n**Bold text describing the fix.** More detail follows.\n';
const r = parseFragment(src);
assert.equal(r.ok, true);
assert.equal(r.fragment.docsExempt, null);
assert.doesNotMatch(r.fragment.body, /^[\r\n]/);
assert.match(r.fragment.body, /^\*\*Bold text describing the fix\.\*\*/);
});
test('CRLF variant: blank line between frontmatter close and body content is stripped identically', () => {
const src = '---\r\ntype: Changed\r\npr: 2036\r\n---\r\n\r\n**Bold text describing the fix.** More detail follows.\r\n';
const r = parseFragment(src);
assert.equal(r.ok, true);
assert.doesNotMatch(r.fragment.body, /^[\r\n]/);
assert.doesNotMatch(r.fragment.body, /[\r]/);
const lfSrc = '---\ntype: Changed\npr: 2036\n---\n\n**Bold text describing the fix.** More detail follows.\n';
assert.equal(r.fragment.body, parseFragment(lfSrc).fragment.body);
});
test('end-to-end: leading-blank-line fragment survives serializeChangelog → parseChangelog round-trip', () => {
const src = '---\ntype: Changed\npr: 2036\n---\n\n**Bold text describing the fix.** More detail follows.\n';
const r = parseFragment(src);
assert.equal(r.ok, true);
const { serializeChangelog, parseChangelog } = require(path.join(__dirname, '..', 'scripts', 'changeset', 'serialize.cjs'));
const out = serializeChangelog({
releaseHeader: { version: '1.0.0', date: '2026-01-01' },
sections: [{ type: 'Changed', bullets: [{ pr: r.fragment.pr, body: r.fragment.body }] }],
priorChangelog: null,
});
const parsed = parseChangelog(out);
assert.equal(parsed.releases.length, 1);
assert.deepEqual(parsed.releases[0].sections, [
{ type: 'Changed', bullets: [{ body: '**Bold text describing the fix.** More detail follows.', pr: 2036 }] },
]);
});
test('exposes a frozen FRAGMENT_ERROR enum with the documented codes', () => {
assert.deepEqual(
Object.keys(FRAGMENT_ERROR).sort(),
@@ -176,6 +218,58 @@ describe('changeset parse: docs-exempt extraction (#3213)', () => {
assert.match(r.fragment.body, /bug fix\./);
});
test('marker as the FIRST line of the body does not leave a leading line terminator (root-cause fix)', () => {
// Before the fix: DOCS_EXEMPT_RE's `$` (multiline mode) does not consume
// the `\n` terminating the marker's own line, so when the marker is the
// first line, `body` was left starting with `\n`. serializeChangelog then
// emits an empty `- ` bullet followed by an orphaned paragraph, and
// parseChangelog's continuation check (requires leading `\s`) treats the
// non-indented paragraph as terminating the bullet — dropping the
// content on re-parse.
const src = '---\ntype: Fixed\npr: 1929\n---\n<!-- docs-exempt: first-line marker -->\nBold text describing the fix.\n';
const r = parseFragment(src);
assert.equal(r.ok, true);
assert.equal(r.fragment.docsExempt, 'first-line marker');
assert.doesNotMatch(r.fragment.body, /^[\r\n]/);
assert.match(r.fragment.body, /Bold text describing the fix\./);
});
test('CRLF-authored fragment with a FIRST-line marker: same leading-terminator fix applies', () => {
const src = '---\r\ntype: Fixed\r\npr: 1929\r\n---\r\n<!-- docs-exempt: first-line marker -->\r\nBold text describing the fix.\r\n';
const r = parseFragment(src);
assert.equal(r.ok, true);
assert.equal(r.fragment.docsExempt, 'first-line marker');
assert.doesNotMatch(r.fragment.body, /^[\r\n]/);
assert.doesNotMatch(r.fragment.body, /[\r]/);
// LF- and CRLF-authored variants of the same fragment must produce the
// identical body — the recurring CRLF bug class (#1658/#1668/#2206/
// #2449/#2450) means these two must never diverge.
const lfSrc = '---\ntype: Fixed\npr: 1929\n---\n<!-- docs-exempt: first-line marker -->\nBold text describing the fix.\n';
const lfResult = parseFragment(lfSrc);
assert.equal(r.fragment.body, lfResult.fragment.body);
});
test('end-to-end: FIRST-line marker fragment survives serializeChangelog → parseChangelog round-trip (#1929 pin)', () => {
// This is the assertion that pins the user-visible defect: a dropped
// bullet in GitHub release notes (scripts/changeset/github-release-notes.cjs),
// built by feeding the CHANGELOG.md text through parseChangelog.
const src = '---\ntype: Fixed\npr: 1929\n---\n<!-- docs-exempt: first-line marker -->\nBold text describing the fix.\n';
const r = parseFragment(src);
assert.equal(r.ok, true);
const { serializeChangelog, parseChangelog } = require(path.join(__dirname, '..', 'scripts', 'changeset', 'serialize.cjs'));
const out = serializeChangelog({
releaseHeader: { version: '1.0.0', date: '2026-01-01' },
sections: [{ type: 'Fixed', bullets: [{ pr: r.fragment.pr, body: r.fragment.body }] }],
priorChangelog: null,
});
const parsed = parseChangelog(out);
assert.equal(parsed.releases.length, 1);
assert.deepEqual(parsed.releases[0].sections, [
{ type: 'Fixed', bullets: [{ body: 'Bold text describing the fix.', pr: 1929 }] },
]);
});
test('marker on its own line trailing a fragment body still wins (real-marker positive case)', () => {
const src =
'---\ntype: Added\npr: 3213\n---\n' +

View File

@@ -358,7 +358,7 @@
"scripts/changeset/github-release-notes.cjs": "795677f0c009b132",
"scripts/changeset/lint.cjs": "23cb53f77a6ea180",
"scripts/changeset/new.cjs": "4991e21fd17f5541",
"scripts/changeset/parse.cjs": "f9a949cbcab56445",
"scripts/changeset/parse.cjs": "c0a9bbc3914aee04",
"scripts/changeset/render.cjs": "e47bc3e1587c3cae",
"scripts/changeset/serialize.cjs": "ac0b8fe6f87cdb0e",
"scripts/fix-slash-commands.cjs": "0519742531ff3529",

View File

@@ -428,7 +428,7 @@
"scripts/changeset/github-release-notes.cjs": "795677f0c009b132",
"scripts/changeset/lint.cjs": "23cb53f77a6ea180",
"scripts/changeset/new.cjs": "4991e21fd17f5541",
"scripts/changeset/parse.cjs": "f9a949cbcab56445",
"scripts/changeset/parse.cjs": "c0a9bbc3914aee04",
"scripts/changeset/render.cjs": "e47bc3e1587c3cae",
"scripts/changeset/serialize.cjs": "ac0b8fe6f87cdb0e",
"scripts/fix-slash-commands.cjs": "0519742531ff3529",

View File

@@ -427,7 +427,7 @@
"scripts/changeset/github-release-notes.cjs": "795677f0c009b132",
"scripts/changeset/lint.cjs": "23cb53f77a6ea180",
"scripts/changeset/new.cjs": "4991e21fd17f5541",
"scripts/changeset/parse.cjs": "f9a949cbcab56445",
"scripts/changeset/parse.cjs": "c0a9bbc3914aee04",
"scripts/changeset/render.cjs": "e47bc3e1587c3cae",
"scripts/changeset/serialize.cjs": "ac0b8fe6f87cdb0e",
"scripts/fix-slash-commands.cjs": "0519742531ff3529",

View File

@@ -356,7 +356,7 @@
"scripts/changeset/github-release-notes.cjs": "795677f0c009b132",
"scripts/changeset/lint.cjs": "23cb53f77a6ea180",
"scripts/changeset/new.cjs": "4991e21fd17f5541",
"scripts/changeset/parse.cjs": "f9a949cbcab56445",
"scripts/changeset/parse.cjs": "c0a9bbc3914aee04",
"scripts/changeset/render.cjs": "e47bc3e1587c3cae",
"scripts/changeset/serialize.cjs": "ac0b8fe6f87cdb0e",
"scripts/fix-slash-commands.cjs": "0519742531ff3529",

View File

@@ -332,7 +332,7 @@
"scripts/changeset/github-release-notes.cjs": "795677f0c009b132",
"scripts/changeset/lint.cjs": "23cb53f77a6ea180",
"scripts/changeset/new.cjs": "4991e21fd17f5541",
"scripts/changeset/parse.cjs": "f9a949cbcab56445",
"scripts/changeset/parse.cjs": "c0a9bbc3914aee04",
"scripts/changeset/render.cjs": "e47bc3e1587c3cae",
"scripts/changeset/serialize.cjs": "ac0b8fe6f87cdb0e",
"scripts/fix-slash-commands.cjs": "0519742531ff3529",

View File

@@ -428,7 +428,7 @@
"scripts/changeset/github-release-notes.cjs": "795677f0c009b132",
"scripts/changeset/lint.cjs": "23cb53f77a6ea180",
"scripts/changeset/new.cjs": "4991e21fd17f5541",
"scripts/changeset/parse.cjs": "f9a949cbcab56445",
"scripts/changeset/parse.cjs": "c0a9bbc3914aee04",
"scripts/changeset/render.cjs": "e47bc3e1587c3cae",
"scripts/changeset/serialize.cjs": "ac0b8fe6f87cdb0e",
"scripts/fix-slash-commands.cjs": "0519742531ff3529",

View File

@@ -437,7 +437,7 @@
"scripts/changeset/github-release-notes.cjs": "795677f0c009b132",
"scripts/changeset/lint.cjs": "23cb53f77a6ea180",
"scripts/changeset/new.cjs": "4991e21fd17f5541",
"scripts/changeset/parse.cjs": "f9a949cbcab56445",
"scripts/changeset/parse.cjs": "c0a9bbc3914aee04",
"scripts/changeset/render.cjs": "e47bc3e1587c3cae",
"scripts/changeset/serialize.cjs": "ac0b8fe6f87cdb0e",
"scripts/fix-slash-commands.cjs": "0519742531ff3529",

View File

@@ -331,7 +331,7 @@
"scripts/changeset/github-release-notes.cjs": "795677f0c009b132",
"scripts/changeset/lint.cjs": "23cb53f77a6ea180",
"scripts/changeset/new.cjs": "4991e21fd17f5541",
"scripts/changeset/parse.cjs": "f9a949cbcab56445",
"scripts/changeset/parse.cjs": "c0a9bbc3914aee04",
"scripts/changeset/render.cjs": "e47bc3e1587c3cae",
"scripts/changeset/serialize.cjs": "ac0b8fe6f87cdb0e",
"scripts/fix-slash-commands.cjs": "0519742531ff3529",

View File

@@ -406,7 +406,7 @@
"scripts/changeset/github-release-notes.cjs": "795677f0c009b132",
"scripts/changeset/lint.cjs": "23cb53f77a6ea180",
"scripts/changeset/new.cjs": "4991e21fd17f5541",
"scripts/changeset/parse.cjs": "f9a949cbcab56445",
"scripts/changeset/parse.cjs": "c0a9bbc3914aee04",
"scripts/changeset/render.cjs": "e47bc3e1587c3cae",
"scripts/changeset/serialize.cjs": "ac0b8fe6f87cdb0e",
"scripts/fix-slash-commands.cjs": "0519742531ff3529",

View File

@@ -357,7 +357,7 @@
"scripts/changeset/github-release-notes.cjs": "795677f0c009b132",
"scripts/changeset/lint.cjs": "23cb53f77a6ea180",
"scripts/changeset/new.cjs": "4991e21fd17f5541",
"scripts/changeset/parse.cjs": "f9a949cbcab56445",
"scripts/changeset/parse.cjs": "c0a9bbc3914aee04",
"scripts/changeset/render.cjs": "e47bc3e1587c3cae",
"scripts/changeset/serialize.cjs": "ac0b8fe6f87cdb0e",
"scripts/fix-slash-commands.cjs": "0519742531ff3529",

View File

@@ -430,7 +430,7 @@
"scripts/changeset/github-release-notes.cjs": "795677f0c009b132",
"scripts/changeset/lint.cjs": "23cb53f77a6ea180",
"scripts/changeset/new.cjs": "4991e21fd17f5541",
"scripts/changeset/parse.cjs": "f9a949cbcab56445",
"scripts/changeset/parse.cjs": "c0a9bbc3914aee04",
"scripts/changeset/render.cjs": "e47bc3e1587c3cae",
"scripts/changeset/serialize.cjs": "ac0b8fe6f87cdb0e",
"scripts/fix-slash-commands.cjs": "0519742531ff3529",

View File

@@ -393,7 +393,7 @@
"scripts/changeset/github-release-notes.cjs": "795677f0c009b132",
"scripts/changeset/lint.cjs": "23cb53f77a6ea180",
"scripts/changeset/new.cjs": "4991e21fd17f5541",
"scripts/changeset/parse.cjs": "f9a949cbcab56445",
"scripts/changeset/parse.cjs": "c0a9bbc3914aee04",
"scripts/changeset/render.cjs": "e47bc3e1587c3cae",
"scripts/changeset/serialize.cjs": "ac0b8fe6f87cdb0e",
"scripts/fix-slash-commands.cjs": "0519742531ff3529",

View File

@@ -430,7 +430,7 @@
"scripts/changeset/github-release-notes.cjs": "795677f0c009b132",
"scripts/changeset/lint.cjs": "23cb53f77a6ea180",
"scripts/changeset/new.cjs": "4991e21fd17f5541",
"scripts/changeset/parse.cjs": "f9a949cbcab56445",
"scripts/changeset/parse.cjs": "c0a9bbc3914aee04",
"scripts/changeset/render.cjs": "e47bc3e1587c3cae",
"scripts/changeset/serialize.cjs": "ac0b8fe6f87cdb0e",
"scripts/fix-slash-commands.cjs": "0519742531ff3529",

View File

@@ -324,7 +324,7 @@
"scripts/changeset/github-release-notes.cjs": "795677f0c009b132",
"scripts/changeset/lint.cjs": "23cb53f77a6ea180",
"scripts/changeset/new.cjs": "4991e21fd17f5541",
"scripts/changeset/parse.cjs": "f9a949cbcab56445",
"scripts/changeset/parse.cjs": "c0a9bbc3914aee04",
"scripts/changeset/render.cjs": "e47bc3e1587c3cae",
"scripts/changeset/serialize.cjs": "ac0b8fe6f87cdb0e",
"scripts/fix-slash-commands.cjs": "0519742531ff3529",

View File

@@ -357,7 +357,7 @@
"scripts/changeset/github-release-notes.cjs": "795677f0c009b132",
"scripts/changeset/lint.cjs": "23cb53f77a6ea180",
"scripts/changeset/new.cjs": "4991e21fd17f5541",
"scripts/changeset/parse.cjs": "f9a949cbcab56445",
"scripts/changeset/parse.cjs": "c0a9bbc3914aee04",
"scripts/changeset/render.cjs": "e47bc3e1587c3cae",
"scripts/changeset/serialize.cjs": "ac0b8fe6f87cdb0e",
"scripts/fix-slash-commands.cjs": "0519742531ff3529",

View File

@@ -329,7 +329,7 @@
"scripts/changeset/github-release-notes.cjs": "795677f0c009b132",
"scripts/changeset/lint.cjs": "23cb53f77a6ea180",
"scripts/changeset/new.cjs": "4991e21fd17f5541",
"scripts/changeset/parse.cjs": "f9a949cbcab56445",
"scripts/changeset/parse.cjs": "c0a9bbc3914aee04",
"scripts/changeset/render.cjs": "e47bc3e1587c3cae",
"scripts/changeset/serialize.cjs": "ac0b8fe6f87cdb0e",
"scripts/fix-slash-commands.cjs": "0519742531ff3529",

View File

@@ -331,7 +331,7 @@
"scripts/changeset/github-release-notes.cjs": "795677f0c009b132",
"scripts/changeset/lint.cjs": "23cb53f77a6ea180",
"scripts/changeset/new.cjs": "4991e21fd17f5541",
"scripts/changeset/parse.cjs": "f9a949cbcab56445",
"scripts/changeset/parse.cjs": "c0a9bbc3914aee04",
"scripts/changeset/render.cjs": "e47bc3e1587c3cae",
"scripts/changeset/serialize.cjs": "ac0b8fe6f87cdb0e",
"scripts/fix-slash-commands.cjs": "0519742531ff3529",

View File

@@ -400,7 +400,7 @@
"scripts/changeset/github-release-notes.cjs": "795677f0c009b132",
"scripts/changeset/lint.cjs": "23cb53f77a6ea180",
"scripts/changeset/new.cjs": "4991e21fd17f5541",
"scripts/changeset/parse.cjs": "f9a949cbcab56445",
"scripts/changeset/parse.cjs": "c0a9bbc3914aee04",
"scripts/changeset/render.cjs": "e47bc3e1587c3cae",
"scripts/changeset/serialize.cjs": "ac0b8fe6f87cdb0e",
"scripts/fix-slash-commands.cjs": "0519742531ff3529",