* test(#3170): extractOneLinerFromBody must anchor to a summary-shaped heading Regression for #3170: the function matched the first heading's first bold run, so an incidental first heading (rule list, deviation notes) contributed its bold text as the milestone accomplishment. Rows 1/2 fail RED on next; rows 3/4 guard Overview recognition and the #2660 Summary-heading form. * fix(#3170): anchor milestone one-liner extraction to a summary-shaped heading extractOneLinerFromBody matched the first heading's first bold run regardless of section, so an incidental first heading (rule list, deviation notes) contributed its bold text as the milestone accomplishment written into MILESTONES.md. Iterate headings and extract from the first Summary/Overview/ Accomplishments one with a bold run, falling back to null when none exists. The #2660 Summary-heading forms and the frontmatter one-liner precedence are preserved. * docs(#3170): add changeset * test(#3170): align extractOneLinerFromBody unit fixtures with summary-heading contract The core-utils unit fixtures used generic # Title headings encoding the old 'any first heading' contract; the #3170 fix anchors to a Summary/Overview/ Accomplishments heading (the function is summary-specific). Update the heading text to Summary-shaped; the extraction assertions (bold, frontmatter strip, colon-label, CRLF, unicode) are unchanged. * docs(#3170): backfill changeset PR number (3401) --------- Co-authored-by: sim <sim@local>
This commit is contained in:
@@ -70,15 +70,26 @@ function extractOneLinerFromBody(content: string | null | undefined): string | n
|
||||
if (!content) return null;
|
||||
const normalized = content.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
||||
const body = normalized.replace(/^---\n[\s\S]*?\n---\n*/, '');
|
||||
const match = body.match(/^#[^\n]*\n+\*\*([^*\n]+)\*\*([^\n]*)/m);
|
||||
if (!match) return null;
|
||||
const boldInner = match[1].trim();
|
||||
const afterBold = match[2];
|
||||
if (/:\s*$/.test(boldInner)) {
|
||||
const prose = afterBold.trim();
|
||||
return prose.length > 0 ? prose : null;
|
||||
// #3170: anchor to a summary-shaped heading (Summary / Overview /
|
||||
// Accomplishments) so an incidental first heading (a rule list, task
|
||||
// breakdown, deviation note) does not contribute its first bold run as the
|
||||
// deliverable one-liner. Iterate headings in document order and extract from
|
||||
// the first summary-shaped one that has a bold run; fall back to null (not the
|
||||
// wrong text) when no such heading exists.
|
||||
const headingRe = /^#+\s*([^\n]*)\n+\*\*([^*\n]+)\*\*([^\n]*)/gm;
|
||||
let match: RegExpExecArray | null;
|
||||
while ((match = headingRe.exec(body)) !== null) {
|
||||
if (!/summary|overview|accomplish/i.test(match[1])) continue;
|
||||
const boldInner = match[2].trim();
|
||||
const afterBold = match[3];
|
||||
if (/:\s*$/.test(boldInner)) {
|
||||
const prose = afterBold.trim();
|
||||
if (prose.length > 0) return prose;
|
||||
} else if (boldInner.length > 0) {
|
||||
return boldInner;
|
||||
}
|
||||
}
|
||||
return boldInner.length > 0 ? boldInner : null;
|
||||
return null;
|
||||
}
|
||||
|
||||
// ─── Misc utilities ───────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user