fix(#3225): guard W006/W007 + consistency loops with isSentinelPhaseId (#3371)

* test(#3225): sentinel phase dirs no longer trigger W007 / consistency warnings / gaps

The W006/W007 (validate health) and the parallel consistency disk↔roadmap and
gap-numbering loops never got the isSentinelPhaseId guard that phase.cts has
(#2786/#2949), so every sentinel phase dir (999.x/0.x — never-on-roadmap by
convention) produced a spurious W007 and a spurious 'Gap in phase numbering:
N → 999'. Add failing-first regressions for both surfaces + the gap check, each
with a non-sentinel orphan negative-space guard.

RED — fails on next; fix follows.

* fix(#3225): guard W006/W007 + consistency + gap loops with isSentinelPhaseId

cmdValidateHealth's W006/W007 loops, cmdValidateConsistency's parallel disk↔
roadmap loops, AND its gap-numbering check never got the isSentinelPhaseId guard
that phase.cts has at 10+ sites (#2786/#2949). So any repo using the sentinel-id
convention (999.x backlog/interim, 0.x drafts) got a permanent spurious W007 and
a spurious 'Gap in phase numbering: N → 999', with advice to add-to-roadmap
(violates the convention) or delete (destroys archived work).

Add isSentinelPhaseId to the phaseIdMod destructure and skip sentinel ids in:
W006 + W007 (cmdValidateHealth); the two plain-warning disk↔roadmap loops and
the gap-numbering integerPhases filter (cmdValidateConsistency — same bug family,
folded in inline per no-silent-defer). Additive only: non-sentinel orphans and
real numbering gaps still warn. The gap-numbering guard was surfaced by the
isolated review (a 999-interim dir would otherwise create a false 'N → 999' gap).
Same family as #3167 (since fixed).

* chore(#3225): add changeset fragment

* chore(#3225): backfill changeset PR number (#3371)

---------

Co-authored-by: sim <sim@local>
This commit is contained in:
Tom Boucher
2026-08-11 21:49:39 -04:00
committed by GitHub
parent 62f5f3b39e
commit ae7dc52972
4 changed files with 98 additions and 2 deletions

View File

@@ -977,6 +977,41 @@ describe('validate health command', () => {
assert.strictEqual(output.errors.length, 0, 'should have no errors');
assert.ok(output.warnings.length > 0, 'should have warnings');
});
// #3225: sentinel phase dirs (999.x backlog/interim, 0.x drafts) are defined as
// never-on-roadmap (SENTINEL_RANGES=[0,999]). The W006/W007 disk↔roadmap loops
// never had the isSentinelPhaseId guard that phase.cts has, so every sentinel dir
// produced a spurious W007 with wrong fix advice ("Add to roadmap or remove
// directory"). Sentinels must be excluded; a real (non-sentinel) orphan must still warn.
test('#3225: sentinel phase dirs (999/0) do not trigger W007; real orphans still do', () => {
writeMinimalRoadmap(tmpDir, ['1']);
writeMinimalStateMd(tmpDir);
writeValidConfigJson(tmpDir);
fs.mkdirSync(path.join(tmpDir, '.planning', 'phases', '01-a'), { recursive: true });
// Sentinel dirs — never-on-roadmap by convention.
fs.mkdirSync(path.join(tmpDir, '.planning', 'phases', '999-interim'), { recursive: true });
fs.mkdirSync(path.join(tmpDir, '.planning', 'phases', '0-drafts'), { recursive: true });
// A real orphan (non-sentinel) that SHOULD still trigger W007.
fs.mkdirSync(path.join(tmpDir, '.planning', 'phases', '77-orphan'), { recursive: true });
const result = runGsdTools('validate health', tmpDir);
assert.ok(result.success, `Command failed: ${result.error}`);
const output = JSON.parse(result.output);
const sentinelW007s = output.warnings.filter(
w => w.code === 'W007' && /\b(0|999)\b/.test(w.message)
);
assert.strictEqual(
sentinelW007s.length, 0,
`sentinel phase dirs must not trigger W007; got: ${JSON.stringify(sentinelW007s)}`
);
// Negative space: the non-sentinel orphan must still be flagged.
assert.ok(
output.warnings.some(w => w.code === 'W007' && /77\b/.test(w.message)),
`expected W007 for the real orphan 77; got: ${JSON.stringify(output.warnings.filter(w => w.code === 'W007'))}`
);
});
});
// ─────────────────────────────────────────────────────────────────────────────

View File

@@ -102,6 +102,46 @@ describe('validate consistency command', () => {
);
});
test('#3225: sentinel phase dirs (999/0) do not warn; real orphans still do', () => {
fs.writeFileSync(
path.join(tmpDir, '.planning', 'ROADMAP.md'),
`# Roadmap\n### Phase 1: A\n`
);
fs.mkdirSync(path.join(tmpDir, '.planning', 'phases', '01-a'), { recursive: true });
// Sentinel dirs — never-on-roadmap by convention (SENTINEL_RANGES=[0,999]).
fs.mkdirSync(path.join(tmpDir, '.planning', 'phases', '999-interim'), { recursive: true });
fs.mkdirSync(path.join(tmpDir, '.planning', 'phases', '0-drafts'), { recursive: true });
// A real orphan (non-sentinel) that SHOULD still warn.
fs.mkdirSync(path.join(tmpDir, '.planning', 'phases', '02-orphan'), { recursive: true });
const result = runGsdTools('validate consistency', tmpDir);
assert.ok(result.success, `Command failed: ${result.error}`);
const output = JSON.parse(result.output);
const sentinelWarnings = output.warnings.filter(
w => w.includes('disk but not in ROADMAP') && /\b(0|999)\b/.test(w)
);
assert.strictEqual(
sentinelWarnings.length, 0,
`sentinel phase dirs must not warn; got: ${JSON.stringify(sentinelWarnings)}`
);
// Negative space: the real orphan must still warn.
assert.ok(
output.warnings.some(w => w.includes('disk but not in ROADMAP') && /02\b/.test(w)),
`expected a warning for the real orphan 02; got: ${JSON.stringify(output.warnings)}`
);
// #3225 (review finding): a sentinel dir must NOT produce a spurious
// "Gap in phase numbering: N → 999" either (the gap check builds its integer
// sequence from diskPhases and would otherwise include 999).
const sentinelGaps = output.warnings.filter(
w => w.includes('Gap in phase numbering') && /999\b/.test(w)
);
assert.strictEqual(
sentinelGaps.length, 0,
`sentinel 999 must not create a spurious numbering gap; got: ${JSON.stringify(sentinelGaps)}`
);
});
test('warns about gaps in phase numbering', () => {
fs.writeFileSync(
path.join(tmpDir, '.planning', 'ROADMAP.md'),