* test(#4748): pin the letter-axis defect at the seven shell sites outside #4660's six
Extends tests/nsegment-phase-grammar.test.cjs one class over: for each of the
seven sites the live shell lines are read off disk by anchor and executed in
bash against a letter-suffixed fixture. The four `$((10#$PHASE_INT))` split
sites must yield PHASE_N without a shell error for `03A` / `12A` / `3A` /
`03A.1.2` and the commit-scope ERE they build must match both `feat(3A-01):`
and `feat(03A-1):`; the review-file lookup must bind init's `padded_phase`
rather than re-pad in shell; the `--from`/`--to`/`--only` and
plan-review-convergence extractions must return `12A` / `23A.1.2` (and
`23.1.2`) whole; the legacy normalizer must pad `3A` to `03A` and must not
mangle an already-padded `08`. Every pre-existing shape (`06`, `08.5`,
`23.1.2`, `36.14`) is a regression control.
tests/init.test.cjs asserts `init execute-phase` emits `padded_phase` for a
directory-backed `03A`, a ROADMAP-only `4B` (→ `04B`), the existing ROADMAP
fallback `1` (→ `01`), and `null` when the phase is not found.
Negative control against the unfixed tree: 41 failures in the grammar file,
exactly the "(fails before the fix)" cases and the three derived from them
(scope ERE, three-flag extraction, the `08` octal trap); 2 in init.test.cjs,
both the new assertions. Every regression control already green.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017cjzdZtYjcBAa3Lqh2VrLK
* fix(#4748): carry a letter-suffixed phase id through the seven shell sites that aborted or truncated it
The canonical phase-number grammar (src/phase-id.cts) is digits, an optional
uppercase letter, then dotted segments — `12A`, `3A`, `23A.1.2` are documented
shapes that `init`, `phase-id.cts` and `phase remove` renumbering already
round-trip. Seven shell sites in shipped workflows and references still
assumed digits-and-dots. Four classes, one fix each:
Class 1 — `PHASE_INT=${PHASE_NUMBER%%.*}; $((10#$PHASE_INT))` (execute-phase.md
×2, completion-reconciliation.md, tdd.md). The post-#4619 split stops at the
first DOT, so on `03A` the "integer" is `03A` and bash aborts with `value too
great for base`. Split at the first NON-DIGIT instead (`%%[!0-9]*`): the
integer half is a pure digit run, and the letter rides along in the rest the
way the dotted fraction already did — `03A.1.2` → PHASE_N `3A\.1\.2`, so the
#4003 zero-pad-tolerant scope ERE matches both `feat(3A-01):` and
`feat(03A-1):`. Byte-identical output for every id that worked before.
Class 2 — `PADDED=$(printf "%02d" "${PHASE_NUMBER}")` before the REVIEW.md
lookup (execute-phase.md). `printf` cannot pad a letter id (prints `03`,
exits 1) — and cannot even re-pad an already-padded `08`, which bash reads as
an invalid octal and prints as `00`, so the lookup resolved phases 08 and 09
to `00-REVIEW.md` today. The disk path hands the workflow the directory's
padded number but the ROADMAP fallback hands it the heading's bare one, which
is why the re-pad existed. `cmdInitExecutePhase` now emits `padded_phase`
through `normalizePhaseName`, exactly as the plan-phase and code-review inits
do, and the workflow binds `{padded_phase}` instead of re-deriving.
Class 3 — `grep -oE '[0-9]+\.?[0-9]*'` (autonomous.md `--from`/`--to`/`--only`,
plan-review-convergence.md). Stops at the letter, so `--from 12A` ran from
phase 12 with no error. Now the canonical ERE `[0-9]+[A-Z]?(\.[0-9]+)*`, which
also closes the single-segment dot-axis gap the same shape carried (`23.1.2`
→ `23.1`, #4568's class in a spelling neither lint saw).
Class 4 — the legacy manual normalizer (phase-argument-parsing.md, reached
from mvp-phase.md). Its two branches (`^[0-9]+$`, `^[0-9]+\.[0-9]+$`) left
`12A` unpadded and never padded `3A` to the `03A` a directory carries; its
integer branch also hit the same `printf` octal trap on `08`. One branch for
the whole canonical token now, padding the digit run via `$((10#…))`.
Whether this legacy surface should instead be retired in favour of `init`'s
normalization is the maintainer call the issue names; extending it keeps the
documented contract true either way.
Driven end to end: `init execute-phase 3A` on a fixture with a
`03A-letter-variant/` directory emits `phase_number: "03A"` and now
`padded_phase: "03A"`; on a ROADMAP-only `### Phase 4B:` it emits `"4B"` /
`"04B"`. The issue's own evidence line claimed `padded_phase` was already in
the execute-phase init output — it was not; that key is emitted by the
code-review / plan-phase inits, which is where the claim was read from.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017cjzdZtYjcBAa3Lqh2VrLK
* chore(#4634): extend lint-phase-id-drift with three ratchets for letter-hostile phase-id consumers
The rules that landed with #4619, #4568 and #4660 police grammar MIRRORS —
regexes that describe a phase id. The #4748 sites are CONSUMERS of one, and
every existing rule reported clean on them: the shell-arithmetic rule's
`_INT` escape trusts a NAME the dot-only split did not earn on `03A`; the
`[0-9]+\.?[0-9]*` shape is neither the bounded form the single-segment rule
bans nor the unbounded form the letterless rule inspects; and nothing looked
at `printf "%02d"` at all. Three narrow additions, one per shape:
- findDotOnlyIntegerSplitDrift — `X_INT=${<phase-var>%%.*}`; the safe split
is `%%[!0-9]*`. Keys on the SOURCE variable being phase-carrying.
- findLooseDottedPhaseRegexDrift — `[0-9]+\.?[0-9]*` / `\d+\.?\d*` on a
phase-carrying line; the canonical form is `[0-9]+[A-Z]?(\.[0-9]+)*`.
Disjoint from the two sibling regex rules by construction.
- findShellPhasePrintfPadDrift — `printf "%0Nd" …` whose arguments name a
phase-carrying, non-`_INT` variable; a pad of an `_INT` via `$((10#…))`
and a `{padded_phase}` binding are the sanctioned shapes.
Same `<!-- phase-id-owner: … -->` sanction, same scan roots as their nearest
sibling (shell idioms over workflows + references, the regex shape over
workflows + references + agents), same documented limit of a per-line
textual scan. The post-#4619 comment that described the `_INT` convention
as proven by `%%.*` is corrected to name the digit-run split. Confirmed
against the base commit: each rule fires on exactly its own unfixed sites
(2+1+1, 3+1, 1+1) and zero violations remain on the fixed tree.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017cjzdZtYjcBAa3Lqh2VrLK
* docs(#4748): add Fixed changeset
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017cjzdZtYjcBAa3Lqh2VrLK
* chore(#4748): refresh the compact-content benchmark baseline and acknowledge emitted growth
The three top-level workflow files below grew by the letter-aware split, the
canonical extraction ERE, the `{padded_phase}` binding, and the comment lines
that name the grammar each site now honours. The committed compact-content
benchmark moved with them; refreshed with `benchmark-compact-content.cjs
--write` (aggregate reduction 15.47% -> 15.45%).
Emitted-Drift-Ack-Growth: execute-phase.md — #4748: first-non-digit PHASE_INT split at the plan-selection and TDD-gate sites, `{padded_phase}` binding at the REVIEW.md lookup, and the comments naming why (482 bytes)
Emitted-Drift-Ack-Growth: autonomous.md — #4748: canonical `[0-9]+[A-Z]?(\.[0-9]+)*` at the --from/--to/--only extractions plus one comment naming the grammar (249 bytes)
Emitted-Drift-Ack-Growth: plan-review-convergence.md — #4748: canonical `[0-9]+[A-Z]?(\.[0-9]+)*` at the phase extraction plus one comment naming the grammar (160 bytes)
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017cjzdZtYjcBAa3Lqh2VrLK
* fix(#4748): name padded_phase in execute-phase.md's init parse list
A `{field}` token inside a workflow bash block is substituted from the init
JSON only for fields the workflow tells the model to parse. `phase_number`
is on that list; `padded_phase` was not, so the `PADDED="{padded_phase}"`
binding at the review lookup would have been a literal — for every phase,
not only letter ones. Found by the pre-file adversarial review (claim 2, the
author's own named suspicion); the test now asserts the parse list carries
the field beside `phase_number`.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017cjzdZtYjcBAa3Lqh2VrLK
* chore(#4634): key the dot-only split rule on its source and widen the printf rule to any %d form
Two false negatives from the pre-file adversarial review of the three #4748
ratchets: `PHASE_PREFIX=${PHASE_NUMBER%%.*}` escaped the split rule because
the destination did not end in `_INT` (the defect is the split, not the
name it lands in), and `printf '%02d'` / `printf "%2d"` escaped the printf
rule because it required double quotes and the zero flag (`%d` cannot parse
a letter id under any width). Both rules now key on the phase-carrying
SOURCE alone; base-site firing counts are unchanged (2+1+1, 1+1) and the
fixed tree stays at zero. The `[[:digit:]]` spelling and the `/phase/i`
heuristic remain the sibling rules' documented limits.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017cjzdZtYjcBAa3Lqh2VrLK
* chore(#4748): refresh the compact-content benchmark baseline after the parse-list edit
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017cjzdZtYjcBAa3Lqh2VrLK
* test(#4748): compose init's emitted padded_phase through the live REVIEW.md lookup
The Class 2 site is a `{padded_phase}` template token, which no test can
execute as written. This substitutes the value init emits
(`normalizePhaseName`) into the three live lookup lines and runs them
against a fixture, so the emitted value, the binding, the path construction
and the status extraction are exercised together — `03A-REVIEW.md` and
`08-REVIEW.md` each resolve to their own status. Suggested by the resumed
adversarial review pass (claim C).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017cjzdZtYjcBAa3Lqh2VrLK
* test(#4748): move the #4619 and #4003 source-parity pins to the letter-safe split
tests/execute-phase-decimal-arithmetic.test.cjs and
tests/safe-resume-gate-anchoring.test.cjs pin the four Class 1 sites'
snippet byte-for-byte, so the first-non-digit split reddened both in the
whole-suite run (scripts/ci-test-scope.cjs does not select either file for
a workflow edit — the scoped run was green). The pinned snippet is now the
shipped one, and the behavioural half of the #4619 file gains the letter
case (`03A` → `3A`, `23A.1.2` → `23A\.1\.2`) beside its decimal cases.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017cjzdZtYjcBAa3Lqh2VrLK
* chore(#4634): key the dot-only split rule on the _INT destination again, tolerating the quoted spelling
Keying on the source alone (the previous commit's widening, from a review
probe) flags `PARENT_PHASE="${PHASE_NUMBER%%.*}"` in
gap-closure-artifacts.md — a correct derivation that wants everything
before the first dot, letter included. The defect this rule polices is a
dot split INTO the name the shell-arithmetic rule trusts as an integer, so
`_INT` is the discriminator on purpose; the quoted spelling that site uses
is now tolerated so the same shape into an `_INT` cannot hide behind it.
Base-site firing unchanged (2+1+1), zero on the fixed tree, and the
parent-phase line is pinned as a silent case.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017cjzdZtYjcBAa3Lqh2VrLK
* test(#4748): use t.after() for the composition test's fixture cleanup
CONTRIBUTING forbids try/finally inside a test body; the per-test cleanup
form is `t.after(() => cleanup(dir))`. Flagged by the filing driver's
test-ruleset gate before the PR was created.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017cjzdZtYjcBAa3Lqh2VrLK
* chore(#4748): set changeset fragment pr to 4768
* chore(#4748): refresh the compact-content benchmark baseline after rebasing onto next
Regenerated with `node scripts/benchmark-compact-content.cjs --write` on the
rebased tree (base 0d6bf19bf); `--check` confirms it matches the live recompute.
Only the execute-phase split and the aggregate totals differ from next's copy.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017cjzdZtYjcBAa3Lqh2VrLK
---------
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: Tom Boucher <trekkie@nomorestars.com>
335 lines
15 KiB
JavaScript
335 lines
15 KiB
JavaScript
'use strict';
|
|
|
|
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const path = require('node:path');
|
|
|
|
const {
|
|
findNameValidityDrift,
|
|
findBranchSlugFallbackDrift,
|
|
findShellPhaseArithDrift,
|
|
findSingleSegmentPhaseRegexDrift,
|
|
scanMarkdownSingleSegmentPhaseRegex,
|
|
findLetterlessPhaseMirrorDrift,
|
|
scanMarkdownLetterlessPhaseMirror,
|
|
findDotOnlyIntegerSplitDrift,
|
|
findLooseDottedPhaseRegexDrift,
|
|
findShellPhasePrintfPadDrift,
|
|
scanMarkdownLetterAxisConsumers,
|
|
} = require('../scripts/lint-phase-id-drift.cjs');
|
|
|
|
const ROOT = path.join(__dirname, '..');
|
|
|
|
test('findNameValidityDrift flags a regex-literal re-derivation of the name-validity class', () => {
|
|
const text = [
|
|
'function isNameable(s) {',
|
|
' return /[\\p{L}\\p{N}]/u.test(s);',
|
|
'}',
|
|
].join('\n');
|
|
const found = findNameValidityDrift(text);
|
|
assert.equal(found.length, 1);
|
|
assert.equal(found[0].line, 2);
|
|
});
|
|
|
|
test('findNameValidityDrift flags the doubled-backslash template-string form', () => {
|
|
const text = [
|
|
'const re = new RegExp(\'[\\\\p{L}\\\\p{N}]\', "u");',
|
|
].join('\n');
|
|
const found = findNameValidityDrift(text);
|
|
assert.equal(found.length, 1);
|
|
});
|
|
|
|
test('findNameValidityDrift does NOT flag a line that calls hasNameableContent(', () => {
|
|
const text = [
|
|
'function wrapper(s) {',
|
|
' return hasNameableContent(s);',
|
|
'}',
|
|
].join('\n');
|
|
assert.deepEqual(findNameValidityDrift(text), []);
|
|
});
|
|
|
|
test('findNameValidityDrift does NOT flag a sanctioned site', () => {
|
|
const text = [
|
|
'// phase-id-owner: deliberate local copy for perf, tracked in #4634',
|
|
'const re = /[\\p{L}\\p{N}]/u;',
|
|
].join('\n');
|
|
assert.deepEqual(findNameValidityDrift(text), []);
|
|
});
|
|
|
|
test('findBranchSlugFallbackDrift flags the commands.cts/init.cts {slug}-fallback shape', () => {
|
|
const text =
|
|
" .replace('{slug}', (phaseInfo['phase_slug'] as string) || 'phase');";
|
|
const found = findBranchSlugFallbackDrift(text);
|
|
assert.equal(found.length, 1);
|
|
assert.equal(found[0].line, 1);
|
|
});
|
|
|
|
test('findBranchSlugFallbackDrift does NOT flag the milestone-branch || \'milestone\' fallback', () => {
|
|
const text =
|
|
" .replace('{slug}', generateSlugInternal(milestone.name) || 'milestone');";
|
|
assert.deepEqual(findBranchSlugFallbackDrift(text), []);
|
|
});
|
|
|
|
test('findBranchSlugFallbackDrift does NOT flag a sanctioned site', () => {
|
|
const text = [
|
|
'// phase-id-owner: deliberate, tracked in #4634',
|
|
" .replace('{slug}', (phaseInfo['phase_slug'] as string) || 'phase');",
|
|
].join('\n');
|
|
assert.deepEqual(findBranchSlugFallbackDrift(text), []);
|
|
});
|
|
|
|
test('findShellPhaseArithDrift flags $((10#...)) base-10-forced arithmetic', () => {
|
|
const text = 'PHASE_N=$((10#$PHASE_NUM))';
|
|
const found = findShellPhaseArithDrift(text);
|
|
assert.equal(found.length, 1);
|
|
assert.equal(found[0].line, 1);
|
|
});
|
|
|
|
test('findShellPhaseArithDrift does NOT flag ordinary arithmetic', () => {
|
|
const text = 'NEXT=$((i+1))';
|
|
assert.deepEqual(findShellPhaseArithDrift(text), []);
|
|
});
|
|
|
|
test('findShellPhaseArithDrift does NOT flag a site sanctioned with an HTML comment', () => {
|
|
const text = [
|
|
'<!-- phase-id-owner: deliberate, tracked in #4634 -->',
|
|
'PHASE_N=$((10#$PHASE_NUM))',
|
|
].join('\n');
|
|
assert.deepEqual(findShellPhaseArithDrift(text), []);
|
|
});
|
|
|
|
test('findShellPhaseArithDrift still flags a raw un-reduced phase variable (#4619 regression)', () => {
|
|
const text = 'PHASE_N=$((10#$PHASE_NUMBER))';
|
|
const found = findShellPhaseArithDrift(text);
|
|
assert.equal(found.length, 1);
|
|
assert.equal(found[0].line, 1);
|
|
});
|
|
|
|
test('findShellPhaseArithDrift does NOT flag arithmetic on an already-`_INT`-reduced phase variable', () => {
|
|
const text = [
|
|
'PHASE_INT=${PHASE_NUMBER%%.*}',
|
|
'PHASE_N=$((10#$PHASE_INT))',
|
|
].join('\n');
|
|
assert.deepEqual(findShellPhaseArithDrift(text), []);
|
|
});
|
|
|
|
test('findShellPhaseArithDrift does NOT flag arithmetic on a plan-id variable (never phase-carrying)', () => {
|
|
const text = 'PLAN_N=$((10#${PLAN_ID}))';
|
|
assert.deepEqual(findShellPhaseArithDrift(text), []);
|
|
});
|
|
|
|
test('findShellPhaseArithDrift skips a full-line comment merely mentioning the pattern as prose', () => {
|
|
const text = '# Note: $((10#$PHASE_NUMBER)) is a hard shell syntax error on a decimal id.';
|
|
assert.deepEqual(findShellPhaseArithDrift(text), []);
|
|
});
|
|
|
|
// #4568 (epic #4634): the single-optional-dotted-segment phase regex ban.
|
|
test('findSingleSegmentPhaseRegexDrift flags the bounded [0-9]+(\\.[0-9]+)? shape on a phase-carrying line', () => {
|
|
const text = 'if ! [[ "$PADDED_PHASE" =~ ^[0-9]+(\\.[0-9]+)?$ ]]; then';
|
|
const found = findSingleSegmentPhaseRegexDrift(text);
|
|
assert.equal(found.length, 1);
|
|
assert.equal(found[0].line, 1);
|
|
});
|
|
|
|
test('findSingleSegmentPhaseRegexDrift flags the \\d near-variant on a phase-carrying line', () => {
|
|
const text = 'if ! [[ "$padded_phase" =~ ^\\d+(\\.\\d+)?$ ]]; then';
|
|
const found = findSingleSegmentPhaseRegexDrift(text);
|
|
assert.equal(found.length, 1);
|
|
});
|
|
|
|
test('findSingleSegmentPhaseRegexDrift flags the doubled-backslash template-string form', () => {
|
|
const text = "const re = new RegExp('^\\\\d+(\\\\.\\\\d+)?$'); // phase check";
|
|
const found = findSingleSegmentPhaseRegexDrift(text);
|
|
assert.equal(found.length, 1);
|
|
});
|
|
|
|
test('findSingleSegmentPhaseRegexDrift is SILENT on the fixed unbounded (*) form', () => {
|
|
const text = 'if ! [[ "$PADDED_PHASE" =~ ^[0-9]+(\\.[0-9]+)*$ ]]; then';
|
|
assert.deepEqual(findSingleSegmentPhaseRegexDrift(text), []);
|
|
});
|
|
|
|
test('findSingleSegmentPhaseRegexDrift does NOT flag a non-phase-carrying line (e.g. a version number)', () => {
|
|
const text = 'if ! [[ "$VERSION" =~ ^[0-9]+(\\.[0-9]+)?$ ]]; then';
|
|
assert.deepEqual(findSingleSegmentPhaseRegexDrift(text), []);
|
|
});
|
|
|
|
test('findSingleSegmentPhaseRegexDrift does NOT flag a site sanctioned with an HTML comment', () => {
|
|
const text = [
|
|
'<!-- phase-id-owner: deliberate, tracked in #4634 -->',
|
|
'if ! [[ "$PADDED_PHASE" =~ ^[0-9]+(\\.[0-9]+)?$ ]]; then',
|
|
].join('\n');
|
|
assert.deepEqual(findSingleSegmentPhaseRegexDrift(text), []);
|
|
});
|
|
|
|
test('scanMarkdownSingleSegmentPhaseRegex against the real repo tree reports zero violations (#4568 fixed)', () => {
|
|
const violations = scanMarkdownSingleSegmentPhaseRegex(ROOT);
|
|
assert.deepEqual(violations, []);
|
|
});
|
|
|
|
// #4660 (epic #4634): the letter-less phase-mirror ban — the letter-axis twin
|
|
// of the single-segment rule above.
|
|
test('findLetterlessPhaseMirrorDrift flags the digit-only [0-9]+(\\.[0-9]+)* shape on a phase-carrying line', () => {
|
|
const text = 'if ! [[ "$PADDED_PHASE" =~ ^[0-9]+(\\.[0-9]+)*$ ]]; then';
|
|
const found = findLetterlessPhaseMirrorDrift(text);
|
|
assert.equal(found.length, 1);
|
|
assert.equal(found[0].line, 1);
|
|
});
|
|
|
|
test('findLetterlessPhaseMirrorDrift flags the extracting grep -oE form', () => {
|
|
const text = "PHASE=$(echo \"$PLAN_PATH\" | grep -oE '[0-9]+(\\.[0-9]+)*-[0-9]+')";
|
|
assert.equal(findLetterlessPhaseMirrorDrift(text).length, 1);
|
|
});
|
|
|
|
test('findLetterlessPhaseMirrorDrift flags the \\d near-variant on a phase-carrying line', () => {
|
|
const text = 'if ! [[ "$padded_phase" =~ ^\\d+(\\.\\d+)*$ ]]; then';
|
|
assert.equal(findLetterlessPhaseMirrorDrift(text).length, 1);
|
|
});
|
|
|
|
test('findLetterlessPhaseMirrorDrift is SILENT on the fixed [A-Z]? form', () => {
|
|
const text = 'if ! [[ "$PADDED_PHASE" =~ ^[0-9]+[A-Z]?(\\.[0-9]+)*$ ]]; then';
|
|
assert.deepEqual(findLetterlessPhaseMirrorDrift(text), []);
|
|
});
|
|
|
|
test('findLetterlessPhaseMirrorDrift tolerates the case-flexible [A-Za-z]? directory-scanning variant', () => {
|
|
const text = 'if [[ "$phase_dir" =~ ^[0-9]+[A-Za-z]?(\\.[0-9]+)*- ]]; then';
|
|
assert.deepEqual(findLetterlessPhaseMirrorDrift(text), []);
|
|
});
|
|
|
|
test('findLetterlessPhaseMirrorDrift does NOT flag the bounded single-segment shape (that is the other rule)', () => {
|
|
const text = 'if ! [[ "$PADDED_PHASE" =~ ^[0-9]+(\\.[0-9]+)?$ ]]; then';
|
|
assert.deepEqual(findLetterlessPhaseMirrorDrift(text), []);
|
|
});
|
|
|
|
test('findLetterlessPhaseMirrorDrift does NOT flag a non-phase-carrying line (e.g. a version number)', () => {
|
|
const text = 'if ! [[ "$VERSION" =~ ^[0-9]+(\\.[0-9]+)*$ ]]; then';
|
|
assert.deepEqual(findLetterlessPhaseMirrorDrift(text), []);
|
|
});
|
|
|
|
test('findLetterlessPhaseMirrorDrift does NOT flag a site sanctioned with an HTML comment', () => {
|
|
const text = [
|
|
'<!-- phase-id-owner: deliberate, tracked in #4660 -->',
|
|
'if ! [[ "$PADDED_PHASE" =~ ^[0-9]+(\\.[0-9]+)*$ ]]; then',
|
|
].join('\n');
|
|
assert.deepEqual(findLetterlessPhaseMirrorDrift(text), []);
|
|
});
|
|
|
|
test('scanMarkdownLetterlessPhaseMirror against the real repo tree reports zero violations (#4660 fixed)', () => {
|
|
assert.deepEqual(scanMarkdownLetterlessPhaseMirror(ROOT), []);
|
|
});
|
|
|
|
// #4748 (epic #4634): the three letter-hostile CONSUMER shapes — a dot-only
|
|
// integer split, a `[0-9]+\.?[0-9]*` extraction, a `printf "%02d"` re-pad.
|
|
|
|
// a. dot-only integer split
|
|
test('findDotOnlyIntegerSplitDrift flags the post-#4619 `PHASE_INT=${PHASE_NUMBER%%.*}` split', () => {
|
|
const text = 'PHASE_INT=${PHASE_NUMBER%%.*}; PHASE_FRAC=${PHASE_NUMBER#"$PHASE_INT"}';
|
|
const found = findDotOnlyIntegerSplitDrift(text);
|
|
assert.equal(found.length, 1);
|
|
assert.equal(found[0].line, 1);
|
|
assert.equal(found[0].found, 'PHASE_INT=${PHASE_NUMBER%%.*}');
|
|
});
|
|
|
|
test('findDotOnlyIntegerSplitDrift flags the prefixed SPOT_ variant and the bare $PHASE source', () => {
|
|
assert.equal(findDotOnlyIntegerSplitDrift('SPOT_PHASE_INT=${SPOT_PHASE_NUMBER%%.*}').length, 1);
|
|
assert.equal(findDotOnlyIntegerSplitDrift('PHASE_INT=${PHASE%%.*}; PHASE_FRAC=${PHASE#"$PHASE_INT"}').length, 1);
|
|
});
|
|
|
|
test('findDotOnlyIntegerSplitDrift flags the quoted spelling of an _INT split', () => {
|
|
assert.equal(findDotOnlyIntegerSplitDrift('PHASE_INT="${PHASE_NUMBER%%.*}"').length, 1);
|
|
});
|
|
|
|
test('findDotOnlyIntegerSplitDrift is SILENT on a dot split into a non-_INT name (a parent-phase derivation is correct as-is)', () => {
|
|
// gap-closure-artifacts.md: the parent of `03A.1` is `03A` — everything before
|
|
// the first dot, letter included. Not an integer, not fed to $((10#…)).
|
|
assert.deepEqual(findDotOnlyIntegerSplitDrift('PARENT_PHASE="${PHASE_NUMBER%%.*}"'), []);
|
|
assert.deepEqual(findDotOnlyIntegerSplitDrift('PHASE_PREFIX=${PHASE_NUMBER%%.*}'), []);
|
|
});
|
|
|
|
test('findDotOnlyIntegerSplitDrift is SILENT on the fixed first-non-digit split', () => {
|
|
const text = 'PHASE_INT=${PHASE_NUMBER%%[!0-9]*}; PHASE_REST=${PHASE_NUMBER#"$PHASE_INT"}';
|
|
assert.deepEqual(findDotOnlyIntegerSplitDrift(text), []);
|
|
});
|
|
|
|
test('findDotOnlyIntegerSplitDrift does NOT flag a split of a non-phase variable (a version, a plan)', () => {
|
|
assert.deepEqual(findDotOnlyIntegerSplitDrift('MAJOR_INT=${VERSION%%.*}'), []);
|
|
assert.deepEqual(findDotOnlyIntegerSplitDrift('PLAN_INT=${PLAN_ID%%.*}'), []);
|
|
});
|
|
|
|
test('findDotOnlyIntegerSplitDrift skips a full-line comment and honours the HTML sanction', () => {
|
|
assert.deepEqual(findDotOnlyIntegerSplitDrift('# was: PHASE_INT=${PHASE_NUMBER%%.*}'), []);
|
|
const text = [
|
|
'<!-- phase-id-owner: deliberate, this site never sees a letter id -->',
|
|
'PHASE_INT=${PHASE_NUMBER%%.*}',
|
|
].join('\n');
|
|
assert.deepEqual(findDotOnlyIntegerSplitDrift(text), []);
|
|
});
|
|
|
|
// b. loose dotted extraction
|
|
test('findLooseDottedPhaseRegexDrift flags the `[0-9]+\\.?[0-9]*` grep -oE extraction on a phase-carrying line', () => {
|
|
const text = "FROM_PHASE=$(echo \"$ARGUMENTS\" | grep -oE '\\-\\-from\\s+[0-9]+\\.?[0-9]*' | awk '{print $2}')";
|
|
const found = findLooseDottedPhaseRegexDrift(text);
|
|
assert.equal(found.length, 1);
|
|
assert.equal(found[0].found, '[0-9]+\\.?[0-9]*');
|
|
});
|
|
|
|
test('findLooseDottedPhaseRegexDrift flags the \\d near-variant', () => {
|
|
assert.equal(findLooseDottedPhaseRegexDrift("PHASE=$(echo \"$ARGUMENTS\" | grep -oE '\\d+\\.?\\d*')").length, 1);
|
|
});
|
|
|
|
test('findLooseDottedPhaseRegexDrift is SILENT on the canonical `[0-9]+[A-Z]?(\\.[0-9]+)*` form', () => {
|
|
const text = "PHASE=$(echo \"$ARGUMENTS\" | grep -oE '[0-9]+[A-Z]?(\\.[0-9]+)*' | head -1)";
|
|
assert.deepEqual(findLooseDottedPhaseRegexDrift(text), []);
|
|
});
|
|
|
|
test('findLooseDottedPhaseRegexDrift does NOT overlap the single-segment or letterless rules', () => {
|
|
const bounded = 'if ! [[ "$PADDED_PHASE" =~ ^[0-9]+(\\.[0-9]+)?$ ]]; then';
|
|
const letterless = 'if ! [[ "$PADDED_PHASE" =~ ^[0-9]+(\\.[0-9]+)*$ ]]; then';
|
|
assert.deepEqual(findLooseDottedPhaseRegexDrift(bounded), []);
|
|
assert.deepEqual(findLooseDottedPhaseRegexDrift(letterless), []);
|
|
});
|
|
|
|
test('findLooseDottedPhaseRegexDrift does NOT flag a non-phase-carrying line (a version) and honours the sanction', () => {
|
|
assert.deepEqual(findLooseDottedPhaseRegexDrift("MAJOR=$(echo \"$VERSION\" | grep -oE '[0-9]+\\.?[0-9]*')"), []);
|
|
const text = [
|
|
'<!-- phase-id-owner: deliberate, tracked in #4748 -->',
|
|
"PHASE=$(echo \"$ARGUMENTS\" | grep -oE '[0-9]+\\.?[0-9]*' | head -1)",
|
|
].join('\n');
|
|
assert.deepEqual(findLooseDottedPhaseRegexDrift(text), []);
|
|
});
|
|
|
|
// c. printf re-pad
|
|
test('findShellPhasePrintfPadDrift flags `printf "%02d"` of a phase variable, braced or bare', () => {
|
|
const found = findShellPhasePrintfPadDrift('PADDED=$(printf "%02d" "${PHASE_NUMBER}")');
|
|
assert.equal(found.length, 1);
|
|
assert.equal(found[0].found, 'printf "%0…d" …$PHASE_NUMBER');
|
|
assert.equal(findShellPhasePrintfPadDrift('PHASE=$(printf "%02d" "$PHASE")').length, 1);
|
|
assert.equal(findShellPhasePrintfPadDrift('PHASE=$(printf "%02d.%s" "${PHASE_MAJOR}" "${PHASE_MINOR}")').length, 1);
|
|
});
|
|
|
|
test('findShellPhasePrintfPadDrift flags the single-quoted format and a width without the zero flag', () => {
|
|
assert.equal(findShellPhasePrintfPadDrift("PADDED=$(printf '%02d' \"$PHASE_NUMBER\")").length, 1);
|
|
assert.equal(findShellPhasePrintfPadDrift('PADDED=$(printf "%2d" "$PHASE_NUMBER")').length, 1);
|
|
});
|
|
|
|
test('findShellPhasePrintfPadDrift is SILENT on a pad of an _INT via $((10#…)) and on init\'s padded_phase binding', () => {
|
|
assert.deepEqual(findShellPhasePrintfPadDrift('PHASE=$(printf "%02d" "$((10#$PHASE_INT))")${BASH_REMATCH[2]}'), []);
|
|
assert.deepEqual(findShellPhasePrintfPadDrift('PADDED="{padded_phase}"'), []);
|
|
});
|
|
|
|
test('findShellPhasePrintfPadDrift does NOT flag a pad of a non-phase variable (a plan number)', () => {
|
|
assert.deepEqual(findShellPhasePrintfPadDrift('PLAN_PADDED=$(printf "%02d" "$PLAN_ID")'), []);
|
|
});
|
|
|
|
test('findShellPhasePrintfPadDrift skips a full-line comment and honours the HTML sanction', () => {
|
|
assert.deepEqual(findShellPhasePrintfPadDrift('# PADDED=$(printf "%02d" "${PHASE_NUMBER}")'), []);
|
|
const text = [
|
|
'<!-- phase-id-owner: integer-only surface, tracked in #4748 -->',
|
|
'PADDED=$(printf "%02d" "${PHASE_NUMBER}")',
|
|
].join('\n');
|
|
assert.deepEqual(findShellPhasePrintfPadDrift(text), []);
|
|
});
|
|
|
|
test('scanMarkdownLetterAxisConsumers against the real repo tree reports zero violations (#4748 fixed)', () => {
|
|
assert.deepEqual(scanMarkdownLetterAxisConsumers(ROOT), []);
|
|
});
|