Fix false-positive placeholder on /reports/live/tests
The snapshot-tests.ts placeholder detector ran its test()/it() regex over raw source — including inside string literals. The verifier itself (c32_sama_verify.ts) handles this correctly via stripStringsAndComments + index-into-mask; the deploy-time snapshot duplicated the regex but skipped the string-aware step. Side-effect on the live site: /reports/live/tests showed "placeholder tests · ⚠ 1 flagged" pointing at c32_sama_verify.test.ts's "does nothing" — which is a backtick- quoted fixture *inside* the verifier's own test, not a real test body. False positive on the very test that proves the detector works. Fix: export stripStringsAndComments from c32_sama_verify.ts and use the same mask approach in snapshot-tests.ts — skip any match whose position lands on whitespace in the stripped copy. Verification: local `bun scripts/p620/snapshot-tests.ts` now reports `193/193 pass, 0 fail, 0 placeholder` (was `1 placeholder`). Live will refresh on next deploy. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
2 files changed · +10 −1
scripts/p620/snapshot-tests.ts
+9
−0
| @@ -17,6 +17,7 @@ | ||
| 17 | 17 | import { spawnSync } from "node:child_process"; |
| 18 | 18 | import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; |
| 19 | 19 | import { resolve } from "node:path"; |
| 20 | +import { stripStringsAndComments } from "../../src/c32_sama_verify.ts"; | |
| 20 | 21 | |
| 21 | 22 | const REPO_ROOT = resolve(import.meta.dir, "..", ".."); |
| 22 | 23 | const OWNER = "syntaxai"; |
| @@ -100,9 +101,17 @@ interface PlaceholderTest { | ||
| 100 | 101 | // the catch is the common failure shape, not every theoretical one. |
| 101 | 102 | const findPlaceholderTests = (testFile: string, content: string): PlaceholderTest[] => { |
| 102 | 103 | const out: PlaceholderTest[] = []; |
| 104 | + // Strip strings & comments to a same-length whitespace mask. Used | |
| 105 | + // below to skip any test()/it() match whose keyword sits inside a | |
| 106 | + // string literal (the c32_sama_verify.test.ts fixtures hold real | |
| 107 | + // test source as backtick strings — those aren't real tests). | |
| 108 | + const mask = stripStringsAndComments(content); | |
| 103 | 109 | const re = /\b(test|it)\s*\(\s*(["'`])((?:\\.|(?!\2).)*)\2\s*,\s*(?:async\s+)?(?:\([^)]*\)|[^=()]*?)\s*=>\s*\{/g; |
| 104 | 110 | let m: RegExpExecArray | null; |
| 105 | 111 | while ((m = re.exec(content)) !== null) { |
| 112 | + // If the match position is whitespace in the mask, the original | |
| 113 | + // was inside a string or comment — skip. | |
| 114 | + if (mask[m.index] === " " || mask[m.index] === "\n") continue; | |
| 106 | 115 | const name = m[3] ?? ""; |
| 107 | 116 | const startBrace = re.lastIndex - 1; |
| 108 | 117 | let depth = 1; |
src/c32_sama_verify.ts
+1
−1
| @@ -49,7 +49,7 @@ const SAMA_PREFIX = /^c(\d{2})_/; | ||
| 49 | 49 | // is the cheapest reliable fix for the test-fixture false-positive: |
| 50 | 50 | // import strings and `test(...)` patterns inside literals/comments |
| 51 | 51 | // would otherwise trigger Sorted/Atomic violations. |
| 52 | -const stripStringsAndComments = (src: string): string => { | |
| 52 | +export const stripStringsAndComments = (src: string): string => { | |
| 53 | 53 | let out = ""; |
| 54 | 54 | let i = 0; |
| 55 | 55 | while (i < src.length) { |