Migrate cmdStateSync, cmdStatePrune, cmdStateUpdate (state.cts) onto the STATE.md Transition Module substrate and close the maintenance bug pair #1760/#1761 (ADR-1769, epic #1769). Completes the substrate: all 10 lifecycle/maintenance transitions now route through transitionCore. - Add {kind: 'sync'|'prune'|'update'} to StateTransitionIntent with syncCore, pruneCore, updateCore in src/state-transition.cts. - updateCore: body-only single-field update (strip/reassemble), mirroring the pre-migration cmdStateUpdate contract. - pruneCore: pure content→content section pruning (Decisions / Recently Completed / resolved Blockers / Performance Metrics rows at or below cutoff), byte-identical tokenizeHeadings splicing. Adapter owns currentPhase, dry-run, and STATE-ARCHIVE.md. - syncCore: body writes (Total Plans in Phase, Progress bar, Last Activity) given disk-derived numbers. Adapter owns the disk scan + roadmap scope. - #1760: cmdStatePrune now derives currentPhase from 'Current Phase' OR 'Phase' (the canonical template emits 'Phase: X of Y'), so prune engages on template-conformant STATE.md instead of bailing 'Only 0 phases'. - #1761: cmdStateSync skips the Progress write (percent=null) when a milestone version is set in frontmatter but the ROADMAP has no versioned heading for it (milestone cannot be bounded). Projects without a milestone version are unaffected. Leaves progress untouched rather than silently writing fallback- derived wrong values. - Regression: bug-1760 (prune engages on template field) + bug-1761 (sync leaves progress untouched when unbounded). ADR-1769 marked Accepted. All 82 transition + 515 regression tests pass. Closes #1793
81 lines
3.0 KiB
JavaScript
81 lines
3.0 KiB
JavaScript
'use strict';
|
|
// Regression test for issue #1760 — `state prune` no-ops on template-conformant
|
|
// STATE.md because it reads `Current Phase` only, never the `Phase: X of Y` line
|
|
// the canonical template emits.
|
|
//
|
|
// ADR-1769 Phase 7 fix: derive the current phase with a `Phase` / `Current Phase`
|
|
// fallback (mirroring buildStateFrontmatter), so prune engages on template STATE.md.
|
|
|
|
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 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');
|
|
}
|
|
|
|
describe('#1760: state prune engages on template-conformant STATE.md (Phase: X of Y)', () => {
|
|
let tmpDir;
|
|
beforeEach(() => { tmpDir = createTempProject(); });
|
|
afterEach(() => { cleanup(tmpDir); });
|
|
|
|
test('prune engages when STATE.md uses "Phase: N of M" (no Current Phase field)', () => {
|
|
// Template-conformant STATE.md: Current Position uses `Phase: 10 of 15`, and
|
|
// there is NO `**Current Phase:**` body field. Pre-fix this made prune bail
|
|
// with "Only 0 phases — nothing to prune".
|
|
writeStateMd(tmpDir, [
|
|
'# Session State',
|
|
'',
|
|
'## Current Position',
|
|
'',
|
|
'Phase: 10 of 15',
|
|
'Plan: 2 of 4',
|
|
'Status: Executing Phase 10',
|
|
'',
|
|
'## Decisions',
|
|
'',
|
|
'- [Phase 1]: Old decision',
|
|
'- [Phase 3]: Older decision',
|
|
'- [Phase 9]: Recent decision',
|
|
'',
|
|
].join('\n'));
|
|
|
|
const result = runGsdTools('state prune --keep-recent 3 --dry-run', tmpDir);
|
|
assert.ok(result.success, `Command failed: ${result.error}`);
|
|
const out = JSON.parse(result.output);
|
|
|
|
// Pre-fix: { pruned: false, reason: 'Only 0 phases — nothing to prune...' }.
|
|
// Post-fix: prune engages and reports a real cutoff_phase (10 - 3 = 7).
|
|
assert.strictEqual(out.pruned, false, 'dry-run must report pruned:false');
|
|
assert.ok(out.reason === undefined || !/Only 0 phases/i.test(String(out.reason)),
|
|
`prune must not bail with "Only 0 phases" on template STATE.md; got reason=${JSON.stringify(out.reason)}`);
|
|
assert.strictEqual(out.cutoff_phase, 7,
|
|
`cutoff_phase must be 7 (current 10 - keep-recent 3); got ${JSON.stringify(out.cutoff_phase)}`);
|
|
});
|
|
|
|
test('prune still engages when "Current Phase:" IS present (no regression)', () => {
|
|
writeStateMd(tmpDir, [
|
|
'# Session State',
|
|
'',
|
|
'**Current Phase:** 10',
|
|
'',
|
|
'## Decisions',
|
|
'',
|
|
'- [Phase 1]: Old decision',
|
|
'- [Phase 9]: Recent decision',
|
|
'',
|
|
].join('\n'));
|
|
|
|
const result = runGsdTools('state prune --keep-recent 3 --dry-run', tmpDir);
|
|
assert.ok(result.success, `Command failed: ${result.error}`);
|
|
const out = JSON.parse(result.output);
|
|
assert.strictEqual(out.cutoff_phase, 7);
|
|
});
|
|
});
|