fix(sdk): extractCurrentMilestone preserves generic Phase Details heading (#3493)
When a roadmap places shared phase-detail bodies under a non-version-prefixed `## Phase Details` heading AFTER a `### 📋 vX.Y+ (Planned)` sibling in document order, the entire Phase Details section fell outside the slice returned by `extractCurrentMilestone`. `gsd-sdk query phase.insert N` then reported "Phase N not found in ROADMAP.md" even though `### Phase N:` was unambiguously present. PR #2455 (closing #2422) added a same-version `continue` branch that already handles the version-prefixed variant (e.g. `## v2.0 Phase Details`). This fix extends the same intent to the generic-label variant: after the initial boundary scan, look for a literal `^#{1,3}\s+Phase\s+Details\b` heading past `sectionEnd` and, if found, append the Phase Details block (up to the next real milestone boundary — version-bearing or milestone-emoji-bearing heading — or EOF) to the returned slice. The intervening planned-milestone content is skipped so it does not leak into the active-milestone view. Bounded to a single append so a malformed roadmap can't loop. Only matches the literal `Phase Details` label (canonical per GSD ROADMAP template); anything else continues to terminate the slice. Does not regress the v2.0/v2.1+ version-prefixed handling shipped by #2455 (existing `bug-2422` test still passes). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -809,6 +809,71 @@ Detail
|
||||
expect(result).toContain('Phase 100');
|
||||
expect(result).toContain('Phase Details');
|
||||
});
|
||||
|
||||
// ─── Bug #3493: generic `## Phase Details` after planned-milestone sibling ──
|
||||
it('bug-3493: preserves generic `## Phase Details` heading after `### 📋 vX.Y+ (Planned)` sibling', async () => {
|
||||
// Minimal repro from issue #3493 verbatim: a generic (non-version-prefixed)
|
||||
// `## Phase Details` heading sits AFTER a `### 📋 v2.1+ (Planned)` sibling
|
||||
// in document order. The 📋-bearing sibling otherwise terminates the slice
|
||||
// and the generic Phase Details body — including `### Phase 4: Next` — is
|
||||
// dropped, even though it belongs to the active v2.0 milestone.
|
||||
const roadmap = `# Roadmap: Example
|
||||
|
||||
## Phases
|
||||
|
||||
<details>
|
||||
<summary>✅ v1.0 First Milestone — SHIPPED</summary>
|
||||
- [x] **Phase 1: First** (1/1 plans)
|
||||
</details>
|
||||
|
||||
### v2.0 Active Milestone (Phases 2–5)
|
||||
|
||||
- [x] **Phase 2: Foundation** (5/5 plans) — completed
|
||||
- [x] **Phase 3: Pipeline** (8/8 plans) — completed
|
||||
- [ ] **Phase 4: Next** — pending
|
||||
- [ ] **Phase 5: Final** — pending
|
||||
|
||||
### 📋 v2.1+ (Planned — Not Yet Scoped)
|
||||
|
||||
Candidates pending milestone selection.
|
||||
|
||||
## Phase Details
|
||||
|
||||
### Phase 2: Foundation
|
||||
**Goal**: Foundation goal.
|
||||
|
||||
### Phase 3: Pipeline
|
||||
**Goal**: Pipeline goal.
|
||||
|
||||
### Phase 4: Next
|
||||
**Goal**: Next goal.
|
||||
|
||||
### Phase 5: Final
|
||||
**Goal**: Final goal.
|
||||
`;
|
||||
const state = `---\nmilestone: v2.0\n---\n# State\n`;
|
||||
await writeFile(join(tmpDir, '.planning', 'STATE.md'), state);
|
||||
await writeFile(join(tmpDir, '.planning', 'ROADMAP.md'), roadmap);
|
||||
|
||||
const slice = await extractCurrentMilestone(roadmap, tmpDir);
|
||||
|
||||
// The generic Phase Details heading and all four detail sections must
|
||||
// survive — they belong to the active v2.0 milestone even though they
|
||||
// sit after the planned-milestone sibling in document order.
|
||||
expect(slice).toContain('## Phase Details');
|
||||
expect(slice).toContain('### Phase 2: Foundation');
|
||||
expect(slice).toContain('### Phase 3: Pipeline');
|
||||
expect(slice).toContain('### Phase 4: Next');
|
||||
expect(slice).toContain('### Phase 5: Final');
|
||||
|
||||
// And roadmapGetPhase (which calls extractCurrentMilestone internally)
|
||||
// must locate Phase 4's detail section.
|
||||
const result = await roadmapGetPhase(['4'], tmpDir);
|
||||
const data = result.data as Record<string, unknown>;
|
||||
expect(data.found).toBe(true);
|
||||
expect(data.phase_number).toBe('4');
|
||||
expect(data.phase_name).toBe('Next');
|
||||
});
|
||||
});
|
||||
|
||||
// ─── roadmapGetPhase ──────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user