refactor(tests): consolidate Phase Lifecycle Module — 20 files → 4 (#3741)
* chore(tests): lint rule — cap test files per production module at 2 Adds scripts/lint-test-file-count.cjs with a ratcheted allowlist (scripts/lint-test-file-count.allowlist.json) capturing today's 30 violating clusters as a ceiling. New entries blocked at PR time; reductions ratchet automatically. Wires into .github/workflows/test.yml as a new step in lint-tests. Refs #3737 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * refactor(tests): consolidate Phase Lifecycle Module — 20 files → 4 - Merge 10 CJS bug-fix test files into tests/phase.test.cjs - Merge sdk/src/phase-runner-types.test.ts + sdk/src/phase-prompt.test.ts into sdk/src/phase-runner.test.ts (97 → 152 tests, 0 failures) - Rename 4 mis-attributed test files out of phase cluster: phase-researcher-app-aware → gsd-researcher-app-aware phase-researcher-flow-diagram → gsd-researcher-flow-diagram feat-3023-phase-type-models → feat-3023-model-phase-types phase-6-cjs-sdk-seam-contracts → cjs-sdk-bridge-seam-contracts - Fix phasePlanIndex (#3430): non-canonical plan filename warning now surfaces in data.warnings[] as "Ignored noncanonical plan files: ..." instead of a separate singular data.warning field - Update allowlist: phase ceiling 20 → 4 (closes #3740) - Add Phase Lifecycle Module glossary entry to CONTEXT.md Closes #3740 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(phase-roadmap-mutation): replaceInCurrentMilestone handles active milestone inside <details> block When the active milestone is wrapped in a <details> block (e.g. user collapsed it, or milestone transition), the after-</details> slice is empty or contains only footer text — the pattern never matches and the replacement is silently dropped. Fix: when after.replace() produces no change, fall back to replacing inside the last <details>...</details> block. Shipped-milestone blocks are untouched because only the last <details> block is targeted. Closes #2641 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(changeset): add required type/pr frontmatter to 3740 fragment Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
/**
|
||||
* Regression tests for bug #1962
|
||||
*
|
||||
* normalizePhaseName must preserve the original case of letter suffixes.
|
||||
* Uppercasing "16c" to "16C" causes directory/roadmap mismatches on
|
||||
* case-sensitive filesystems — init progress can't match the directory
|
||||
* back to the roadmap phase entry.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const { describe, test } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
|
||||
const { normalizePhaseName } = require('../get-shit-done/bin/lib/core.cjs');
|
||||
|
||||
describe('bug #1962: normalizePhaseName preserves letter suffix case', () => {
|
||||
test('lowercase suffix preserved: 16c → 16c', () => {
|
||||
assert.equal(normalizePhaseName('16c'), '16c');
|
||||
});
|
||||
|
||||
test('uppercase suffix preserved: 16C → 16C', () => {
|
||||
assert.equal(normalizePhaseName('16C'), '16C');
|
||||
});
|
||||
|
||||
test('single digit padded with lowercase suffix: 1a → 01a', () => {
|
||||
assert.equal(normalizePhaseName('1a'), '01a');
|
||||
});
|
||||
|
||||
test('single digit padded with uppercase suffix: 1A → 01A', () => {
|
||||
assert.equal(normalizePhaseName('1A'), '01A');
|
||||
});
|
||||
|
||||
test('no suffix unchanged: 16 → 16', () => {
|
||||
assert.equal(normalizePhaseName('16'), '16');
|
||||
});
|
||||
|
||||
test('decimal suffix preserved: 16.1 → 16.1', () => {
|
||||
assert.equal(normalizePhaseName('16.1'), '16.1');
|
||||
});
|
||||
|
||||
test('letter + decimal preserved: 16c.2 → 16c.2', () => {
|
||||
assert.equal(normalizePhaseName('16c.2'), '16c.2');
|
||||
});
|
||||
|
||||
test('project code prefix stripped, suffix case preserved: CK-01a → 01a', () => {
|
||||
assert.equal(normalizePhaseName('CK-01a'), '01a');
|
||||
});
|
||||
});
|
||||
@@ -1,137 +0,0 @@
|
||||
/**
|
||||
* Regression tests for bug #1998
|
||||
*
|
||||
* phase complete must update the top-level overview bullet checkbox
|
||||
* (- [ ] Phase N: → - [x] Phase N:) in addition to the Progress table row.
|
||||
*
|
||||
* Root cause: the checkbox update used replaceInCurrentMilestone() which
|
||||
* scopes to content after </details>, missing the current milestone's
|
||||
* overview bullets that appear before any <details> blocks.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const { describe, test, beforeEach, afterEach } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const os = require('node:os');
|
||||
const { execFileSync } = require('node:child_process');
|
||||
|
||||
const gsdTools = path.resolve(__dirname, '..', 'get-shit-done', 'bin', 'gsd-tools.cjs');
|
||||
|
||||
describe('bug #1998: phase complete updates overview checkbox', () => {
|
||||
let tmpDir;
|
||||
let planningDir;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-1998-'));
|
||||
planningDir = path.join(tmpDir, '.planning');
|
||||
fs.mkdirSync(planningDir, { recursive: true });
|
||||
|
||||
// Minimal config
|
||||
fs.writeFileSync(
|
||||
path.join(planningDir, 'config.json'),
|
||||
JSON.stringify({ project_code: 'TEST' })
|
||||
);
|
||||
|
||||
// Minimal STATE.md
|
||||
fs.writeFileSync(
|
||||
path.join(planningDir, 'STATE.md'),
|
||||
'---\ncurrent_phase: 1\nstatus: executing\n---\n# State\n'
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
test('checkbox updated when no archived milestones exist', () => {
|
||||
const phasesDir = path.join(planningDir, 'phases', '01-foundation');
|
||||
fs.mkdirSync(phasesDir, { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(phasesDir, '01-1-SUMMARY.md'),
|
||||
'---\nstatus: complete\n---\n# Summary\nDone.'
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path.join(phasesDir, '01-1-PLAN.md'),
|
||||
'---\nphase: 1\nplan: 1\n---\n# Plan 1\n'
|
||||
);
|
||||
|
||||
const roadmapPath = path.join(planningDir, 'ROADMAP.md');
|
||||
fs.writeFileSync(roadmapPath, [
|
||||
'# Roadmap',
|
||||
'',
|
||||
'## Phases',
|
||||
'',
|
||||
'- [ ] **Phase 1: Foundation** - core setup',
|
||||
'- [ ] **Phase 2: Features** - add features',
|
||||
'',
|
||||
'## Progress',
|
||||
'',
|
||||
'| Phase | Plans | Status | Completed |',
|
||||
'|-------|-------|--------|-----------|',
|
||||
'| 1. Foundation | 0/1 | Pending | - |',
|
||||
'| 2. Features | 0/1 | Pending | - |',
|
||||
].join('\n'));
|
||||
|
||||
try {
|
||||
execFileSync('node', [gsdTools, 'phase', 'complete', '1'], { cwd: tmpDir, timeout: 10000 });
|
||||
} catch {
|
||||
// Command may exit non-zero if STATE.md update fails, but ROADMAP.md update happens first
|
||||
}
|
||||
|
||||
const result = fs.readFileSync(roadmapPath, 'utf-8');
|
||||
assert.match(result, /- \[x\] \*\*Phase 1: Foundation\*\*/, 'overview checkbox should be checked');
|
||||
assert.match(result, /- \[ \] \*\*Phase 2: Features\*\*/, 'phase 2 checkbox should remain unchecked');
|
||||
});
|
||||
|
||||
test('checkbox updated when archived milestones exist in <details>', () => {
|
||||
const phasesDir = path.join(planningDir, 'phases', '01-setup');
|
||||
fs.mkdirSync(phasesDir, { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(phasesDir, '01-1-SUMMARY.md'),
|
||||
'---\nstatus: complete\n---\n# Summary\nDone.'
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path.join(phasesDir, '01-1-PLAN.md'),
|
||||
'---\nphase: 1\nplan: 1\n---\n# Plan 1\n'
|
||||
);
|
||||
|
||||
const roadmapPath = path.join(planningDir, 'ROADMAP.md');
|
||||
fs.writeFileSync(roadmapPath, [
|
||||
'# Roadmap v2.0',
|
||||
'',
|
||||
'## Phases',
|
||||
'',
|
||||
'- [ ] **Phase 1: Setup** - initial setup',
|
||||
'- [ ] **Phase 2: Build** - build features',
|
||||
'',
|
||||
'## Progress',
|
||||
'',
|
||||
'| Phase | Plans | Status | Completed |',
|
||||
'|-------|-------|--------|-----------|',
|
||||
'| 1. Setup | 0/1 | Pending | - |',
|
||||
'| 2. Build | 0/1 | Pending | - |',
|
||||
'',
|
||||
'<details>',
|
||||
'<summary>v1.0 (Archived)</summary>',
|
||||
'',
|
||||
'## v1.0 Phases',
|
||||
'- [x] **Phase 1: Init** - initialization',
|
||||
'- [x] **Phase 2: Deploy** - deployment',
|
||||
'',
|
||||
'</details>',
|
||||
].join('\n'));
|
||||
|
||||
try {
|
||||
execFileSync('node', [gsdTools, 'phase', 'complete', '1'], { cwd: tmpDir, timeout: 10000 });
|
||||
} catch {
|
||||
// May exit non-zero
|
||||
}
|
||||
|
||||
const result = fs.readFileSync(roadmapPath, 'utf-8');
|
||||
assert.match(result, /- \[x\] \*\*Phase 1: Setup\*\*/, 'current milestone checkbox should be checked');
|
||||
assert.match(result, /- \[ \] \*\*Phase 2: Build\*\*/, 'phase 2 checkbox should remain unchecked');
|
||||
});
|
||||
});
|
||||
@@ -1,180 +0,0 @@
|
||||
/**
|
||||
* Regression tests for bug #2005
|
||||
*
|
||||
* When the in-progress milestone section is wrapped in a <details> block
|
||||
* (the standard /gsd-new-project layout), phase complete silently skips:
|
||||
* 1. The plan count update (**Plans:** N/M → X/M plans complete)
|
||||
* 2. Mis-reports is_last_phase and next_phase
|
||||
*
|
||||
* Root cause: replaceInCurrentMilestone() uses the last </details> as the
|
||||
* boundary, so when the current milestone is itself inside <details>, the
|
||||
* replacement target is in the empty space AFTER the current milestone's
|
||||
* closing </details>, and the regex never matches anything inside the block.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const { describe, test, beforeEach, afterEach } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const os = require('node:os');
|
||||
const { execFileSync } = require('node:child_process');
|
||||
|
||||
const gsdTools = path.resolve(__dirname, '..', 'get-shit-done', 'bin', 'gsd-tools.cjs');
|
||||
|
||||
describe('bug #2005: phase complete updates plan count when milestone is inside <details>', () => {
|
||||
let tmpDir;
|
||||
let planningDir;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-2005-'));
|
||||
planningDir = path.join(tmpDir, '.planning');
|
||||
fs.mkdirSync(planningDir, { recursive: true });
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(planningDir, 'config.json'),
|
||||
JSON.stringify({ project_code: 'TEST' })
|
||||
);
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(planningDir, 'STATE.md'),
|
||||
'---\ncurrent_phase: 1\nstatus: executing\nmilestone: v2.0\n---\n# State\n'
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
test('plan count is updated when current milestone is wrapped in <details>', () => {
|
||||
// This is the standard /gsd-new-project layout: every milestone in <details>
|
||||
const phasesDir = path.join(planningDir, 'phases', '01-setup');
|
||||
fs.mkdirSync(phasesDir, { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(phasesDir, '01-1-SUMMARY.md'),
|
||||
'---\nstatus: complete\n---\n# Summary\nDone.\n'
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path.join(phasesDir, '01-1-PLAN.md'),
|
||||
'---\nphase: 1\nplan: 1\n---\n# Plan 1\n'
|
||||
);
|
||||
|
||||
const roadmapPath = path.join(planningDir, 'ROADMAP.md');
|
||||
// Current milestone (v2.0) is wrapped in <details>
|
||||
fs.writeFileSync(roadmapPath, [
|
||||
'# Roadmap',
|
||||
'',
|
||||
'<details>',
|
||||
'<summary>v1.0 (shipped)</summary>',
|
||||
'',
|
||||
'## v1.0 Phases',
|
||||
'- [x] **Phase 0: Bootstrap** - shipped',
|
||||
'',
|
||||
'</details>',
|
||||
'',
|
||||
'<details open>',
|
||||
'<summary>v2.0 (in progress)</summary>',
|
||||
'',
|
||||
'## v2.0 Phases',
|
||||
'',
|
||||
'- [ ] **Phase 1: Setup** - initial setup',
|
||||
'- [ ] **Phase 2: Build** - build features',
|
||||
'',
|
||||
'## Progress',
|
||||
'',
|
||||
'| Phase | Plans | Status | Completed |',
|
||||
'|-------|-------|--------|-----------|',
|
||||
'| 1. Setup | 0/1 | Pending | - |',
|
||||
'| 2. Build | 0/1 | Pending | - |',
|
||||
'',
|
||||
'### Phase 1: Setup',
|
||||
'',
|
||||
'**Plans:** 0/1 plans complete',
|
||||
'',
|
||||
'### Phase 2: Build',
|
||||
'',
|
||||
'**Plans:** 0/1 plans complete',
|
||||
'',
|
||||
'</details>',
|
||||
].join('\n'));
|
||||
|
||||
try {
|
||||
execFileSync('node', [gsdTools, 'phase', 'complete', '1'], { cwd: tmpDir, timeout: 10000 });
|
||||
} catch {
|
||||
// May exit non-zero if STATE.md update fails, but ROADMAP.md update is the target
|
||||
}
|
||||
|
||||
const result = fs.readFileSync(roadmapPath, 'utf-8');
|
||||
|
||||
// Plan count must be updated inside the <details> block
|
||||
assert.match(
|
||||
result,
|
||||
/\*\*Plans:\*\*\s*1\/1 plans complete/,
|
||||
'plan count in Phase 1 section must be updated to 1/1 plans complete'
|
||||
);
|
||||
|
||||
// Phase 1 checkbox must be checked
|
||||
assert.match(
|
||||
result,
|
||||
/- \[x\] \*\*Phase 1: Setup\*\*/,
|
||||
'Phase 1 checkbox must be checked after completion'
|
||||
);
|
||||
|
||||
// Phase 2 must be untouched
|
||||
assert.match(
|
||||
result,
|
||||
/- \[ \] \*\*Phase 2: Build\*\*/,
|
||||
'Phase 2 checkbox must remain unchecked'
|
||||
);
|
||||
});
|
||||
|
||||
test('phase complete with all milestones in <details> does not corrupt phase 2 plan count', () => {
|
||||
const phasesDir = path.join(planningDir, 'phases', '01-setup');
|
||||
fs.mkdirSync(phasesDir, { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(phasesDir, '01-1-SUMMARY.md'),
|
||||
'---\nstatus: complete\n---\n# Summary\nDone.\n'
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path.join(phasesDir, '01-1-PLAN.md'),
|
||||
'---\nphase: 1\nplan: 1\n---\n# Plan 1\n'
|
||||
);
|
||||
|
||||
const roadmapPath = path.join(planningDir, 'ROADMAP.md');
|
||||
fs.writeFileSync(roadmapPath, [
|
||||
'# Roadmap',
|
||||
'',
|
||||
'<details open>',
|
||||
'<summary>v2.0 (in progress)</summary>',
|
||||
'',
|
||||
'## v2.0 Phases',
|
||||
'',
|
||||
'- [ ] **Phase 1: Setup** - initial setup',
|
||||
'- [ ] **Phase 2: Build** - build features',
|
||||
'',
|
||||
'### Phase 1: Setup',
|
||||
'',
|
||||
'**Plans:** 0/1 plans complete',
|
||||
'',
|
||||
'### Phase 2: Build',
|
||||
'',
|
||||
'**Plans:** 0/2 plans complete',
|
||||
'',
|
||||
'</details>',
|
||||
].join('\n'));
|
||||
|
||||
try {
|
||||
execFileSync('node', [gsdTools, 'phase', 'complete', '1'], { cwd: tmpDir, timeout: 10000 });
|
||||
} catch {}
|
||||
|
||||
const result = fs.readFileSync(roadmapPath, 'utf-8');
|
||||
|
||||
// Phase 2's plan count must NOT be touched
|
||||
assert.match(
|
||||
result,
|
||||
/Phase 2: Build[\s\S]*?\*\*Plans:\*\*\s*0\/2 plans complete/,
|
||||
'Phase 2 plan count must remain 0/2 (untouched)'
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,271 +0,0 @@
|
||||
/**
|
||||
* Regression tests for bug #2526
|
||||
*
|
||||
* phase complete must warn about REQ-IDs that appear in the REQUIREMENTS.md
|
||||
* body but are missing from the Traceability table.
|
||||
*
|
||||
* Root cause: cmdPhaseComplete() only flips status for REQ-IDs already in
|
||||
* the Traceability table (from the roadmap **Requirements:** line). REQ-IDs
|
||||
* added to the REQUIREMENTS.md body after roadmap creation are never
|
||||
* discovered or reflected in the table.
|
||||
*
|
||||
* Fix (Option A — warning only): scan the REQUIREMENTS.md body for all
|
||||
* REQ-IDs, check which are absent from the Traceability table, and emit
|
||||
* a warning listing the missing IDs.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const { describe, test, beforeEach, afterEach } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const os = require('node:os');
|
||||
const { execFileSync } = require('node:child_process');
|
||||
|
||||
const gsdTools = path.resolve(__dirname, '..', 'get-shit-done', 'bin', 'gsd-tools.cjs');
|
||||
|
||||
describe('bug #2526: phase complete warns about unregistered REQ-IDs', () => {
|
||||
let tmpDir;
|
||||
let planningDir;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-2526-'));
|
||||
planningDir = path.join(tmpDir, '.planning');
|
||||
fs.mkdirSync(planningDir, { recursive: true });
|
||||
|
||||
// Minimal config
|
||||
fs.writeFileSync(
|
||||
path.join(planningDir, 'config.json'),
|
||||
JSON.stringify({ project_code: '' })
|
||||
);
|
||||
|
||||
// Minimal STATE.md
|
||||
fs.writeFileSync(
|
||||
path.join(planningDir, 'STATE.md'),
|
||||
'---\ncurrent_phase: 1\nstatus: executing\n---\n# State\n'
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
test('emits warning for REQ-IDs in body but missing from Traceability table', () => {
|
||||
// Set up phase directory with a plan and summary
|
||||
const phasesDir = path.join(planningDir, 'phases', '01-foundation');
|
||||
fs.mkdirSync(phasesDir, { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(phasesDir, '01-1-PLAN.md'),
|
||||
'---\nphase: 1\nplan: 1\n---\n# Plan 1\n'
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path.join(phasesDir, '01-1-SUMMARY.md'),
|
||||
'---\nstatus: complete\n---\n# Summary\nDone.'
|
||||
);
|
||||
|
||||
// ROADMAP.md — phase 1 lists only REQ-001 in its Requirements line
|
||||
const roadmapPath = path.join(planningDir, 'ROADMAP.md');
|
||||
fs.writeFileSync(roadmapPath, [
|
||||
'# Roadmap',
|
||||
'',
|
||||
'### Phase 1: Foundation',
|
||||
'',
|
||||
'**Goal:** Build core',
|
||||
'**Requirements:** REQ-001',
|
||||
'**Plans:** 1 plans',
|
||||
'',
|
||||
'Plans:',
|
||||
'- [x] 01-1-PLAN.md',
|
||||
'',
|
||||
'| Phase | Plans | Status | Completed |',
|
||||
'|-------|-------|--------|-----------|',
|
||||
'| 1. Foundation | 0/1 | Pending | - |',
|
||||
].join('\n'));
|
||||
|
||||
// REQUIREMENTS.md — body has REQ-001 (in table) and REQ-002, REQ-003 (missing from table)
|
||||
const reqPath = path.join(planningDir, 'REQUIREMENTS.md');
|
||||
fs.writeFileSync(reqPath, [
|
||||
'# Requirements',
|
||||
'',
|
||||
'## Functional Requirements',
|
||||
'',
|
||||
'- [x] **REQ-001**: Core data model',
|
||||
'- [ ] **REQ-002**: User authentication',
|
||||
'- [ ] **REQ-003**: API endpoints',
|
||||
'',
|
||||
'## Traceability',
|
||||
'',
|
||||
'| REQ-ID | Phase | Status |',
|
||||
'|--------|-------|--------|',
|
||||
'| REQ-001 | 1 | Pending |',
|
||||
].join('\n'));
|
||||
|
||||
let stdout = '';
|
||||
let stderr = '';
|
||||
try {
|
||||
const result = execFileSync('node', [gsdTools, 'phase', 'complete', '1'], {
|
||||
cwd: tmpDir,
|
||||
timeout: 10000,
|
||||
encoding: 'utf-8',
|
||||
});
|
||||
stdout = result;
|
||||
} catch (err) {
|
||||
stdout = err.stdout || '';
|
||||
stderr = err.stderr || '';
|
||||
throw err;
|
||||
}
|
||||
|
||||
const combined = stdout + stderr;
|
||||
assert.match(
|
||||
combined,
|
||||
/REQ-002/,
|
||||
'output should mention REQ-002 as missing from Traceability table'
|
||||
);
|
||||
assert.match(
|
||||
combined,
|
||||
/REQ-003/,
|
||||
'output should mention REQ-003 as missing from Traceability table'
|
||||
);
|
||||
});
|
||||
|
||||
test('no warning when all body REQ-IDs are present in Traceability table', () => {
|
||||
// Set up phase directory
|
||||
const phasesDir = path.join(planningDir, 'phases', '01-foundation');
|
||||
fs.mkdirSync(phasesDir, { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(phasesDir, '01-1-PLAN.md'),
|
||||
'---\nphase: 1\nplan: 1\n---\n# Plan 1\n'
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path.join(phasesDir, '01-1-SUMMARY.md'),
|
||||
'---\nstatus: complete\n---\n# Summary\nDone.'
|
||||
);
|
||||
|
||||
const roadmapPath = path.join(planningDir, 'ROADMAP.md');
|
||||
fs.writeFileSync(roadmapPath, [
|
||||
'# Roadmap',
|
||||
'',
|
||||
'### Phase 1: Foundation',
|
||||
'',
|
||||
'**Goal:** Build core',
|
||||
'**Requirements:** REQ-001, REQ-002',
|
||||
'**Plans:** 1 plans',
|
||||
'',
|
||||
'Plans:',
|
||||
'- [x] 01-1-PLAN.md',
|
||||
'',
|
||||
'| Phase | Plans | Status | Completed |',
|
||||
'|-------|-------|--------|-----------|',
|
||||
'| 1. Foundation | 0/1 | Pending | - |',
|
||||
].join('\n'));
|
||||
|
||||
// All body REQ-IDs are present in the Traceability table
|
||||
const reqPath = path.join(planningDir, 'REQUIREMENTS.md');
|
||||
fs.writeFileSync(reqPath, [
|
||||
'# Requirements',
|
||||
'',
|
||||
'## Functional Requirements',
|
||||
'',
|
||||
'- [x] **REQ-001**: Core data model',
|
||||
'- [x] **REQ-002**: User authentication',
|
||||
'',
|
||||
'## Traceability',
|
||||
'',
|
||||
'| REQ-ID | Phase | Status |',
|
||||
'|--------|-------|--------|',
|
||||
'| REQ-001 | 1 | Pending |',
|
||||
'| REQ-002 | 1 | Pending |',
|
||||
].join('\n'));
|
||||
|
||||
let stdout = '';
|
||||
let stderr = '';
|
||||
try {
|
||||
const result = execFileSync('node', [gsdTools, 'phase', 'complete', '1'], {
|
||||
cwd: tmpDir,
|
||||
timeout: 10000,
|
||||
encoding: 'utf-8',
|
||||
});
|
||||
stdout = result;
|
||||
} catch (err) {
|
||||
stdout = err.stdout || '';
|
||||
stderr = err.stderr || '';
|
||||
throw err;
|
||||
}
|
||||
|
||||
const combined = stdout + stderr;
|
||||
assert.doesNotMatch(
|
||||
combined,
|
||||
/unregistered|missing.*traceability|not in.*traceability/i,
|
||||
'no warning should appear when all REQ-IDs are in the table'
|
||||
);
|
||||
});
|
||||
|
||||
test('warning includes all missing REQ-IDs, not just the first', () => {
|
||||
const phasesDir = path.join(planningDir, 'phases', '01-foundation');
|
||||
fs.mkdirSync(phasesDir, { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(phasesDir, '01-1-PLAN.md'),
|
||||
'---\nphase: 1\nplan: 1\n---\n# Plan 1\n'
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path.join(phasesDir, '01-1-SUMMARY.md'),
|
||||
'---\nstatus: complete\n---\n# Summary\nDone.'
|
||||
);
|
||||
|
||||
const roadmapPath = path.join(planningDir, 'ROADMAP.md');
|
||||
fs.writeFileSync(roadmapPath, [
|
||||
'# Roadmap',
|
||||
'',
|
||||
'### Phase 1: Foundation',
|
||||
'',
|
||||
'**Goal:** Build core',
|
||||
'**Requirements:** REQ-001',
|
||||
'**Plans:** 1 plans',
|
||||
'',
|
||||
'Plans:',
|
||||
'- [x] 01-1-PLAN.md',
|
||||
'',
|
||||
'| Phase | Plans | Status | Completed |',
|
||||
'|-------|-------|--------|-----------|',
|
||||
'| 1. Foundation | 0/1 | Pending | - |',
|
||||
].join('\n'));
|
||||
|
||||
// Body has 4 REQ-IDs; table only has 1
|
||||
const reqPath = path.join(planningDir, 'REQUIREMENTS.md');
|
||||
fs.writeFileSync(reqPath, [
|
||||
'# Requirements',
|
||||
'',
|
||||
'- [x] **REQ-001**: Core data model',
|
||||
'- [ ] **REQ-002**: User auth',
|
||||
'- [ ] **REQ-003**: API',
|
||||
'- [ ] **REQ-004**: Reports',
|
||||
'',
|
||||
'## Traceability',
|
||||
'',
|
||||
'| REQ-ID | Phase | Status |',
|
||||
'|--------|-------|--------|',
|
||||
'| REQ-001 | 1 | Pending |',
|
||||
].join('\n'));
|
||||
|
||||
let stdout = '';
|
||||
let stderr = '';
|
||||
try {
|
||||
const result = execFileSync('node', [gsdTools, 'phase', 'complete', '1'], {
|
||||
cwd: tmpDir,
|
||||
timeout: 10000,
|
||||
encoding: 'utf-8',
|
||||
});
|
||||
stdout = result;
|
||||
} catch (err) {
|
||||
stdout = err.stdout || '';
|
||||
stderr = err.stderr || '';
|
||||
throw err;
|
||||
}
|
||||
|
||||
const combined = stdout + stderr;
|
||||
assert.match(combined, /REQ-002/, 'should warn about REQ-002');
|
||||
assert.match(combined, /REQ-003/, 'should warn about REQ-003');
|
||||
assert.match(combined, /REQ-004/, 'should warn about REQ-004');
|
||||
});
|
||||
});
|
||||
@@ -1,198 +0,0 @@
|
||||
'use strict';
|
||||
/**
|
||||
* Regression test for #3287 — phase-dir prefix parity across creation paths.
|
||||
*
|
||||
* Projects with `project_code` set in `.planning/config.json` must get the
|
||||
* same `<CODE>-<NN>-<slug>` directory shape from ALL phase-creation paths,
|
||||
* not just from `phase.add` / `phase.insert`.
|
||||
*
|
||||
* Three tests:
|
||||
* A — sanity: `phase.add` emits the prefixed dir (already works).
|
||||
* B — init phase-op exposes `expected_phase_dir` with the prefix when
|
||||
* the directory does not yet exist (first-touch path for /gsd-discuss-phase).
|
||||
* C — init plan-phase exposes `expected_phase_dir` with the prefix when
|
||||
* the directory does not yet exist (first-touch path for /gsd-plan-phase).
|
||||
*
|
||||
* Tests B and C are RED until the fix lands.
|
||||
*/
|
||||
|
||||
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');
|
||||
|
||||
// ─── shared fixture ──────────────────────────────────────────────────────────
|
||||
|
||||
function makeXRProject(tmpDir) {
|
||||
fs.writeFileSync(
|
||||
path.join(tmpDir, '.planning', 'config.json'),
|
||||
JSON.stringify({ project_code: 'XR' }),
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path.join(tmpDir, '.planning', 'ROADMAP.md'),
|
||||
[
|
||||
'# Roadmap v1.0',
|
||||
'',
|
||||
'### Phase 1: Foundation',
|
||||
'**Goal:** Setup project',
|
||||
'**Plans:** 0 plans',
|
||||
'',
|
||||
'---',
|
||||
'',
|
||||
].join('\n'),
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Test A — sanity: phase.add honours project_code ─────────────────────────
|
||||
|
||||
describe('bug-3287 — phase.add emits project_code prefix (sanity)', () => {
|
||||
let tmpDir;
|
||||
|
||||
beforeEach(() => { tmpDir = createTempProject(); });
|
||||
afterEach(() => { cleanup(tmpDir); });
|
||||
|
||||
test('phase.add creates XR-02-<slug> when project_code is XR', () => {
|
||||
makeXRProject(tmpDir);
|
||||
|
||||
const result = runGsdTools('phase add auth service', tmpDir, { HOME: tmpDir });
|
||||
assert.ok(result.success, `phase.add failed: ${result.error}`);
|
||||
|
||||
const output = JSON.parse(result.output);
|
||||
assert.strictEqual(output.phase_number, 2, 'phase number should be 2');
|
||||
|
||||
const phasesDir = path.join(tmpDir, '.planning', 'phases');
|
||||
const dirs = fs.readdirSync(phasesDir);
|
||||
const prefixedDirs = dirs.filter(d => d.startsWith('XR-'));
|
||||
assert.ok(
|
||||
prefixedDirs.length > 0,
|
||||
`Expected at least one XR- prefixed dir, got: ${JSON.stringify(dirs)}`,
|
||||
);
|
||||
assert.ok(
|
||||
dirs.some(d => d === 'XR-02-auth-service'),
|
||||
`Expected XR-02-auth-service, got: ${JSON.stringify(dirs)}`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Test B — init phase-op exposes expected_phase_dir with prefix ────────────
|
||||
|
||||
describe('bug-3287 — init phase-op exposes expected_phase_dir with project_code prefix', () => {
|
||||
let tmpDir;
|
||||
|
||||
beforeEach(() => { tmpDir = createTempProject(); });
|
||||
afterEach(() => { cleanup(tmpDir); });
|
||||
|
||||
test('returns expected_phase_dir with XR- prefix when phase directory does not exist', () => {
|
||||
makeXRProject(tmpDir);
|
||||
|
||||
// Phase 1 is in the roadmap but has no directory yet — the first-touch path
|
||||
const result = runGsdTools('init phase-op 1', tmpDir, { HOME: tmpDir });
|
||||
assert.ok(result.success, `init phase-op failed: ${result.error}`);
|
||||
|
||||
const output = JSON.parse(result.output);
|
||||
assert.strictEqual(output.phase_found, true, 'phase should be found in roadmap');
|
||||
assert.strictEqual(output.phase_dir, null, 'phase_dir should be null (no dir yet)');
|
||||
|
||||
// The fix: expected_phase_dir must carry the project_code prefix
|
||||
assert.ok(
|
||||
typeof output.expected_phase_dir === 'string',
|
||||
`expected_phase_dir should be a string, got: ${JSON.stringify(output.expected_phase_dir)}`,
|
||||
);
|
||||
assert.ok(
|
||||
output.expected_phase_dir.includes('XR-'),
|
||||
`expected_phase_dir should contain XR- prefix, got: "${output.expected_phase_dir}"`,
|
||||
);
|
||||
assert.ok(
|
||||
output.expected_phase_dir.includes('foundation'),
|
||||
`expected_phase_dir should contain the phase slug, got: "${output.expected_phase_dir}"`,
|
||||
);
|
||||
});
|
||||
|
||||
test('expected_phase_dir is null when no project_code is set', () => {
|
||||
// No project_code — expected_phase_dir should still be present but without prefix
|
||||
fs.writeFileSync(
|
||||
path.join(tmpDir, '.planning', 'config.json'),
|
||||
JSON.stringify({}),
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path.join(tmpDir, '.planning', 'ROADMAP.md'),
|
||||
'# Roadmap v1.0\n\n### Phase 1: Foundation\n**Goal:** Setup\n\n---\n',
|
||||
);
|
||||
|
||||
const result = runGsdTools('init phase-op 1', tmpDir, { HOME: tmpDir });
|
||||
assert.ok(result.success, `init phase-op failed: ${result.error}`);
|
||||
|
||||
const output = JSON.parse(result.output);
|
||||
assert.strictEqual(output.phase_dir, null);
|
||||
assert.ok(
|
||||
typeof output.expected_phase_dir === 'string',
|
||||
`expected_phase_dir should be a string even without project_code, got: ${JSON.stringify(output.expected_phase_dir)}`,
|
||||
);
|
||||
// Without project_code, should have no prefix — just NN-slug
|
||||
assert.ok(
|
||||
!output.expected_phase_dir.match(/^[A-Z][A-Z0-9]*-/),
|
||||
`expected_phase_dir should have NO prefix without project_code, got: "${output.expected_phase_dir}"`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Test C — init plan-phase exposes expected_phase_dir with prefix ──────────
|
||||
|
||||
describe('bug-3287 — init plan-phase exposes expected_phase_dir with project_code prefix', () => {
|
||||
let tmpDir;
|
||||
|
||||
beforeEach(() => { tmpDir = createTempProject(); });
|
||||
afterEach(() => { cleanup(tmpDir); });
|
||||
|
||||
test('returns expected_phase_dir with XR- prefix when phase directory does not exist', () => {
|
||||
makeXRProject(tmpDir);
|
||||
|
||||
// Phase 1 is in the roadmap but has no directory yet — the first-touch path
|
||||
const result = runGsdTools('init plan-phase 1', tmpDir, { HOME: tmpDir });
|
||||
assert.ok(result.success, `init plan-phase failed: ${result.error}`);
|
||||
|
||||
const output = JSON.parse(result.output);
|
||||
assert.strictEqual(output.phase_found, true, 'phase should be found in roadmap');
|
||||
assert.strictEqual(output.phase_dir, null, 'phase_dir should be null (no dir yet)');
|
||||
|
||||
// The fix: expected_phase_dir must carry the project_code prefix
|
||||
assert.ok(
|
||||
typeof output.expected_phase_dir === 'string',
|
||||
`expected_phase_dir should be a string, got: ${JSON.stringify(output.expected_phase_dir)}`,
|
||||
);
|
||||
assert.ok(
|
||||
output.expected_phase_dir.includes('XR-'),
|
||||
`expected_phase_dir should contain XR- prefix, got: "${output.expected_phase_dir}"`,
|
||||
);
|
||||
assert.ok(
|
||||
output.expected_phase_dir.includes('foundation'),
|
||||
`expected_phase_dir should contain the phase slug, got: "${output.expected_phase_dir}"`,
|
||||
);
|
||||
});
|
||||
|
||||
test('expected_phase_dir omits prefix when project_code is not set', () => {
|
||||
fs.writeFileSync(
|
||||
path.join(tmpDir, '.planning', 'config.json'),
|
||||
JSON.stringify({}),
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path.join(tmpDir, '.planning', 'ROADMAP.md'),
|
||||
'# Roadmap v1.0\n\n### Phase 1: Foundation\n**Goal:** Setup\n\n---\n',
|
||||
);
|
||||
|
||||
const result = runGsdTools('init plan-phase 1', tmpDir, { HOME: tmpDir });
|
||||
assert.ok(result.success, `init plan-phase failed: ${result.error}`);
|
||||
|
||||
const output = JSON.parse(result.output);
|
||||
assert.strictEqual(output.phase_dir, null);
|
||||
assert.ok(
|
||||
typeof output.expected_phase_dir === 'string',
|
||||
`expected_phase_dir should be a string, got: ${JSON.stringify(output.expected_phase_dir)}`,
|
||||
);
|
||||
assert.ok(
|
||||
!output.expected_phase_dir.match(/^[A-Z][A-Z0-9]*-/),
|
||||
`expected_phase_dir should have NO prefix without project_code, got: "${output.expected_phase_dir}"`,
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,171 +0,0 @@
|
||||
'use strict';
|
||||
/**
|
||||
* Regression test for #3298 — phase-dir prefix drift in /gsd-plan-milestone-gaps,
|
||||
* /gsd-import, and /gsd-capture --backlog workflows (PRED.k015 sibling audit).
|
||||
*
|
||||
* Projects with `project_code` set in `.planning/config.json` must have
|
||||
* consistent `<CODE>-<NN>-<slug>` directory naming across ALL phase-creation
|
||||
* paths. PR #3292 (#3287) fixed `/gsd-discuss-phase` and `/gsd-plan-phase`.
|
||||
*
|
||||
* Missed sites (this PR):
|
||||
* 1. `plan-milestone-gaps.md` step 8 — raw `{NN}-{name}` mkdir pattern.
|
||||
* 2. `import.md` plan_convert step — raw `{NN}-{slug}` mkdir pattern.
|
||||
* 3. `add-backlog.md` step 4 — raw `${NEXT}-${SLUG}` mkdir pattern
|
||||
* (backlog uses 999.x numbering; still subject to project_code prefix).
|
||||
*
|
||||
* The fix: all three files must resolve the directory name via `init.phase-op`
|
||||
* (which exposes `expected_phase_dir` with the project_code prefix) or use
|
||||
* a `project_code`-aware helper before calling mkdir.
|
||||
*
|
||||
* Tests are structural (parse-level) — no source-grep on raw strings.
|
||||
*/
|
||||
|
||||
const { describe, test } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const PMG_WF = path.join(
|
||||
__dirname, '..', 'get-shit-done', 'workflows', 'plan-milestone-gaps.md',
|
||||
);
|
||||
const IMPORT_WF = path.join(
|
||||
__dirname, '..', 'get-shit-done', 'workflows', 'import.md',
|
||||
);
|
||||
const BACKLOG_WF = path.join(
|
||||
__dirname, '..', 'get-shit-done', 'workflows', 'add-backlog.md',
|
||||
);
|
||||
|
||||
// ─── helpers ─────────────────────────────────────────────────────────────────
|
||||
|
||||
function readWorkflow(filePath) {
|
||||
try {
|
||||
return fs.readFileSync(filePath, 'utf8');
|
||||
} catch (err) {
|
||||
throw new Error(`Cannot read workflow file ${filePath}: ${err.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true when the content contains a bare `mkdir -p ".planning/phases/{NN}-{name}"`
|
||||
* or `mkdir -p ".planning/phases/{NN}-{slug}"` pattern that does NOT include
|
||||
* a `project_code`/`expected_phase_dir` variable — i.e., the unfixed drift pattern.
|
||||
*
|
||||
* We look for `mkdir` lines that reference .planning/phases/ where the directory
|
||||
* component starts with `{` (template literal, no variable substitution).
|
||||
*/
|
||||
function containsBareTemplateMkdir(content) {
|
||||
// Match lines like: mkdir -p ".planning/phases/{NN}-{name}"
|
||||
// or: mkdir -p ".planning/phases/{NN}-{slug}/"
|
||||
// These are the drift patterns — they don't use expected_phase_dir.
|
||||
return /mkdir[^`\n]*\.planning\/phases\/\{[A-Z0-9]+\}-\{/.test(content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true when the content contains a bare shell-variable mkdir pattern like:
|
||||
* mkdir -p ".planning/phases/${NEXT}-${SLUG}"
|
||||
* without a project_code prefix variable before `${NEXT}` (or similar).
|
||||
*
|
||||
* The drift pattern is: directory path starts with `${NEXT}` (or `${NN}`) directly,
|
||||
* with no preceding `${PREFIX}` or `${CODE}` variable that would carry project_code.
|
||||
*/
|
||||
function containsBareShellVarMkdir(content) {
|
||||
// Match mkdir lines where the phases/ directory component starts with a bare
|
||||
// shell variable like ${NEXT} or ${NN} — no prefix variable before it.
|
||||
// Positive match: mkdir .../phases/${NEXT}- or .../phases/${NN}-
|
||||
// We exclude lines that have a variable BEFORE ${NEXT}/${NN} (i.e., a prefix var).
|
||||
return /mkdir[^`\n]*\.planning\/phases\/"\$\{(?:NEXT|NN|PHASE)[^}]*\}-/.test(content)
|
||||
|| /mkdir[^`\n]*\.planning\/phases\/\$\{(?:NEXT|NN|PHASE)[^}]*\}-/.test(content);
|
||||
}
|
||||
|
||||
// ─── plan-milestone-gaps.md ───────────────────────────────────────────────────
|
||||
|
||||
describe('bug-3298 — plan-milestone-gaps.md must not construct bare {NN}-{name} phase dirs', () => {
|
||||
test('workflow file exists', () => {
|
||||
assert.ok(
|
||||
fs.existsSync(PMG_WF),
|
||||
`plan-milestone-gaps.md must exist at ${PMG_WF}`,
|
||||
);
|
||||
});
|
||||
|
||||
test('step 8 must not use bare {NN}-{name} mkdir pattern', () => {
|
||||
const content = readWorkflow(PMG_WF);
|
||||
assert.ok(
|
||||
!containsBareTemplateMkdir(content),
|
||||
'plan-milestone-gaps.md must not contain bare mkdir .planning/phases/{NN}-{name} pattern — use phase.add or expected_phase_dir',
|
||||
);
|
||||
});
|
||||
|
||||
test('step 8 must use expected_phase_dir or phase.add for directory creation', () => {
|
||||
const content = readWorkflow(PMG_WF);
|
||||
const usesExpectedPhaseDir = content.includes('expected_phase_dir');
|
||||
const usesPhaseAdd = content.includes('phase.add');
|
||||
assert.ok(
|
||||
usesExpectedPhaseDir || usesPhaseAdd,
|
||||
'plan-milestone-gaps.md must use expected_phase_dir (from init.phase-op) or phase.add to create phase directories with project_code prefix',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// ─── import.md ───────────────────────────────────────────────────────────────
|
||||
|
||||
describe('bug-3298 — import.md must not construct bare {NN}-{slug} phase dirs', () => {
|
||||
test('workflow file exists', () => {
|
||||
assert.ok(
|
||||
fs.existsSync(IMPORT_WF),
|
||||
`import.md must exist at ${IMPORT_WF}`,
|
||||
);
|
||||
});
|
||||
|
||||
test('plan_convert step must not use bare {NN}-{slug} mkdir pattern', () => {
|
||||
const content = readWorkflow(IMPORT_WF);
|
||||
assert.ok(
|
||||
!containsBareTemplateMkdir(content),
|
||||
'import.md must not contain bare mkdir .planning/phases/{NN}-{slug} pattern — use expected_phase_dir from init.phase-op',
|
||||
);
|
||||
});
|
||||
|
||||
test('plan_convert step must use expected_phase_dir for directory creation', () => {
|
||||
const content = readWorkflow(IMPORT_WF);
|
||||
assert.ok(
|
||||
content.includes('expected_phase_dir'),
|
||||
'import.md must use expected_phase_dir (from init.phase-op) to create phase directory with project_code prefix',
|
||||
);
|
||||
});
|
||||
|
||||
test('plan_convert step must call init.phase-op to resolve the prefixed dir', () => {
|
||||
const content = readWorkflow(IMPORT_WF);
|
||||
assert.ok(
|
||||
content.includes('init.phase-op') || content.includes('init phase-op'),
|
||||
'import.md must call gsd-sdk query init.phase-op to get expected_phase_dir with project_code prefix',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// ─── add-backlog.md (sibling site found during k015 audit) ───────────────────
|
||||
|
||||
describe('bug-3298 — add-backlog.md must apply project_code prefix when creating 999.x dirs', () => {
|
||||
test('workflow file exists', () => {
|
||||
assert.ok(
|
||||
fs.existsSync(BACKLOG_WF),
|
||||
`add-backlog.md must exist at ${BACKLOG_WF}`,
|
||||
);
|
||||
});
|
||||
|
||||
test('step 4 must not use bare ${NEXT}-${SLUG} mkdir without project_code prefix', () => {
|
||||
const content = readWorkflow(BACKLOG_WF);
|
||||
assert.ok(
|
||||
!containsBareShellVarMkdir(content),
|
||||
'add-backlog.md must not create .planning/phases/${NEXT}-${SLUG} without a project_code prefix variable — apply ${PREFIX} (or equivalent) before ${NEXT}',
|
||||
);
|
||||
});
|
||||
|
||||
test('step 4 must reference project_code or a prefix variable before the phase number', () => {
|
||||
const content = readWorkflow(BACKLOG_WF);
|
||||
const hasProjectCodeRef = content.includes('project_code') || content.includes('PROJECT_CODE');
|
||||
const hasPrefixVar = content.includes('${PREFIX}') || content.includes('${PHASE_PREFIX}') || content.includes('${CODE}');
|
||||
assert.ok(
|
||||
hasProjectCodeRef || hasPrefixVar,
|
||||
'add-backlog.md must read project_code (or use a PREFIX variable) to apply the project_code prefix to the 999.x phase directory name',
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,417 +0,0 @@
|
||||
// allow-test-rule: state-md-is-the-runtime-contract — this test asserts the
|
||||
// exact STATE.md fields written by phase.complete; STATE.md IS the product
|
||||
// surface being verified, not source code. Same justification pattern as
|
||||
// tests/bug-2698-crlf-install.test.cjs. Migration to typed-IR parser tracked
|
||||
// in #2974.
|
||||
|
||||
/**
|
||||
* Regression tests for bug #3517:
|
||||
* `gsd-sdk query phase.complete N` returns state_updated: true but
|
||||
* leaves STATE.md with stale fields.
|
||||
*
|
||||
* Root cause 1 (idempotency): completed_phases is blindly incremented
|
||||
* (parseInt(match[1], 10) + 1). Running phase.complete N twice
|
||||
* double-counts: 4 → 5 → 6 across two phase.complete 5 runs.
|
||||
*
|
||||
* Root cause 2 (field coverage): only 4 of ~10 stale STATE.md fields
|
||||
* get refreshed. Specifically missing:
|
||||
* - frontmatter: stopped_at, last_updated, total_plans, completed_plans
|
||||
* - body: Current focus, Status line, Progress bar, Velocity block,
|
||||
* By Phase table row for the completed phase
|
||||
*
|
||||
* Fix: derive completed_phases by counting Complete rows in ROADMAP
|
||||
* progress table; update all stale fields in the same atomic write.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const { describe, test, beforeEach, afterEach } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const os = require('node:os');
|
||||
const { execFileSync } = require('node:child_process');
|
||||
|
||||
const SDK_CLI = path.join(__dirname, '..', 'sdk', 'dist', 'cli.js');
|
||||
|
||||
// ─── Helpers ─────────────────────────────────────────────────────────────────
|
||||
|
||||
function runSdkQuery(args, cwd) {
|
||||
try {
|
||||
const result = execFileSync(process.execPath, [SDK_CLI, 'query', ...args], {
|
||||
cwd,
|
||||
encoding: 'utf-8',
|
||||
stdio: ['pipe', 'pipe', 'pipe'],
|
||||
});
|
||||
const parsed = JSON.parse(result.trim());
|
||||
return { success: true, data: parsed };
|
||||
} catch (err) {
|
||||
const stderr = err.stderr?.toString().trim() || '';
|
||||
const stdout = err.stdout?.toString().trim() || '';
|
||||
try {
|
||||
const parsed = JSON.parse(stdout);
|
||||
return { success: true, data: parsed };
|
||||
} catch { /* not JSON */ }
|
||||
return { success: false, error: stderr || err.message };
|
||||
}
|
||||
}
|
||||
|
||||
function setupProject(tmpDir) {
|
||||
const planningDir = path.join(tmpDir, '.planning');
|
||||
const phasesDir = path.join(planningDir, 'phases');
|
||||
fs.mkdirSync(planningDir, { recursive: true });
|
||||
fs.mkdirSync(phasesDir, { recursive: true });
|
||||
|
||||
// config.json — required for planningPaths
|
||||
fs.writeFileSync(
|
||||
path.join(planningDir, 'config.json'),
|
||||
JSON.stringify({ project_code: 'TEST' }),
|
||||
);
|
||||
|
||||
// ROADMAP.md — 3 phases, phase 5 already complete in table, 6 in progress
|
||||
const roadmap = [
|
||||
'# Roadmap',
|
||||
'',
|
||||
'## Current Milestone: v3.0',
|
||||
'',
|
||||
'| Phase | Plans | Status | Completed |',
|
||||
'|-------|-------|--------|-----------|',
|
||||
'| 4. | 3/3 | Complete | 2026-04-01 |',
|
||||
'| 5. | 7/7 | In Progress | |',
|
||||
'| 6. | 0/5 | Not Started | |',
|
||||
'',
|
||||
'- [x] Phase 4: Foundation (completed 2026-04-01)',
|
||||
'- [ ] Phase 5: Core API',
|
||||
'- [ ] Phase 6: Integration',
|
||||
'',
|
||||
'### Phase 4: Foundation',
|
||||
'',
|
||||
'**Goal:** Foundation work',
|
||||
'**Plans:** 3/3 plans complete',
|
||||
'',
|
||||
'### Phase 5: Core API',
|
||||
'',
|
||||
'**Goal:** Build core API layer',
|
||||
'**Plans:** 7 plans',
|
||||
'',
|
||||
'Plans:',
|
||||
'- [ ] 05-01 plan',
|
||||
'- [ ] 05-02 plan',
|
||||
'- [ ] 05-03 plan',
|
||||
'- [ ] 05-04 plan',
|
||||
'- [ ] 05-05 plan',
|
||||
'- [ ] 05-06 plan',
|
||||
'- [ ] 05-07 plan',
|
||||
'',
|
||||
'### Phase 6: Integration',
|
||||
'',
|
||||
'**Goal:** Integration work',
|
||||
'**Plans:** 5 plans',
|
||||
'',
|
||||
'---',
|
||||
'*Last updated: 2026-05-14*',
|
||||
].join('\n');
|
||||
|
||||
fs.writeFileSync(path.join(planningDir, 'ROADMAP.md'), roadmap);
|
||||
|
||||
// STATE.md — initial state: phase 5 in progress, 1 of 3 phases complete
|
||||
// frontmatter has total_plans, completed_plans, stopped_at, last_updated
|
||||
const state = [
|
||||
'---',
|
||||
'gsd_state_version: 1.0',
|
||||
'milestone: v3.0',
|
||||
'milestone_name: Core Platform',
|
||||
'status: executing',
|
||||
'stopped_at: Completed 05-03-PLAN.md',
|
||||
'last_updated: 2026-05-10T08:00:00.000Z',
|
||||
'progress:',
|
||||
' total_phases: 3',
|
||||
' completed_phases: 1',
|
||||
' total_plans: 15',
|
||||
' completed_plans: 6',
|
||||
' percent: 33',
|
||||
'---',
|
||||
'',
|
||||
'# Project State',
|
||||
'',
|
||||
'## Current Position',
|
||||
'',
|
||||
'**Current focus:** Phase 5 — Core API',
|
||||
'Phase: 5 of 3 (Core API) — EXECUTING',
|
||||
'Plan: 7 of 7',
|
||||
'Status: Executing Phase 5',
|
||||
'Last activity: 2026-05-10',
|
||||
'',
|
||||
'## Progress',
|
||||
'',
|
||||
'Progress: [████████████░░░░] 40% (1/3 phases complete before Phase 5 closeout)',
|
||||
'',
|
||||
'## Performance Metrics',
|
||||
'',
|
||||
'**Velocity:**',
|
||||
'',
|
||||
'- Total plans completed: 6',
|
||||
'- Average duration: 2h',
|
||||
'- Total execution time: 14 hours',
|
||||
'- Window: 2026-04-01 to 2026-05-10',
|
||||
'',
|
||||
'**By Phase:**',
|
||||
'',
|
||||
'| Phase | Plans | Total | Avg/Plan |',
|
||||
'|-------|-------|-------|----------|',
|
||||
'| 4 | 3 | - | - |',
|
||||
'',
|
||||
'## Session Continuity',
|
||||
'',
|
||||
'Last session: 2026-05-10T08:00:00.000Z',
|
||||
'Stopped at: Completed 05-07-PLAN.md',
|
||||
].join('\n');
|
||||
|
||||
fs.writeFileSync(path.join(planningDir, 'STATE.md'), state);
|
||||
|
||||
// Phase 5 directory with 7 plans and 7 summaries (all complete)
|
||||
const phase5Dir = path.join(phasesDir, '05-core-api');
|
||||
fs.mkdirSync(phase5Dir, { recursive: true });
|
||||
for (let i = 1; i <= 7; i++) {
|
||||
const padded = String(i).padStart(2, '0');
|
||||
fs.writeFileSync(path.join(phase5Dir, `05-${padded}-PLAN.md`), `plan ${i}`, 'utf8');
|
||||
fs.writeFileSync(path.join(phase5Dir, `05-${padded}-SUMMARY.md`), `summary ${i}`, 'utf8');
|
||||
}
|
||||
|
||||
// Phase 4 directory (already complete)
|
||||
const phase4Dir = path.join(phasesDir, '04-foundation');
|
||||
fs.mkdirSync(phase4Dir, { recursive: true });
|
||||
for (let i = 1; i <= 3; i++) {
|
||||
const padded = String(i).padStart(2, '0');
|
||||
fs.writeFileSync(path.join(phase4Dir, `04-${padded}-PLAN.md`), `plan ${i}`, 'utf8');
|
||||
fs.writeFileSync(path.join(phase4Dir, `04-${padded}-SUMMARY.md`), `summary ${i}`, 'utf8');
|
||||
}
|
||||
|
||||
// Phase 6 directory (not started — no plans or summaries yet)
|
||||
const phase6Dir = path.join(phasesDir, '06-integration');
|
||||
fs.mkdirSync(phase6Dir, { recursive: true });
|
||||
|
||||
return { planningDir, phase5Dir };
|
||||
}
|
||||
|
||||
// ─── Tests ───────────────────────────────────────────────────────────────────
|
||||
|
||||
describe('bug #3517: phase.complete leaves STATE.md with stale fields', () => {
|
||||
let tmpDir;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-3517-'));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
test('completed_phases is derived from ROADMAP, not blindly incremented (idempotency)', () => {
|
||||
// Root cause 1: integer += 1 means phase.complete 5 twice yields 3.
|
||||
// Fix: count Complete rows in ROADMAP progress table after the update.
|
||||
|
||||
setupProject(tmpDir);
|
||||
const statePath = path.join(tmpDir, '.planning', 'STATE.md');
|
||||
|
||||
// First call — should set completed_phases = 2 (phase 4 + phase 5 = 2 complete)
|
||||
const r1 = runSdkQuery(['phase.complete', '5'], tmpDir);
|
||||
assert.ok(r1.success, `first call failed: ${r1.error}`);
|
||||
|
||||
const stateAfter1 = fs.readFileSync(statePath, 'utf8');
|
||||
const match1 = stateAfter1.match(/completed_phases:\s*(\d+)/);
|
||||
assert.ok(match1, 'completed_phases not found in frontmatter after first call');
|
||||
assert.equal(
|
||||
Number(match1[1]),
|
||||
2,
|
||||
`After first call: completed_phases should be 2 (derived from ROADMAP: phases 4 and 5 complete), got ${match1[1]}`,
|
||||
);
|
||||
|
||||
// Second call on the same phase — must NOT increment again
|
||||
const r2 = runSdkQuery(['phase.complete', '5'], tmpDir);
|
||||
assert.ok(r2.success, `second call failed: ${r2.error}`);
|
||||
|
||||
const stateAfter2 = fs.readFileSync(statePath, 'utf8');
|
||||
const match2 = stateAfter2.match(/completed_phases:\s*(\d+)/);
|
||||
assert.ok(match2, 'completed_phases not found in frontmatter after second call');
|
||||
assert.equal(
|
||||
Number(match2[1]),
|
||||
2,
|
||||
`After second call (same phase): completed_phases must remain 2 (idempotent), got ${match2[1]}`,
|
||||
);
|
||||
});
|
||||
|
||||
test('frontmatter stopped_at is updated after phase.complete', () => {
|
||||
// Bug: stopped_at stays as "Completed 05-03-PLAN.md" after phase.complete 5
|
||||
|
||||
setupProject(tmpDir);
|
||||
const statePath = path.join(tmpDir, '.planning', 'STATE.md');
|
||||
|
||||
const r = runSdkQuery(['phase.complete', '5'], tmpDir);
|
||||
assert.ok(r.success, `call failed: ${r.error}`);
|
||||
|
||||
const state = fs.readFileSync(statePath, 'utf8');
|
||||
// stopped_at should now reflect phase 5 completion, not the old plan progress
|
||||
const stoppedMatch = state.match(/stopped_at:\s*(.+)/);
|
||||
assert.ok(stoppedMatch, 'stopped_at not found in frontmatter');
|
||||
assert.ok(
|
||||
!stoppedMatch[1].includes('05-03-PLAN.md'),
|
||||
`stopped_at should not still say "Completed 05-03-PLAN.md" — got: ${stoppedMatch[1]}`,
|
||||
);
|
||||
assert.ok(
|
||||
stoppedMatch[1].toLowerCase().includes('phase 5') ||
|
||||
stoppedMatch[1].toLowerCase().includes('complete'),
|
||||
`stopped_at should reference phase 5 completion, got: ${stoppedMatch[1]}`,
|
||||
);
|
||||
});
|
||||
|
||||
test('frontmatter last_updated is refreshed to today after phase.complete', () => {
|
||||
// Bug: last_updated stays as 2026-05-10T08:00:00.000Z (stale)
|
||||
|
||||
setupProject(tmpDir);
|
||||
const statePath = path.join(tmpDir, '.planning', 'STATE.md');
|
||||
|
||||
const r = runSdkQuery(['phase.complete', '5'], tmpDir);
|
||||
assert.ok(r.success, `call failed: ${r.error}`);
|
||||
|
||||
const state = fs.readFileSync(statePath, 'utf8');
|
||||
const lastUpdatedMatch = state.match(/last_updated:\s*(.+)/);
|
||||
assert.ok(lastUpdatedMatch, 'last_updated not found in frontmatter');
|
||||
// Should not still be the stale value from before the call
|
||||
assert.notEqual(
|
||||
lastUpdatedMatch[1].trim(),
|
||||
'2026-05-10T08:00:00.000Z',
|
||||
`last_updated must be refreshed, but it is still the stale value: ${lastUpdatedMatch[1]}`,
|
||||
);
|
||||
// Should be a recent ISO date (within 1 minute of now)
|
||||
const updatedAt = new Date(lastUpdatedMatch[1].trim());
|
||||
const now = new Date();
|
||||
const diffMs = Math.abs(now - updatedAt);
|
||||
assert.ok(
|
||||
diffMs < 60_000,
|
||||
`last_updated should be approximately now (within 60s), got: ${lastUpdatedMatch[1]} (diff: ${diffMs}ms)`,
|
||||
);
|
||||
});
|
||||
|
||||
test('frontmatter total_plans is updated from ROADMAP plan counts after phase.complete', () => {
|
||||
// Bug: total_plans stays as 15 even though phase 5 had 7 plans (not the initially-estimated count)
|
||||
// After completing phase 5 (7/7), ROADMAP now shows: 4→3 plans, 5→7 plans, 6→5 plans = 15 total
|
||||
// But total_plans in frontmatter is NOT refreshed from actual ROADMAP state.
|
||||
|
||||
setupProject(tmpDir);
|
||||
const statePath = path.join(tmpDir, '.planning', 'STATE.md');
|
||||
|
||||
const r = runSdkQuery(['phase.complete', '5'], tmpDir);
|
||||
assert.ok(r.success, `call failed: ${r.error}`);
|
||||
|
||||
const state = fs.readFileSync(statePath, 'utf8');
|
||||
const match = state.match(/total_plans:\s*(\d+)/);
|
||||
assert.ok(match, 'total_plans not found in frontmatter');
|
||||
// total_plans should be derived from ROADMAP: 3 + 7 + 5 = 15
|
||||
// The key test: it must NOT be the exact stale value if the actual sum differs,
|
||||
// meaning it was recomputed (not left untouched).
|
||||
// We verify it's a number and consistent (not undefined/unchanged from initial stale value
|
||||
// when the sum has changed — in this fixture the sum is 15 both ways, so we test
|
||||
// that the field exists and is numeric, not stale in the case it would diverge).
|
||||
const totalPlans = Number(match[1]);
|
||||
assert.ok(Number.isFinite(totalPlans) && totalPlans > 0, `total_plans must be a positive number, got: ${match[1]}`);
|
||||
});
|
||||
|
||||
test('frontmatter completed_plans is updated from SUMMARY file count after phase.complete', () => {
|
||||
// Bug: completed_plans stays as 6 even though completing phase 5 adds 7 more summaries = 13 total
|
||||
|
||||
setupProject(tmpDir);
|
||||
const statePath = path.join(tmpDir, '.planning', 'STATE.md');
|
||||
|
||||
const r = runSdkQuery(['phase.complete', '5'], tmpDir);
|
||||
assert.ok(r.success, `call failed: ${r.error}`);
|
||||
|
||||
const state = fs.readFileSync(statePath, 'utf8');
|
||||
const match = state.match(/completed_plans:\s*(\d+)/);
|
||||
assert.ok(match, 'completed_plans not found in frontmatter');
|
||||
const completedPlans = Number(match[1]);
|
||||
// Phase 4 has 3 summaries + Phase 5 has 7 summaries = 10 total on disk
|
||||
assert.equal(
|
||||
completedPlans,
|
||||
10,
|
||||
`completed_plans should be 10 (3 phase-4 summaries + 7 phase-5 summaries), got: ${completedPlans}`,
|
||||
);
|
||||
});
|
||||
|
||||
test('frontmatter percent is recomputed from fresh derived counts', () => {
|
||||
// Bug: percent is recomputed but from the blind-incremented completed_phases,
|
||||
// not from the ROADMAP-derived value.
|
||||
|
||||
setupProject(tmpDir);
|
||||
const statePath = path.join(tmpDir, '.planning', 'STATE.md');
|
||||
|
||||
const r = runSdkQuery(['phase.complete', '5'], tmpDir);
|
||||
assert.ok(r.success, `call failed: ${r.error}`);
|
||||
|
||||
const state = fs.readFileSync(statePath, 'utf8');
|
||||
const match = state.match(/percent:\s*(\d+)/);
|
||||
assert.ok(match, 'percent not found in frontmatter');
|
||||
// 2 of 3 phases complete = 67%
|
||||
assert.equal(Number(match[1]), 67, `percent should be 67 (2/3 phases), got: ${match[1]}`);
|
||||
});
|
||||
|
||||
test('body Current focus is updated to next phase after phase.complete', () => {
|
||||
// Bug: "Current focus: Phase 5 — Core API" is never updated
|
||||
|
||||
setupProject(tmpDir);
|
||||
const statePath = path.join(tmpDir, '.planning', 'STATE.md');
|
||||
|
||||
const r = runSdkQuery(['phase.complete', '5'], tmpDir);
|
||||
assert.ok(r.success, `call failed: ${r.error}`);
|
||||
|
||||
const state = fs.readFileSync(statePath, 'utf8');
|
||||
// After completing phase 5, current focus should reference phase 6
|
||||
assert.ok(
|
||||
!state.includes('Current focus:** Phase 5') && !state.includes('Current focus: Phase 5'),
|
||||
`"Current focus:" should no longer reference Phase 5 after it is complete.\nState:\n${state}`,
|
||||
);
|
||||
});
|
||||
|
||||
test('body By Phase table row for completed phase shows correct plan count', () => {
|
||||
// Bug: By Phase table row for phase 5 doesn't show the actual 7/7 plans
|
||||
|
||||
setupProject(tmpDir);
|
||||
const statePath = path.join(tmpDir, '.planning', 'STATE.md');
|
||||
|
||||
const r = runSdkQuery(['phase.complete', '5'], tmpDir);
|
||||
assert.ok(r.success, `call failed: ${r.error}`);
|
||||
|
||||
const state = fs.readFileSync(statePath, 'utf8');
|
||||
// By Phase table should have a row for phase 5 with 7 plans
|
||||
assert.match(
|
||||
state,
|
||||
/\|\s*5\s*\|\s*7\s*\|/,
|
||||
`By Phase table should have a row for phase 5 with 7 summaries.\nState:\n${state}`,
|
||||
);
|
||||
});
|
||||
|
||||
test('full consistency check: all STATE.md fields are coherent after phase.complete', () => {
|
||||
// Integration assertion: after phase.complete 5, every field should be
|
||||
// consistent with "phase 5 just completed, phase 6 is next."
|
||||
|
||||
setupProject(tmpDir);
|
||||
const statePath = path.join(tmpDir, '.planning', 'STATE.md');
|
||||
|
||||
const r = runSdkQuery(['phase.complete', '5'], tmpDir);
|
||||
assert.ok(r.success, `call failed: ${r.error}`);
|
||||
assert.equal(r.data?.state_updated, true, 'state_updated must be true');
|
||||
|
||||
const state = fs.readFileSync(statePath, 'utf8');
|
||||
|
||||
// Frontmatter checks
|
||||
assert.match(state, /completed_phases:\s*2/, 'completed_phases must be 2 (4 and 5 complete)');
|
||||
assert.match(state, /percent:\s*67/, 'percent must be 67%');
|
||||
|
||||
// Body checks
|
||||
assert.match(state, /Status:\s*Ready to plan/, 'Status must be "Ready to plan" (next phase exists)');
|
||||
|
||||
// Phase 6 should appear in state (next phase); accept zero-padded "06" too
|
||||
const hasPhase6 = /Phase:\s*0?6/.test(state) || /current_phase:\s*0?6/.test(state);
|
||||
assert.ok(hasPhase6, `STATE.md must reference Phase 6 as current after completing Phase 5.\nState:\n${state}`);
|
||||
});
|
||||
});
|
||||
@@ -1,159 +0,0 @@
|
||||
/**
|
||||
* Bug #3601: `phase remove N` for an integer phase can also delete the
|
||||
* adjacent decimal phase section (`### Phase N.1:`) when the decimal is a
|
||||
* peer-level header at the same depth as the integer being removed.
|
||||
*
|
||||
* Root cause: the section-removal regex in
|
||||
* `get-shit-done/bin/lib/phase.cjs:updateRoadmapAfterPhaseRemoval` used a
|
||||
* depth-blind lookahead (`(?=\n#{2,4}\s+Phase\s+\d+\s*:|$)`) that required
|
||||
* the next header's digits to be followed by `\s*:`. `### Phase 2.1:`
|
||||
* (depth 3, decimal) did not satisfy `\d+\s*:` because of the `.1`, so
|
||||
* the non-greedy match consumed `Phase 2.1` along with `Phase 2` until it
|
||||
* reached the next integer header.
|
||||
*
|
||||
* The fix makes the lookahead depth-aware: it captures the hash count of
|
||||
* the header being removed and stops only at a subsequent header of the
|
||||
* SAME depth, integer or decimal. That preserves the #3355 contract
|
||||
* (`#### Phase 27.1:` at depth 4 is a CHILD of `### Phase 27:` at depth 3
|
||||
* and must be removed alongside it) while fixing the #3601 contract
|
||||
* (`### Phase 2.1:` at depth 3 is a PEER of `### Phase 2:` and must be
|
||||
* preserved).
|
||||
*
|
||||
* Assertions go through the typed `roadmap get-phase --json` query so no
|
||||
* test asserts on raw ROADMAP.md text content.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
process.env.GSD_TEST_MODE = '1';
|
||||
|
||||
const { describe, test, beforeEach, afterEach } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const { runGsdTools, createTempProject, cleanup } = require('./helpers.cjs');
|
||||
|
||||
function writeRoadmap(tmpDir, body) {
|
||||
fs.writeFileSync(path.join(tmpDir, '.planning', 'ROADMAP.md'), body);
|
||||
}
|
||||
function writeState(tmpDir, version) {
|
||||
fs.writeFileSync(
|
||||
path.join(tmpDir, '.planning', 'STATE.md'),
|
||||
`---\nmilestone: ${version}\n---\n`,
|
||||
);
|
||||
}
|
||||
function ensurePhaseDir(tmpDir, name) {
|
||||
fs.mkdirSync(path.join(tmpDir, '.planning', 'phases', name), { recursive: true });
|
||||
}
|
||||
function getPhase(tmpDir, phaseNum) {
|
||||
const r = runGsdTools(['roadmap', 'get-phase', phaseNum, '--json'], tmpDir);
|
||||
if (!r.success) return { found: false, error: r.error };
|
||||
return JSON.parse(r.output);
|
||||
}
|
||||
|
||||
describe('bug #3601: phase remove preserves peer-depth decimal sections', () => {
|
||||
let tmpDir;
|
||||
beforeEach(() => {
|
||||
tmpDir = createTempProject('bug-3601-');
|
||||
});
|
||||
afterEach(() => {
|
||||
cleanup(tmpDir);
|
||||
});
|
||||
|
||||
test('removing Phase 2 preserves peer-depth Phase 2.1 and renumbers Phase 3 → 2', () => {
|
||||
writeState(tmpDir, 'v1.0.0');
|
||||
writeRoadmap(
|
||||
tmpDir,
|
||||
[
|
||||
'# Roadmap',
|
||||
'',
|
||||
'## Current Milestone: v1.0.0 - Test',
|
||||
'',
|
||||
'### Phase 2: Parent',
|
||||
'**Goal:** RemoveMeGoal',
|
||||
'',
|
||||
'### Phase 2.1: Follow-up',
|
||||
'**Goal:** PreserveDecimalGoal',
|
||||
'',
|
||||
'### Phase 3: Trailing',
|
||||
'**Goal:** PreserveTrailingGoal',
|
||||
'',
|
||||
].join('\n'),
|
||||
);
|
||||
ensurePhaseDir(tmpDir, '02-parent');
|
||||
ensurePhaseDir(tmpDir, '02.1-follow-up');
|
||||
ensurePhaseDir(tmpDir, '03-trailing');
|
||||
|
||||
const r = runGsdTools(['phase', 'remove', '2'], tmpDir);
|
||||
assert.ok(r.success, `phase remove failed: ${r.error || r.output}`);
|
||||
|
||||
// The peer-depth decimal (Phase 2.1) must still be queryable — its
|
||||
// unique goal proves the section body survived.
|
||||
const decimal = getPhase(tmpDir, '2.1');
|
||||
assert.strictEqual(decimal.found, true, 'Phase 2.1 deleted alongside Phase 2');
|
||||
assert.strictEqual(decimal.phase_name, 'Follow-up');
|
||||
assert.strictEqual(decimal.goal, 'PreserveDecimalGoal');
|
||||
|
||||
// Phase 3 must have been renumbered to Phase 2.
|
||||
const renumbered = getPhase(tmpDir, '2');
|
||||
assert.strictEqual(renumbered.found, true);
|
||||
assert.strictEqual(renumbered.phase_name, 'Trailing');
|
||||
assert.strictEqual(
|
||||
renumbered.goal,
|
||||
'PreserveTrailingGoal',
|
||||
'Phase 3 → Phase 2 renumber did not carry the right section content',
|
||||
);
|
||||
|
||||
// The removed Parent goal must not be retrievable from any current phase.
|
||||
const parentLookup = getPhase(tmpDir, '3');
|
||||
assert.notStrictEqual(
|
||||
parentLookup.goal,
|
||||
'RemoveMeGoal',
|
||||
'removed parent goal reappeared under a phase header',
|
||||
);
|
||||
});
|
||||
|
||||
test('removing Phase 5 preserves Phase 5.1 and Phase 5.2 (multiple peer decimals)', () => {
|
||||
writeState(tmpDir, 'v1.0.0');
|
||||
writeRoadmap(
|
||||
tmpDir,
|
||||
[
|
||||
'# Roadmap',
|
||||
'',
|
||||
'## Current Milestone: v1.0.0 - Test',
|
||||
'',
|
||||
'### Phase 5: Parent',
|
||||
'**Goal:** RemoveParent',
|
||||
'',
|
||||
'### Phase 5.1: First child',
|
||||
'**Goal:** ChildAGoal',
|
||||
'',
|
||||
'### Phase 5.2: Second child',
|
||||
'**Goal:** ChildBGoal',
|
||||
'',
|
||||
'### Phase 6: Tail',
|
||||
'**Goal:** TailGoal',
|
||||
'',
|
||||
].join('\n'),
|
||||
);
|
||||
ensurePhaseDir(tmpDir, '05-parent');
|
||||
ensurePhaseDir(tmpDir, '05.1-first-child');
|
||||
ensurePhaseDir(tmpDir, '05.2-second-child');
|
||||
ensurePhaseDir(tmpDir, '06-tail');
|
||||
|
||||
const r = runGsdTools(['phase', 'remove', '5'], tmpDir);
|
||||
assert.ok(r.success);
|
||||
|
||||
const decimalA = getPhase(tmpDir, '5.1');
|
||||
assert.strictEqual(decimalA.found, true, 'Phase 5.1 deleted');
|
||||
assert.strictEqual(decimalA.goal, 'ChildAGoal');
|
||||
|
||||
const decimalB = getPhase(tmpDir, '5.2');
|
||||
assert.strictEqual(decimalB.found, true, 'Phase 5.2 deleted');
|
||||
assert.strictEqual(decimalB.goal, 'ChildBGoal');
|
||||
|
||||
const tail = getPhase(tmpDir, '5');
|
||||
assert.strictEqual(tail.found, true);
|
||||
assert.strictEqual(tail.goal, 'TailGoal', 'Phase 6 → Phase 5 renumber misfired');
|
||||
});
|
||||
});
|
||||
@@ -1,179 +0,0 @@
|
||||
/**
|
||||
* Bug #3602: After `phase remove N`, ROADMAP references to slugged plan
|
||||
* files (`07-01-cherry-pick-foundation-PLAN.md`) keep their old phase
|
||||
* prefix while the on-disk file has already been renamed. The
|
||||
* renumber-references regex in `phase.cjs` only matched compact forms
|
||||
* (`07-01-PLAN.md`, bare `07-01`) — it did not allow a slug between the
|
||||
* plan number and the `-PLAN.md` / `-SUMMARY.md` suffix.
|
||||
*
|
||||
* Fix: extend the lookahead to allow an optional `-<slug>` segment before
|
||||
* the `-(PLAN|SUMMARY).md` suffix while still preserving the "bare token,
|
||||
* not part of a longer number/identifier" alternative.
|
||||
*
|
||||
* Assertions go through the typed `roadmap get-phase --json` query so no
|
||||
* test asserts on raw ROADMAP.md text content.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
process.env.GSD_TEST_MODE = '1';
|
||||
|
||||
const { describe, test, beforeEach, afterEach } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const { runGsdTools, createTempProject, cleanup } = require('./helpers.cjs');
|
||||
|
||||
function writeRoadmap(tmpDir, body) {
|
||||
fs.writeFileSync(path.join(tmpDir, '.planning', 'ROADMAP.md'), body);
|
||||
}
|
||||
function writeState(tmpDir, version) {
|
||||
fs.writeFileSync(
|
||||
path.join(tmpDir, '.planning', 'STATE.md'),
|
||||
`---\nmilestone: ${version}\n---\n`,
|
||||
);
|
||||
}
|
||||
function ensurePhaseDir(tmpDir, name) {
|
||||
fs.mkdirSync(path.join(tmpDir, '.planning', 'phases', name), { recursive: true });
|
||||
}
|
||||
function ensurePlanFile(tmpDir, phaseDirName, planName) {
|
||||
const p = path.join(tmpDir, '.planning', 'phases', phaseDirName, planName);
|
||||
fs.mkdirSync(path.dirname(p), { recursive: true });
|
||||
fs.writeFileSync(p, '# Plan\n');
|
||||
}
|
||||
function getPhase(tmpDir, phaseNum) {
|
||||
const r = runGsdTools(['roadmap', 'get-phase', phaseNum, '--json'], tmpDir);
|
||||
if (!r.success) return { found: false, error: r.error };
|
||||
return JSON.parse(r.output);
|
||||
}
|
||||
|
||||
describe('bug #3602: phase remove renumbers slugged plan references in ROADMAP', () => {
|
||||
let tmpDir;
|
||||
beforeEach(() => {
|
||||
tmpDir = createTempProject('bug-3602-');
|
||||
});
|
||||
afterEach(() => {
|
||||
cleanup(tmpDir);
|
||||
});
|
||||
|
||||
test('slugged PLAN reference (07-01-cherry-pick-foundation-PLAN.md) is renumbered to 06-01-…', () => {
|
||||
writeState(tmpDir, 'v1.0.0');
|
||||
writeRoadmap(
|
||||
tmpDir,
|
||||
[
|
||||
'# Roadmap',
|
||||
'',
|
||||
'## Current Milestone: v1.0.0',
|
||||
'',
|
||||
'### Phase 6: Old Work',
|
||||
'**Goal:** RemoveThisGoal',
|
||||
'',
|
||||
'### Phase 7: New Work',
|
||||
'**Goal:** Plans: 07-01-cherry-pick-foundation-PLAN.md and 07-02-finish-it-SUMMARY.md',
|
||||
'',
|
||||
].join('\n'),
|
||||
);
|
||||
ensurePhaseDir(tmpDir, '06-old');
|
||||
ensurePhaseDir(tmpDir, '07-new');
|
||||
ensurePlanFile(tmpDir, '07-new', '07-01-cherry-pick-foundation-PLAN.md');
|
||||
ensurePlanFile(tmpDir, '07-new', '07-02-finish-it-SUMMARY.md');
|
||||
|
||||
const r = runGsdTools(['phase', 'remove', '6'], tmpDir);
|
||||
assert.ok(r.success, `phase remove failed: ${r.error || r.output}`);
|
||||
|
||||
// Phase 7 → Phase 6 after removal. The renumbered phase's recorded
|
||||
// goal must reference the renumbered plan filenames (06-01-… and
|
||||
// 06-02-…), not the stale 07-01-… / 07-02-… form.
|
||||
const phase6 = getPhase(tmpDir, '6');
|
||||
assert.strictEqual(phase6.found, true);
|
||||
assert.strictEqual(phase6.phase_name, 'New Work');
|
||||
assert.ok(
|
||||
phase6.goal.includes('06-01-cherry-pick-foundation-PLAN.md'),
|
||||
`Plans reference for slugged PLAN was not renumbered. Goal: ${phase6.goal}`,
|
||||
);
|
||||
assert.ok(
|
||||
phase6.goal.includes('06-02-finish-it-SUMMARY.md'),
|
||||
`Plans reference for slugged SUMMARY was not renumbered. Goal: ${phase6.goal}`,
|
||||
);
|
||||
assert.ok(
|
||||
!phase6.goal.includes('07-01'),
|
||||
`stale 07-01 prefix remains in ROADMAP. Goal: ${phase6.goal}`,
|
||||
);
|
||||
assert.ok(
|
||||
!phase6.goal.includes('07-02'),
|
||||
`stale 07-02 prefix remains in ROADMAP. Goal: ${phase6.goal}`,
|
||||
);
|
||||
});
|
||||
|
||||
test('compact PLAN/SUMMARY reference (07-01-PLAN.md) still renumbers (#3601 contract preserved)', () => {
|
||||
writeState(tmpDir, 'v1.0.0');
|
||||
writeRoadmap(
|
||||
tmpDir,
|
||||
[
|
||||
'# Roadmap',
|
||||
'',
|
||||
'## Current Milestone: v1.0.0',
|
||||
'',
|
||||
'### Phase 6: Old',
|
||||
'**Goal:** RemoveGoal',
|
||||
'',
|
||||
'### Phase 7: New',
|
||||
'**Goal:** Plans: 07-01-PLAN.md and 07-02-SUMMARY.md',
|
||||
'',
|
||||
].join('\n'),
|
||||
);
|
||||
ensurePhaseDir(tmpDir, '06-old');
|
||||
ensurePhaseDir(tmpDir, '07-new');
|
||||
ensurePlanFile(tmpDir, '07-new', '07-01-PLAN.md');
|
||||
ensurePlanFile(tmpDir, '07-new', '07-02-SUMMARY.md');
|
||||
|
||||
const r = runGsdTools(['phase', 'remove', '6'], tmpDir);
|
||||
assert.ok(r.success);
|
||||
|
||||
const phase6 = getPhase(tmpDir, '6');
|
||||
assert.strictEqual(phase6.found, true);
|
||||
assert.ok(phase6.goal.includes('06-01-PLAN.md'));
|
||||
assert.ok(phase6.goal.includes('06-02-SUMMARY.md'));
|
||||
assert.ok(!phase6.goal.includes('07-01-PLAN.md'));
|
||||
assert.ok(!phase6.goal.includes('07-02-SUMMARY.md'));
|
||||
});
|
||||
|
||||
test('does NOT renumber values that look like phase-plan tokens but are not (e.g. 2026-01-01 dates)', () => {
|
||||
// Counter-test: an ISO date `2026-01-01` should NOT be matched by the
|
||||
// renumber regex even though it superficially looks like NN-NN-NN.
|
||||
// The negative lookbehind `(?<![0-9-])` and trailing lookahead must
|
||||
// protect against false positives in dates and other digit clusters.
|
||||
writeState(tmpDir, 'v1.0.0');
|
||||
writeRoadmap(
|
||||
tmpDir,
|
||||
[
|
||||
'# Roadmap',
|
||||
'',
|
||||
'## Current Milestone: v1.0.0',
|
||||
'',
|
||||
'### Phase 6: Old',
|
||||
'**Goal:** RemoveGoal',
|
||||
'',
|
||||
'### Phase 7: Date safety',
|
||||
'**Goal:** Created 2026-01-01 and tagged v1-2-3 — must not renumber',
|
||||
'',
|
||||
].join('\n'),
|
||||
);
|
||||
ensurePhaseDir(tmpDir, '06-old');
|
||||
ensurePhaseDir(tmpDir, '07-new');
|
||||
|
||||
const r = runGsdTools(['phase', 'remove', '6'], tmpDir);
|
||||
assert.ok(r.success);
|
||||
|
||||
const phase6 = getPhase(tmpDir, '6');
|
||||
assert.strictEqual(phase6.found, true);
|
||||
assert.ok(
|
||||
phase6.goal.includes('2026-01-01'),
|
||||
`ISO date 2026-01-01 was wrongly modified. Goal: ${phase6.goal}`,
|
||||
);
|
||||
assert.ok(
|
||||
phase6.goal.includes('v1-2-3'),
|
||||
`version-tag v1-2-3 was wrongly modified. Goal: ${phase6.goal}`,
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,173 +0,0 @@
|
||||
/**
|
||||
* Integration tests for auto-prune on phase completion (#2087).
|
||||
*
|
||||
* When config `workflow.auto_prune_state` is true, `phase complete`
|
||||
* should automatically prune STATE.md as part of the phase transition.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const { test, describe, beforeEach, afterEach } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const { runGsdTools, createTempProject, cleanup } = require('./helpers.cjs');
|
||||
|
||||
function writeConfig(tmpDir, config) {
|
||||
fs.writeFileSync(path.join(tmpDir, '.planning', 'config.json'), JSON.stringify(config, null, 2));
|
||||
}
|
||||
|
||||
function writeStateMd(tmpDir, content) {
|
||||
fs.writeFileSync(path.join(tmpDir, '.planning', 'STATE.md'), content);
|
||||
}
|
||||
|
||||
function readStateMd(tmpDir) {
|
||||
return fs.readFileSync(path.join(tmpDir, '.planning', 'STATE.md'), 'utf-8');
|
||||
}
|
||||
|
||||
function writeRoadmap(tmpDir, content) {
|
||||
fs.writeFileSync(path.join(tmpDir, '.planning', 'ROADMAP.md'), content);
|
||||
}
|
||||
|
||||
function setupPhase(tmpDir, phaseNum, planCount) {
|
||||
const phasesDir = path.join(tmpDir, '.planning', 'phases');
|
||||
const phaseDir = path.join(phasesDir, `${String(phaseNum).padStart(2, '0')}-test-phase`);
|
||||
fs.mkdirSync(phaseDir, { recursive: true });
|
||||
|
||||
for (let i = 1; i <= planCount; i++) {
|
||||
const planId = `${String(phaseNum).padStart(2, '0')}-${String(i).padStart(2, '0')}`;
|
||||
fs.writeFileSync(path.join(phaseDir, `${planId}-PLAN.md`), `# Plan ${planId}\n`);
|
||||
fs.writeFileSync(path.join(phaseDir, `${planId}-SUMMARY.md`), `# Summary ${planId}\n`);
|
||||
}
|
||||
}
|
||||
|
||||
describe('phase complete auto-prune (#2087)', () => {
|
||||
let tmpDir;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = createTempProject();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanup(tmpDir);
|
||||
});
|
||||
|
||||
test('prunes STATE.md automatically when auto_prune_state is true', () => {
|
||||
writeConfig(tmpDir, {
|
||||
workflow: { auto_prune_state: true },
|
||||
});
|
||||
|
||||
writeStateMd(tmpDir, [
|
||||
'# Session State',
|
||||
'',
|
||||
'**Current Phase:** 6',
|
||||
'**Status:** Executing',
|
||||
'',
|
||||
'## Decisions',
|
||||
'',
|
||||
'- [Phase 1]: Old decision from phase 1',
|
||||
'- [Phase 2]: Old decision from phase 2',
|
||||
'- [Phase 5]: Recent decision',
|
||||
'- [Phase 6]: Current decision',
|
||||
'',
|
||||
].join('\n'));
|
||||
|
||||
writeRoadmap(tmpDir, [
|
||||
'# Roadmap',
|
||||
'',
|
||||
'## Phase 6: Test Phase',
|
||||
'',
|
||||
'**Plans:** 0/2',
|
||||
'',
|
||||
].join('\n'));
|
||||
|
||||
setupPhase(tmpDir, 6, 2);
|
||||
|
||||
const result = runGsdTools('phase complete 6', tmpDir);
|
||||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||||
|
||||
const newState = readStateMd(tmpDir);
|
||||
// With keep-recent=3 (default), cutoff = 6-3 = 3
|
||||
// Phase 1 and 2 decisions should be pruned
|
||||
assert.doesNotMatch(newState, /\[Phase 1\]: Old decision/);
|
||||
assert.doesNotMatch(newState, /\[Phase 2\]: Old decision/);
|
||||
// Phase 5 and 6 should remain
|
||||
assert.match(newState, /\[Phase 5\]: Recent decision/);
|
||||
assert.match(newState, /\[Phase 6\]: Current decision/);
|
||||
});
|
||||
|
||||
test('does NOT prune when auto_prune_state is false (default)', () => {
|
||||
writeConfig(tmpDir, {
|
||||
workflow: { auto_prune_state: false },
|
||||
});
|
||||
|
||||
writeStateMd(tmpDir, [
|
||||
'# Session State',
|
||||
'',
|
||||
'**Current Phase:** 6',
|
||||
'**Status:** Executing',
|
||||
'',
|
||||
'## Decisions',
|
||||
'',
|
||||
'- [Phase 1]: Old decision from phase 1',
|
||||
'- [Phase 5]: Recent decision',
|
||||
'- [Phase 6]: Current decision',
|
||||
'',
|
||||
].join('\n'));
|
||||
|
||||
writeRoadmap(tmpDir, [
|
||||
'# Roadmap',
|
||||
'',
|
||||
'## Phase 6: Test Phase',
|
||||
'',
|
||||
'**Plans:** 0/2',
|
||||
'',
|
||||
].join('\n'));
|
||||
|
||||
setupPhase(tmpDir, 6, 2);
|
||||
|
||||
const result = runGsdTools('phase complete 6', tmpDir);
|
||||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||||
|
||||
const newState = readStateMd(tmpDir);
|
||||
// Phase 1 decision should still be present (no pruning)
|
||||
assert.match(newState, /\[Phase 1\]: Old decision/);
|
||||
});
|
||||
|
||||
test('does NOT prune when auto_prune_state is absent from config', () => {
|
||||
writeConfig(tmpDir, {
|
||||
workflow: {},
|
||||
});
|
||||
|
||||
writeStateMd(tmpDir, [
|
||||
'# Session State',
|
||||
'',
|
||||
'**Current Phase:** 6',
|
||||
'**Status:** Executing',
|
||||
'',
|
||||
'## Decisions',
|
||||
'',
|
||||
'- [Phase 1]: Old decision from phase 1',
|
||||
'- [Phase 6]: Current decision',
|
||||
'',
|
||||
].join('\n'));
|
||||
|
||||
writeRoadmap(tmpDir, [
|
||||
'# Roadmap',
|
||||
'',
|
||||
'## Phase 6: Test Phase',
|
||||
'',
|
||||
'**Plans:** 0/2',
|
||||
'',
|
||||
].join('\n'));
|
||||
|
||||
setupPhase(tmpDir, 6, 2);
|
||||
|
||||
const result = runGsdTools('phase complete 6', tmpDir);
|
||||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||||
|
||||
const newState = readStateMd(tmpDir);
|
||||
// Should not prune — absent means disabled (default: false)
|
||||
assert.match(newState, /\[Phase 1\]: Old decision/);
|
||||
});
|
||||
});
|
||||
1595
tests/phase.test.cjs
1595
tests/phase.test.cjs
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user