* fix(#1580): exclude 0/999 sentinels from milestone-complete guard and roadmap analyze Closed #1445 added the `^999` backlog-sentinel exclusion to the progress denominators but missed two other resolvers, leaving two user-facing failures live on a milestone whose only directory-less ROADMAP heading is a backlog sentinel: (A) `milestone complete` was blocked by the unstarted-phase guard in src/milestone.cts — it flagged `### Phase 999: Backlog` as an unstarted phase and refused to close a fully-shipped milestone without --force. (B) `roadmap analyze` (src/roadmap.cts) counted the sentinel in phase_count and routed `next_phase` straight into Phase 999. Both now skip Phase 0 (pre-milestone) and Phase 999 (backlog) sentinels, mirroring the engine-wide convention (phase-id getMilestoneFromPhaseId, roadmap-command-router SENTINELS, the #1445 progress filters). Symptom (C) (state.cts total_phases) was already fixed inline by #1445/#1514 and is out of scope here. Regression coverage folded into tests/fix-1445-*.test.cjs (scenarios C and D); updated tests/bug-978 fixture to use a real unstarted phase (Phase 2) instead of a 999 sentinel, since the sentinel is now correctly excluded from that guard. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * chore(#1580): add changeset for 0/999 sentinel exclusion fix Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
93 lines
3.3 KiB
JavaScript
93 lines
3.3 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Regression test for bug #978: `gsd-tools milestone complete --force` was a
|
|
* dead flag. The milestone source (src/milestone.cts) has a guard that checks
|
|
* `options.force` and tells users to "Re-run with --force to override", but the
|
|
* CLI dispatcher (gsd-core/bin/gsd-tools.cjs) never parsed `--force` and never
|
|
* passed it into the options object. So `options.force` was always `undefined`
|
|
* and the guard could never be overridden regardless of what the user typed.
|
|
*/
|
|
|
|
const { test, describe, 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');
|
|
|
|
/**
|
|
* Build a fixture where the guard will fire:
|
|
* - STATE.md has `milestone: <version>` so the guard's version-match check is
|
|
* satisfied.
|
|
* - ROADMAP.md lists a `### Phase 2: Real Work` heading for that milestone, but
|
|
* there is NO on-disk phase directory for it.
|
|
*
|
|
* This guarantees "unstarted phase" detection without touching any real phases.
|
|
* NOTE: the unstarted phase must be a REAL phase number — Phase 0 and Phase 999
|
|
* are backlog/pre-milestone sentinels that are intentionally excluded from this
|
|
* guard (#1580), so they would not fire it.
|
|
*/
|
|
function makeGuardFixture(tmpDir, version) {
|
|
// STATE.md with frontmatter milestone field matching the version
|
|
fs.writeFileSync(
|
|
path.join(tmpDir, '.planning', 'STATE.md'),
|
|
`---\nmilestone: ${version}\n---\n# State\n\n**Status:** In progress\n**Last Activity:** 2025-01-01\n**Last Activity Description:** Working\n`,
|
|
);
|
|
|
|
// ROADMAP.md — the heading must include the version so getMilestonePhaseFilter
|
|
// does not return missingExplicitVersion. Phase 2 has no on-disk dir.
|
|
fs.writeFileSync(
|
|
path.join(tmpDir, '.planning', 'ROADMAP.md'),
|
|
`# Roadmap ${version}\n\n### Phase 2: Real Work\n**Goal:** Not started\n`,
|
|
);
|
|
}
|
|
|
|
describe('bug-978: milestone complete --force overrides unstarted-phase guard', () => {
|
|
let tmpDir;
|
|
|
|
beforeEach(() => {
|
|
tmpDir = createTempProject('gsd-bug-978-');
|
|
});
|
|
|
|
afterEach(() => {
|
|
cleanup(tmpDir);
|
|
});
|
|
|
|
test('without --force the guard fires and emits the documented error message', () => {
|
|
makeGuardFixture(tmpDir, 'v1.0');
|
|
|
|
const result = runGsdTools(
|
|
['milestone', 'complete', 'v1.0', '--name', 'Regression Test'],
|
|
tmpDir,
|
|
);
|
|
|
|
assert.strictEqual(result.success, false, 'command should fail without --force');
|
|
assert.ok(
|
|
result.error.includes('Re-run with --force to override'),
|
|
`expected guard error message; got: ${result.error}`,
|
|
);
|
|
});
|
|
|
|
test('with --force the guard is bypassed and the command succeeds', () => {
|
|
makeGuardFixture(tmpDir, 'v1.0');
|
|
|
|
const result = runGsdTools(
|
|
['milestone', 'complete', 'v1.0', '--name', 'Regression Test', '--force'],
|
|
tmpDir,
|
|
);
|
|
|
|
assert.ok(
|
|
result.success,
|
|
`command should succeed with --force but failed: ${result.error}`,
|
|
);
|
|
|
|
const output = JSON.parse(result.output);
|
|
assert.strictEqual(output.version, 'v1.0');
|
|
// Milestone entry should have been created even though phase 2 has no dir
|
|
assert.ok(
|
|
fs.existsSync(path.join(tmpDir, '.planning', 'MILESTONES.md')),
|
|
'MILESTONES.md should have been created',
|
|
);
|
|
});
|
|
});
|