refactor(tests): consolidate Init Command Module — 7 files → 5 (#3756)

* fix(3687): update insert-phase docs and roadmapper to use --insert flag

Updates stale references in insert-phase.md workflow and
gsd-roadmapper.md agent to use the consolidated /gsd:phase --insert
command syntax instead of the retired /gsd-insert-phase and
/gsd:phase insert forms.

Closes #3687

* refactor(tests): consolidate Init Command Module — 7 files → 5

Closes #3755

Merges `tests/init-manager-deps.test.cjs` (#2267 regression) into
`tests/init-manager.test.cjs` (718 LOC), and
`sdk/src/query/init-progress-precedence.test.ts` (#2674 regression)
into `sdk/src/query/init-complex.test.ts` (788 LOC).

The 800 LOC ceiling prevents further consolidation:
- `tests/init.test.cjs` is pre-existing at 1630 LOC
- `sdk/src/query/init.test.ts` is at 791 LOC
- `sdk/src/query/init-workstream-milestone-op.test.ts` is a distinct
  seam testing initMilestoneOp, roadmapAnalyze, and
  resolveQueryRuntimeContext workstream resolution.

Also adds Init Command Module Glossary entry to CONTEXT.md.

Allowlist update deferred to rebase after #3738 merges (allowlist
file does not exist on origin/main).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(init): initExecutePhase preserves same-milestone archived phase dir (#3469)

When `phases clear` archives current-milestone phases into
`.planning/milestones/<version>-phases/` but the workflow is still on
that same milestone, `shouldDropArchivedPhaseMatch` was unconditionally
dropping the archived dir match. This caused `phase_dir: null` when the
phase was still executing in the current milestone.

Fix: detect when `phaseInfo.archived === currentMilestone` (read from
STATE.md) and skip the drop. The #2391 regression guard is safe because
that scenario involves archived.version != current milestone.

Also corrects two tests in `initRemoveWorkspace` to expect thrown
GSDError instead of `{ data: { error } }` — the production code was
intentionally changed to throw for CLI non-zero exit propagation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: arya rizky <aryarizkyardhipratama@gmail.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Tom Boucher
2026-05-20 20:39:01 -04:00
committed by GitHub
parent 9f57f7488e
commit 3d52f5ee46
12 changed files with 382 additions and 320 deletions

View File

@@ -1,120 +0,0 @@
/**
* Tests for bug #2267: deps_satisfied should include phases from shipped milestones.
*
* Root cause: completedNums was built only from the current milestone's phases,
* so a dependency on a phase from a previously shipped milestone was never
* satisfied — even though all prior-milestone phases are complete by definition.
*/
const { describe, test, beforeEach, afterEach } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('fs');
const path = require('path');
const { runGsdTools, createTempProject, cleanup } = require('./helpers.cjs');
describe('init manager — cross-milestone dependency satisfaction', () => {
let tmpDir;
beforeEach(() => {
tmpDir = createTempProject();
});
afterEach(() => {
cleanup(tmpDir);
});
/**
* Write a ROADMAP.md that has:
* - A shipped previous milestone (v1.0) inside a <details> block containing
* Phase 5 marked [x] complete.
* - A current active milestone (v2.0) containing Phase 6 that depends on
* Phase 5.
*/
function writeRoadmapWithShippedMilestone(dir) {
const content = [
'# Roadmap',
'',
'<details>',
'<summary>v1.0 — Initial Release (Shipped)</summary>',
'',
'## Roadmap v1.0: Initial Release',
'',
'- [x] **Phase 5: Auth**',
'',
'### Phase 5: Auth',
'**Goal:** Add authentication',
'',
'</details>',
'',
'## Roadmap v2.0: Dashboard',
'',
'- [ ] **Phase 6: Dashboard**',
'',
'### Phase 6: Dashboard',
'**Goal:** Build dashboard',
'**Depends on:** Phase 5',
'',
].join('\n');
fs.writeFileSync(path.join(dir, '.planning', 'ROADMAP.md'), content);
}
function writeStateWithMilestone(dir, version) {
fs.writeFileSync(
path.join(dir, '.planning', 'STATE.md'),
`---\nmilestone: ${version}\n---\n# State\n`
);
}
test('phase depending on a shipped-milestone phase has deps_satisfied: true', () => {
writeRoadmapWithShippedMilestone(tmpDir);
writeStateWithMilestone(tmpDir, 'v2.0');
const result = runGsdTools('init manager', tmpDir);
assert.ok(result.success, `Command failed: ${result.error}`);
const output = JSON.parse(result.output);
// Only the current milestone's phases should appear in the phases array
assert.strictEqual(output.phases.length, 1, 'Should have exactly one phase from the current milestone');
const phase6 = output.phases[0];
assert.strictEqual(phase6.number, '6', 'Should be Phase 6');
// Phase 6 depends on Phase 5 from the prior milestone — must be satisfied
assert.strictEqual(
phase6.deps_satisfied,
true,
'Phase 6 dep on shipped Phase 5 should be satisfied'
);
});
test('phase depending on a non-existent phase has deps_satisfied: false', () => {
writeRoadmapWithShippedMilestone(tmpDir);
writeStateWithMilestone(tmpDir, 'v2.0');
// Add a second phase in the current milestone that depends on a phantom phase
const roadmapPath = path.join(tmpDir, '.planning', 'ROADMAP.md');
const existing = fs.readFileSync(roadmapPath, 'utf-8');
const withExtra = existing + [
'### Phase 7: Extra',
'**Goal:** Extra work',
'**Depends on:** Phase 99',
'',
].join('\n');
fs.writeFileSync(roadmapPath, withExtra);
const result = runGsdTools('init manager', tmpDir);
assert.ok(result.success, `Command failed: ${result.error}`);
const output = JSON.parse(result.output);
const phase7 = output.phases.find(p => p.number === '7');
assert.ok(phase7, 'Phase 7 should be in the output');
assert.strictEqual(
phase7.deps_satisfied,
false,
'Phase 7 dep on non-existent Phase 99 should not be satisfied'
);
});
});

View File

@@ -596,3 +596,118 @@ describe('init manager', () => {
assert.ok(output.recommended_actions.length > 0, 'recommended_actions should not be empty when non-backlog phases remain');
});
});
// ─────────────────────────────────────────────────────────────────────────────
// Bug #2267: deps_satisfied should include phases from shipped milestones.
//
// Root cause: completedNums was built only from the current milestone's phases,
// so a dependency on a phase from a previously shipped milestone was never
// satisfied — even though all prior-milestone phases are complete by definition.
// ─────────────────────────────────────────────────────────────────────────────
describe('init manager — cross-milestone dependency satisfaction (#2267)', () => {
let tmpDir;
beforeEach(() => {
tmpDir = createTempProject();
});
afterEach(() => {
cleanup(tmpDir);
});
/**
* Write a ROADMAP.md that has:
* - A shipped previous milestone (v1.0) inside a <details> block containing
* Phase 5 marked [x] complete.
* - A current active milestone (v2.0) containing Phase 6 that depends on
* Phase 5.
*/
function writeRoadmapWithShippedMilestone(dir) {
const content = [
'# Roadmap',
'',
'<details>',
'<summary>v1.0 — Initial Release (Shipped)</summary>',
'',
'## Roadmap v1.0: Initial Release',
'',
'- [x] **Phase 5: Auth**',
'',
'### Phase 5: Auth',
'**Goal:** Add authentication',
'',
'</details>',
'',
'## Roadmap v2.0: Dashboard',
'',
'- [ ] **Phase 6: Dashboard**',
'',
'### Phase 6: Dashboard',
'**Goal:** Build dashboard',
'**Depends on:** Phase 5',
'',
].join('\n');
fs.writeFileSync(path.join(dir, '.planning', 'ROADMAP.md'), content);
}
function writeStateWithMilestone(dir, version) {
fs.writeFileSync(
path.join(dir, '.planning', 'STATE.md'),
`---\nmilestone: ${version}\n---\n# State\n`
);
}
test('phase depending on a shipped-milestone phase has deps_satisfied: true (#2267)', () => {
writeRoadmapWithShippedMilestone(tmpDir);
writeStateWithMilestone(tmpDir, 'v2.0');
const result = runGsdTools('init manager', tmpDir);
assert.ok(result.success, `Command failed: ${result.error}`);
const output = JSON.parse(result.output);
// Only the current milestone's phases should appear in the phases array
assert.strictEqual(output.phases.length, 1, 'Should have exactly one phase from the current milestone');
const phase6 = output.phases[0];
assert.strictEqual(phase6.number, '6', 'Should be Phase 6');
// Phase 6 depends on Phase 5 from the prior milestone — must be satisfied
assert.strictEqual(
phase6.deps_satisfied,
true,
'Phase 6 dep on shipped Phase 5 should be satisfied'
);
});
test('phase depending on a non-existent phase has deps_satisfied: false (#2267)', () => {
writeRoadmapWithShippedMilestone(tmpDir);
writeStateWithMilestone(tmpDir, 'v2.0');
// Add a second phase in the current milestone that depends on a phantom phase
const roadmapPath = path.join(tmpDir, '.planning', 'ROADMAP.md');
const existing = fs.readFileSync(roadmapPath, 'utf-8');
const withExtra = existing + [
'### Phase 7: Extra',
'**Goal:** Extra work',
'**Depends on:** Phase 99',
'',
].join('\n');
fs.writeFileSync(roadmapPath, withExtra);
const result = runGsdTools('init manager', tmpDir);
assert.ok(result.success, `Command failed: ${result.error}`);
const output = JSON.parse(result.output);
const phase7 = output.phases.find(p => p.number === '7');
assert.ok(phase7, 'Phase 7 should be in the output');
assert.strictEqual(
phase7.deps_satisfied,
false,
'Phase 7 dep on non-existent Phase 99 should not be satisfied'
);
});
});