test(#1971): consolidate 48 gsd-tools CLI regression tests into subcommand suites
Fold 48 issue-named gsd-tools CLI regression files into the canonical test file that owns each subcommand subject (state, roadmap, phase, milestone, audit, config, router/dispatch, stats, verify, health, etc.), preserving every assertion and its origin issue number as provenance (block-scoped describe wrappers, 299 subtests conserved 1:1). No monolithic gsd-tools.test.cjs created — routes into 18 existing per-subject suites. Removes 48 tests/ files. Regenerates regression-name allowlist (271->231), ratchets the file-count allowlist across 6 buckets (audit/milestone/phase/roadmap/state/verify), and makes 10 relocated allow-test-rule exemptions issue-ref-compliant (ADR-456; prunes 10 stale ids). Repoints one CONTEXT.md symptom ref and ADR-3524's parity-test ref. lint:ci green. Part of epic #1969. Closes #1971. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -421,3 +421,138 @@ describe('phase-command-router — integration: real hub + CJS phase handler', (
|
||||
assert.deepEqual(calls[0].descriptions, ['Alpha', 'Beta']);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// ────────────────────────────────────────────────────────────────────────
|
||||
// Folded from tests/fix-1437-phase-list-plans.test.cjs — consolidation epic #1969 (B2 #1971)
|
||||
// ────────────────────────────────────────────────────────────────────────
|
||||
{
|
||||
const { describe: __foldDescribe } = require('node:test');
|
||||
__foldDescribe("folded:fix-1437-phase-list-plans (consolidation epic #1969 B2 #1971)", () => {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Regression tests for `gsd-tools query phase.list-plans <N>` (#1437).
|
||||
*
|
||||
* Prior to this fix, `phase.list-plans` was not registered in the
|
||||
* phase-command-router, so any invocation produced:
|
||||
* "Error: Unknown phase subcommand. Available: uat-passed, next-decimal, ..."
|
||||
*
|
||||
* These tests exercise the full dispatch path:
|
||||
* gsd-tools → phase-command-router → phase.cmdPhaseListPlans
|
||||
*/
|
||||
|
||||
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');
|
||||
|
||||
// ─── Fixture helpers ──────────────────────────────────────────────────────────
|
||||
|
||||
function setupProject(phaseSlug = '01-feature') {
|
||||
const tmpDir = createTempProject();
|
||||
// Minimal ROADMAP so findPhaseInternal can resolve the phase directory
|
||||
fs.writeFileSync(
|
||||
path.join(tmpDir, '.planning', 'ROADMAP.md'),
|
||||
[
|
||||
'# Roadmap',
|
||||
'',
|
||||
'- [ ] Phase 1: Feature',
|
||||
'',
|
||||
'### Phase 1: Feature',
|
||||
'**Goal:** Build feature',
|
||||
'**Plans:** 1 plans',
|
||||
'',
|
||||
].join('\n'),
|
||||
);
|
||||
const phaseDir = path.join(tmpDir, '.planning', 'phases', phaseSlug);
|
||||
fs.mkdirSync(phaseDir, { recursive: true });
|
||||
return { tmpDir, phaseDir };
|
||||
}
|
||||
|
||||
function touch(dir, ...files) {
|
||||
for (const f of files) {
|
||||
fs.writeFileSync(path.join(dir, f), '');
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Tests ────────────────────────────────────────────────────────────────────
|
||||
|
||||
let tmpDir;
|
||||
let phaseDir;
|
||||
|
||||
beforeEach(() => {
|
||||
const proj = setupProject('01-feature');
|
||||
tmpDir = proj.tmpDir;
|
||||
phaseDir = proj.phaseDir;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanup(tmpDir);
|
||||
});
|
||||
|
||||
describe('bug-1437 — phase.list-plans is wired in gsd-tools', () => {
|
||||
test('command no longer returns Unknown phase subcommand error', () => {
|
||||
touch(phaseDir, '01-01-PLAN.md');
|
||||
const result = runGsdTools(['query', 'phase.list-plans', '1'], tmpDir);
|
||||
// Previously this would fail with "Unknown phase subcommand"
|
||||
assert.ok(result.success, `Command failed: ${result.error}\nOutput: ${result.output}`);
|
||||
assert.ok(!result.error || !result.error.includes('Unknown phase subcommand'),
|
||||
`got unexpected error: ${result.error}`);
|
||||
});
|
||||
|
||||
test('returns JSON with plan_count and plans array when plans exist', () => {
|
||||
touch(phaseDir, '01-01-PLAN.md', '01-02-PLAN.md');
|
||||
const result = runGsdTools(['query', 'phase.list-plans', '1', '--raw'], tmpDir);
|
||||
assert.ok(result.success, `Command failed: ${result.error}\nOutput: ${result.output}`);
|
||||
const data = JSON.parse(result.output);
|
||||
assert.equal(data.plan_count, 2, 'plan_count should be 2');
|
||||
assert.equal(data.has_plans, true, 'has_plans should be true');
|
||||
assert.ok(Array.isArray(data.plans), 'plans should be an array');
|
||||
assert.equal(data.plans.length, 2, 'plans array should have 2 entries');
|
||||
});
|
||||
|
||||
test('returns plan_count 0 and empty plans array when phase has no plan files', () => {
|
||||
// Phase directory exists but has no *-PLAN.md files
|
||||
touch(phaseDir, 'CONTEXT.md');
|
||||
const result = runGsdTools(['query', 'phase.list-plans', '1', '--raw'], tmpDir);
|
||||
assert.ok(result.success, `Command failed: ${result.error}\nOutput: ${result.output}`);
|
||||
const data = JSON.parse(result.output);
|
||||
assert.equal(data.plan_count, 0);
|
||||
assert.equal(data.has_plans, false);
|
||||
assert.deepEqual(data.plans, []);
|
||||
});
|
||||
|
||||
test('returns has_plans false when phase number is not found', () => {
|
||||
// Phase 99 does not exist in the fixture
|
||||
const result = runGsdTools(['query', 'phase.list-plans', '99', '--raw'], tmpDir);
|
||||
assert.ok(result.success, `Command failed: ${result.error}\nOutput: ${result.output}`);
|
||||
const data = JSON.parse(result.output);
|
||||
assert.equal(data.has_plans, false);
|
||||
assert.equal(data.plan_count, 0);
|
||||
});
|
||||
|
||||
test('plan paths are relative to project root and posix-style', () => {
|
||||
touch(phaseDir, '01-01-PLAN.md');
|
||||
const result = runGsdTools(['query', 'phase.list-plans', '1', '--raw'], tmpDir);
|
||||
assert.ok(result.success, `Command failed: ${result.error}\nOutput: ${result.output}`);
|
||||
const data = JSON.parse(result.output);
|
||||
assert.equal(data.plans.length, 1);
|
||||
// Paths must be forward-slash separated (posix) and relative (not absolute)
|
||||
const planPath = data.plans[0];
|
||||
assert.ok(!path.isAbsolute(planPath), `expected relative path, got: ${planPath}`);
|
||||
assert.ok(!planPath.includes('\\'), `expected posix path, got: ${planPath}`);
|
||||
assert.ok(planPath.includes('01-01-PLAN.md'), `expected plan filename in path: ${planPath}`);
|
||||
});
|
||||
|
||||
test('dotted form phase.list-plans (without query prefix) also works', () => {
|
||||
touch(phaseDir, '01-01-PLAN.md');
|
||||
const result = runGsdTools(['phase.list-plans', '1', '--raw'], tmpDir);
|
||||
assert.ok(result.success, `Command failed: ${result.error}\nOutput: ${result.output}`);
|
||||
const data = JSON.parse(result.output);
|
||||
assert.equal(data.plan_count, 1);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user