syntaxai/tdd.md · commit a62513c

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]>
author
syntaxai <[email protected]>
date
2026-05-22 13:40:20 +01:00
parent
a485ee9
commit
a62513cab1b5fe7ee649f49c7ac065a0d4b5336b

2 files changed · +10 −1

modified scripts/p620/snapshot-tests.ts +9 −0
@@ -17,6 +17,7 @@
1717 import { spawnSync } from "node:child_process";
1818 import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
1919 import { resolve } from "node:path";
20+import { stripStringsAndComments } from "../../src/c32_sama_verify.ts";
2021
2122 const REPO_ROOT = resolve(import.meta.dir, "..", "..");
2223 const OWNER = "syntaxai";
@@ -100,9 +101,17 @@ interface PlaceholderTest {
100101 // the catch is the common failure shape, not every theoretical one.
101102 const findPlaceholderTests = (testFile: string, content: string): PlaceholderTest[] => {
102103 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);
103109 const re = /\b(test|it)\s*\(\s*(["'`])((?:\\.|(?!\2).)*)\2\s*,\s*(?:async\s+)?(?:\([^)]*\)|[^=()]*?)\s*=>\s*\{/g;
104110 let m: RegExpExecArray | null;
105111 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;
106115 const name = m[3] ?? "";
107116 const startBrace = re.lastIndex - 1;
108117 let depth = 1;
modified src/c32_sama_verify.ts +1 −1
@@ -49,7 +49,7 @@ const SAMA_PREFIX = /^c(\d{2})_/;
4949 // is the cheapest reliable fix for the test-fixture false-positive:
5050 // import strings and `test(...)` patterns inside literals/comments
5151 // would otherwise trigger Sorted/Atomic violations.
52-const stripStringsAndComments = (src: string): string => {
52+export const stripStringsAndComments = (src: string): string => {
5353 let out = "";
5454 let i = 0;
5555 while (i < src.length) {