Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

ci(isolation-lint): one awk pass over every candidate file; 123 s to 1.3 s with identical findings (#8053)

garrytana541335e27ea
diff --git a/scripts/check-test-isolation.sh b/scripts/check-test-isolation.sh
index c2a796bb0a..36e73b43d8 100755
--- a/scripts/check-test-isolation.sh
+++ b/scripts/check-test-isolation.sh
@@ -108,32 +108,12 @@ fi
ALLOWLIST_FILE="$ROOT/scripts/check-test-isolation.allowlist"
# Read allowlist (one filename per line, # comments allowed). Empty file
-# is fine — every violation will fail. Cached into ALLOWLIST so the
-# per-file check (~700 lookups per run) is one pure-bash `case` match.
+# is fine — every violation will fail. The scan matches whole lines.
ALLOWLIST=""
if [ -f "$ALLOWLIST_FILE" ]; then
ALLOWLIST="$(grep -v '^[[:space:]]*#' "$ALLOWLIST_FILE" | grep -v '^[[:space:]]*$' || true)"
fi
-is_allowlisted() {
- local f="$1"
- if [ -z "$ALLOWLIST" ]; then
- return 1
- fi
- # Use a pure-bash `case` whole-line match against the newline-delimited
- # allowlist instead of `echo | grep -qxF`. v0.41.8 CI flake (verify job
- # 77771356276): the grep pipe form occasionally failed to match the
- # first allowlist entry on Ubuntu 24.04 + bash 5 under
- # `bun run` + GNU `timeout` (couldn't reproduce on macOS bash 3.2 with
- # the same allowlist file content + lint script content + checkout
- # state). Pure-bash case is locale-free, pipe-free, subshell-free,
- # set-e-quirk-free, and ~100x faster on every call.
- case $'\n'"$ALLOWLIST"$'\n' in
- *$'\n'"$f"$'\n'*) return 0 ;;
- esac
- return 1
-}
-
# Find non-serial unit test files (excluding test/e2e). Portable across
# bash 3.2 (macOS default) and bash 4+; no mapfile.
if [ "$AS_PARALLEL" = 1 ]; then
@@ -150,224 +130,177 @@ MODULE_MOCK_PATTERN='mock\.module[[:space:]]*\('
ENGINE_PATTERN='new PGLiteEngine[[:space:]]*\('
GATEWAY_PATTERN='configureGateway[[:space:]]*\('
GATEWAY_OPT_OUT='isolation-lint: R5-subprocess-only'
-# Comment removal for R5, line by line: a block comment that opens at the
-# start of a line (JSDoc included) is dropped through its closing */, and a
-# // comment is dropped from the // to the end of the line when it follows
-# the line start, whitespace or punctuation (so a URL's :// survives).
-# Block comments opening mid-line are left alone: a glob such as
-# 'test/*.ts' would otherwise swallow the rest of the file.
VERDICT_PATTERN='currentExitCode[[:space:]]*\('
-# R6: same comment removal as GATEWAY_CODE_SCAN; a reset inside an
-# afterEach/afterAll block (tracked by brace depth from the hook's line)
-# does not count as a baseline. Prints the reads when no baseline is left.
-VERDICT_CODE_SCAN='
- in_block {
- if (index($0, "*/") == 0) next
- in_block = 0
- next
- }
- /^[[:space:]]*\/\*/ {
- if (index(substr($0, index($0, "/*") + 2), "*/") == 0) in_block = 1
- next
- }
- {
- code = $0
- sub(/(^|[[:space:];,(){}])\/\/.*$/, "", code)
- opens = gsub(/\{/, "{", code); closes = gsub(/\}/, "}", code)
- if (in_after) { depth += opens - closes; if (depth <= 0) in_after = 0; next }
- if (code ~ /after(Each|All)[[:space:]]*\(/) { depth = opens - closes; if (depth > 0) in_after = 1; next }
- if (code ~ /_resetCliExitVerdictForTests[[:space:]]*\(|setCliExitVerdict[[:space:]]*\([[:space:]]*0[[:space:]]*\)/) baseline = 1
- if (code ~ /currentExitCode[[:space:]]*\(/ && code !~ /import/) reads = reads NR ":" $0 "\n"
- }
- END { if (reads != "" && !baseline) printf "%s", reads }
-'
-GATEWAY_CODE_SCAN='
- in_block {
- if (index($0, "*/") == 0) next
- in_block = 0
- next
- }
- /^[[:space:]]*\/\*/ {
- if (index(substr($0, index($0, "/*") + 2), "*/") == 0) in_block = 1
- next
- }
- {
- code = $0
- sub(/(^|[[:space:];,(){}])\/\/.*$/, "", code)
- if (code ~ /resetGateway[[:space:]]*\(/) restored = 1
- if (code ~ /configureGateway[[:space:]]*\(/) calls = calls NR ":" $0 "\n"
- }
- END { if (calls != "" && !restored) printf "%s", calls }
-'
UNCONFIGURE_PATTERN='(__unconfigureGatewayForTests|_clearGatewayForTests)[[:space:]]*\('
# R8: a scratch path joined onto this file's own directory.
SOURCE_TREE_SCRATCH_PATTERN="(import\\.meta\\.dir(name)?|__dirname)[[:space:]]*,[[:space:]]*['\"\`]\\.?tmp[-_./'\"\`]"
-# R7: same comment removal; a resetGateway call counts only inside an
-# afterEach/afterAll block (brace depth from the hook's line) or on the
-# hook line itself. Prints the unconfigure lines when no hook restore is left.
-UNCONFIGURE_CODE_SCAN='
- in_block {
- if (index($0, "*/") == 0) next
- in_block = 0
- next
- }
- /^[[:space:]]*\/\*/ {
- if (index(substr($0, index($0, "/*") + 2), "*/") == 0) in_block = 1
- next
- }
- {
- code = $0
- sub(/(^|[[:space:];,(){}])\/\/.*$/, "", code)
- opens = gsub(/\{/, "{", code); closes = gsub(/\}/, "}", code)
- if (in_after) { depth += opens - closes; if (code ~ /resetGateway[[:space:]]*\(/) restored = 1; if (depth <= 0) in_after = 0; next }
- if (code ~ /after(Each|All)[[:space:]]*\(/) {
- if (code ~ /resetGateway/) restored = 1
- depth = opens - closes; if (depth > 0) in_after = 1; next
- }
- if (code ~ /(__unconfigureGatewayForTests|_clearGatewayForTests)[[:space:]]*\(/ && code !~ /import/) calls = calls NR ":" $0 "\n"
- }
- END { if (calls != "" && !restored) printf "%s", calls }
-'
# R9: installer pattern|restorer name, one pair per line.
PAIRED_RULES='installOutputCapture[[:space:]]*[(]|startCliSocketServer[[:space:]]*[(]|_uninstallOutputCaptureForTests
redirectStdoutLoggingToStderr[[:space:]]*[(]|_resetStdoutRedirectForTests[[:space:]]*[(]|_resetStdoutRedirectForTests
installSigchldHandler[[:space:]]*[(]|_uninstallSigchldHandlerForTests'
PAIRED_PATTERN='installOutputCapture[[:space:]]*[(]|startCliSocketServer[[:space:]]*[(]|redirectStdoutLoggingToStderr[[:space:]]*[(]|_resetStdoutRedirectForTests[[:space:]]*[(]|installSigchldHandler[[:space:]]*[(]'
-# R9: same comment removal and after-hook tracking as UNCONFIGURE_CODE_SCAN,
-# with the installer pattern in trig and the restorer name in rest.
-PAIRED_CODE_SCAN='
- in_block {
- if (index($0, "*/") == 0) next
- in_block = 0
- next
+
+# One awk process lints every candidate file (#8053): a grep or awk process
+# per rule per file cost about 90 s for 2,000 candidates. Each file is read
+# once into L[], then every rule runs over it with its own state, in rule order.
+#
+# Comment removal (R5, R6, R7, R9), line by line: a block comment that opens
+# at the start of a line (JSDoc included) is dropped through its closing */,
+# and a // comment is dropped from the // to the end of the line when it
+# follows the line start, whitespace or punctuation (so a URL's :// survives).
+# Block comments opening mid-line are left alone: a glob such as 'test/*.ts'
+# would otherwise swallow the rest of the file. R6, R7 and R9 track
+# afterEach/afterAll blocks by brace depth from the hook's line: a restore
+# counts only inside one (or on the hook line itself), and an R6 reset inside
+# one is not a baseline.
+read -r -d '' SCAN_AWK <<'AWK' || true
+function emit(f, rule, detail, lines, n, a, i) {
+ print "ERROR: " f
+ print " rule " rule ": " detail
+ sub(/\n+$/, "", lines)
+ if (lines != "") {
+ n = split(lines, a, "\n")
+ for (i = 1; i <= n && i <= 3; i++) print " " a[i]
}
- /^[[:space:]]*\/\*/ {
- if (index(substr($0, index($0, "/*") + 2), "*/") == 0) in_block = 1
- next
+}
+function strip(line) {
+ if (in_block) {
+ if (index(line, "*/") != 0) in_block = 0
+ return 0
}
- {
- code = $0
- sub(/(^|[[:space:];,(){}])\/\/.*$/, "", code)
- opens = gsub(/\{/, "{", code); closes = gsub(/\}/, "}", code)
- if (in_after) { depth += opens - closes; if (code ~ ENVIRON["REST"]) restored = 1; if (depth <= 0) in_after = 0; next }
- if (code ~ /after(Each|All)[[:space:]]*\(/) {
- if (code ~ ENVIRON["REST"]) restored = 1
- depth = opens - closes; if (depth > 0) in_after = 1; next
- }
- if (code ~ ENVIRON["TRIG"] && code !~ /import/) calls = calls NR ":" $0 "\n"
+ if (line ~ /^[[:space:]]*\/\*/) {
+ if (index(substr(line, index(line, "/*") + 2), "*/") == 0) in_block = 1
+ return 0
}
- END { if (calls != "" && !restored) printf "%s", calls }
-'
-CANDIDATES="$(guard_candidates -E -e "$ENV_MUTATION_PATTERN" -e "$MODULE_MOCK_PATTERN" -e "$ENGINE_PATTERN" -e "$GATEWAY_PATTERN" -e "$VERDICT_PATTERN" -e "$UNCONFIGURE_PATTERN" -e "$SOURCE_TREE_SCRATCH_PATTERN" -e "$PAIRED_PATTERN" <<< "$FILE_LIST")"
-
-violations=0
-file_count=0
-
-emit_violation() {
- local f="$1" rule="$2" detail="$3" lines="$4"
- if is_allowlisted "$f"; then
- return
- fi
- echo "ERROR: $f"
- echo " rule $rule: $detail"
- if [ -n "$lines" ]; then
- echo "$lines" | head -3 | sed 's/^/ /'
- fi
- violations=$((violations + 1))
+ CODE = line
+ sub(/(^|[[:space:];,(){}])\/\/.*$/, "", CODE)
+ return 1
}
+function hook( code, opens, closes) {
+ code = CODE
+ opens = gsub(/\{/, "{", code); closes = gsub(/\}/, "}", code)
+ if (in_after) { depth += opens - closes; if (depth <= 0) in_after = 0; return 1 }
+ if (CODE ~ /after(Each|All)[[:space:]]*\(/) { depth = opens - closes; if (depth > 0) in_after = 1; return 1 }
+ return 0
+}
+function scan(f, nl, line, i, k, env, mock, scratch, engine, gw, opt, verdict, unconf, paired, after_all, disconnect, last_before_all, bad, calls, reads, restored, baseline, seen) {
+ split("", L)
+ nl = 0
+ while ((getline line < f) > 0) L[++nl] = line
+ close(f)
-# Read newline-separated file list; OK on macOS bash 3.2.
-while IFS= read -r f; do
- [ -z "$f" ] && continue
- file_count=$((file_count + 1))
- case $'\n'"$CANDIDATES"$'\n' in
- *$'\n'"$f"$'\n'*) ;;
- *) continue ;;
- esac
- if is_allowlisted "$f"; then
- continue
- fi
- # R1: env mutations.
- env_lines=$(grep -nE "$ENV_MUTATION_PATTERN" "$f" 2>/dev/null || true)
- if [ -n "$env_lines" ]; then
- emit_violation "$f" "R1" "process.env mutation; use withEnv() or rename to *.serial.test.ts" "$env_lines"
- fi
+ for (i = 1; i <= nl; i++) {
+ line = L[i]
+ if (line ~ ENV_RE) env = env i ":" line "\n"
+ if (line ~ MOCK_RE) mock = mock i ":" line "\n"
+ if (line ~ SCRATCH_RE) scratch = scratch i ":" line "\n"
+ if (line ~ ENGINE_RE) engine = 1
+ if (line ~ GATEWAY_RE) gw = 1
+ if (index(line, OPT_OUT)) opt = 1
+ if (line ~ VERDICT_RE) verdict = 1
+ if (line ~ UNCONFIGURE_RE) unconf = 1
+ if (line ~ PAIRED_RE) paired = 1
+ if (line ~ /afterAll[[:space:]]*\(/) after_all = 1
+ if (line ~ /\.disconnect[[:space:]]*\(/) disconnect = 1
+ }
+ # R1: env mutations.
+ if (env != "") emit(f, "R1", "process.env mutation; use withEnv() or rename to *.serial.test.ts", env)
# R2: mock.module() anywhere.
- mock_lines=$(grep -nE "$MODULE_MOCK_PATTERN" "$f" 2>/dev/null || true)
- if [ -n "$mock_lines" ]; then
- emit_violation "$f" "R2" "mock.module() leaks across files in the shard process; rename to *.serial.test.ts" "$mock_lines"
- fi
-
+ if (mock != "") emit(f, "R2", "mock.module() leaks across files in the shard process; rename to *.serial.test.ts", mock)
# R3: PGLiteEngine outside ~50 lines after a beforeAll(.
- if grep -qE "$ENGINE_PATTERN" "$f" 2>/dev/null; then
- bad=$(awk '
- BEGIN { last_before_all = -1000 }
- /beforeAll[[:space:]]*\(/ { last_before_all = NR }
- /new PGLiteEngine[[:space:]]*\(/ {
- if (NR - last_before_all > 50) {
- printf "%d:%s\n", NR, $0
- }
- }
- ' "$f" 2>/dev/null)
- if [ -n "$bad" ]; then
- emit_violation "$f" "R3" "new PGLiteEngine(...) outside beforeAll() context (>50 lines); move into beforeAll" "$bad"
- fi
- fi
-
+ if (engine) {
+ last_before_all = -1000
+ for (i = 1; i <= nl; i++) {
+ if (L[i] ~ /beforeAll[[:space:]]*\(/) last_before_all = i
+ if (L[i] ~ /new PGLiteEngine[[:space:]]*\(/ && i - last_before_all > 50) bad = bad i ":" L[i] "\n"
+ }
+ if (bad != "") emit(f, "R3", "new PGLiteEngine(...) outside beforeAll() context (>50 lines); move into beforeAll", bad)
+ }
# R4: PGLiteEngine creation requires afterAll{disconnect}.
- if grep -qE "$ENGINE_PATTERN" "$f" 2>/dev/null; then
- if ! grep -qE 'afterAll[[:space:]]*\(' "$f" 2>/dev/null \
- || ! grep -qE '\.disconnect[[:space:]]*\(' "$f" 2>/dev/null; then
- emit_violation "$f" "R4" "creates PGLiteEngine but missing afterAll(() => engine.disconnect()); engine leaks across files in the shard process" ""
- fi
- fi
-
- # R5: gateway configured but never restored. GATEWAY_CODE_SCAN reads the
- # file with comments removed and prints the configureGateway lines only
- # when no resetGateway call is left.
- if grep -qE "$GATEWAY_PATTERN" "$f" 2>/dev/null && ! grep -qF "$GATEWAY_OPT_OUT" "$f" 2>/dev/null; then
- unrestored=$(awk "$GATEWAY_CODE_SCAN" "$f" 2>/dev/null || true)
- if [ -n "$unrestored" ]; then
- emit_violation "$f" "R5" "configureGateway() with no resetGateway(); the gateway is process-global, so this config reaches every later file in the shard. Add afterAll(() => resetGateway()) or rename to *.serial.test.ts" "$unrestored"
- fi
- fi
-
+ if (engine && (!after_all || !disconnect)) emit(f, "R4", "creates PGLiteEngine but missing afterAll(() => engine.disconnect()); engine leaks across files in the shard process", "")
+ # R5: gateway configured but never restored.
+ if (gw && !opt) {
+ in_block = 0; restored = 0; calls = ""
+ for (i = 1; i <= nl; i++) {
+ if (!strip(L[i])) continue
+ if (CODE ~ /resetGateway[[:space:]]*\(/) restored = 1
+ if (CODE ~ /configureGateway[[:space:]]*\(/) calls = calls i ":" L[i] "\n"
+ }
+ if (calls != "" && !restored) emit(f, "R5", "configureGateway() with no resetGateway(); the gateway is process-global, so this config reaches every later file in the shard. Add afterAll(() => resetGateway()) or rename to *.serial.test.ts", calls)
+ }
# R6: the CLI exit verdict is read with no baseline outside an after-hook.
- if grep -qE "$VERDICT_PATTERN" "$f" 2>/dev/null; then
- unbased=$(awk "$VERDICT_CODE_SCAN" "$f" 2>/dev/null || true)
- if [ -n "$unbased" ]; then
- emit_violation "$f" "R6" "currentExitCode() read with no baseline; the verdict is process-global, so the first test reads whatever the previous file in the shard left. Call _resetCliExitVerdictForTests() in beforeEach (or before the run it checks), not only in afterEach" "$unbased"
- fi
- fi
+ if (verdict) {
+ in_block = 0; in_after = 0; depth = 0
+ for (i = 1; i <= nl; i++) {
+ if (!strip(L[i]) || hook()) continue
+ if (CODE ~ /_resetCliExitVerdictForTests[[:space:]]*\(|setCliExitVerdict[[:space:]]*\([[:space:]]*0[[:space:]]*\)/) baseline = 1
+ if (CODE ~ /currentExitCode[[:space:]]*\(/ && CODE !~ /import/) reads = reads i ":" L[i] "\n"
+ }
+ if (reads != "" && !baseline) emit(f, "R6", "currentExitCode() read with no baseline; the verdict is process-global, so the first test reads whatever the previous file in the shard left. Call _resetCliExitVerdictForTests() in beforeEach (or before the run it checks), not only in afterEach", reads)
+ }
# R7: the gateway is unconfigured but no after-hook puts the baseline back.
- if grep -qE "$UNCONFIGURE_PATTERN" "$f" 2>/dev/null; then
- unrestored=$(awk "$UNCONFIGURE_CODE_SCAN" "$f" 2>/dev/null || true)
- if [ -n "$unrestored" ]; then
- emit_violation "$f" "R7" "__unconfigureGatewayForTests()/_clearGatewayForTests() with no resetGateway() in an afterEach/afterAll hook; an empty gateway is process-global, so the next file's beforeAll sizes its schema from nothing. Add afterEach(() => resetGateway()) (an inline restore does not survive a throw or a -t filter) or rename to *.serial.test.ts" "$unrestored"
- fi
- fi
+ if (unconf) {
+ in_block = 0; in_after = 0; depth = 0; restored = 0; calls = ""
+ for (i = 1; i <= nl; i++) {
+ if (!strip(L[i])) continue
+ if (in_after && CODE ~ /resetGateway[[:space:]]*\(/) restored = 1
+ if (!in_after && CODE ~ /after(Each|All)[[:space:]]*\(/ && CODE ~ /resetGateway/) restored = 1
+ if (hook()) continue
+ if (CODE ~ /(__unconfigureGatewayForTests|_clearGatewayForTests)[[:space:]]*\(/ && CODE !~ /import/) calls = calls i ":" L[i] "\n"
+ }
+ if (calls != "" && !restored) emit(f, "R7", "__unconfigureGatewayForTests()/_clearGatewayForTests() with no resetGateway() in an afterEach/afterAll hook; an empty gateway is process-global, so the next file's beforeAll sizes its schema from nothing. Add afterEach(() => resetGateway()) (an inline restore does not survive a throw or a -t filter) or rename to *.serial.test.ts", calls)
+ }
# R8: scratch directory inside the source tree.
- scratch_lines=$(grep -nE "$SOURCE_TREE_SCRATCH_PATTERN" "$f" 2>/dev/null || true)
- if [ -n "$scratch_lines" ]; then
- emit_violation "$f" "R8" "scratch directory inside the source tree; tree walkers in the same lane (test-reads-source-smell) fail with ENOENT when it is created or removed mid-walk. Use mkdtempSync(join(tmpdir(), '...'))" "$scratch_lines"
- fi
+ if (scratch != "") emit(f, "R8", "scratch directory inside the source tree; tree walkers in the same lane (test-reads-source-smell) fail with ENOENT when it is created or removed mid-walk. Use mkdtempSync(join(tmpdir(), '...'))", scratch)
# R9: a process-global hook installed with no after-hook undo.
- if grep -qE "$PAIRED_PATTERN" "$f" 2>/dev/null; then
- while IFS= read -r pair; do
- trig="${pair%|*}"; rest="${pair##*|}"
- grep -qE "$trig" "$f" 2>/dev/null || continue
- unrestored=$(TRIG="$trig" REST="$rest" awk "$PAIRED_CODE_SCAN" "$f" 2>/dev/null || true)
- if [ -n "$unrestored" ]; then
- emit_violation "$f" "R9" "process-global hook installed with no $rest() in an afterEach/afterAll hook; it stays installed for every later file in the shard. Add afterEach(() => $rest()) or rename to *.serial.test.ts" "$unrestored"
- fi
- done <<PAIRS
-$PAIRED_RULES
-PAIRS
- fi
-done <<EOF
-$FILE_LIST
-EOF
+ if (paired) {
+ for (k = 1; k <= npairs; k++) {
+ seen = 0
+ for (i = 1; i <= nl; i++) if (L[i] ~ TRIG[k]) { seen = 1; break }
+ if (!seen) continue
+ in_block = 0; in_after = 0; depth = 0; restored = 0; calls = ""
+ for (i = 1; i <= nl; i++) {
+ if (!strip(L[i])) continue
+ if ((in_after || CODE ~ /after(Each|All)[[:space:]]*\(/) && CODE ~ REST[k]) restored = 1
+ if (hook()) continue
+ if (CODE ~ TRIG[k] && CODE !~ /import/) calls = calls i ":" L[i] "\n"
+ }
+ if (calls != "" && !restored) emit(f, "R9", "process-global hook installed with no " REST[k] "() in an afterEach/afterAll hook; it stays installed for every later file in the shard. Add afterEach(() => " REST[k] "()) or rename to *.serial.test.ts", calls)
+ }
+ }
+}
+BEGIN {
+ ENV_RE = ENVIRON["ENV_MUTATION_PATTERN"]; MOCK_RE = ENVIRON["MODULE_MOCK_PATTERN"]
+ ENGINE_RE = ENVIRON["ENGINE_PATTERN"]; GATEWAY_RE = ENVIRON["GATEWAY_PATTERN"]
+ OPT_OUT = ENVIRON["GATEWAY_OPT_OUT"]; VERDICT_RE = ENVIRON["VERDICT_PATTERN"]
+ UNCONFIGURE_RE = ENVIRON["UNCONFIGURE_PATTERN"]; SCRATCH_RE = ENVIRON["SOURCE_TREE_SCRATCH_PATTERN"]
+ PAIRED_RE = ENVIRON["PAIRED_PATTERN"]
+ n = split(ENVIRON["ALLOWLIST"], a, "\n")
+ for (i = 1; i <= n; i++) allowed[a[i]] = 1
+ npairs = split(ENVIRON["PAIRED_RULES"], p, "\n")
+ for (k = 1; k <= npairs; k++) {
+ match(p[k], /\|[^|]*$/)
+ TRIG[k] = substr(p[k], 1, RSTART - 1); REST[k] = substr(p[k], RSTART + 1)
+ }
+}
+$0 != "" && !($0 in allowed) { scan($0) }
+AWK
+
+CANDIDATES="$(guard_candidates -E -e "$ENV_MUTATION_PATTERN" -e "$MODULE_MOCK_PATTERN" -e "$ENGINE_PATTERN" -e "$GATEWAY_PATTERN" -e "$VERDICT_PATTERN" -e "$UNCONFIGURE_PATTERN" -e "$SOURCE_TREE_SCRATCH_PATTERN" -e "$PAIRED_PATTERN" <<< "$FILE_LIST")"
+REPORT=""
+if [ -n "$CANDIDATES" ]; then
+ REPORT="$(printf '%s\n' "$CANDIDATES" | ENV_MUTATION_PATTERN="$ENV_MUTATION_PATTERN" MODULE_MOCK_PATTERN="$MODULE_MOCK_PATTERN" \
+ ENGINE_PATTERN="$ENGINE_PATTERN" GATEWAY_PATTERN="$GATEWAY_PATTERN" GATEWAY_OPT_OUT="$GATEWAY_OPT_OUT" \
+ VERDICT_PATTERN="$VERDICT_PATTERN" UNCONFIGURE_PATTERN="$UNCONFIGURE_PATTERN" \
+ SOURCE_TREE_SCRATCH_PATTERN="$SOURCE_TREE_SCRATCH_PATTERN" PAIRED_PATTERN="$PAIRED_PATTERN" \
+ PAIRED_RULES="$PAIRED_RULES" ALLOWLIST="$ALLOWLIST" awk "$SCAN_AWK")"
+fi
+file_count="$(printf '%s\n' "$FILE_LIST" | grep -c . || true)"
+violations="$(printf '%s\n' "$REPORT" | grep -c '^ERROR: ' || true)"
+if [ -n "$REPORT" ]; then
+ printf '%s\n' "$REPORT"
+fi
if [ $violations -gt 0 ]; then
echo
diff --git a/test/scripts/check-test-isolation.test.ts b/test/scripts/check-test-isolation.test.ts
index c460435857..f358a4702a 100644
--- a/test/scripts/check-test-isolation.test.ts
+++ b/test/scripts/check-test-isolation.test.ts
@@ -90,6 +90,35 @@ describe('check-test-isolation.sh', () => {
rmSync(bin, { recursive: true, force: true });
}
});
+ it('lints candidate files in one pass instead of starting grep or awk per file (#8053)', () => {
+ const bin = mkdtempSync(join(tmpdir(), 'lint-candidate-count-'));
+ const log = join(bin, 'calls');
+ for (const tool of ['grep', 'awk']) {
+ writeFileSync(join(bin, tool), '#!/usr/bin/env bash\nprintf "' + tool + '\\n" >> "$CALL_LOG"\nexec "' + Bun.which(tool)! + '" "$@"\n', { mode: 0o755 });
+ }
+ try {
+ const candidate = [
+ "import { beforeAll, afterAll } from 'bun:test';",
+ 'let engine;',
+ 'beforeAll(async () => { engine = new PGLiteEngine(); });',
+ 'afterAll(async () => { await engine.disconnect(); });',
+ '',
+ ].join('\n');
+ const files = Array.from({ length: 200 }, (_, i) => ({ path: 'candidate ' + i + '.test.ts', contents: candidate }));
+ const env = { PATH: bin + ':' + process.env.PATH, CALL_LOG: log };
+ const r = runLintIn(files, [], env);
+ expect(r.status).toBe(0);
+ expect(r.stdout).toContain('200 non-serial unit files scanned');
+ expect(readFileSync(log, 'utf8').trim().split('\n').length).toBeLessThan(12);
+ const bad = runLintIn([...files, { path: 'z bad.test.ts', contents: 'const engine = new PGLiteEngine();\n' }], [], env);
+ expect(bad.status).toBe(1);
+ expect(bad.stdout).toContain('ERROR: test/z bad.test.ts\n rule R3:');
+ expect(bad.stdout).toContain(' 1:const engine = new PGLiteEngine();\nERROR: test/z bad.test.ts\n rule R4:');
+ expect(bad.stdout).toContain('check-test-isolation: FAIL (2 violation(s))');
+ } finally {
+ rmSync(bin, { recursive: true, force: true });
+ }
+ });
});
describe('R1 — env mutation', () => {