* test(#3185): failing-first phase-enumeration single-owner suite Covers the enumeration rows with direct code evidence: 999.* backlog dirs listed by progress/stats, the phase-0 sentinel divergence, the #1324 letter-prefixed-decimal negative space, and the destructive-path find — cmdPhasesClear carries a fifth sentinel copy (/^999(?:\.|$)/) that excludes 999 but not 0, so a 0-* directory roadmap.analyze preserves is deleted there. Also covers the pass-all degrade, which is where the defect actually lives: when the milestone window declares no phases the filter becomes a literal () => true and its heading-side sentinel exclusion is unreachable. A fixture carrying phase headings keeps the filter active and never reaches that path. Named for the derivation, not a module: the suite drives commands, phase, milestone, workstream-inventory and state, and both the phase and phase-locator buckets are already at the per-module test-file cap. Committed alone so the remote runner records the failure before the fix. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QELmgcSwcNBgbUs3kzJeqG * refactor(#3185): phase enumeration has one owner and a decidable scope Adds phase-locator.cts::listMilestonePhaseDirs as the single canonical owner of "which phase directories belong to the current milestone". It applies the milestone window AND the sentinel filter and returns a ScopedResult, so a caller can tell a genuinely-empty milestone from an enumeration that could not be scoped. The sentinel test now runs against DIRECTORY NAMES and is unconditional. getMilestonePhaseFilter excludes sentinels from its ROADMAP heading set, but degrades to a literal () => true pass-all predicate when that set is empty -- at which point the heading set is never consulted and its sentinel exclusion is unreachable exactly when it is needed. That degrade is the #3167 path, and it is why stats already used the filter and still listed backlog directories. The narrowing is sentinel-only: pass-all stays over-inclusive otherwise. Sentinel copies deleted, canonical isSentinelPhaseId adopted: - cmdRoadmapAnalyze's local closure (parseInt === 0 || === 999), 2 call sites - cmdPhasesClear's /^999(?:\.|$)/ -- the DESTRUCTIVE path, which excluded 999 but not 0, so a 0-* directory roadmap.analyze preserves was deleted cmdStats also seeded rows from ROADMAP headings with no sentinel filter, so a 999 heading produced a row with no directory; that seed is filtered now. cmdPhasesList routes only its ENUMERATION. --phase lookup searches the physical set (scoping it would report an out-of-window phase as not found) and --include-archived still merges archived dirs (they are by definition from other milestones). Both exempt by documented reason, never a file allowlist. Fixed inline, found while building: isDirInMilestone could not match a #1324 letter-prefixed-decimal directory (P0.0-foundation) to its own Phase P0.0 heading, so stats reported the phase with plans: 0 while its directory held plan files. Defers to phase-id's extractPhaseToken rather than widening a fourth bespoke regex; additive, so it can only admit directories. Refs #3180. Closes #3185. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QELmgcSwcNBgbUs3kzJeqG * refactor(#3185): route the last two enumeration re-derivations workstream-inventory countRoadmapPhases counted every `Phase` heading across the whole ROADMAP -- no window, no sentinel filter -- so it counted 999.* backlog and Phase 0 and spanned every milestone the document ever had. Its own caller already resolved a currentVersion and passed it to getMilestonePhaseFilter elsewhere in the same file; this was the sibling copy that never got the fix. state.cts phaseInventoryProvider enumerated phase dirs with its own /^(\d+)-(.+)$/ convention regex and neither filter, so a rebuilt STATE.md inventory carried backlog and sentinel directories as current-milestone phases. A non-COMPLETE enumeration scope now throws to the outer catch as a real scan failure rather than reporting a confident undercount, mirroring the per-phase scanPhasePlans contract beside it. Refs #3180 #3185. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QELmgcSwcNBgbUs3kzJeqG * refactor(#3185): consolidate 23 sentinel re-derivations onto one predicate The whole-repo drift guard (ADR-3180 Decision 4a, no file allowlist) found the sentinel rule re-implemented 23 times across 8 modules, in three regex variants plus four integer-comparison forms. Most tested 999 only, so Phase 0 slipped through them while roadmap.analyze and the engine-wide convention (#1580) both treat 0 and 999 alike. That disagreement is the defect class this epic removes. All 23 now call phase-id's isSentinelPhaseId (SENTINEL_RANGES [0,999]). Sites: init recommended-actions and backlog counts, milestone phase scan, the phase-lifecycle progress table, phase.cts used-number collection and the four renumber-on-remove guards, roadmap-parser's heading and bullet milestone counts, roadmap get-phase fallbacks, and state's heading denominator. Excluding Phase 0 at these sites is a deliberate behavior change and the point of the consolidation — several carried comments already saying 0 should be excluded while the literal beside them caught only 999. Adds scripts/lint-phase-enumeration-drift.cjs, wired into lint:ci. It scans the whole src/ tree with no file allowlist and reports both shapes: an independent phases-dir enumeration, and an independent sentinel literal. Exemptions are function-scoped with a written reason. The guard is comment-aware — its first pass flagged JSDoc and a comment documenting that the code below uses the canonical owner, which would have trained readers to exempt prose. Refs #3180 #3185. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QELmgcSwcNBgbUs3kzJeqG * refactor(#3185): resolve every phases-dir enumeration; drift guard reports zero Per-site triage of the 31 remaining whole-repo guard hits, applying the rule generalized from #3183's Amendment 1: a LOOKUP, DIAGNOSTIC, ARCHIVAL or MUTATION pass wants the physical set; only "which phases belong to this milestone" wants the scoped set. Routed (10): init new-milestone phase_dir_count, init milestone-op fallback count, init manager, init progress, milestone complete stats/dry-run/archive move, phase complete's next-phase scan, state update-progress, state frontmatter stats, and uat audit's active set. Exempt with a written function-scoped reason (never a file allowlist): the audit/UAT/verification sweeps that deliberately scan every directory to report gaps, phase create/insert/rename/renumber mutations, single-phase lookups, roadmap-upgrade's cross-milestone migration, cmdPhasesClear's whole-tree destructive pass, and the reads that list a phase dir's FILES rather than enumerating the phases dir at all. Latent defects fixed by the routing: sentinel directories leaked into cmdInitNewMilestone's phase_dir_count, cmdMilestoneComplete's stats, dry-run AND ARCHIVE MOVE, cmdStateUpdateProgress, buildStateFrontmatter and cmdAuditUat's active set — every one of those hand-rolled an isDirInMilestone filter with no sentinel exclusion, so `milestone complete` was archiving backlog directories. scripts/lint-phase-enumeration-drift.cjs now reports 0 re-derivations and npm run lint:ci is green. Refs #3180 #3185. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QELmgcSwcNBgbUs3kzJeqG * docs(#3185): document milestone-scoped enumeration and record ADR Amendment 3 Changeset fragment (Changed), CLI-TOOLS/COMMANDS/USER-GUIDE updates for the scoped output of progress, stats, phases list, phases clear and milestone complete, the CONTEXT.md Phase Locator glossary entry naming listMilestonePhaseDirs, and ADR-3180 Amendment 3. Amendment 3 records: the SCOPE contract held unchanged; the declared deviation from Decision 1's provisional signature (the window needs cwd/ws, which the locked roadmapContent parameter cannot supply); the copy count being a lower bound for the third consecutive phase (4 scoped vs 54 found); the load-bearing finding that the sentinel exclusion sat on the heading set and was unreachable under the pass-all degrade; the two destructive-path defects; and the generalized exemption rule. Refs #3180 #3185. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QELmgcSwcNBgbUs3kzJeqG * fix(#3185): wire scope to consumers; revert two wrong routings the suite caught Review + remote runner findings, all fixed: The three consumers computed the enumeration scope and threw it away, so TRUNCATED/UNSCOPED/UNREADABLE collapsed into the same output as COMPLETE -- reproducing this epic's own output-identical-failure defect one layer up. progress, stats and phases list now emit phase_scope (null on the phases list --phase lookup path, which performs no enumeration). Two routings were wrong and the suite proved it: roadmap-parser's two milestone phase-count scans are reverted to the 999-only literal. isSentinelPhaseId is BROADER than what it replaced: its legacy branch runs /^0*(\d+)/ over "00.1", which backtracks to capture 0, so it read #2554's decimal phase ids as sentinel milestone 0 and stopped counting them. state.cts phaseInventoryProvider is reverted to the physical disk scan. `state rebuild` is a RECONCILIATION pass -- scoping it made it throw on healthy trees whose fixture resolves no window, swallowed the raw readdirSync fault message #3057 B1 requires verbatim, and stopped it dropping orphan STATE.md rows, which is the job. Both are now function-scoped guard exemptions with written reasons, not silent reverts. This is the consolidation trap named in the epic: a canonical rule can cover MORE than the copy it replaces, and only real inputs show it. Adds phases list coverage, a scope-branch test, and a drift-guard unit suite; backports comment-awareness to the milestone-window and plan-count guards so all three siblings share one false-positive profile; names #3161 alongside #3167 in Amendment 3's subsumption record. Refs #3180 #3185. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QELmgcSwcNBgbUs3kzJeqG * fix(#3185): correct isSentinelPhaseId's decimal-zero misclassification An isolated security review caught this branch committing the epic's own sin: the over-broad predicate was worked around at ONE call site and left live at the destructive ones. isSentinelPhaseId's legacy branch ran /^0*(\d+)/, which backtracks so any id whose leading digit run is all zeros before a non-digit captures 0 -- "0.1", "00.1" and "0.2554" all read as sentinel milestone 0. Two pinned contracts disagree with that: #2554 requires "00.1" to be counted as a real phase, and the 999 icebox is a whole reserved milestone so "999.1" must stay sentinel. The rule is asymmetric and now says so explicitly: 999 is sentinel with or without a decimal part; 0 is sentinel only when bare. A decimal phase under either is a real phase for 0 and reserved for 999, because 999 reserves a MILESTONE while 0 reserves a PHASE. Fixing the owner lets the earlier workaround go: getMilestonePhaseFilter's two scans route through isSentinelPhaseId again and the guard exemption that existed only to accommodate the defect is deleted. The state.cts cmdStateRebuild exemption stays -- that one is a genuine reconciliation-wants-the-physical-set case. Also corrects tests/adr-612-bracket-grammar.test.cjs, which asserted isSentinelPhaseId('0.1') === true and so had encoded the defect as expected behavior. Refs #3180 #3185. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QELmgcSwcNBgbUs3kzJeqG * fix(#3185): keep isSentinelPhaseId's semantics — 0.x is layered, not wrong Reverts the previous commit. The remote suite failed six tests proving it wrong, and the reason is the sharpest finding of this phase. An isolated security review observed that isSentinelPhaseId reads 0.1 and 00.1 as sentinel milestone 0 and judged that a defect against #2554. Correcting the canonical predicate broke #2949. Both contracts are pinned and both are right, because they ask different questions: #2554 is this dir part of the current milestone's phase SET? -> count 00.1 #2949 must this phase COMPLETE before the milestone closes? -> 0.x sentinel No single global predicate answers both. isSentinelPhaseId keeps its semantics (0.x IS a sentinel, #2949), and the milestone-window layer keeps a narrower 999-only rule (#2554) as a function-scoped guard exemption with a written reason — not a second silent copy. That corrects how Decision 1 reads: "one owner per derivation" governs who computes an answer, not how many questions share it. An over-broad canonical rule is as much a defect as a divergent copy and fails worse, because it looks like consolidation. Recorded in Amendment 3 as the lesson for Phases 4 and 5. Where a review's inference about intent conflicts with a pinned contract, the pinned contract wins; the finding is adjudicated, not fixed. The boundary tables in the enumeration suite are corrected to assert 0.x IS a sentinel, with the layering explained. Refs #3180 #3185. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QELmgcSwcNBgbUs3kzJeqG * chore(#3185): set changeset fragment pr to 3222 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QELmgcSwcNBgbUs3kzJeqG --------- Co-authored-by: sim <sim@local> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
487 lines
21 KiB
JavaScript
487 lines
21 KiB
JavaScript
/**
|
|
* Tests for the phase-ENUMERATION single-owner contract (#3185, epic #3180
|
|
* Phase 3, ADR-3180 Decision 1 row "Phase enumeration").
|
|
* Matrix: .gsd/phase/refactor-3185-phase-enumeration-single-owner/50-test-matrix.md
|
|
*
|
|
* This file lands FAILING-FIRST. Every test below asserts the behavior the
|
|
* design requires and that the tree does NOT have yet, so the remote runner
|
|
* records a real RED before the fix.
|
|
*
|
|
* Rows covered here are the ones with direct code evidence in the design:
|
|
* - row 36 `progress` lists 999.* backlog dirs as current-milestone phases
|
|
* - row 39 a `0-*` sentinel directory is listed by `stats`/`progress`
|
|
* - row 14 negative space: `P0.0-foundation` is a REAL phase (#1324
|
|
* letter-prefixed-decimal family), not sentinel milestone 0
|
|
* - row 38 a `### Phase 999.1:` ROADMAP heading produces a `stats` row
|
|
* - row 43 `phases clear --confirm` DELETES a `0-*` directory, because
|
|
* cmdPhasesClear carries its own 5th sentinel copy
|
|
* (`/^999(?:\.|$)/`) excluding 999 but NOT 0 — while
|
|
* `roadmap analyze` treats Phase 0 as a sentinel to preserve.
|
|
*
|
|
* Assertions are on `--json` output (a typed surface), never on rendered
|
|
* prose — CONTRIBUTING.md bans raw-text matching on test outputs. Row 43 also
|
|
* carries the NEGATIVE PROOF that the directory still exists on disk, because
|
|
* an exit code alone cannot distinguish "refused" from "deleted and reported
|
|
* success".
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const { test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const {
|
|
createTempProject,
|
|
createTempGitProject,
|
|
cleanup,
|
|
runGsdTools,
|
|
} = require('./helpers.cjs');
|
|
const { SCOPE } = require('../gsd-core/bin/lib/planning-scope.cjs');
|
|
const { isSentinelPhaseId } = require('../gsd-core/bin/lib/phase-id.cjs');
|
|
|
|
// ─── Fixture helpers ───────────────────────────────────────────────────────
|
|
|
|
function planningDirOf(cwd) {
|
|
return path.join(cwd, '.planning');
|
|
}
|
|
|
|
function writeRoadmap(cwd, lines) {
|
|
fs.mkdirSync(planningDirOf(cwd), { recursive: true });
|
|
fs.writeFileSync(path.join(planningDirOf(cwd), 'ROADMAP.md'), lines.join('\n'));
|
|
}
|
|
|
|
function writeState(cwd, fields) {
|
|
fs.mkdirSync(planningDirOf(cwd), { recursive: true });
|
|
const lines = ['---'];
|
|
for (const [k, v] of Object.entries(fields)) lines.push(`${k}: ${v}`);
|
|
lines.push('---', '');
|
|
fs.writeFileSync(path.join(planningDirOf(cwd), 'STATE.md'), lines.join('\n'));
|
|
}
|
|
|
|
/** Create `<cwd>/.planning/phases/<dirName>/` and optionally seed files. */
|
|
function makePhaseDir(cwd, dirName, files = {}) {
|
|
const dir = path.join(planningDirOf(cwd), 'phases', dirName);
|
|
fs.mkdirSync(dir, { recursive: true });
|
|
for (const [name, content] of Object.entries(files)) {
|
|
fs.writeFileSync(path.join(dir, name), content);
|
|
}
|
|
return dir;
|
|
}
|
|
|
|
/** A ROADMAP with a real current milestone plus a 999 backlog heading. */
|
|
function roadmapWithBacklog() {
|
|
return [
|
|
'# Roadmap',
|
|
'',
|
|
'## v1.0 Current 🚧',
|
|
'',
|
|
'### Phase 1: Foundation',
|
|
'',
|
|
'**Goal:** lay the foundation',
|
|
'',
|
|
'### Phase 999.1: Icebox item',
|
|
'',
|
|
'**Goal:** someday',
|
|
'',
|
|
];
|
|
}
|
|
|
|
function parseJson(result, label) {
|
|
assert.ok(result.success, `${label} should exit 0: ${result.error || ''}`);
|
|
try {
|
|
return JSON.parse(result.output);
|
|
} catch (err) {
|
|
throw new Error(`${label} did not emit parseable JSON: ${err.message}`);
|
|
}
|
|
}
|
|
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
// Row 36 — `progress` must not list 999.* backlog dirs as milestone phases
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
|
|
test('progress does not list a 999 backlog directory as a current-milestone phase', (t) => {
|
|
const cwd = createTempProject('gsd-phase-enum-');
|
|
t.after(() => cleanup(cwd));
|
|
|
|
writeState(cwd, { milestone: 'v1.0' });
|
|
writeRoadmap(cwd, roadmapWithBacklog());
|
|
makePhaseDir(cwd, '01-foundation', { '01-PLAN.md': '# Plan\n' });
|
|
makePhaseDir(cwd, '999.1-icebox', { '01-PLAN.md': '# Plan\n' });
|
|
|
|
const report = parseJson(runGsdTools('progress json', cwd), 'progress json');
|
|
|
|
const numbers = (report.phases || []).map((p) => String(p.number));
|
|
assert.ok(
|
|
!numbers.some((n) => n.startsWith('999')),
|
|
`999.* backlog directories must not appear as current-milestone phases; got ${JSON.stringify(numbers)}`,
|
|
);
|
|
assert.ok(
|
|
numbers.includes('01') || numbers.includes('1'),
|
|
`the real in-window phase must still be listed; got ${JSON.stringify(numbers)}`,
|
|
);
|
|
});
|
|
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
// Row 39 / row 14 — phase-0 sentinel vs the letter-prefixed-decimal family
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
|
|
test('progress does not list a phase-0 sentinel directory', (t) => {
|
|
const cwd = createTempProject('gsd-phase-enum-');
|
|
t.after(() => cleanup(cwd));
|
|
|
|
writeState(cwd, { milestone: 'v1.0' });
|
|
writeRoadmap(cwd, roadmapWithBacklog());
|
|
makePhaseDir(cwd, '0-prep', { '01-PLAN.md': '# Plan\n' });
|
|
makePhaseDir(cwd, '01-foundation', { '01-PLAN.md': '# Plan\n' });
|
|
|
|
const report = parseJson(runGsdTools('progress json', cwd), 'progress json');
|
|
|
|
const numbers = (report.phases || []).map((p) => String(p.number));
|
|
assert.ok(
|
|
!numbers.some((n) => /^0+$/.test(n)),
|
|
`phase-0 sentinel directories must not appear as milestone phases; got ${JSON.stringify(numbers)}`,
|
|
);
|
|
});
|
|
|
|
test('a letter-prefixed decimal directory is NOT read as a phase-0 sentinel', (t) => {
|
|
// Negative space (matrix row 14): `P0.0-foundation` is a real phase from the
|
|
// #1324 letter-prefixed-decimal family, NOT sentinel milestone 0. A sentinel
|
|
// rule that strips a bare letter prefix would silently delete this family
|
|
// from three commands.
|
|
const cwd = createTempProject('gsd-phase-enum-');
|
|
t.after(() => cleanup(cwd));
|
|
|
|
writeState(cwd, { milestone: 'v1.0' });
|
|
writeRoadmap(cwd, [
|
|
'# Roadmap',
|
|
'',
|
|
'## v1.0 Current 🚧',
|
|
'',
|
|
'### Phase P0.0: Foundation',
|
|
'',
|
|
'**Goal:** real work',
|
|
'',
|
|
]);
|
|
makePhaseDir(cwd, 'P0.0-foundation', { '01-PLAN.md': '# Plan\n' });
|
|
|
|
const report = parseJson(runGsdTools('progress json', cwd), 'progress json');
|
|
const numbers = (report.phases || []).map((p) => String(p.number));
|
|
assert.ok(
|
|
numbers.length > 0,
|
|
'a letter-prefixed decimal phase must survive the sentinel filter, not be dropped as milestone 0',
|
|
);
|
|
});
|
|
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
// Row 38 — a 999 ROADMAP heading must not produce a `stats` row
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
|
|
test('stats does not emit a row for a 999 backlog heading with no directory', (t) => {
|
|
const cwd = createTempProject('gsd-phase-enum-');
|
|
t.after(() => cleanup(cwd));
|
|
|
|
writeState(cwd, { milestone: 'v1.0' });
|
|
writeRoadmap(cwd, roadmapWithBacklog());
|
|
makePhaseDir(cwd, '01-foundation', { '01-PLAN.md': '# Plan\n' });
|
|
|
|
const report = parseJson(runGsdTools('stats json', cwd), 'stats json');
|
|
|
|
const numbers = (report.phases || []).map((p) => String(p.number));
|
|
assert.ok(
|
|
!numbers.some((n) => n.startsWith('999')),
|
|
`a 999 heading must not seed a stats row; got ${JSON.stringify(numbers)}`,
|
|
);
|
|
});
|
|
|
|
test('stats does not list a phase-0 sentinel directory', (t) => {
|
|
const cwd = createTempProject('gsd-phase-enum-');
|
|
t.after(() => cleanup(cwd));
|
|
|
|
writeState(cwd, { milestone: 'v1.0' });
|
|
writeRoadmap(cwd, roadmapWithBacklog());
|
|
makePhaseDir(cwd, '0-prep', { '01-PLAN.md': '# Plan\n' });
|
|
makePhaseDir(cwd, '01-foundation', { '01-PLAN.md': '# Plan\n' });
|
|
|
|
const report = parseJson(runGsdTools('stats json', cwd), 'stats json');
|
|
const numbers = (report.phases || []).map((p) => String(p.number));
|
|
assert.ok(
|
|
!numbers.some((n) => /^0+$/.test(n)),
|
|
`phase-0 sentinel directories must not appear in stats; got ${JSON.stringify(numbers)}`,
|
|
);
|
|
});
|
|
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
// Row 43 — the destructive path: `phases clear` must not delete a sentinel
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
|
|
test('phases clear preserves a phase-0 sentinel directory, with negative proof on disk', (t) => {
|
|
// cmdPhasesClear carries the FIFTH copy of the sentinel rule and the THIRD
|
|
// regex variant — `/^999(?:\.|$)/` — which excludes 999 but NOT 0. So a
|
|
// `0-*` directory that `roadmap analyze` treats as a preserved sentinel is
|
|
// DELETED here. The exit code alone cannot show this, so the load-bearing
|
|
// assertion is that the directory still exists afterwards.
|
|
const cwd = createTempGitProject('gsd-phase-enum-clear-');
|
|
t.after(() => cleanup(cwd));
|
|
|
|
writeState(cwd, { milestone: 'v1.0' });
|
|
writeRoadmap(cwd, roadmapWithBacklog());
|
|
const zeroDir = makePhaseDir(cwd, '0-prep', { '01-PLAN.md': '# Plan\n' });
|
|
const backlogDir = makePhaseDir(cwd, '999.1-icebox', { '01-PLAN.md': '# Plan\n' });
|
|
makePhaseDir(cwd, '01-foundation', { '01-PLAN.md': '# Plan\n' });
|
|
|
|
runGsdTools('phases clear --confirm --force', cwd);
|
|
|
|
assert.ok(
|
|
fs.existsSync(zeroDir),
|
|
'a phase-0 sentinel directory must be preserved by `phases clear`, exactly as the 999 sentinel already is',
|
|
);
|
|
assert.ok(
|
|
fs.existsSync(backlogDir),
|
|
'the 999 sentinel directory must remain preserved (unchanged behavior)',
|
|
);
|
|
});
|
|
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
// Rows 7-9 — the PASS-ALL degrade, which is where the defect actually lives
|
|
//
|
|
// When the milestone window yields NO phase headings, getMilestonePhaseFilter
|
|
// degrades to a literal `() => true` predicate and stops consulting its
|
|
// heading set at all — so its `/^999\b/` heading-side sentinel exclusion
|
|
// becomes unreachable and every directory on disk is reported as a
|
|
// current-milestone phase. A fixture that contains phase headings keeps the
|
|
// filter ACTIVE and never exercises this path, which is why the sibling
|
|
// phase-0 test above passes today for the wrong reason.
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
|
|
/** A ROADMAP whose current milestone declares NO phases — the pass-all path. */
|
|
function roadmapWithNoPhaseHeadings() {
|
|
return [
|
|
'# Roadmap',
|
|
'',
|
|
'## v1.0 Current 🚧',
|
|
'',
|
|
'This milestone has been declared but has no phases yet.',
|
|
'',
|
|
];
|
|
}
|
|
|
|
test('pass-all degrade still excludes a 999 sentinel directory', (t) => {
|
|
const cwd = createTempProject('gsd-phase-enum-passall-');
|
|
t.after(() => cleanup(cwd));
|
|
|
|
writeState(cwd, { milestone: 'v1.0' });
|
|
writeRoadmap(cwd, roadmapWithNoPhaseHeadings());
|
|
makePhaseDir(cwd, '999.1-icebox', { '01-PLAN.md': '# Plan\n' });
|
|
|
|
const report = parseJson(runGsdTools('progress json', cwd), 'progress json');
|
|
const numbers = (report.phases || []).map((p) => String(p.number));
|
|
assert.ok(
|
|
!numbers.some((n) => n.startsWith('999')),
|
|
`the pass-all degrade must still filter sentinels; got ${JSON.stringify(numbers)}`,
|
|
);
|
|
});
|
|
|
|
test('pass-all degrade still excludes a phase-0 sentinel directory', (t) => {
|
|
const cwd = createTempProject('gsd-phase-enum-passall-');
|
|
t.after(() => cleanup(cwd));
|
|
|
|
writeState(cwd, { milestone: 'v1.0' });
|
|
writeRoadmap(cwd, roadmapWithNoPhaseHeadings());
|
|
makePhaseDir(cwd, '0-prep', { '01-PLAN.md': '# Plan\n' });
|
|
|
|
const report = parseJson(runGsdTools('progress json', cwd), 'progress json');
|
|
const numbers = (report.phases || []).map((p) => String(p.number));
|
|
assert.ok(
|
|
!numbers.some((n) => /^0+$/.test(n)),
|
|
`the pass-all degrade must still filter phase-0 sentinels; got ${JSON.stringify(numbers)}`,
|
|
);
|
|
});
|
|
|
|
test('pass-all degrade stays over-inclusive for NON-sentinel directories', (t) => {
|
|
// Negative space (matrix row 9): the narrowing is sentinel-only. The
|
|
// documented "over-inclusive, never under-inclusive" promise in
|
|
// getMilestonePhaseFilter's own comment is narrowed minimally, not revoked —
|
|
// an ordinary phase directory must still be listed when the window declares
|
|
// no phases, or a project mid-migration loses its real phases from view.
|
|
const cwd = createTempProject('gsd-phase-enum-passall-');
|
|
t.after(() => cleanup(cwd));
|
|
|
|
writeState(cwd, { milestone: 'v1.0' });
|
|
writeRoadmap(cwd, roadmapWithNoPhaseHeadings());
|
|
makePhaseDir(cwd, '04-thing', { '01-PLAN.md': '# Plan\n' });
|
|
|
|
const report = parseJson(runGsdTools('progress json', cwd), 'progress json');
|
|
const numbers = (report.phases || []).map((p) => String(p.number));
|
|
assert.ok(
|
|
numbers.length > 0,
|
|
'an ordinary phase directory must still be listed under the pass-all degrade',
|
|
);
|
|
});
|
|
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
// `phases list` — ADR-3180 Decision 4(c): the identity assertion belongs at
|
|
// EACH consumer's own observable output, not only at progress/stats.
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
|
|
test('phases list excludes a 999 backlog dir and a 0-sentinel dir, keeps the real one', (t) => {
|
|
const cwd = createTempProject('gsd-phase-enum-list-');
|
|
t.after(() => cleanup(cwd));
|
|
|
|
writeState(cwd, { milestone: 'v1.0' });
|
|
writeRoadmap(cwd, roadmapWithBacklog());
|
|
makePhaseDir(cwd, '01-foundation', { '01-PLAN.md': '# Plan\n' });
|
|
makePhaseDir(cwd, '999.1-icebox', { '01-PLAN.md': '# Plan\n' });
|
|
makePhaseDir(cwd, '0-prep', { '01-PLAN.md': '# Plan\n' });
|
|
|
|
const report = parseJson(runGsdTools('phases list', cwd), 'phases list');
|
|
const dirs = report.directories || [];
|
|
|
|
assert.ok(
|
|
!dirs.some((d) => d.startsWith('999')),
|
|
`999.* backlog directories must not appear in phases list; got ${JSON.stringify(dirs)}`,
|
|
);
|
|
assert.ok(
|
|
!dirs.some((d) => /^0(?:[-.]|$)/.test(d)),
|
|
`phase-0 sentinel directories must not appear in phases list; got ${JSON.stringify(dirs)}`,
|
|
);
|
|
assert.ok(
|
|
dirs.includes('01-foundation'),
|
|
`the real in-window phase directory must still be listed; got ${JSON.stringify(dirs)}`,
|
|
);
|
|
});
|
|
|
|
test('phases list --phase still finds an out-of-window phase (documented exemption)', (t) => {
|
|
const cwd = createTempProject('gsd-phase-enum-list-lookup-');
|
|
t.after(() => cleanup(cwd));
|
|
|
|
// v1.0 is current; phase 5 belongs to a different (later) milestone and is
|
|
// never mentioned in v1.0's window, so it is genuinely OUT-OF-WINDOW.
|
|
writeState(cwd, { milestone: 'v1.0' });
|
|
writeRoadmap(cwd, [
|
|
'# Roadmap',
|
|
'',
|
|
'## v1.0 Current 🚧',
|
|
'',
|
|
'### Phase 1: Foundation',
|
|
'',
|
|
'## v2.0 Next',
|
|
'',
|
|
'### Phase 5: Later Work',
|
|
'',
|
|
]);
|
|
makePhaseDir(cwd, '01-foundation', { '01-PLAN.md': '# Plan\n' });
|
|
makePhaseDir(cwd, '05-later-work', { '01-PLAN.md': '# Plan\n' });
|
|
|
|
const result = runGsdTools('phases list --phase 5', cwd);
|
|
const report = parseJson(result, 'phases list --phase 5');
|
|
|
|
assert.strictEqual(
|
|
report.error,
|
|
undefined,
|
|
`--phase lookup must find an out-of-window phase by design (ADR-3180 Decision 4a); got ${JSON.stringify(report)}`,
|
|
);
|
|
assert.deepStrictEqual(report.directories, ['05-later-work']);
|
|
});
|
|
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
// `phase_scope` — epic #3180 Done-when #7: the enumeration path can fail
|
|
// distinguishably. Mirrors the TRUNCATED fixture shape from
|
|
// tests/milestone-window-single-owner.test.cjs's buildTruncatedFixture: an
|
|
// ACTIVE milestone heading with no phase headings inside its own window,
|
|
// followed by a later milestone heading whose section DOES carry phase
|
|
// headings -- the window closes before the phase region.
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
|
|
function writeTruncatedRoadmap(cwd) {
|
|
writeRoadmap(cwd, [
|
|
'# Roadmap',
|
|
'',
|
|
'## v3.0 In Progress 🚧',
|
|
'',
|
|
'Some preamble notes. No phase headings here.',
|
|
'',
|
|
'## v4.0 Next',
|
|
'',
|
|
'### Phase 1: Foo',
|
|
'',
|
|
'### Phase 2: Bar',
|
|
'',
|
|
]);
|
|
}
|
|
|
|
test('progress json phase_scope is not complete when the milestone window is truncated', (t) => {
|
|
const cwd = createTempProject('gsd-phase-enum-scope-truncated-');
|
|
t.after(() => cleanup(cwd));
|
|
|
|
writeState(cwd, { milestone: 'v3.0' });
|
|
writeTruncatedRoadmap(cwd);
|
|
makePhaseDir(cwd, '1-foo', { '01-PLAN.md': '# Plan\n' });
|
|
makePhaseDir(cwd, '2-bar', { '01-PLAN.md': '# Plan\n' });
|
|
|
|
const report = parseJson(runGsdTools('progress json', cwd), 'progress json');
|
|
assert.notStrictEqual(
|
|
report.phase_scope,
|
|
SCOPE.COMPLETE,
|
|
`a truncated window must not report phase_scope: "complete"; got ${JSON.stringify(report.phase_scope)}`,
|
|
);
|
|
});
|
|
|
|
test('progress json phase_scope is complete for a healthy, in-window fixture', (t) => {
|
|
const cwd = createTempProject('gsd-phase-enum-scope-complete-');
|
|
t.after(() => cleanup(cwd));
|
|
|
|
writeState(cwd, { milestone: 'v1.0' });
|
|
writeRoadmap(cwd, roadmapWithBacklog());
|
|
makePhaseDir(cwd, '01-foundation', { '01-PLAN.md': '# Plan\n' });
|
|
|
|
const report = parseJson(runGsdTools('progress json', cwd), 'progress json');
|
|
assert.strictEqual(report.phase_scope, SCOPE.COMPLETE);
|
|
});
|
|
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
// isSentinelPhaseId boundary (#3185, reverted 5fcb7a5a2): #2554 and #2949
|
|
// are pinned contracts that ask DIFFERENT QUESTIONS about `0.x` ids, so one
|
|
// global predicate cannot answer both:
|
|
// - #2554 (tests/roadmap-parser.test.cjs) asks "is this directory part of
|
|
// the current milestone's phase set?" -- a `00.1-<slug>` directory
|
|
// declared as `### Phase 00.1:` MUST be counted there.
|
|
// - #2949 (tests/issue-2949-phase-complete-stage3-sentinel.test.cjs) asks
|
|
// "must this phase be completed before the milestone can close?" -- a
|
|
// `0.x` id IS a sentinel for that question, and must not block
|
|
// `is_last_phase=true`.
|
|
// isSentinelPhaseId answers the #2949 (completion) question, so `0.x` stays
|
|
// a sentinel here. The #2554 (milestone-window) question is answered by a
|
|
// narrower, 999-only rule inside getMilestonePhaseFilter in
|
|
// src/roadmap-parser.cts, not by this predicate. The two questions are
|
|
// deliberately answered at two different layers.
|
|
// ═════════════════════════════════════════════════════════════════════════
|
|
|
|
const SENTINEL_IDS = [
|
|
'0',
|
|
'00',
|
|
'0-prep',
|
|
'00-prep',
|
|
'0.1',
|
|
'00.1',
|
|
'0.1-slug',
|
|
'999',
|
|
'999.1',
|
|
'999.1-icebox',
|
|
'GSD-999-icebox',
|
|
];
|
|
const NON_SENTINEL_IDS = ['01-foundation', 'P0.0-foundation', '9990-x', '998-x', '1000-x', '04-thing'];
|
|
|
|
test('isSentinelPhaseId: sentinel boundary table', () => {
|
|
for (const id of SENTINEL_IDS) {
|
|
assert.strictEqual(isSentinelPhaseId(id), true, `expected sentinel: ${JSON.stringify(id)}`);
|
|
}
|
|
});
|
|
|
|
test('isSentinelPhaseId: NOT-sentinel boundary table', () => {
|
|
for (const id of NON_SENTINEL_IDS) {
|
|
assert.strictEqual(isSentinelPhaseId(id), false, `expected NOT sentinel: ${JSON.stringify(id)}`);
|
|
}
|
|
});
|