fix(subdirectory): reinstate invariants scan, harden scanner

The shard-6 hang reproduced on master independently of this PR — earlier
diagnostic edits (skipping the invariants scan) are no longer needed.

Reinstates the static-invariant scan in
`navigationUtils.invariants.test.ts` and keeps the previously seeded
PATH_UTILS_IMPORT_ALLOWLIST so the suite is GREEN today and shrinks as
each migration commit lands.

Also hoists the regex compile out of the per-line loop in
`scanSource`. With no `g` flag, `RegExp.exec()` ignores `lastIndex`, so
recompiling per line was wasted allocation across ~1.5M lines workspace-
wide. If the source pattern includes `g`, the helper now strips it once
at the top of the file rather than relying on per-line construction.

Adds `jest.setTimeout(20000)` to `navigationUtils.test.ts` as a
defence-in-depth safety net — any future hang surfaces a Jest timeout
error with the test name rather than running for the workflow's
six-hour wallclock limit.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Joe Li
2026-05-07 22:08:12 -07:00
parent 986f19c2f7
commit cfaeb11468
3 changed files with 38 additions and 19 deletions

View File

@@ -173,11 +173,15 @@ export function scanSource(options: ScanOptions): ScanHit[] {
const contents = readFileSync(absoluteFile, 'utf8');
const lines = contents.split('\n');
// Reuse a single regex per file. Without the `g` flag, RegExp's
// `lastIndex` is ignored on `.exec()` — recompiling per-line was
// wasted allocation across ~1.5M lines workspace-wide.
const lineRegex = pattern.flags.includes('g')
? new RegExp(pattern.source, pattern.flags.replace('g', ''))
: pattern;
for (let index = 0; index < lines.length; index += 1) {
const lineText = lines[index];
// Re-create the regex per line so the global flag's lastIndex doesn't
// bleed across iterations.
const lineRegex = new RegExp(pattern.source, pattern.flags);
const match = lineRegex.exec(lineText);
if (match) {
hits.push({