Files
msd-core/tests/milestone-helper.test.cjs
Tom Boucher 0a12b06381 feat(#39): milestone-prefixed phase IDs (M-NN convention) + migration tool + validation (#565)
* feat(#39): milestone-prefixed phase IDs (M-NN convention) + migration tool + validation

- Add getMilestoneFromPhaseId() / getPhaseDirFromPhaseId() helpers to core.cjs
- Fix isDirInMilestone to match M-NN-style dirs (02-01-setup) against M-NN ROADMAP headings
- Extend heading regex to tolerate [bracket-token] scope prefix on phase headings
- Add W021 validation rule for milestone prefix mismatch
- Add gsd-tools roadmap validate + roadmap upgrade --convention milestone-prefixed
- Add phase_id_convention config field (null default, backwards-compatible)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(#39): address 4 Codex review findings in milestone-prefixed phase ID implementation

- getMilestoneFromPhaseId: tighten regex to require a digit after the hyphen (rejects '1-' and '1-abc')
- isDirInMilestone: use convention-aware regex — only capture M-NN segments when ROADMAP itself uses hyphenated phase IDs, preventing legacy dirs like '01-02-setup' from being misread as phase '1-02'
- checkW021: add UNPREFIXED_PHASE_RE path so unprefixed headings (### Phase 1:) also fire W021 when convention is milestone-prefixed
- roadmap-upgrade: remove isMigratedDirName dir-name check (false-positive for legacy dirs); config + ROADMAP heading checks at lines 194 and 212 are sufficient

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* chore: update changeset pr reference to #565

* fix(#39): restore phaseDirNameRe 2-digit minimum; add roadmap-upgrade to inventory

- validate.cjs: \d{1,} → \d{2,} to keep single-digit prefix rejection per W005 contract
- docs/INVENTORY.md: 79 → 80, add roadmap-upgrade.cjs row
- docs/INVENTORY-MANIFEST.json: regenerated (roadmap-upgrade.cjs entry)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 23:15:55 -04:00

91 lines
2.9 KiB
JavaScript

// Tests for getMilestoneFromPhaseId and getPhaseDirFromPhaseId helpers (issue #39).
'use strict';
const { describe, test } = require('node:test');
const assert = require('node:assert/strict');
const {
getMilestoneFromPhaseId,
getPhaseDirFromPhaseId,
} = require('../get-shit-done/bin/lib/core.cjs');
// ─── getMilestoneFromPhaseId ────────────────────────────────────────────────
describe('getMilestoneFromPhaseId', () => {
test('maps milestone integer 1 to v1.0', () => {
assert.strictEqual(getMilestoneFromPhaseId('1-01'), 'v1.0');
});
test('uses only the top-level integer: 2-4-1 → v2.0', () => {
assert.strictEqual(getMilestoneFromPhaseId('2-4-1'), 'v2.0');
});
test('handles double-digit milestone: 10-01 → v10.0', () => {
assert.strictEqual(getMilestoneFromPhaseId('10-01'), 'v10.0');
});
test('returns null for sentinel 999 (backlog)', () => {
assert.strictEqual(getMilestoneFromPhaseId('999-1'), null);
});
test('returns null for sentinel 0 (pre-milestone spike)', () => {
assert.strictEqual(getMilestoneFromPhaseId('0-1'), null);
});
test('returns null when there is no hyphen separator', () => {
assert.strictEqual(getMilestoneFromPhaseId('1'), null);
});
test('strips project_code prefix: CK-2-01 → v2.0', () => {
assert.strictEqual(getMilestoneFromPhaseId('CK-2-01'), 'v2.0');
});
test('strips longer project_code prefix: GSD-10-01 → v10.0', () => {
assert.strictEqual(getMilestoneFromPhaseId('GSD-10-01'), 'v10.0');
});
test('returns null for fully non-numeric input', () => {
assert.strictEqual(getMilestoneFromPhaseId('invalid'), null);
});
});
// ─── getPhaseDirFromPhaseId ─────────────────────────────────────────────────
describe('getPhaseDirFromPhaseId', () => {
test('produces zero-padded dir with project code', () => {
assert.strictEqual(
getPhaseDirFromPhaseId('2-01', 'Setup Database', 'GSD'),
'GSD-02-01-setup-database',
);
});
test('omits project code when not provided', () => {
assert.strictEqual(
getPhaseDirFromPhaseId('2-01', 'Setup Database'),
'02-01-setup-database',
);
});
test('handles double-digit milestone with project code', () => {
assert.strictEqual(
getPhaseDirFromPhaseId('10-01', 'Build Feature', 'CK'),
'CK-10-01-build-feature',
);
});
test('produces zero-padded dir without project code: 1-01 → 01-01-setup', () => {
assert.strictEqual(
getPhaseDirFromPhaseId('1-01', 'Setup'),
'01-01-setup',
);
});
test('returns null for phase IDs without the M-NN hyphen form', () => {
assert.strictEqual(
getPhaseDirFromPhaseId('nohyphen', 'Some Title', 'GSD'),
null,
);
});
});