fix(#145): extractCurrentMilestone selects active sub-milestone over closed sibling (#380)

* fix(#145): extractCurrentMilestone selects active sub-milestone over closed sibling

extractCurrentMilestone used a non-global regex with content.match()
(first-match) to locate the milestone section for the STATE.md version.
When the milestone is a shared semver prefix (e.g. v8.0) and ROADMAP.md
holds both a closed sub-milestone (## v8.0 ... CLOSED/FAIL) and an active
one (## v8.0-B ... STARTED), the first match was always the closed
heading, so the active section and its phases were excised from the slice
and downstream phase ops failed with "Phase N not found in current
milestone".

Switch to a global matchAll over candidate headings, skip headings
carrying a closed marker (CLOSED/ARCHIVED/ABANDONED/SHIPPED/FAILED/FAIL/
✅/🗄️), and select the first non-closed match (falling back to the first
match when every candidate is closed, preserving legacy behavior). Anchor
the preamble slice to the first heading index so a closed sibling's body
no longer leaks into the preamble when the selected section is later.

Harden version matching with a trailing word boundary (so v8.0-B does not
match v8.0-Beta), narrow the FAIL marker to FAILED, match a bare 🗄, and
add an active-marker override (STARTED/🚧/ACTIVE) so a heading carrying an
explicit active status is never treated as closed even if its name contains
a completion word. Also anchor the preamble at the first any-version
milestone heading so unmatched sibling sections do not leak into the
preamble.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* ci(#145): add changeset fragment for milestone-selection fix

Adds the required .changeset/*.md fragment for this user-facing fix
(changeset-lint gate).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Tom Boucher
2026-05-27 20:21:08 -04:00
committed by GitHub
parent 2b9fa009d3
commit d17bb4ea1e
3 changed files with 464 additions and 7 deletions

View File

@@ -969,19 +969,28 @@ function extractCurrentMilestone(content, cwd) {
// Match headings like: ## Roadmap v3.0: Name, ## v3.0 Name, etc.
const escapedVersion = escapeRegex(version);
const sectionPattern = new RegExp(
`(^#{1,3}\\s+.*${escapedVersion}[^\\n]*)`,
'mi'
`(^#{1,3}\\s+.*${escapedVersion}\\b[^\\n]*)`,
'gmi'
);
const sectionMatch = content.match(sectionPattern);
const allMatches = [...content.matchAll(sectionPattern)];
if (!sectionMatch) return stripShippedMilestones(content);
if (allMatches.length === 0) return stripShippedMilestones(content);
const sectionStart = sectionMatch.index;
// Select the first non-closed heading; fall back to first match if all are closed.
// A heading is "closed" only if it carries a closed marker AND no active marker.
const closedMarkerPattern = /\b(?:CLOSED|ARCHIVED|ABANDONED|SHIPPED|FAILED)\b|✅|🗄/i;
const activeMarkerPattern = /\b(?:STARTED|ACTIVE|WIP)\b|in\s+progress|🚧/i;
const isClosed = (h) => closedMarkerPattern.test(h) && !activeMarkerPattern.test(h);
const firstMatch = allMatches[0];
const selected = allMatches.find((m) => !isClosed(m[1])) || firstMatch;
const sectionStart = selected.index;
// Find the end: next milestone heading at same or higher level, or EOF.
// Milestone headings look like: ## v2.0, ## Roadmap v2.0, ## ✅ v1.0, etc.
// Scan line-by-line so that heading-like lines inside fenced code blocks
// (``` or ~~~) are not mistaken for milestone boundaries. See #2787.
const sectionMatch = selected;
const headingLevel = sectionMatch[1].match(/^(#{1,3})\s/)[1].length;
const restContent = content.slice(sectionStart + sectionMatch[0].length);
// Exclude phase headings (e.g. "### Phase 12: v1.0 Tech-Debt Closure") from
@@ -1017,8 +1026,16 @@ function extractCurrentMilestone(content, cwd) {
}
// Return everything before the current milestone section (non-milestone content
// like title, overview) plus the current milestone section
const beforeMilestones = content.slice(0, sectionStart);
// like title, overview) plus the current milestone section.
// Anchor the preamble at the first *any-version* milestone heading so that
// unmatched sibling sections (e.g. v2.0-Beta when STATE=v2.0-B) do not leak
// in as preamble content.
const anyMilestonePattern = /^#{1,3}\s+(?!Phase\s+\S)(?:.*v\d+\.\d+|✅|📋|🚧)/im;
const firstMilestoneMatch = content.match(anyMilestonePattern);
const preambleCutoff = firstMilestoneMatch
? firstMilestoneMatch.index
: firstMatch.index;
const beforeMilestones = content.slice(0, preambleCutoff);
const currentSection = content.slice(sectionStart, sectionEnd);
// Also include any content before the first milestone heading (title, overview, etc.)