| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| import { execFileSync } from "node:child_process"; |
| import { fileURLToPath } from "node:url"; |
| import path from "node:path"; |
|
|
| const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); |
|
|
| interface RgMatch { |
| file: string; |
| line: number; |
| text: string; |
| } |
|
|
| function rgFindMarkers(): RgMatch[] { |
| |
| |
| let out = ""; |
| try { |
| out = execFileSync( |
| "rg", |
| [ |
| "--no-heading", |
| "-n", |
| "QUARANTINE-CONT-[0-9]{3}", |
| "-g", |
| "*.{ts,tsx,js,jsx,mts,cts}", |
| "-g", |
| "!**/audit-quarantine.ts", |
| "-g", |
| "!**/quarantine/index.ts", |
| "-g", |
| "!**/quarantine-enforcement.test.ts", |
| "-g", |
| "!**/honest-baseline-117.md", |
| "artifacts/", |
| "lib/", |
| "scripts/", |
| ], |
| { cwd: ROOT, encoding: "utf8" }, |
| ); |
| } catch (err: unknown) { |
| |
| const e = err as { status?: number; stdout?: string }; |
| if (e.status === 1) return []; |
| throw err; |
| } |
| const matches: RgMatch[] = []; |
| for (const raw of out.split("\n")) { |
| if (!raw.trim()) continue; |
| const m = raw.match(/^(.+?):(\d+):(.*)$/); |
| if (!m) continue; |
| matches.push({ file: m[1], line: Number(m[2]), text: m[3] }); |
| } |
| return matches; |
| } |
|
|
| function extractContId(text: string): string | null { |
| const m = text.match(/QUARANTINE-(CONT-\d{3})/); |
| return m ? m[1] : null; |
| } |
|
|
| async function main(): Promise<void> { |
| const { KNOWN_CONTAMINATIONS } = await import( |
| "../artifacts/api-server/src/lib/quarantine/index.ts" |
| ); |
| const knownIds = new Set(KNOWN_CONTAMINATIONS.map((c) => c.id)); |
| const markers = rgFindMarkers(); |
| const seenIds = new Set<string>(); |
| const orphanMarkers: string[] = []; |
|
|
| for (const m of markers) { |
| const id = extractContId(m.text); |
| if (!id) continue; |
| if (!knownIds.has(id)) { |
| orphanMarkers.push(`${m.file}:${m.line} ${id} not in KNOWN_CONTAMINATIONS`); |
| continue; |
| } |
| seenIds.add(id); |
| } |
|
|
| const missing: string[] = []; |
| for (const id of knownIds) { |
| if (!seenIds.has(id)) missing.push(id); |
| } |
|
|
| console.log( |
| `[audit-quarantine] markers found: ${markers.length}, distinct ids: ${seenIds.size}, registry: ${knownIds.size}`, |
| ); |
| let rc = 0; |
| if (orphanMarkers.length) { |
| console.error("\n[audit-quarantine] ORPHAN MARKERS (in code, not in KNOWN_CONTAMINATIONS):"); |
| for (const o of orphanMarkers) console.error(" - " + o); |
| rc = 1; |
| } |
| if (missing.length) { |
| console.error( |
| "\n[audit-quarantine] MISSING MARKERS (registered in KNOWN_CONTAMINATIONS, no `// QUARANTINE-<id>` marker found in source):", |
| ); |
| for (const id of missing) console.error(" - " + id); |
| rc = 1; |
| } |
| if (rc === 0) { |
| console.log("[audit-quarantine] ✓ all good (registry ↔ source markers consistent)"); |
| } |
| process.exit(rc); |
| } |
|
|
| main().catch((err) => { |
| console.error("[audit-quarantine] crashed:", err); |
| process.exit(2); |
| }); |
|
|