|
24 | 24 | * Usage: |
25 | 25 | * node scripts/boundary-audit.mjs [--root <dir>] [--out <report.json>] |
26 | 26 | * |
27 | | - * Exit: 0 = clean, 1 = violations found (fail-closed), 2 = scanner error. |
| 27 | + * Exit: 0 = clean, 1 = violations found (fail-closed), 2 = scanner error — |
| 28 | + * a root that does not exist, or a scan that yields zero in-scope files, |
| 29 | + * exits 2: an empty scan certifies nothing and must never report PASS. |
28 | 30 | * Matched content is never echoed — only paths, check ids, and a redacted |
29 | 31 | * SHA-256 prefix. |
30 | 32 | */ |
31 | 33 |
|
32 | 34 | import { createHash } from "node:crypto"; |
33 | | -import { readFileSync, readdirSync, statSync, writeFileSync } from "node:fs"; |
| 35 | +import { existsSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs"; |
34 | 36 | import { dirname, join, relative, resolve } from "node:path"; |
35 | 37 | import { fileURLToPath } from "node:url"; |
36 | 38 |
|
@@ -129,7 +131,16 @@ function main() { |
129 | 131 | const root = resolve(rootIdx >= 0 ? args[rootIdx + 1] : REPO); |
130 | 132 | const outPath = outIdx >= 0 ? args[outIdx + 1] : null; |
131 | 133 |
|
| 134 | + if (!existsSync(root) || !statSync(root).isDirectory()) { |
| 135 | + console.error(`BOUNDARY-AUDIT: ERROR root does not exist or is not a directory: ${root}`); |
| 136 | + process.exit(2); |
| 137 | + } |
| 138 | + |
132 | 139 | const files = walk(root); |
| 140 | + if (files.length === 0) { |
| 141 | + console.error(`BOUNDARY-AUDIT: ERROR 0 files in scan scope under ${root} — refusing to certify an empty scan (fail-closed)`); |
| 142 | + process.exit(2); |
| 143 | + } |
133 | 144 | const findings = []; |
134 | 145 | let scannedText = 0; |
135 | 146 | let scannedJson = 0; |
|
0 commit comments