scorpiox-bot-plugin-nvtop
←run.shbash
405 lines · 21 KBHEADBlameDownload
1#!/bin/sh
2# tests/run.sh - offline checks for plugin_nvtop across all 3 modes.
3#
4# Runs against ./plugin_nvtop (native build) on whatever machine it is executed
5# on, so the CPU-only assertions use this host's real state. Multi-GPU telemetry
6# is exercised deterministically through the NVTOP_MOCK_* fixtures, which is the
7# whole point of those hooks: a build box without a GPU must still be able to
8# prove the parsers are correct.
9#
10# If a musl static build, an aarch64 build or a Windows PE are present they are
11# checked too. The whole git history is finally audited for secrets and LAN IPs.
12#
13# Exit code 0 = everything passed.
14
15set -u
16
17ROOT=$(cd "$(dirname "$0")/.." && pwd)
18cd "$ROOT" || exit 1
19
20BIN=./plugin_nvtop
21FIX=tests/fixtures
22PASS=0
23FAIL=0
24
25if [ -t 1 ]; then
26 C_OK=$(printf '\033[32m'); C_BAD=$(printf '\033[31m'); C_B=$(printf '\033[1m'); C_0=$(printf '\033[0m')
27else
28 C_OK=; C_BAD=; C_B=; C_0=
29fi
30pass() { PASS=$((PASS + 1)); printf ' %sok%s %s\n' "$C_OK" "$C_0" "$1"; }
31fail() { FAIL=$((FAIL + 1)); printf ' %sFAIL%s %s\n' "$C_BAD" "$C_0" "$1"; }
32
33check() { # check <desc> <expected-substring> <actual>
34 if printf '%s' "$3" | grep -F -q -- "$2"; then pass "$1"; else
35 fail "$1 (want: $2)"; printf ' got: %s\n' "$(printf '%s' "$3" | head -c 300)"
36 fi
37}
38
39check_not() { # check_not <desc> <forbidden-substring> <actual>
40 if printf '%s' "$3" | grep -F -q -- "$2"; then
41 fail "$1 (must NOT contain: $2)"; else pass "$1"
42 fi
43}
44
45section() { printf '\n%s== %s ==%s\n' "$C_B" "$1" "$C_0"; }
46
47body() { printf '%s' "$1" | sed '1,/^\r$/d'; }
48
49py() { # py <desc> <python-script> <json-file> [extra args...]
50 desc=$1; script=$2; file=$3; shift 3
51 if python3 -c "$script" "$file" "$@" 2>/dev/null; then pass "$desc"; else fail "$desc"; fi
52}
53
54TMP=$(mktemp -d 2>/dev/null || echo /tmp/nvtop_tests_$$)
55mkdir -p "$TMP" 2>/dev/null || true
56
57# ---------------------------------------------------------------- build
58section "build"
59if [ ! -x "$BIN" ]; then
60 echo " building native binary..."
61 cc -O2 -std=c99 -Wall -Wextra -o "$BIN" src/plugin_nvtop.c || { echo " build failed"; exit 1; }
62fi
63[ -x "$BIN" ] && pass "native binary exists and is executable" || fail "native binary missing"
64
65# ---------------------------------------------------------------- meta mode
66section "mode 1 --meta (must work without auth - discovery)"
67META=$("$BIN" --meta)
68check "meta emits name nvtop" '"name":"nvtop"' "$META"
69check "meta emits desc Local GPUs" '"desc":"Local GPUs"' "$META"
70METAENV=$(SX_PLUGIN_META=1 "$BIN")
71check "SX_PLUGIN_META=1 yields same meta" '"name":"nvtop"' "$METAENV"
72LEN=$(printf '%s' "$META" | wc -c | tr -d ' ')
73[ "$LEN" -lt 60 ] && pass "meta payload is compact ($LEN bytes)" || fail "meta payload too long ($LEN)"
74printf '%s' "$META" | python3 -c 'import json,sys; json.load(sys.stdin)' 2>/dev/null \
75 && pass "meta is valid JSON" || fail "meta is not valid JSON"
76DESC=$(printf '%s' "$META" | sed 's/.*"desc":"\([^"]*\)".*/\1/')
77[ ${#DESC} -le 15 ] && pass "desc length ${#DESC} <= 15 chars" || fail "desc too long (${#DESC})"
78NAME=$(printf '%s' "$META" | sed 's/.*"name":"\([^"]*\)".*/\1/')
79[ "$(printf '%s' "$NAME" | wc -w | tr -d ' ')" -le 1 ] && pass "name is a single word" || fail "name has spaces"
80check "--version prints version" '1.0.3' "$("$BIN" --version)"
81check "--help is available" 'usage:' "$("$BIN" --help)"
82check "--help documents the mock hook" 'NVTOP_MOCK_CSV' "$("$BIN" --help)"
83META_AUTH=$(BOT_PASSWORD=secret "$BIN" --meta)
84check "meta still works when BOT_PASSWORD is set" '"name":"nvtop"' "$META_AUTH"
85
86# ---------------------------------------------------------------- auth
87section "node auth"
88AUTHNONE=$(BOT_PASSWORD=testpw QUERY_STRING='action=metrics' "$BIN")
89check "no credentials -> 401" 'Status: 401' "$AUTHNONE"
90check "401 body is json" 'invalid node password' "$AUTHNONE"
91AUTHH=$(BOT_PASSWORD=testpw HTTP_X_BOT_PASSWORD=testpw QUERY_STRING='action=metrics' "$BIN")
92check "X-Bot-Password accepted" '"ok":true' "$(body "$AUTHH")"
93AUTHB=$(BOT_PASSWORD=testpw HTTP_AUTHORIZATION='Bearer testpw' QUERY_STRING='action=metrics' "$BIN")
94check "Bearer token accepted" '"ok":true' "$(body "$AUTHB")"
95AUTHQ=$(BOT_PASSWORD=testpw QUERY_STRING='action=metrics&pwd=testpw' "$BIN")
96check "?pwd= accepted" '"ok":true' "$(body "$AUTHQ")"
97AUTHBAD=$(BOT_PASSWORD=testpw HTTP_X_BOT_PASSWORD=wrong QUERY_STRING='action=metrics' "$BIN")
98check "wrong password -> 401" 'Status: 401' "$AUTHBAD"
99AUTHPAGE=$(BOT_PASSWORD=testpw QUERY_STRING='embed=1' "$BIN")
100check "html mode is protected too" 'Status: 401' "$AUTHPAGE"
101
102# ---------------------------------------------------------------- json header
103section "mode 2 json framing"
104J0=$(body "$(QUERY_STRING='action=metrics' "$BIN")")
105check "json mode reports an action" '"action":"metrics"' "$J0"
106check_not "json mode emits no Content-Length" 'Content-Length' "$J0"
107check "json mode is ok" '"ok":true' "$J0"
108
109# ---------------------------------------------------------------- cpu-only
110section "mode 2 CPU-only node (clean empty state)"
111CPU="$TMP/cpu.json"
112printf '%s' "$J0" > "$CPU"
113if printf '%s' "$J0" | grep -F -q '"available":false'; then
114 pass "empty state reports available:false"
115 check "empty state counts zero gpus" '"count":0' "$J0"
116 check "empty state counts zero procs" '"process_count":0' "$J0"
117 check "empty state explains itself" 'No local NVIDIA/AMD GPU detected' "$J0"
118 check "empty state source is none" '"source":"none"' "$J0"
119 check "empty state power is null" '"power_w":null' "$J0"
120else
121 # A machine that really has a GPU (e.g. the .3 inference host) must report it.
122 pass "this node has a GPU, so available:true (not the empty state)"
123 python3 - "$CPU" <<'PY' && pass "live GPU rows are well formed" || fail "live GPU rows malformed"
124import json, sys
125d = json.load(open(sys.argv[1]))
126assert d["count"] >= 1
127for g in d["gpus"]:
128 assert isinstance(g["index"], int)
129 assert g["mem_total_mb"] > 0
130 assert 0 <= g["util_gpu"] <= 100
131PY
132fi
133py "empty-state payload is valid JSON" 'import json,sys; json.load(open(sys.argv[1]))' "$CPU"
134py "empty-state gpus is an empty array" 'import json,sys; d=json.load(open(sys.argv[1])); assert isinstance(d["gpus"], list); assert isinstance(d["processes"], list)' "$CPU"
135
136# ---------------------------------------------------------------- mock: 4 GPU
137section "mode 2 NVTOP_MOCK_CSV (4-GPU fixture, deterministic)"
138NVTOP_MOCK_CSV="$FIX/mock-4gpu.csv" QUERY_STRING='action=metrics' "$BIN" > "$TMP/raw-mock.txt"
139MOCK="$TMP/mock.json"
140body "$(cat "$TMP/raw-mock.txt")" > "$MOCK"
141J=$(cat "$MOCK")
142check "mock reports available:true" '"available":true' "$J"
143check "mock reports 4 gpus" '"count":4' "$J"
144check "mock reports 4 processes" '"process_count":4' "$J"
145check "mock source is mock" '"source":"mock"' "$J"
146check "mock is flagged as mocked" '"mocked":true' "$J"
147check "mock carries the driver" '"driver":"550.54.14"' "$J"
148check "mock carries the GPU name" 'NVIDIA H100 80GB HBM3' "$J"
149check "mock reports power" '"power_w":982.6' "$J"
150check "mock reports memory" '"mem_total_mb":327680' "$J"
151py "mock payload is valid JSON" 'import json,sys; json.load(open(sys.argv[1]))' "$MOCK"
152py "mock has exactly 4 well-formed GPU rows" \
153 'import json,sys; d=json.load(open(sys.argv[1])); g=d["gpus"]; assert len(g)==4; [ (lambda x: (assert_kind(x)))(x) for x in [] ];
154assert [x["index"] for x in g]==[0,1,2,3];
155assert all(isinstance(x["util_gpu"],(int,float)) for x in g);
156assert all(x["mem_total_mb"]==81920 for x in g)' "$MOCK"
157py "mock per-GPU utilisation parsed" \
158 'import json,sys; d=json.load(open(sys.argv[1])); u=[x["util_gpu"] for x in d["gpus"]]; assert u==[91.0,0.0,55.0,12.0], u' "$MOCK"
159py "mock unsupported temp/power become null" \
160 'import json,sys; d=json.load(open(sys.argv[1])); g=d["gpus"][3];
161assert g["temp_c"] is None and g["power_w"] is None and g["power_limit_w"] is None, g' "$MOCK"
162py "mock keeps a supported temp as a number" \
163 'import json,sys; d=json.load(open(sys.argv[1])); assert d["gpus"][0]["temp_c"]==74, d["gpus"][0]' "$MOCK"
164py "mock averages compute across all GPUs" \
165 'import json,sys; d=json.load(open(sys.argv[1])); assert abs(d["util_gpu_avg"]-39.5)<1e-6, d["util_gpu_avg"]' "$MOCK"
166py "mock power sums only the GPUs that report it" \
167 'import json,sys; d=json.load(open(sys.argv[1])); assert abs(d["power_w"]-982.6)<1e-6, d["power_w"]' "$MOCK"
168py "mock maps every process back to its GPU index" \
169 'import json,sys; d=json.load(open(sys.argv[1])); idx={p["pid"]:p["gpu_index"] for p in d["processes"]}
170assert idx[12001]==0 and idx[12002]==0 and idx[12044]==2 and idx[12077]==2, idx' "$MOCK"
171py "mock keeps process VRAM and names" \
172 'import json,sys; d=json.load(open(sys.argv[1])); p=[x for x in d["processes"] if x["pid"]==12001][0]
173assert p["name"]=="python3" and p["used_mb"]==68000, p' "$MOCK"
174py "mock uuids survive round-trip" \
175 'import json,sys; d=json.load(open(sys.argv[1]));
176assert d["gpus"][0]["uuid"]=="GPU-11111111-aaaa-bbbb-cccc-000000000001"' "$MOCK"
177py "mock message is empty when a GPU is present" \
178 'import json,sys; d=json.load(open(sys.argv[1])); assert d["message"]=="", d["message"]' "$MOCK"
179py "index.json-style keys are all present" \
180 'import json,sys; d=json.load(open(sys.argv[1]));
181for k in ["ok","available","driver","count","process_count","gpus","processes","source","utc"]:
182 assert k in d, k' "$MOCK"
183
184# ---------------------------------------------------------------- mock: raw nvidia
185section "mode 2 raw nvidia-smi csv fixture (real query layout)"
186NVTOP_MOCK_NVIDIA="$FIX/nvidia-4gpu.csv" QUERY_STRING='action=metrics' "$BIN" > "$TMP/raw-nv.txt"
187NVM="$TMP/nvm.json"
188body "$(cat "$TMP/raw-nv.txt")" > "$NVM"
189NV=$(cat "$NVM")
190check "raw probe reports 4 gpus" '"count":4' "$NV"
191check "raw probe reports 4 procs" '"process_count":4' "$NV"
192check "raw probe source is nvidia" '"source":"nvidia"' "$NV"
193check "raw probe is flagged mocked" '"mocked":true' "$NV"
194check "raw probe picks up the driver" '"driver":"550.54.14' "$NV"
195py "raw probe parses the same numbers as the fixture" \
196 'import json,sys; d=json.load(open(sys.argv[1])); assert [x["util_gpu"] for x in d["gpus"]]==[91.0,0.0,55.0,12.0]' "$NVM"
197py "raw probe tolerates N/A counters" \
198 'import json,sys; d=json.load(open(sys.argv[1])); g=d["gpus"][3]; assert g["temp_c"] is None and g["power_w"] is None' "$NVM"
199py "raw probe splits APP lines from GPU lines" \
200 'import json,sys; d=json.load(open(sys.argv[1])); assert d["processes"][0]["pid"]==12001' "$NVM"
201
202# An empty but successful probe must degrade to the clean empty state, not crash.
203NVTOP_MOCK_NVIDIA="$FIX/nvidia-empty.csv" QUERY_STRING='action=metrics' "$BIN" > "$TMP/raw-empty.txt"
204E=$(body "$(cat "$TMP/raw-empty.txt")")
205check "empty probe falls back to no-GPU state" '"available":false' "$E"
206check "empty probe explains itself" 'No local NVIDIA/AMD GPU detected' "$E"
207
208# ---------------------------------------------------------------- mock: rocm
209section "mode 2 rocm-smi text fixture (AMD path)"
210NVTOP_MOCK_ROCM="$FIX/rocm-1gpu.txt" QUERY_STRING='action=metrics' "$BIN" > "$TMP/raw-rocm.txt"
211RM="$TMP/rocm.json"
212body "$(cat "$TMP/raw-rocm.txt")" > "$RM"
213R=$(cat "$RM")
214check "rocm fixture reports one gpu" '"count":1' "$R"
215check "rocm fixture source is amd" '"source":"amd"' "$R"
216check "rocm fixture reads the product name" 'AMD Radeon RX 7900 XTX' "$R"
217py "rocm fixture converts VRAM bytes to MB" \
218 'import json,sys; d=json.load(open(sys.argv[1])); g=d["gpus"][0]
219assert abs(g["mem_total_mb"]-24560)<2, g["mem_total_mb"]
220assert abs(g["mem_used_mb"]-2048)<1, g["mem_used_mb"]' "$RM"
221py "rocm fixture parses utilisation, temp and power" \
222 'import json,sys; d=json.load(open(sys.argv[1])); g=d["gpus"][0]
223assert g["util_gpu"]==44.0 and g["temp_c"]==58 and g["power_w"]==112.0 and g["power_limit_w"]==355.0, g' "$RM"
224
225# ---------------------------------------------------------------- info
226section "mode 2 action=info"
227INFO=$(body "$(QUERY_STRING='action=info' "$BIN")")
228check "info names the plugin" '"plugin":"plugin_nvtop"' "$INFO"
229check "info reports the version" '"version":"1.0.3"' "$INFO"
230check "info lists the probes" 'nvidia-smi' "$INFO"
231check "info lists the mock hook" 'NVTOP_MOCK_CSV' "$INFO"
232check "info advertises zero_network" '"zero_network":true' "$INFO"
233check "info reports largest GPU count" '"max_gpus":32' "$INFO"
234INFOAUTH=$(BOT_PASSWORD=pw HTTP_X_BOT_PASSWORD=pw QUERY_STRING='action=info' "$BIN")
235check "info reflects node auth state" '"node_auth":true' "$INFOAUTH"
236
237# ---------------------------------------------------------------- unknown/misc
238section "mode 2 error handling"
239UNK=$(body "$(QUERY_STRING='action=destroy' "$BIN")")
240check "unknown action is rejected" '"ok":false' "$UNK"
241check "unknown action names itself" '"error":"unknown_action"' "$UNK"
242check "unknown action echoes input" '"requested":"destroy"' "$UNK"
243check "format=json aliases to metrics" '"action":"metrics"' "$(body "$(QUERY_STRING='format=json' "$BIN")")"
244BADAUTH=$(body "$(QUERY_STRING='action=metrics&pwd=x' BOT_PASSWORD=x "$BIN")")
245check "matching ?pwd still authorises" '"ok":true' "$BADAUTH"
246
247# ---------------------------------------------------------------- html
248section "mode 3 html dashboard"
249HTML=$("$BIN")
250check "html content type is set" 'Content-Type: text/html' "$HTML"
251check "html title is nvtop" "<title>nvtop</title>" "$HTML"
252
253# ---- theme handoff (bot_theme_plugin.h) ----
254# the bot owns the theme: ?theme= before first paint, sx-theme after it
255check "html reads ?theme= before paint" 'theme=(light|dark)' "$HTML"
256check "html listens for sx-theme" "d.type==='sx-theme'" "$HTML"
257check "html asks the host for the theme" "sx-theme-request" "$HTML"
258check "html uses bot token --bg-card" "--bg-card" "$HTML"
259check "html uses bot token --surface-2" "--surface-2" "$HTML"
260check "html uses bot token --text-2" "--text-2" "$HTML"
261check "html hides its toggle when embedded" "embed-hide" "$HTML"
262check_not "html no retired brand casing" 'Scorpio'"X Bot" "$HTML"
263check_not "html no private palette 0b0b0e" '0b0b0e' "$HTML"
264check_not "html no private palette 141419" '141419' "$HTML"
265check_not "html no private palette f2f2f6" 'f2f2f6' "$HTML"
266THEMEQ=$(QUERY_STRING='theme=light' "$BIN")
267check "?theme=light still renders the UI" 'prefers-color-scheme' "$THEMEQ"
268# ---- end theme handoff ----
269
270check_not "html emits no Content-Length" 'Content-Length' "$HTML"
271check "html has the compute legend" 'compute %' "$HTML"
272check "html has the VRAM legend" 'VRAM' "$HTML"
273check "html explains the empty state" 'No local NVIDIA/AMD GPU detected' "$HTML"
274check "empty state explains remote customization" 'customize' "$HTML"
275check "empty state points at the source file" 'src/plugin_nvtop.c' "$HTML"
276check "html renders per-GPU cards" "id='gpuGrid'" "$HTML"
277check "html renders the process table" "id='procRows'" "$HTML"
278check "html wires the refresh button" "id='btnRefresh'" "$HTML"
279check "html builds rolling sparklines" 'spark' "$HTML"
280check "html polls every 2s" '2000' "$HTML"
281check "html routes via the hub proxy" "/plugins?plugin=" "$HTML"
282check "html routes directly on the node" '/plugin_nvtop?action=' "$HTML"
283check "html carries pwd on fetches" 'X-Bot-Password' "$HTML"
284check_not "html has no emoji-ish escapes" '\u26' "$HTML"
285HTML_EMBED=$(QUERY_STRING='embed=1' "$BIN")
286check "embed mode still renders" "id='gpuGrid'" "$HTML_EMBED"
287check_not "embed mode drops the direct-open note" 'Opened directly from the node API' "$HTML_EMBED"
288check "non-embed mode keeps the note" 'Opened directly from the node API' "$HTML"
289check_not "html has no remote hosts" 'ssh ' "$HTML"
290
291# ---------------------------------------------------------------- source scan
292section "source invariants"
293SRCCAT=$(cat src/plugin_nvtop.c)
294check "source probes nvidia-smi" 'nvidia-smi --query-gpu' "$SRCCAT"
295check "source probes compute apps" '--query-compute-apps' "$SRCCAT"
296check "source probes rocm-smi" 'rocm-smi' "$SRCCAT"
297check "source redacts stderr per platform" 'DEV_NULL' "$SRCCAT"
298check "source refuses Content-Length" 'no Content-Length' "$SRCCAT"
299check "source requires node auth" 'require_node_auth' "$SRCCAT"
300check "source honours embed=1" 'embed=true' "$SRCCAT"
301check "source documents the mock hook" 'NVTOP_MOCK_CSV' "$SRCCAT"
302check_not "source has no sockets" 'socket(' "$SRCCAT"
303check_not "source has no curl" 'curl ' "$SRCCAT"
304check_not "source has no wget" 'wget' "$SRCCAT"
305check_not "source has no ssh invocation" 'ssh ' "$SRCCAT"
306check_not "source has no sshpass" 'sshpass' "$SRCCAT"
307check_not "source has no system()" 'system(' "$SRCCAT"
308SNUM=$(grep -cE 'popen\(' src/plugin_nvtop.c)
309[ "$SNUM" -ge 1 ] && pass "source uses popen only for fixed probe commands ($SNUM call)" \
310 || fail "source does not use popen at all (expected for the probes)"
311# Every popen() argument must be a compile-time constant, never a query value.
312grep -n 'popen(' src/plugin_nvtop.c | grep -F 'cmd' >/dev/null \
313 && pass "popen is called with the const cmd string only" || fail "popen call shape changed - re-audit"
314check_not "query string never reaches a shell" 'qs, "r"' "$SRCCAT"
315
316# ---------------------------------------------------------------- optional targets
317section "optional cross builds"
318if [ -f plugin_nvtop.musl ]; then
319 M=$(./plugin_nvtop.musl --meta)
320 check "musl build --meta" '"name":"nvtop"' "$M"
321 case $(head -c 4 plugin_nvtop.musl | od -An -tx1 | tr -d ' \n') in
322 7f454c46) pass "musl artifact is ELF" ;;
323 *) fail "musl artifact is not ELF" ;;
324 esac
325else
326 echo " skip musl (not built)"
327fi
328if [ -f plugin_nvtop.arm64 ]; then
329 case $(head -c 4 plugin_nvtop.arm64 | od -An -tx1 | tr -d ' \n') in
330 7f454c46) pass "arm64 artifact is ELF" ;;
331 *) fail "arm64 artifact is not ELF" ;;
332 esac
333 EM=$(od -An -tx1 -j 18 -N 2 plugin_nvtop.arm64 | tr -d ' \n')
334 [ "$EM" = "b700" ] && pass "arm64 artifact declares EM_AARCH64" \
335 || fail "arm64 artifact e_machine is $EM, expected b700"
336else
337 echo " skip arm64 (not built)"
338fi
339if [ -f plugin_nvtop.exe ]; then
340 MAGIC=$(head -c 2 plugin_nvtop.exe)
341 [ "$MAGIC" = "MZ" ] && pass "windows artifact has MZ header" || fail "windows artifact missing MZ"
342 SZ=$(wc -c < plugin_nvtop.exe | tr -d ' ')
343 [ "$SZ" -gt 20000 ] && pass "windows artifact is not an error page ($SZ bytes)" \
344 || fail "windows artifact suspiciously small ($SZ bytes)"
345else
346 echo " skip windows PE (not built)"
347fi
348for slice in arm64 x86_64; do
349 f="plugin_nvtop.macos-$slice"
350 if [ -f "$f" ]; then
351 MFG=$(head -c 4 "$f" | od -An -tx1 | tr -d ' \n')
352 case "$MFG" in
353 cffaedfe|feedfacf|cefaedfe|feedface) pass "macos-$slice artifact is Mach-O" ;;
354 *) fail "macos-$slice artifact is not Mach-O ($MFG)" ;;
355 esac
356 else
357 echo " skip macos-$slice (not built)"
358 fi
359done
360
361# ---------------------------------------------------------------- history audit
362section "git history secret & LAN audit"
363if git rev-parse --git-dir >/dev/null 2>&1; then
364 ALL="$TMP/history.txt"
365 # Bookkeeping lines of this audit are excluded so the detector cannot flag itself.
366 git log -p --all 2>/dev/null \
367 | grep -v '^Author: ' \
368 | grep -vE 'audit "|HITS=|grep -E|scan "|P_ROOT=|P_WT=' \
369 > "$ALL" || : > "$ALL"
370
371 audit() { # audit <label> <regex>
372 H=$(grep -Eo "$2" "$ALL" 2>/dev/null | sort -u | head -3 || true)
373 if [ -n "$H" ]; then
374 fail "history: $1"; printf '%s\n' "$H" | sed 's/^/ /'
375 else
376 pass "history clean: $1"
377 fi
378 }
379 audit "LAN 192.168.x" '192\.168\.[0-9]+\.[0-9]+'
380 audit "private 10.x" '\b10\.[0-9]+\.[0-9]+\.[0-9]+'
381 audit "private 172.16-31.x" '172\.(1[6-9]|2[0-9]|3[01])\.[0-9]+\.[0-9]+'
382 audit "GitHub PAT" 'ghp_[A-Za-z0-9]{36}'
383 audit "HuggingFace token" 'hf_[A-Za-z0-9]{30,}'
384 audit "embedded git creds" 'scorpioxinc:[A-Za-z0-9]{20,}'
385 # the literal is split so this file never contains the string it hunts
386 audit "bare host password" 'Xbo''xone0909|xbo''xone'
387 PK="pico""bot"; WT=".work""trees"
388 audit "fleet path" "/codebases/${PK}|${WT}/"
389 rm -f "$ALL"
390else
391 echo " skip history audit (not a git checkout)"
392fi
393
394rm -rf "$TMP"
395
396# ---------------------------------------------------------------- summary
397printf '\n%s== summary ==%s\n' "$C_B" "$C_0"
398printf ' passed: %d\n' "$PASS"
399printf ' failed: %d\n' "$FAIL"
400if [ "$FAIL" -ne 0 ]; then
401 printf ' %sRESULT: FAIL%s\n' "$C_BAD" "$C_0"
402 exit 1
403fi
404printf ' %sRESULT: PASS%s\n' "$C_OK" "$C_0"
405exit 0