fix(#4830): re-land #4768's letter-suffix phase-id fix and its lint-phase-id-drift ratchets on current next (#4873)
* fix(#4830): re-land #4768's letter-suffix phase-id fix and its lint-phase-id-drift ratchets on current next Commit740ba0d8a(#4781) removed every change #4768 had merged for #4748: the first-non-digit split at execute-phase.md's two arithmetic sites, the init-emitted `padded_phase` the REVIEW.md lookup binds instead of `printf "%02d"`, the canonical-grammar extractions in autonomous.md and plan-review-convergence.md, the `.changeset/zesty-wolves-tumble.md` fragment, and the three lint-phase-id-drift ratchets with their tests. The guard and the code it guarded left together, so nothing went red. This is a cherry-pick of092d9256bonto current `next`, resolved against the #4683 threat-id fields on execute-phase.md's Parse-JSON line, with the changeset `pr:` reset to the placeholder and the compact-content benchmark baseline regenerated against the current base. (cherry picked from commit092d9256b8) Emitted-Drift-Ack-Growth: autonomous.md — restores #4768's canonical-grammar extraction and its explanatory comment for --from/--to/--only Emitted-Drift-Ack-Growth: execute-phase.md — restores #4768's first-non-digit split at two arithmetic sites and the padded_phase binding for the REVIEW.md lookup Emitted-Drift-Ack-Growth: plan-review-convergence.md — restores #4768's canonical-grammar phase extraction and its comment Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AX7LXxc3uAkGki6iaYiAMP * chore(#4830): set changeset fragment pr to 4873 --------- Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com> Co-authored-by: Tom Boucher <trekkie@nomorestars.com>
This commit is contained in:
@@ -12,6 +12,10 @@ const {
|
||||
scanMarkdownSingleSegmentPhaseRegex,
|
||||
findLetterlessPhaseMirrorDrift,
|
||||
scanMarkdownLetterlessPhaseMirror,
|
||||
findDotOnlyIntegerSplitDrift,
|
||||
findLooseDottedPhaseRegexDrift,
|
||||
findShellPhasePrintfPadDrift,
|
||||
scanMarkdownLetterAxisConsumers,
|
||||
} = require('../scripts/lint-phase-id-drift.cjs');
|
||||
|
||||
const ROOT = path.join(__dirname, '..');
|
||||
@@ -212,3 +216,119 @@ test('findLetterlessPhaseMirrorDrift does NOT flag a site sanctioned with an HTM
|
||||
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), []);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user