fix(#4433,#4569,#4126): consolidate the phase-identity seam at name-validity, allocation, and branch-slug (#4640)
* fix(#4433): apply the name-validity guard symmetrically to every milestone-name capture extractMilestoneHeadingName already refused a punctuation-only captured name (#4134), but its two sibling capture sites in getMilestoneInfo — the STATE.md-anchored 🚧-bullet match and the no-STATE.md in-progress 🚧-bullet fallback — skipped straight to a bare truthiness check, so a malformed bullet whose only content past the version was punctuation passed through as a real milestone name. Extracts the existing inline /[\p{L}\p{N}]/u check into a single shared hasNameableContent predicate and applies it at all three capture sites, so the guard is one owner rather than a copy that happened to land at only one of them. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * test(#4433): pin the name-validity guard at all three milestone-name capture sites Failing-first coverage for the hasNameableContent extraction: a punctuation-only 🚧-bullet name must not surface as a real milestone name, either on the STATE.md-anchored path or the no-STATE.md in-progress fallback, while a real name (including a digits-only one) still resolves COMPLETE exactly as before. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * fix(#4569): consolidate decimal-phase-number allocation into one function cmdPhaseInsert allocated its next decimal sub-phase number by scanning only on-disk phases/ directories and ### Phase N.M: headings, never the roadmap summary checklist — so a decimal that existed only as a checklist bullet (no heading yet, no on-disk directory yet) was invisible, and phase insert could silently reallocate an already-used number. It also always nested one level deeper under afterPhase, with no way to request a sibling. cmdPhaseNextDecimal had its own separate, near-identical two-source scan (missing the checklist source too) — the exact "duplicate implementations kept in sync instead of deleted" pattern this issue exists to close. Extracts scanExistingDecimalPhaseNumbers (directories + headings + checklist bullets, in one place) and migrates both cmdPhaseInsert and cmdPhaseNextDecimal onto it — deleting cmdPhaseNextDecimal's own copy rather than patching it in parallel. Adds an allocation: 'nested' | 'sibling' argument to cmdPhaseInsert (default 'nested', matching every existing caller's behavior); a top-level phase with no existing decimal segment falls back to nested since there is no sibling level to join. No CLI flag wires 'sibling' yet — that is a separate, disclosed follow-up. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * test(#4569): pin decimal-allocation coverage across phase insert and next-decimal Failing-first coverage for scanExistingDecimalPhaseNumbers: a checklist-only decimal must not be reallocated by phase insert; a decimal present in heading, checklist, and on-disk directory simultaneously must count once; an unrelated phase family's checklist bullet must not cross-pollute; and phase next-decimal (migrated onto the same shared helper) must see a checklist-only decimal too, closing the same gap in a second command. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * chore(#4634): extend the phase-id drift guard for name-validity and shell arithmetic The epic's ratchet requirement: lint-phase-id-drift.cjs must cover the two new predicates this PR introduces, and must also scan shell inside gsd-core/workflows/**/*.md and gsd-core/references/**/*.md for integer-coercing phase-number arithmetic ($((10#...)) and friends), which neither the canonical TypeScript module nor a source-only lint can reach. Adds findNameValidityDrift (bans re-deriving /[\p{L}\p{N}]/u outside hasNameableContent's owner file) and findShellPhaseArithDrift + scanMarkdownShellArith (bans $((10#...)) in workflow/reference markdown, sanctioned via <!-- phase-id-owner: --> on the preceding line). scanRepo keeps its existing, narrower contract (src/**/*.cts only) so the already-passing "the live repo is clean" test is untouched; a new scanAll merges both for the CLI's full report. Running the guard directly against this tree correctly reports the 7 pre-existing #4619 shell sites (workflows/execute-phase.md x4, workflows/execute-phase/steps/completion-reconciliation.md x2, references/tdd.md x1) as violations — demonstrating the ratchet works, not fixing them. #4619 is a live regression tracked and fixed separately; this PR does not touch those markdown files. A characterization test pins the current count of 7 so a future change to that number is investigated rather than silently absorbed. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * fix(#4569): wire --sibling through phase insert's CLI so the argument is reachable cmdPhaseInsert's allocation parameter had no CLI path to 'sibling' — shipped, untested, unreachable code (code-review finding: a guaranteed surviving mutant). Adds --sibling to phase insert's argument parsing, threads it through, and documents the flag in docs/CLI-TOOLS.md. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * test(#4569): exercise --sibling end-to-end through the real CLI Confirms --sibling joins afterPhase's parent decimal level rather than nesting, and falls back to nested when afterPhase has no existing decimal segment (no sibling level to join). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * test(#4634): demonstrate the two new drift detectors end-to-end via a planted violation The epic asks for the guard to be "demonstrated by watching it go red" on a reintroduced copy. The two new detectors (name-validity, shell-arith) had only unit-level fixture tests; mirrors the existing bracket-rule's planted-violation-in-a-temp-tree test for both, proving they're actually wired into scanRepo/scanMarkdownShellArith end-to-end, not just correct in isolation. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * chore(#4634): consolidate the drift guard's own owner-sanction-check logic Standards review flagged the "walk to nearest preceding non-blank line, check for a phase-id-owner comment" logic as duplicated across all four detector functions in a PR whose whole point is eliminating exactly that pattern. Extracts isSanctionedByPrecedingComment, shared by all four; behavior-preserving (verified: identical output before/after, same 7 known #4619 violations, zero token/bracket/name-validity). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * chore(#4634): add Fixed changeset for the name-validity guard and allocation consolidation pr:0 placeholder — backfilled once the real PR number exists. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * fix(#4126): consolidate branch-name slug substitution into one shared renderer cmdCommit (commands.cts) and cmdInitExecutePhase (init.cts) each independently implemented branch-name template substitution, and both substituted the literal string 'phase' when phase_slug was empty or undeliverable — producing a non-identifying branch name (gsd/phase-08-phase) that contradicted the honestly-reported phase_slug: null in the same payload. Same structural defect as the other three gaps in this epic: two consumers reimplementing one concept independently instead of sharing an owner. Adds renderPhaseBranchName (src/phase-id.cts) as the sole owner: a real slug substitutes normally; an empty/undeliverable one drops the {slug} token plus one adjacent separator (collapsing/trimming the result) rather than substituting a placeholder word, for the shipped default template and any user-configured shape alike. Both call sites now delegate to it; the old inline duplicates are deleted, not kept in sync. {project} substitution stays a separate step in init.cts, unchanged, since it is a config-level field with its own fallback contract. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * test(#4126): pin renderPhaseBranchName and both migrated call sites Property-based coverage for the shared renderer's degrade-path invariant (output, when non-null, never contains {slug} and never starts/ends with a separator), plus example coverage for real-slug substitution, empty/null/ non-string slug, token position at either edge, a doubled-separator template, and the only-{slug} -> null case. One regression test each in commands.test.cjs and init.test.cjs confirms a phase with no derivable slug no longer produces a branch name ending in the literal '-phase'. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * fix: route scanExistingDecimalPhaseNumbers through the canonical enumeration owner Caught by an actual gsd-test run, not a hypothesis: the new decimal-scan helper (fix(#4569)) enumerated phases/ directories via a raw fs.readdirSync, which the pre-existing phase-enumeration drift guard (#3185/#3882) correctly flags as an unsanctioned re-derivation outside its canonical owner (listAllPhaseDirs / isSentinelPhaseId). Ironic given this epic's own thesis, and exactly why the guard exists: consolidating one seam can reintroduce drift in an adjacent one if the new code doesn't route through what's already there. Migrates the enumeration to listAllPhaseDirs; identical decimal-detection output for every existing case. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * chore(#4634): extend the drift guard for branch-slug fallback; fix a real regex bug Adds the fourth detector the epic's ratchet section names ("both branch-name sites"): bans a `.replace('{slug}', ... || 'phase')` call outright, sanctioned via renderPhaseBranchName or a dedicated comment. Wired into scanRepo (no per-file exemption — this is a banned anti-pattern everywhere, not a grammar with one legitimate owner). Now that #4126's fix (prior commit) has landed, scanRepo reports zero violations across all four .cts-scanning rules, restoring the simple "the live repo is clean" assertion instead of a pinned-known-count characterization. Also fixes a real bug an actual gsd-test run caught: findNameValidityDrift's regex didn't tolerate the doubled-backslash template-string form its own test claimed to cover (0 !== 1) — widened to \{1,2} matching TOKEN_DRIFT_RE's existing tolerance for the same two forms. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * docs(#4126): document the {slug} degrade behavior; update changeset for the full seam Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * fix: detectPhaseNumberFromFiles wrongly rejected bare, slug-less phase directories Caught by an actual gsd-test run on the #4126 regression test, not a hypothesis: a bare phase directory with no slug remainder (e.g. .planning/phases/01/) has extractPhaseToken correctly return "01" — which is simply identical to the directory name in that case, not its no-match fallback. A stale `token !== phaseDir` check treated that equality as "no numeric token found" and rejected it regardless, leaving phaseNum null and silently skipping cmdCommit's phase-branching block entirely (the commit proceeded on whatever branch was already checked out instead of the phase branch). phaseTokenShape.test(normalized) already excludes every genuine non-phase case on its own: extractPhaseToken's real no-match fallback only fires for a dirName that doesn't start with a digit or short letter+digit prefix, and normalizePhaseName's leading-\d+ requirement rejects those regardless. The equality check was redundant for real rejections and actively wrong for bare-numeric directories. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * chore: backfill changeset PR number to 4640 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> --------- Co-authored-by: sim <sim@local> Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,34 @@
|
||||
* directly above). Sites that build their regex from `PHASE_NUMBER_TOKEN_SOURCE`
|
||||
* carry no literal grammar and pass automatically.
|
||||
*
|
||||
* #4634 extends the same pattern with two more detectors:
|
||||
*
|
||||
* - name-validity-guard drift: `hasNameableContent(s)` in `src/roadmap-parser.cts`
|
||||
* is the sole owner of the "does this string have nameable content" predicate
|
||||
* (`/[\p{L}\p{N}]/u.test(s)`). Any other `src/**` file re-deriving that exact
|
||||
* character class (regex-literal or `new RegExp` template form) instead of
|
||||
* calling `hasNameableContent` is drift, sanctioned the same way as the token
|
||||
* and bracket rules (`// phase-id-owner:` on the nearest preceding non-blank
|
||||
* line), with a line-level escape for a line that already calls
|
||||
* `hasNameableContent(`.
|
||||
*
|
||||
* - shell phase-number-arithmetic ban: `$((10#...))` base-10-forced arithmetic
|
||||
* inside `gsd-core/workflows/**\/*.md` and `gsd-core/references/**\/*.md` breaks
|
||||
* on decimal or multi-segment phase ids and is banned outright. This scan runs
|
||||
* over markdown, not `.cts` source, so its sanction is an HTML comment on the
|
||||
* nearest preceding non-blank line: `<!-- phase-id-owner: <reason> -->`.
|
||||
*
|
||||
* - branch-slug fallback drift: a `.replace('{slug}', ... || 'phase')` call
|
||||
* silently substitutes the literal string `'phase'` when a phase's slug
|
||||
* can't be derived, producing a non-identifying branch name like
|
||||
* `gsd/phase-08-phase` (#4126, now fixed via the shared renderPhaseBranchName
|
||||
* owner in phase-id.cts, consumed by both prior call sites). Sanctioned
|
||||
* the same way as the token/bracket/name-validity rules (`// phase-id-owner:`
|
||||
* on the nearest preceding non-blank line), with a line-level escape for a
|
||||
* line that already calls `renderPhaseBranchName(`. Unlike the other
|
||||
* `.cts`-scanning rules, this one has no per-file exemption — it is a banned
|
||||
* anti-pattern everywhere, not a grammar with one legitimate owner site.
|
||||
*
|
||||
* Detection is intentionally NARROW: only the contiguous canonical token
|
||||
* (`\d+[A-Z]?(?:\.\d+)*`, its `[A-Za-z]` and `[.-]` near-variants, in both
|
||||
* regex-literal `\d` and `new RegExp` template `\\d` escaping) is drift. Bare
|
||||
@@ -82,6 +110,18 @@ const BRACKET_CODE_DRIFT_RE = /\[A-Z(?:a-z)?\]\[A-Z(?:a-z)?0-9_\]\*/;
|
||||
const BRACKET_OWNER_HINT =
|
||||
'BRACKET_PROJECT_CODE_SRC / BRACKET_ID_SRC / bracketMilestoneIntroSrcFor / BRACKET_MILESTONE_INTRO_CAPTURING_SRC';
|
||||
|
||||
/**
|
||||
* Pure: true if the nearest preceding non-blank line to `lines[i]` is a
|
||||
* dedicated sanction comment matching `ownerRe`. Shared by every detector in
|
||||
* this file so the "how do you sanction a finding" walk has one owner instead
|
||||
* of four independent copies that could silently diverge.
|
||||
*/
|
||||
function isSanctionedByPrecedingComment(lines, i, ownerRe) {
|
||||
let j = i - 1;
|
||||
while (j >= 0 && lines[j].trim() === '') j--; // nearest preceding non-blank line
|
||||
return j >= 0 && ownerRe.test(lines[j]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pure: find every literal re-derivation of the canonical phase-number token in
|
||||
* `text` that is NOT sanctioned. A site is sanctioned when the nearest preceding
|
||||
@@ -100,9 +140,7 @@ function findPhaseIdRegexDrift(text) {
|
||||
const m = TOKEN_DRIFT_RE.exec(line);
|
||||
if (!m) continue;
|
||||
if (line.includes(CANON_REF)) continue;
|
||||
let j = i - 1;
|
||||
while (j >= 0 && lines[j].trim() === '') j--; // nearest preceding non-blank line
|
||||
if (j >= 0 && OWNER_RE.test(lines[j])) continue;
|
||||
if (isSanctionedByPrecedingComment(lines, i, OWNER_RE)) continue;
|
||||
out.push({ line: i + 1, found: m[0] });
|
||||
}
|
||||
return out;
|
||||
@@ -122,21 +160,148 @@ function findBracketGrammarDrift(text) {
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const m = BRACKET_CODE_DRIFT_RE.exec(lines[i]);
|
||||
if (!m) continue;
|
||||
let j = i - 1;
|
||||
while (j >= 0 && lines[j].trim() === '') j--; // nearest preceding non-blank line
|
||||
if (j >= 0 && OWNER_RE.test(lines[j])) continue;
|
||||
if (isSanctionedByPrecedingComment(lines, i, OWNER_RE)) continue;
|
||||
out.push({ line: i + 1, found: m[0] });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// #4634: the name-validity-guard grammar — `hasNameableContent(s)` in
|
||||
// `src/roadmap-parser.cts` is `/[\p{L}\p{N}]/u.test(s)`. Tolerates both the
|
||||
// regex-literal single-backslash form and the doubled-backslash template
|
||||
// form (`new RegExp('[\\p{L}\\p{N}]'`), mirroring how TOKEN_DRIFT_RE tolerates
|
||||
// both escapings.
|
||||
const NAME_VALIDITY_DRIFT_RE = /\[\\{1,2}p\{L\}\\{1,2}p\{N\}\]/;
|
||||
const NAME_VALIDITY_CANON_REF = 'hasNameableContent(';
|
||||
|
||||
/**
|
||||
* Pure: find every literal re-derivation of the canonical name-validity
|
||||
* character class in `text` that is NOT sanctioned. Same sanction mechanism
|
||||
* as the token/bracket rules — a dedicated `// phase-id-owner:` comment on
|
||||
* the nearest preceding non-blank line — plus a line-level escape for a line
|
||||
* that already calls `hasNameableContent(`. Returns [{ line, found }].
|
||||
*/
|
||||
function findNameValidityDrift(text) {
|
||||
const out = [];
|
||||
const lines = text.split('\n');
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const line = lines[i];
|
||||
const m = NAME_VALIDITY_DRIFT_RE.exec(line);
|
||||
if (!m) continue;
|
||||
if (line.includes(NAME_VALIDITY_CANON_REF)) continue;
|
||||
if (isSanctionedByPrecedingComment(lines, i, OWNER_RE)) continue;
|
||||
out.push({ line: i + 1, found: m[0] });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// #4634: the branch-slug fallback anti-pattern (#4126) — a
|
||||
// `.replace('{slug}', ... || 'phase')` call silently falls back to the
|
||||
// literal string `'phase'` when a phase's slug can't be derived, producing a
|
||||
// non-identifying branch name like `gsd/phase-08-phase`. Now fixed at both
|
||||
// prior call sites (commands.cts, init.cts) via the shared
|
||||
// `renderPhaseBranchName` owner in phase-id.cts; this rule is the ratchet
|
||||
// against a THIRD site reintroducing the inline fallback. Deliberately
|
||||
// narrow: it requires the literal `'phase'` fallback on the same line as the
|
||||
// `{slug}` template token, so it does NOT match the sibling milestone-branch
|
||||
// fallback (`|| 'milestone'`), which is a different, correct-as-is case.
|
||||
const BRANCH_SLUG_FALLBACK_DRIFT_RE = /\{slug\}'.*\|\|\s*'phase'/;
|
||||
|
||||
// The canonical fix is `renderPhaseBranchName(...)`. There is no "owner file"
|
||||
// for this rule the way there is for the token/bracket/name-validity
|
||||
// grammars above — it is a banned anti-pattern everywhere, so no per-file
|
||||
// exemption exists.
|
||||
const BRANCH_SLUG_FALLBACK_CANON_REF = 'renderPhaseBranchName(';
|
||||
|
||||
/**
|
||||
* Pure: find every unsanctioned branch-slug `|| 'phase'` fallback in `text`.
|
||||
* Same sanction mechanism as the token/bracket/name-validity rules — a
|
||||
* dedicated `// phase-id-owner:` comment on the nearest preceding non-blank
|
||||
* line — plus a line-level escape for a line that already calls
|
||||
* `renderPhaseBranchName(`. Returns [{ line, found }].
|
||||
*/
|
||||
function findBranchSlugFallbackDrift(text) {
|
||||
const out = [];
|
||||
const lines = text.split('\n');
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const line = lines[i];
|
||||
const m = BRANCH_SLUG_FALLBACK_DRIFT_RE.exec(line);
|
||||
if (!m) continue;
|
||||
if (line.includes(BRANCH_SLUG_FALLBACK_CANON_REF)) continue;
|
||||
if (isSanctionedByPrecedingComment(lines, i, OWNER_RE)) continue;
|
||||
out.push({ line: i + 1, found: m[0] });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// #4634: ban base-10-forced shell arithmetic (`$((10#...))`) on any variable —
|
||||
// this construct is exactly the pattern that breaks on a decimal or
|
||||
// multi-segment phase id, so any occurrence is banned outright, full stop.
|
||||
const SHELL_PHASE_ARITH_DRIFT_RE = /\$\(\(\s*10#/;
|
||||
|
||||
// A markdown comment can't easily carry a `//` line, so the sanction for the
|
||||
// shell-arithmetic rule is an HTML comment on the nearest preceding non-blank
|
||||
// line: `<!-- phase-id-owner: <reason> -->`.
|
||||
const MD_OWNER_RE = /^\s*<!--.*phase-id-owner:/;
|
||||
|
||||
/**
|
||||
* Pure: find every unsanctioned `$((10#...))` base-10-forced shell arithmetic
|
||||
* site in `text`. Sanctioned by an HTML comment `<!-- phase-id-owner: ... -->`
|
||||
* on the nearest preceding non-blank line. Returns [{ line, found }].
|
||||
*/
|
||||
function findShellPhaseArithDrift(text) {
|
||||
const out = [];
|
||||
const lines = text.split('\n');
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const m = SHELL_PHASE_ARITH_DRIFT_RE.exec(lines[i]);
|
||||
if (!m) continue;
|
||||
if (isSanctionedByPrecedingComment(lines, i, MD_OWNER_RE)) continue;
|
||||
out.push({ line: i + 1, found: m[0] });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// #4634: the markdown scan roots — shell embedded in workflow/reference docs.
|
||||
const MD_SCAN_DIRS = [path.join('gsd-core', 'workflows'), path.join('gsd-core', 'references')];
|
||||
|
||||
/**
|
||||
* Scan `gsd-core/workflows/**\/*.md` and `gsd-core/references/**\/*.md` for
|
||||
* unsanctioned `$((10#...))` shell arithmetic. Returns [{ file, line, found }]
|
||||
* with repo-relative paths.
|
||||
*/
|
||||
function scanMarkdownShellArith(root) {
|
||||
const violations = [];
|
||||
for (const dir of MD_SCAN_DIRS) {
|
||||
for (const file of walkMd(path.join(root, dir), [])) {
|
||||
const rel = path.relative(root, file);
|
||||
let text;
|
||||
try {
|
||||
text = fs.readFileSync(file, 'utf8');
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
for (const d of findShellPhaseArithDrift(text)) {
|
||||
violations.push({ file: rel, kind: 'shell-arith', ...d });
|
||||
}
|
||||
}
|
||||
}
|
||||
return violations;
|
||||
}
|
||||
|
||||
// Authored TypeScript source only (the generated bin/lib/*.cjs mirror it).
|
||||
const SCAN_DIRS = ['src'];
|
||||
const SCAN_EXT = new Set(['.cts', '.ts', '.mts']);
|
||||
// The canonical owner defines the grammar; it is exempt by construction.
|
||||
const EXEMPT = new Set([path.join('src', 'phase-id.cts')]);
|
||||
|
||||
function walk(dir, acc) {
|
||||
// #4634: the name-validity-guard rule owns a DIFFERENT file (roadmap-parser.cts
|
||||
// defines `hasNameableContent`), so it needs its own exemption set — the
|
||||
// token/bracket rules above must NOT start exempting roadmap-parser.cts too,
|
||||
// since it is not their owner.
|
||||
const NAME_VALIDITY_EXEMPT = new Set([path.join('src', 'roadmap-parser.cts')]);
|
||||
|
||||
function walk(dir, acc, ext) {
|
||||
const extSet = ext || SCAN_EXT;
|
||||
let entries;
|
||||
try {
|
||||
entries = fs.readdirSync(dir, { withFileTypes: true });
|
||||
@@ -147,14 +312,22 @@ function walk(dir, acc) {
|
||||
const full = path.join(dir, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
if (entry.name === 'node_modules' || entry.name === 'dist' || entry.name === '.git') continue;
|
||||
walk(full, acc);
|
||||
} else if (entry.isFile() && SCAN_EXT.has(path.extname(entry.name))) {
|
||||
walk(full, acc, extSet);
|
||||
} else if (entry.isFile() && extSet.has(path.extname(entry.name))) {
|
||||
acc.push(full);
|
||||
}
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
|
||||
// #4634: markdown scan for the shell phase-arithmetic ban walks a disjoint set
|
||||
// of roots/extensions from the src/**/*.cts scan above, so it gets its own thin
|
||||
// wrapper over the same `walk` rather than a parallel tree-walker.
|
||||
const MD_EXT = new Set(['.md']);
|
||||
function walkMd(dir, acc) {
|
||||
return walk(dir, acc, MD_EXT);
|
||||
}
|
||||
|
||||
// ─── #2761 M4: the heading-baseline selector census ────────────────────────
|
||||
//
|
||||
// `phaseHeadingPrefixSrcFor(PHASE_HEADING_BASELINE.<MODE>)` is the other half
|
||||
@@ -239,23 +412,55 @@ function scanRepo(root) {
|
||||
for (const d of findBracketGrammarDrift(text)) {
|
||||
violations.push({ file: rel, kind: 'bracket', ...d });
|
||||
}
|
||||
// #4634: name-validity-guard drift, exempting only its own owner file.
|
||||
if (!NAME_VALIDITY_EXEMPT.has(rel)) {
|
||||
for (const d of findNameValidityDrift(text)) {
|
||||
violations.push({ file: rel, kind: 'name-validity', ...d });
|
||||
}
|
||||
}
|
||||
// #4634: branch-slug fallback anti-pattern, exempt nowhere.
|
||||
for (const d of findBranchSlugFallbackDrift(text)) {
|
||||
violations.push({ file: rel, kind: 'branch-slug-fallback', ...d });
|
||||
}
|
||||
}
|
||||
}
|
||||
return violations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan EVERYTHING this seam guards: the `src/**\/*.cts` token/bracket/
|
||||
* name-validity invariants (`scanRepo`) plus the markdown shell
|
||||
* phase-arithmetic ban (`scanMarkdownShellArith`). This is what the CLI runs;
|
||||
* `scanRepo` alone stays narrowly scoped to its original src/** contract so
|
||||
* a live, separately-tracked markdown defect (#4619) cannot make the
|
||||
* pinned-clean `scanRepo` test spuriously fail.
|
||||
*/
|
||||
function scanAll(root) {
|
||||
return [...scanRepo(root), ...scanMarkdownShellArith(root)];
|
||||
}
|
||||
|
||||
function main() {
|
||||
const root = path.join(__dirname, '..');
|
||||
const violations = scanRepo(root);
|
||||
const violations = scanAll(root);
|
||||
if (violations.length === 0) {
|
||||
process.stdout.write('ok phase-id-drift: no unsanctioned phase-token or bracket-grammar re-derivations outside phase-id.cts\n');
|
||||
process.stdout.write(
|
||||
'ok phase-id-drift: no unsanctioned phase-token, bracket-grammar, name-validity, ' +
|
||||
'branch-slug-fallback, or shell phase-arithmetic re-derivations found\n',
|
||||
);
|
||||
return;
|
||||
}
|
||||
process.stderr.write('phase-id-drift: literal re-derivation(s) of a canonical grammar found.\n');
|
||||
process.stderr.write(`Build the regex from phase-id.cjs \`${CANON_REF}\` (or phaseMarkdownRegexSource for a\n`);
|
||||
process.stderr.write(`known number) for the phase-number token, or from ${BRACKET_OWNER_HINT}\n`);
|
||||
process.stderr.write('for the bracket grammar — or sanction the site with a dedicated\n');
|
||||
process.stderr.write('`// phase-id-owner: <reason>` comment on the line directly above the regex:\n');
|
||||
process.stderr.write('for the bracket grammar, or call `hasNameableContent(` (src/roadmap-parser.cts) for\n');
|
||||
process.stderr.write('the name-validity predicate — or sanction the site with a dedicated\n');
|
||||
process.stderr.write('`// phase-id-owner: <reason>` comment on the line directly above the regex.\n');
|
||||
process.stderr.write('`$((10#...))` base-10-forced shell arithmetic is banned outright in\n');
|
||||
process.stderr.write('gsd-core/workflows/**/*.md and gsd-core/references/**/*.md — sanction with\n');
|
||||
process.stderr.write('`<!-- phase-id-owner: <reason> -->` on the line directly above.\n');
|
||||
process.stderr.write('A `.replace(\'{slug}\', ... || \'phase\')` fallback is banned outright (#4126) —\n');
|
||||
process.stderr.write('use `renderPhaseBranchName(` or sanction with\n');
|
||||
process.stderr.write('`// phase-id-owner: <reason>` on the line directly above:\n');
|
||||
for (const d of violations) {
|
||||
process.stderr.write(` [${d.kind}] ${d.file}:${d.line} ${d.found}\n`);
|
||||
}
|
||||
@@ -267,9 +472,17 @@ if (require.main === module) main();
|
||||
module.exports = {
|
||||
findPhaseIdRegexDrift,
|
||||
findBracketGrammarDrift,
|
||||
findNameValidityDrift,
|
||||
findBranchSlugFallbackDrift,
|
||||
findShellPhaseArithDrift,
|
||||
scanMarkdownShellArith,
|
||||
scanRepo,
|
||||
scanAll,
|
||||
countSelectorBaselines,
|
||||
scanSelectorBaselines,
|
||||
TOKEN_DRIFT_RE,
|
||||
BRACKET_CODE_DRIFT_RE,
|
||||
NAME_VALIDITY_DRIFT_RE,
|
||||
BRANCH_SLUG_FALLBACK_DRIFT_RE,
|
||||
SHELL_PHASE_ARITH_DRIFT_RE,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user