fix(#2043): reject single-digit slug word in phase-token extraction (all sites)
A phase whose slug's first word is a bare single digit (dir
`46-6-rs-pipeline-orchestrator`, roadmap phase "6 Rs Pipeline Orchestrator" →
slug `6-rs-…`) had its phase token over-collected as `46-6` instead of `46`, so
`gsd-tools` phase-by-number lookups (init.plan-phase, init.phase-op, and
downstream execute/verify/ship) resolved phase_dir=null / has_context=false.
Root cause: an over-broad "looks numeric" test (`/^\d/`, `\d+(?:-\d+)*`)
classified token segments and could not distinguish a legitimate zero-padded
sub-phase segment (`01`, `02`) from a single-digit slug word (`6`). Zero-padded
phase/sub-phase segments are always ≥2 digits, so requiring ≥2 digits is the
structural distinguisher. Applied consistently across every same-class
implementation the triage identified (fixing extractPhaseToken alone leaves the
health-check and milestone-filter subsystems exposed):
- src/phase-id.cts extractPhaseToken — a pure-numeric leading segment continues
only with ≥2-digit segments; a letter-prefixed milestone id (`M1`) still
admits its single-digit sub-phase (`M1-2`).
- src/validate.cts PHASE_TOKEN_FROM_DIR_RE (W005/W006/W007 health checks) and
canonicalPlanStem (I001 plan/summary pairing).
- src/roadmap-parser.cts isDirInMilestone numericRe (getMilestonePhaseFilter —
highest blast radius: a false negative silently excludes a phase from the
milestone).
- src/core-utils.cts + its verbatim duplicate src/phase.cts extractCanonicalPlanId.
Regression tests added across tests/{phase-id,health-validation,core-utils,
roadmap-parser}.test.cjs using the shared `46-6-rs-…` fixture, asserting the
token resolves to `46` (not `46-6`) while legit multi-segment tokens
(`01-02`, `02-03-04`, `M1-2`, `68-01`, `02-01`) are unchanged. The
roadmap-parser test exercises the real getMilestonePhaseFilter end-to-end.
The residual ≥2-digit-leading-slug case (e.g. `NN-2024-roadmap`) stays out of
scope — subsumed by the #612 / #565 phase-ID convention work, per the issue.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -217,6 +217,27 @@ describe('extractPhaseToken', () => {
|
||||
test('stops at first non-numeric-starting segment', () => {
|
||||
assert.strictEqual(phaseId.extractPhaseToken('01-02-name-03'), '01-02');
|
||||
});
|
||||
|
||||
test('rejects a single-digit slug word after a phase number (#2043)', () => {
|
||||
// A phase dir like "46-6-rs-pipeline-orchestrator" (roadmap phase name
|
||||
// "6 Rs Pipeline Orchestrator" → slug "6-rs-...") must yield token "46",
|
||||
// not "46-6" — the "6" is the slug's first word, not a sub-phase segment.
|
||||
assert.strictEqual(phaseId.extractPhaseToken('46-6-rs-pipeline-orchestrator'), '46');
|
||||
assert.strictEqual(phaseId.extractPhaseToken('68-6-rs'), '68');
|
||||
// Legit cases are unaffected: a real zero-padded milestone-sub-phase pair
|
||||
// stays intact, and a single-digit sub-phase after a letter-prefixed
|
||||
// milestone id (e.g. "M1-2") is still valid.
|
||||
assert.strictEqual(phaseId.extractPhaseToken('01-02-some-name'), '01-02');
|
||||
assert.strictEqual(phaseId.extractPhaseToken('M1-2-brain'), 'M1-2');
|
||||
// Milestone-prefixed convention: "M1-" strips as a project-code prefix, so
|
||||
// the same rule fixes the slug-collision there too — a phase 46 named
|
||||
// "6 Rs …" under milestone M1 yields "M1-46", not "M1-46-6". Phase 6 under
|
||||
// M1 ("M1-6-rs") correctly stays "M1-6" (the 6 is the phase number).
|
||||
assert.strictEqual(phaseId.extractPhaseToken('M1-46-6-rs-pipeline-orchestrator'), 'M1-46');
|
||||
assert.strictEqual(phaseId.extractPhaseToken('M1-6-rs-pipeline'), 'M1-6');
|
||||
// Single-digit + letter-suffix phase id ("1A") is a real token, not a slug word.
|
||||
assert.strictEqual(phaseId.extractPhaseToken('1A-brain'), '1A');
|
||||
});
|
||||
});
|
||||
|
||||
// ─── phaseTokenMatches ────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user