chore(#2880): close ADR-2143 deployment misses — table-regex fingerprint + state-document seam migration (#2889)
* chore(#2880): close ADR-2143 seam misses — widen table-regex fingerprint, migrate state-document onto the seam The no-adhoc-markdown-parsing rule matched only a negated class whose sole member was a pipe ([^|]), so the stricter and more common [^|\n] spelling evaded it entirely -- src/state-document.cts hand-rolled exactly that shape and linted clean. Widen the fingerprint to any negated class excluding a pipe, which is the ADR-2143 section 7 prohibition as written. With the rule fixed, state-document.cts goes red. Replace tableRowPattern with locateFieldRow: a line scan using the markdown-table seam's splitTableRow for cell semantics, returning the value cell's byte range, and splice that range instead of running a whole-document content.replace. An edit now physically cannot cross a row boundary (section 4). Behavior is frozen -- stateReplaceField has 79 dependents across 5 command processes. Characterization tests lock all 14 table-branch rows plus CRLF, extract round-trip and the withFallback caller shape; a fast-check property asserts every non-target line stays byte-identical. Refs #2880, epic #2143 * fix(#2880): address adversarial review — lone-CR rows, field-name padding, quadratic scan, over-broad fingerprint Isolated adversarial review found four defects in the first commit. 1. locateFieldRow split lines on \n only. JS treats a lone \r as a line terminator, so the regex it replaced matched rows separated by bare CR. "| Phase | 3 |\r| Other | 9 |" returned 3 before and null after. Now CR, LF and CRLF are all terminators, byte offsets unchanged. 2. The field name was normalised with trim().toLowerCase(). The old regex embedded it verbatim, so its whitespace had to be absorbed by the row's own padding -- and because the group is a literal-character match rather than a whitespace class, a tab-padded cell does not accept a space-padded name. Replaced with an offset-aligned search reproducing the original backtracking exactly. 3. The widened fingerprint regex had two unbounded [^\]]* around an optional and ran quadratically over every regex source in every linted file: 256000 chars took 23 seconds. Replaced with a single-pass scanner that never rescans; the same input is now ~1ms. 4. The fingerprint also matched non-table idioms such as [^\s|] and [^"|]. Narrowed to a class excluding the pipe plus only \n, \r or \t. Differential fuzz against origin/next: 20000 cases, 0 mismatches. Refs #2880, epic #2143 * test(#2880): drop wall-clock assertion from the ReDoS regression guard local/no-elapsed-assertion flagged the elapsed-time check, and CLAUDE.md bans timing assertions outright as flaky. The 256000-char input stays as the regression guard for the quadratic scan; correctness of the verdict is what is asserted. If the quadratic path returns, the test stops completing and surfaces as a suite timeout rather than a silent pass. Also adds the changeset fragment for #2880. Refs #2880 * fix(#2880): spec-correct case folding, property tests, naming Code-review findings. The field-name comparison used toLowerCase(). The regex it replaced used /i WITHOUT /u, and ECMAScript Canonicalize deliberately does not fold a non-ASCII character onto an ASCII one -- KELVIN SIGN U+212A matched ASCII K where the old code returned null. Replaced with spec-correct Canonicalize, including the multi-character uppercase case (eszett -> SS), which a naive uppercase comparison also gets wrong. Added the fast-check property tests CLAUDE.md requires for parsers: one for the negated-class scanner, one for the field-name fold semantics, each against an independent reference implementation. Both reference impls failed on first run against real bugs, so neither property is vacuous. Renamed p2/p3 to name the exactly-three-pipes invariant, and reduced a duplicated comment to a cross-reference. Differential fuzz vs origin/next: 20000 runs, 0 mismatches, with the harness proven to discriminate the KELVIN case. Refs #2880 * chore(#2880): backfill changeset PR number (#2889) * docs(#2890): correct the local ESLint plugin path in CONTEXT.md CONTEXT.md named the local AST-rule plugin directory as scripts/eslint-rules/, which does not exist. The real location is eslint-rules/ at the repo root -- what eslint.config.mjs actually imports -- and CONTEXT.md's own later entry already says so explicitly, so the file disagreed with itself. Found by a line-by-line audit of all 1036 lines against the live graph; this was the only confirmed inaccuracy. Closes #2890 --------- Co-authored-by: Test <test@example.com>
This commit is contained in:
@@ -170,11 +170,92 @@ const rule = {
|
||||
// [^\|]), indicating a hand-rolled table-row/cell scan such as /\|[^|]*\|/.
|
||||
// Conservative by design: a bare escaped-pipe delimiter probe with no
|
||||
// negated-pipe cell class is NOT flagged.
|
||||
//
|
||||
// The negated class qualifies ONLY when its body is the pipe (escaped or
|
||||
// bare) plus zero or more of the two-character line-terminator/tab escapes
|
||||
// `\n`, `\r`, `\t` (#2880): the common, and strictly MORE correct, spelling
|
||||
// is `[^|\n]` (a GFM cell can span neither a pipe nor a line break) —
|
||||
// `src/state-document.cts` used exactly that and evaded the rule entirely,
|
||||
// which is the ADR-2143 §7 enforcement hole this widening closes. A
|
||||
// negated class that excludes the pipe alongside anything ELSE — e.g.
|
||||
// `[^\s|]`, `[^"|]`, `[^a-z|]` — is a different (non-table) idiom and is
|
||||
// NOT flagged, and a negated class that does not exclude a pipe at all
|
||||
// (`[^\n]`, `[^a-z]`) is still NOT a cell scan.
|
||||
//
|
||||
// Implemented as a single-pass scanner (not a regex) — see
|
||||
// hasQualifyingNegatedPipeClass below for why the regex encoding of this
|
||||
// fingerprint was rejected (quadratic-on-failure blowup).
|
||||
function isTableRegexSource(src) {
|
||||
// Must contain an escaped pipe
|
||||
if (!src.includes('\\|')) return false;
|
||||
// Must ALSO contain a negated-pipe cell-capture class: [^|] or [^\|]
|
||||
return /\[\^\\?\|\]/.test(src);
|
||||
return hasQualifyingNegatedPipeClass(src);
|
||||
}
|
||||
|
||||
// ── Single-pass negated-character-class scanner (FIX 3 + FIX 4) ─────────
|
||||
// Walks `src` once, left to right. On encountering a negated class
|
||||
// `[^...]` it scans forward to the class's closing `]` (honoring `\`
|
||||
// escapes within the class) exactly once, then resumes scanning
|
||||
// immediately AFTER that `]` — never backtracking into the class body.
|
||||
// This keeps the whole walk O(n) regardless of how many negated classes
|
||||
// (or how large) the source contains — unlike the regex it replaces,
|
||||
// /\[\^[^\]]*\\?\|[^\]]*\]/, which is quadratic on failure (two unbounded
|
||||
// [^\]]* runs around an optional), measured at ~23s for a 256000-char
|
||||
// adversarial input.
|
||||
//
|
||||
// Returns true if ANY negated class in `src` QUALIFIES as a hand-rolled
|
||||
// GFM cell-capture class: it excludes a pipe (`\|` or bare `|`) and,
|
||||
// after removing that pipe, every remaining member is one of the
|
||||
// two-character line-terminator/tab escapes `\n`, `\r`, `\t` (zero extra
|
||||
// members is fine — `[^|]` alone qualifies). A class that excludes the
|
||||
// pipe alongside anything ELSE (`[^\s|]`, `[^"|]`, `[^a-z|]`) does NOT
|
||||
// qualify — that is a different, non-table idiom. A class that never
|
||||
// excludes a pipe at all (`[^\n]`, `[^a-z]`) does not qualify either.
|
||||
function hasQualifyingNegatedPipeClass(src) {
|
||||
let i = 0;
|
||||
while (i < src.length) {
|
||||
const ch = src[i];
|
||||
if (ch === '\\') {
|
||||
i += 2;
|
||||
continue;
|
||||
}
|
||||
if (ch === '[' && src[i + 1] === '^') {
|
||||
let j = i + 2;
|
||||
let classHasPipe = false;
|
||||
let classIsPure = true;
|
||||
let closed = false;
|
||||
while (j < src.length) {
|
||||
const cc = src[j];
|
||||
if (cc === '\\') {
|
||||
const next = src[j + 1];
|
||||
if (next === '|') {
|
||||
classHasPipe = true;
|
||||
}
|
||||
else if (next !== 'n' && next !== 'r' && next !== 't') {
|
||||
classIsPure = false;
|
||||
}
|
||||
j += 2;
|
||||
continue;
|
||||
}
|
||||
if (cc === ']') {
|
||||
closed = true;
|
||||
j += 1;
|
||||
break;
|
||||
}
|
||||
if (cc === '|') {
|
||||
classHasPipe = true;
|
||||
}
|
||||
else {
|
||||
classIsPure = false;
|
||||
}
|
||||
j += 1;
|
||||
}
|
||||
if (closed && classHasPipe && classIsPure) return true;
|
||||
i = closed ? j : src.length;
|
||||
continue;
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function isTableRegex(node) {
|
||||
|
||||
Reference in New Issue
Block a user