refactor: split gsd-tools.test.cjs into domain test files
Move 81 tests (18 describe blocks) from single monolithic test file into 7 domain-specific test files under tests/ with shared helpers. Test parity verified: 81/81 pass before and after split. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
156
tests/state.test.cjs
Normal file
156
tests/state.test.cjs
Normal file
@@ -0,0 +1,156 @@
|
||||
/**
|
||||
* GSD Tools Tests - State
|
||||
*/
|
||||
|
||||
const { test, describe, beforeEach, afterEach } = require('node:test');
|
||||
const assert = require('node:assert');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { runGsdTools, createTempProject, cleanup } = require('./helpers.cjs');
|
||||
|
||||
describe('state-snapshot command', () => {
|
||||
let tmpDir;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = createTempProject();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanup(tmpDir);
|
||||
});
|
||||
|
||||
test('missing STATE.md returns error', () => {
|
||||
const result = runGsdTools('state-snapshot', tmpDir);
|
||||
assert.ok(result.success, `Command should succeed: ${result.error}`);
|
||||
|
||||
const output = JSON.parse(result.output);
|
||||
assert.strictEqual(output.error, 'STATE.md not found', 'should report missing file');
|
||||
});
|
||||
|
||||
test('extracts basic fields from STATE.md', () => {
|
||||
fs.writeFileSync(
|
||||
path.join(tmpDir, '.planning', 'STATE.md'),
|
||||
`# Project State
|
||||
|
||||
**Current Phase:** 03
|
||||
**Current Phase Name:** API Layer
|
||||
**Total Phases:** 6
|
||||
**Current Plan:** 03-02
|
||||
**Total Plans in Phase:** 3
|
||||
**Status:** In progress
|
||||
**Progress:** 45%
|
||||
**Last Activity:** 2024-01-15
|
||||
**Last Activity Description:** Completed 03-01-PLAN.md
|
||||
`
|
||||
);
|
||||
|
||||
const result = runGsdTools('state-snapshot', tmpDir);
|
||||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||||
|
||||
const output = JSON.parse(result.output);
|
||||
assert.strictEqual(output.current_phase, '03', 'current phase extracted');
|
||||
assert.strictEqual(output.current_phase_name, 'API Layer', 'phase name extracted');
|
||||
assert.strictEqual(output.total_phases, 6, 'total phases extracted');
|
||||
assert.strictEqual(output.current_plan, '03-02', 'current plan extracted');
|
||||
assert.strictEqual(output.total_plans_in_phase, 3, 'total plans extracted');
|
||||
assert.strictEqual(output.status, 'In progress', 'status extracted');
|
||||
assert.strictEqual(output.progress_percent, 45, 'progress extracted');
|
||||
assert.strictEqual(output.last_activity, '2024-01-15', 'last activity date extracted');
|
||||
});
|
||||
|
||||
test('extracts decisions table', () => {
|
||||
fs.writeFileSync(
|
||||
path.join(tmpDir, '.planning', 'STATE.md'),
|
||||
`# Project State
|
||||
|
||||
**Current Phase:** 01
|
||||
|
||||
## Decisions Made
|
||||
|
||||
| Phase | Decision | Rationale |
|
||||
|-------|----------|-----------|
|
||||
| 01 | Use Prisma | Better DX than raw SQL |
|
||||
| 02 | JWT auth | Stateless authentication |
|
||||
`
|
||||
);
|
||||
|
||||
const result = runGsdTools('state-snapshot', tmpDir);
|
||||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||||
|
||||
const output = JSON.parse(result.output);
|
||||
assert.strictEqual(output.decisions.length, 2, 'should have 2 decisions');
|
||||
assert.strictEqual(output.decisions[0].phase, '01', 'first decision phase');
|
||||
assert.strictEqual(output.decisions[0].summary, 'Use Prisma', 'first decision summary');
|
||||
assert.strictEqual(output.decisions[0].rationale, 'Better DX than raw SQL', 'first decision rationale');
|
||||
});
|
||||
|
||||
test('extracts blockers list', () => {
|
||||
fs.writeFileSync(
|
||||
path.join(tmpDir, '.planning', 'STATE.md'),
|
||||
`# Project State
|
||||
|
||||
**Current Phase:** 03
|
||||
|
||||
## Blockers
|
||||
|
||||
- Waiting for API credentials
|
||||
- Need design review for dashboard
|
||||
`
|
||||
);
|
||||
|
||||
const result = runGsdTools('state-snapshot', tmpDir);
|
||||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||||
|
||||
const output = JSON.parse(result.output);
|
||||
assert.deepStrictEqual(output.blockers, [
|
||||
'Waiting for API credentials',
|
||||
'Need design review for dashboard',
|
||||
], 'blockers extracted');
|
||||
});
|
||||
|
||||
test('extracts session continuity info', () => {
|
||||
fs.writeFileSync(
|
||||
path.join(tmpDir, '.planning', 'STATE.md'),
|
||||
`# Project State
|
||||
|
||||
**Current Phase:** 03
|
||||
|
||||
## Session
|
||||
|
||||
**Last Date:** 2024-01-15
|
||||
**Stopped At:** Phase 3, Plan 2, Task 1
|
||||
**Resume File:** .planning/phases/03-api/03-02-PLAN.md
|
||||
`
|
||||
);
|
||||
|
||||
const result = runGsdTools('state-snapshot', tmpDir);
|
||||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||||
|
||||
const output = JSON.parse(result.output);
|
||||
assert.strictEqual(output.session.last_date, '2024-01-15', 'session date extracted');
|
||||
assert.strictEqual(output.session.stopped_at, 'Phase 3, Plan 2, Task 1', 'stopped at extracted');
|
||||
assert.strictEqual(output.session.resume_file, '.planning/phases/03-api/03-02-PLAN.md', 'resume file extracted');
|
||||
});
|
||||
|
||||
test('handles paused_at field', () => {
|
||||
fs.writeFileSync(
|
||||
path.join(tmpDir, '.planning', 'STATE.md'),
|
||||
`# Project State
|
||||
|
||||
**Current Phase:** 03
|
||||
**Paused At:** Phase 3, Plan 1, Task 2 - mid-implementation
|
||||
`
|
||||
);
|
||||
|
||||
const result = runGsdTools('state-snapshot', tmpDir);
|
||||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||||
|
||||
const output = JSON.parse(result.output);
|
||||
assert.strictEqual(output.paused_at, 'Phase 3, Plan 1, Task 2 - mid-implementation', 'paused_at extracted');
|
||||
});
|
||||
});
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// summary-extract command
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user