scorpiox-bot-plugin-logs
←run.shbash
441 lines · 24 KBHEADBlameDownload
1#!/bin/sh
2# tests/run.sh - offline checks for plugin_logs across all 3 modes.
3#
4# Runs against ./plugin_logs (native build) on the live machine. Journal output
5# is replayed from a captured fixture so the parser is tested on the real
6# `journalctl -o json` layout without needing a running journald, and the file
7# reader is pointed at fixture logs through the SX_LOGS_EXTRA_ROOT knob. The
8# last section audits the whole git history for secrets and internal addresses.
9#
10# Exit code 0 = everything passed.
11
12set -u
13
14ROOT=$(cd "$(dirname "$0")/.." && pwd)
15cd "$ROOT" || exit 1
16
17BIN=./plugin_logs
18PASS=0
19FAIL=0
20TMP=$(mktemp -d 2>/dev/null || echo /tmp/logs_test_$$)
21mkdir -p "$TMP"
22trap 'rm -rf "$TMP"' EXIT
23
24if [ -t 1 ]; then
25 C_OK=$(printf '\033[32m'); C_BAD=$(printf '\033[31m'); C_B=$(printf '\033[1m'); C_0=$(printf '\033[0m')
26else
27 C_OK=; C_BAD=; C_B=; C_0=
28fi
29pass() { PASS=$((PASS + 1)); printf ' %sok%s %s\n' "$C_OK" "$C_0" "$1"; }
30fail() { FAIL=$((FAIL + 1)); printf ' %sFAIL%s %s\n' "$C_BAD" "$C_0" "$1"; }
31
32check() { # check <desc> <expected-substring> <actual>
33 if printf '%s' "$3" | grep -F -q -- "$2"; then pass "$1"; else
34 fail "$1 (want: $2)"; printf ' got: %s\n' "$(printf '%s' "$3" | head -c 300)"
35 fi
36}
37
38check_not() { # check_not <desc> <forbidden-substring> <actual>
39 if printf '%s' "$3" | grep -F -q -- "$2"; then
40 fail "$1 (must NOT contain: $2)"; else pass "$1"
41 fi
42}
43
44section() { printf '\n%s== %s ==%s\n' "$C_B" "$1" "$C_0"; }
45body() { printf '%s' "$1" | sed '1,/^\r$/d'; }
46
47# ---------------------------------------------------------------- fixtures
48# A journal stream in the exact shape journalctl -o json emits (one object per
49# line, microsecond epoch timestamps, string PRIORITY, arrays for binary fields).
50JFIX="$TMP/journal.jsonl"
51cat > "$JFIX" <<'JSONL'
52{"__REALTIME_TIMESTAMP":"1762923001000000","PRIORITY":"3","_SYSTEMD_UNIT":"nginx.service","MESSAGE":"upstream timed out while reading response header"}
53{"__REALTIME_TIMESTAMP":"1762923002000000","PRIORITY":"4","_SYSTEMD_UNIT":"systemd","MESSAGE":"Some unit is deprecated"}
54{"__REALTIME_TIMESTAMP":"1762923003000000","PRIORITY":"6","SYSLOG_IDENTIFIER":"kernel","MESSAGE":"eth0 link up"}
55{"__REALTIME_TIMESTAMP":"1762923004000000","PRIORITY":"6","_SYSTEMD_UNIT":"cron.service","MESSAGE":["multi","line"]}
56{"__REALTIME_TIMESTAMP":"1762923005000000","PRIORITY":"6","_SYSTEMD_UNIT":"sshd.service","MESSAGE":"Accepted publickey for root"}
57JSONL
58
59FROOT="$TMP/fixtures"
60mkdir -p "$FROOT/sub/deeper"
61printf 'Nov 12 06:30:01 host sshd[123]: error: failed login\nNov 12 06:30:02 host cron[9]: (root) CMD ok\n' > "$FROOT/sub/app.log"
62cat > "$FROOT/sub/deeper/iso.log" <<'LOG'
632026-11-12T06:31:00Z warn: something is deprecated
642026-11-12T06:31:05Z FATAL: disk controller panic
65plain line with no timestamp at all
66LOG
67printf 'not a log file\n' > "$FROOT/sub/notes.txt"
68ZEROS="$FROOT/sub/deeper/empty.log"
69: > "$ZEROS"
70
71export SX_LOGS_JOURNAL_FIXTURE="$JFIX"
72export SX_LOGS_EXTRA_ROOT="$FROOT"
73
74jq_() { # jq_ <desc> <python-expression using d> <json>
75 printf '%s' "$3" > "$TMP/_j.json"
76 if python3 - "$TMP/_j.json" "$2" <<'PY' 2>/dev/null
77import json, sys
78d = json.load(open(sys.argv[1]))
79assert eval(sys.argv[2], {"d": d}), sys.argv[2]
80PY
81 then pass "$1"; else fail "$1"; fi
82}
83
84# ---------------------------------------------------------------- build
85section "build"
86if [ ! -x "$BIN" ]; then
87 echo " building native binary..."
88 cc -O2 -std=c99 -Wall -Wextra -I src -o "$BIN" src/plugin_logs.c || { echo " build failed"; exit 1; }
89fi
90[ -x "$BIN" ] && pass "native binary exists and is executable" || fail "native binary missing"
91
92# ---------------------------------------------------------------- meta mode
93section "mode 1 --meta (must work without auth - discovery)"
94META=$("$BIN" --meta)
95check "meta emits name logs" '"name":"logs"' "$META"
96check "meta emits desc Log viewer" '"desc":"Log viewer"' "$META"
97METAENV=$(SX_PLUGIN_META=1 "$BIN")
98check "SX_PLUGIN_META=1 yields same meta" '"name":"logs"' "$METAENV"
99LEN=$(printf '%s' "$META" | wc -c | tr -d ' ')
100[ "$LEN" -lt 60 ] && pass "meta payload is compact ($LEN bytes)" || fail "meta payload too long ($LEN)"
101printf '%s' "$META" | python3 -c 'import json,sys; json.load(sys.stdin)' 2>/dev/null \
102 && pass "meta is valid JSON" || fail "meta is not valid JSON"
103DESC=$(printf '%s' "$META" | sed 's/.*"desc":"\([^"]*\)".*/\1/')
104[ ${#DESC} -le 15 ] && pass "desc length ${#DESC} <= 15 chars" || fail "desc too long (${#DESC})"
105NAME=$(printf '%s' "$META" | sed 's/.*"name":"\([^"]*\)".*/\1/')
106[ "$(printf '%s' "$NAME" | wc -w | tr -d ' ')" -le 2 ] && pass "name is at most two words" || fail "name has too many words"
107check "--version prints version" '1.0.0' "$("$BIN" --version)"
108check "--help is available" 'usage:' "$("$BIN" --help)"
109META_AUTH=$(BOT_PASSWORD=secret "$BIN" --meta)
110check "meta still works when BOT_PASSWORD is set" '"name":"logs"' "$META_AUTH"
111
112# ---------------------------------------------------------------- auth
113section "node auth"
114AUTHNONE=$(BOT_PASSWORD=testpw QUERY_STRING='action=sources' "$BIN")
115check "no credentials -> 401" 'Status: 401' "$AUTHNONE"
116check "401 body is json" 'invalid node password' "$AUTHNONE"
117AUTHH=$(body "$(BOT_PASSWORD=testpw HTTP_X_BOT_PASSWORD=testpw QUERY_STRING='action=sources' "$BIN")")
118check "X-Bot-Password accepted" '"ok":true' "$AUTHH"
119AUTHB=$(body "$(BOT_PASSWORD=testpw HTTP_AUTHORIZATION='Bearer testpw' QUERY_STRING='action=sources' "$BIN")")
120check "Authorization Bearer accepted" '"ok":true' "$AUTHB"
121AUTHQ=$(body "$(BOT_PASSWORD=testpw QUERY_STRING='action=sources&pwd=testpw' "$BIN")")
122check "?pwd= accepted (plugin iframe)" '"ok":true' "$AUTHQ"
123AUTHBAD=$(BOT_PASSWORD=testpw QUERY_STRING='action=sources&pwd=wrong' "$BIN")
124check "wrong ?pwd= -> 401" 'Status: 401' "$AUTHBAD"
125META_NOAUTH=$(BOT_PASSWORD=testpw "$BIN" --meta)
126check "--meta is never gated by auth" '"name":"logs"' "$META_NOAUTH"
127
128# ---------------------------------------------------------------- sources
129section "mode 2 action=sources"
130SRCJSON=$(body "$(QUERY_STRING='action=sources' "$BIN")")
131check "sources ok:true" '"ok":true' "$SRCJSON"
132check "sources echoes the action" '"action":"sources"' "$SRCJSON"
133check "sources reports journal availability" '"journal_available":' "$SRCJSON"
134check "sources carries the plugin id" '"plugin":"plugin_logs"' "$SRCJSON"
135check "sources reports truncation flag" '"truncated":' "$SRCJSON"
136check "fixture log listed" "file:$FROOT/sub/app.log" "$SRCJSON"
137check "nested fixture log listed" "deeper/iso.log" "$SRCJSON"
138check_not "non-.log fixture is not listed" "notes.txt" "$SRCJSON"
139jq_ 'sources has one entry per listed item' 'd["count"] == len(d["sources"])' "$SRCJSON"
140jq_ 'every source has id/label/kind' 'all(s.get("id") and s.get("label") and s.get("kind") for s in d["sources"])' "$SRCJSON"
141jq_ 'file sources carry a positive size' 'all(s["size"] > 0 for s in d["sources"] if s["kind"] == "file")' "$SRCJSON"
142jq_ 'every source path is inside an allowlisted root' 'all((s["id"].startswith("file:/var/log/") or s["id"].startswith("file:/workspace/") or s["id"].startswith("file:" + __import__("os").environ["HOME"] + "/.scorpiox/") or s["id"].startswith("file:'"$FROOT"'/") or s["id"] in ("journal",) or s["id"].startswith("event:")) for s in d["sources"])' "$SRCJSON"
143
144# ---------------------------------------------------------------- tail (journal)
145section "mode 2 action=tail (journal fixture)"
146JT=$(body "$(QUERY_STRING='action=tail&src=journal&lines=10' "$BIN")")
147check "journal tail ok:true" '"ok":true' "$JT"
148check "journal tail echoes src" '"src":"journal"' "$JT"
149check "journal tail kind journal" '"kind":"journal"' "$JT"
150check "journal severity err from PRIORITY=3" '"sev":"err"' "$JT"
151check "journal severity warn from PRIORITY=4" '"sev":"warn"' "$JT"
152check "journal unit extracted" '"unit":"nginx.service"' "$JT"
153check "journal message extracted" 'upstream timed out' "$JT"
154check "binary MESSAGE rendered as a placeholder" '"(binary)"' "$JT"
155check "SYSLOG_IDENTIFIER used when no unit" '"unit":"kernel"' "$JT"
156jq_ 'journal tail returns exactly the fixture entries' 'd["count"] == 5 and len(d["entries"]) == 5' "$JT"
157jq_ 'journal timestamps are formatted' 'all(len(e["ts"]) >= 8 for e in d["entries"])' "$JT"
158jq_ 'journal severities are one of info/warn/err' 'all(e["sev"] in ("info","warn","err") for e in d["entries"])' "$JT"
159jq_ 'journal text is never empty' 'all(e["text"] != "" for e in d["entries"])' "$JT"
160
161J1=$(body "$(QUERY_STRING='action=tail&src=journal&lines=1' "$BIN")")
162jq_ 'lines=1 limits the fixture window to one entry' 'd["count"] >= 1 and d["requested"] == 1' "$J1"
163JBIG=$(body "$(QUERY_STRING='action=tail&src=journal&lines=999999' "$BIN")")
164check "absurd lines still answers ok" '"ok":true' "$JBIG"
165check "absurd lines is capped" '"requested":2000' "$JBIG"
166JZERO=$(body "$(QUERY_STRING='action=tail&src=journal&lines=0' "$BIN")")
167check "lines=0 falls back to the default" '"requested":200' "$JZERO"
168
169# ---------------------------------------------------------------- tail (file)
170section "mode 2 action=tail (log file)"
171FSRC="file:$FROOT/sub/app.log"
172FT=$(body "$(QUERY_STRING="action=tail&src=$FSRC&lines=10" "$BIN")")
173check "file tail ok:true" '"ok":true' "$FT"
174check "file tail kind file" '"kind":"file"' "$FT"
175check "syslog timestamp parsed" '"ts":"Nov 12 06:30:01"' "$FT"
176check "syslog unit parsed" '"unit":"sshd[123]"' "$FT"
177check "syslog message parsed" 'error: failed login' "$FT"
178check "error line is severity err" '"sev":"err"' "$FT"
179jq_ 'file tail returns every fixture line' 'd["count"] == 2' "$FT"
180
181ISRC="file:$FROOT/sub/deeper/iso.log"
182IT=$(body "$(QUERY_STRING="action=tail&src=$ISRC&lines=10" "$BIN")")
183check "ISO-8601 timestamp parsed" '"ts":"2026-11-12T06:31:00Z"' "$IT"
184check "FATAL line is severity err" 'disk controller panic' "$IT"
185check "plain line still has text" 'plain line with no timestamp' "$IT"
186jq_ 'plain line carries no timestamp' 'any(e["ts"] == "" for e in d["entries"])' "$IT"
187
188ESRC="file:$FROOT/sub/deeper/empty.log"
189ET=$(body "$(QUERY_STRING="action=tail&src=$ESRC&lines=5" "$BIN")")
190check "empty file answers ok (or is simply not listed)" '"ok":' "$ET"
191
192# ---------------------------------------------------------------- search
193section "mode 2 action=search"
194ST=$(body "$(QUERY_STRING="action=search&src=$FSRC&q=FAILED" "$BIN")")
195check "search is case-insensitive" 'error: failed login' "$ST"
196check "search echoes the query" '"q":"FAILED"' "$ST"
197check "search reports scanned count" '"scanned":' "$ST"
198jq_ 'case-insensitive search finds exactly the failing line' 'd["count"] == 1' "$ST"
199jq_ 'search response carries hit objects' 'all("ts" in h and "sev" in h and "text" in h for h in d["hits"])' "$ST"
200
201SMISS=$(body "$(QUERY_STRING="action=search&src=$FSRC&q=zzzznotthere" "$BIN")")
202jq_ 'a query with no match returns zero hits' 'd["ok"] is True and d["count"] == 0' "$SMISS"
203check "no-match is not an error" '"ok":true' "$SMISS"
204
205JS=$(body "$(QUERY_STRING='action=search&src=journal&q=deprecated' "$BIN")")
206jq_ 'journal search filters the fixture' 'd["count"] == 1 and d["scanned"] == 5' "$JS"
207check "journal search keeps severity" '"sev":"warn"' "$JS"
208
209NOQ=$(body "$(QUERY_STRING="action=search&src=$FSRC" "$BIN")")
210check "search without q is rejected" 'missing_query' "$NOQ"
211
212# ---------------------------------------------------------------- refusals
213section "mode 2 refusals (read allowlist)"
214for bad in 'file:/etc/passwd' 'file:/etc/shadow' 'file:/proc/self/environ' \
215 '../../../../etc/passwd' 'journal:../../etc' 'file:' ''; do
216 R=$(body "$(QUERY_STRING="action=tail&src=$bad&lines=5" "$BIN")")
217 if printf '%s' "$R" | grep -F -q 'source_not_allowed' || printf '%s' "$R" | grep -F -q 'source_unavailable'; then
218 pass "refused: ${bad:-<empty>}"
219 else
220 fail "should have refused: ${bad:-<empty>}"
221 printf ' got: %s\n' "$(printf '%s' "$R" | head -c 200)"
222 fi
223done
224R=$(body "$(QUERY_STRING='action=tail&src=file:/workspace' "$BIN")")
225check_not "a directory is never opened as a log" '"ok":true' "$R"
226RU=$(body "$(QUERY_STRING='action=tail&src=journal:--help' "$BIN")")
227check_not "a unit name starting with '-' is refused" '"ok":true' "$RU"
228RU2=$(body "$(QUERY_STRING='action=tail&src=journal:nginx.service;rm -rf /' "$BIN")")
229check_not "a unit name with shell text is refused" '"ok":true' "$RU2"
230
231UNK=$(body "$(QUERY_STRING='action=bogus' "$BIN")")
232check "unknown action rejected" 'unknown_action' "$UNK"
233check "unknown action lists supported" '"supported":["sources","tail","search","units","info"]' "$UNK"
234check "unknown action echoes request" '"requested":"bogus"' "$UNK"
235
236# ---------------------------------------------------------------- units / info
237section "mode 2 action=units and action=info"
238UNITS=$(body "$(QUERY_STRING='action=units' "$BIN")")
239check "units ok:true" '"ok":true' "$UNITS"
240check "units reports availability" '"available":' "$UNITS"
241jq_ 'units count matches the array' 'd["count"] == len(d["units"])' "$UNITS"
242jq_ 'every unit offers a journal:<name> src' 'all(u["src"].startswith("journal:") for u in d["units"])' "$UNITS"
243
244INFO=$(body "$(QUERY_STRING='action=info' "$BIN")")
245check "info ok:true" '"ok":true' "$INFO"
246check "info action info" '"action":"info"' "$INFO"
247check "info declares zero network" '"zero_network":true' "$INFO"
248check "info declares read-only" '"read_only":true' "$INFO"
249check "info node_auth false when unset" '"node_auth":false' "$INFO"
250check "info publishes the line cap" '"lines_max":2000' "$INFO"
251check "info publishes the hit cap" '"search_hits_max":500' "$INFO"
252INFOAUTH=$(body "$(BOT_PASSWORD=pw QUERY_STRING='action=info&pwd=pw' "$BIN")")
253check "info node_auth true when set" '"node_auth":true' "$INFOAUTH"
254printf '%s' "$INFO" | python3 -c 'import json,sys; json.load(sys.stdin)' 2>/dev/null \
255 && pass "info body is valid JSON" || fail "info body JSON invalid"
256check "format=json works as an alias" '"ok":true' "$(body "$(QUERY_STRING='format=json&action=info' "$BIN")")"
257
258# ---------------------------------------------------------------- html
259section "mode 3 HTML"
260HTML=$(QUERY_STRING='' "$BIN")
261check "html content-type" 'Content-Type: text/html; charset=utf-8' "$HTML"
262check_not "html has no Content-Length" 'Content-Length' "$HTML"
263check "html has viewport meta" 'width=device-width' "$HTML"
264check "html title logs" '<title>logs</title>' "$HTML"
265check "html back-link present" 'Back to Bot' "$HTML"
266check "html theme switch hook" 'bot_theme' "$HTML"
267check "html source picker present" "id='srcSel'" "$HTML"
268check "html log viewport present" "id='log'" "$HTML"
269check "html search input present" "id='q'" "$HTML"
270check "html follow toggle present" "id='btnFollow'" "$HTML"
271check "html wrap toggle present" "id='btnWrap'" "$HTML"
272check "html copy button present" "id='btnCopy'" "$HTML"
273check "html line-count segmented control" 'data-n=' "$HTML"
274check "html calls action=sources" 'action=sources' "$HTML"
275check "html calls action=tail" 'action=tail' "$HTML"
276check "html calls action=search" 'action=search' "$HTML"
277check "html uses /plugins?plugin= route" "/plugins?plugin=" "$HTML"
278check "html falls back to /plugin_logs" "/plugin_logs" "$HTML"
279check "html highlights matches with mark" "'mark'" "$HTML"
280check "html polls every 3s when following" '3000' "$HTML"
281check "html pauses when the tab is hidden" 'visibilitychange' "$HTML"
282check "html closes document" '</html>' "$HTML"
283check "html declares read-only local read" 'read-only' "$HTML"
284
285# ---- theme handoff (bot_theme_plugin.h) ----
286check "html reads ?theme= before paint" 'theme=(light|dark)' "$HTML"
287check "html has the sx-theme listener" "type==='sx-theme'" "$HTML"
288check "html asks the host for its theme" 'sx-theme-request' "$HTML"
289check "html uses the shared bot_theme key" "localStorage.getItem('bot_theme')" "$HTML"
290check "html carries bot theme tokens" '--bg-card' "$HTML"
291check_not "html no private palette 0b0b0e" '0b0b0e' "$HTML"
292check_not "html no private palette 141419" '141419' "$HTML"
293check_not "html no private palette f2f2f6" 'f2f2f6' "$HTML"
294THEMEQ=$(QUERY_STRING='theme=light' "$BIN")
295check "?theme=light still renders the UI" 'prefers-color-scheme' "$THEMEQ"
296
297EMB=$(QUERY_STRING='embed=1' "$BIN")
298check_not "embed=1 strips the back-link" 'Back to Bot' "$EMB"
299check "embed=1 still renders the UI" "id='log'" "$EMB"
300EMBT=$(QUERY_STRING='embed=true' "$BIN")
301check_not "embed=true also strips back-link" 'Back to Bot' "$EMBT"
302
303ZEROEMOJI=$(printf '%s' "$HTML" | python3 -c '
304import sys
305s = sys.stdin.read()
306bad = [c for c in s if ord(c) > 0x2600 and ord(c) not in (0x2014, 0x2013, 0x2026)]
307print(len(bad))
308')
309[ "$ZEROEMOJI" = "0" ] && pass "HTML contains no emoji glyphs" || fail "HTML has $ZEROEMOJI emoji glyph(s)"
310
311check_not "html has no <script src=>" '<script src=' "$HTML"
312check_not "html has no CDN reference" 'cdnjs' "$HTML"
313check_not "html has no external font" 'fonts.googleapis' "$HTML"
314PK="pico""bot"
315check_not "html has no internal fleet paths" "$PK" "$HTML"
316check_not "html has no private IPs" "192.168." "$HTML"
317check_not "html has no ssh/sshpass" "sshpass" "$HTML"
318
319section "responsive markup"
320check "html has a 760px breakpoint" '@media(max-width:760px)' "$HTML"
321check "html has a 480px breakpoint" '@media(max-width:480px)' "$HTML"
322check "html hides the unit column on mobile" 'ln .un{display:none}' "$HTML"
323check "html scrolls the log viewport" 'overflow:auto' "$HTML"
324
325# ---------------------------------------------------------------- source audit
326section "no sockets, no user-controlled shell"
327SRCCAT=$(cat src/plugin_logs.c)
328check_not "source opens no sockets" 'socket(' "$SRCCAT"
329check_not "source has no curl or wget" 'wget' "$SRCCAT"
330check_not "source has no ssh invocation" 'ssh ' "$SRCCAT"
331check_not "source has no sshpass" 'sshpass' "$SRCCAT"
332check_not "source never calls system()" 'system(' "$SRCCAT"
333check "journal argv is built with snprintf" 'journalctl -o json --no-pager' "$SRCCAT"
334check "macOS log is called by absolute path" '/usr/bin/log show --style compact' "$SRCCAT"
335check "wevtutil argv names the channel" 'wevtutil qe %s /c:%d /rd:true /f:text' "$SRCCAT"
336# the journal kind means journalctl on Linux and `log show` on macOS, so the
337# platform branch must come BEFORE the generic kind check in both collectors
338check "platform branch precedes the journalctl branch" \
339 'if defined(__APPLE__)
340 if (strcmp(s->kind, "journal") == 0)' "$(printf '%s' "$SRCCAT" | sed -n '/static int collect_tail/,/^}/p')"
341check "search collector dispatches by platform too" \
342 '/usr/bin/log show' "$SRCCAT"
343check "unit names are validated" 'valid_unit' "$SRCCAT"
344check "files are opened read-only" '"rb"' "$SRCCAT"
345check "tail reads are bounded" 'FILE_TAIL_BYTES' "$SRCCAT"
346check "walks have a per-root budget" 'ROOT_BUDGET' "$SRCCAT"
347check "symlinks are never followed" 'S_ISLNK' "$SRCCAT"
348
349# ---------------------------------------------------------------- optional targets
350section "optional cross builds"
351if [ -f plugin_logs.musl ]; then
352 M=$(./plugin_logs.musl --meta)
353 check "musl build --meta" '"name":"logs"' "$M"
354 case $(head -c 4 plugin_logs.musl | od -An -tx1 | tr -d ' \n') in
355 7f454c46) pass "musl artifact is ELF" ;;
356 *) fail "musl artifact is not ELF" ;;
357 esac
358else
359 echo " skip musl (not built)"
360fi
361if [ -f plugin_logs.arm64 ]; then
362 case $(head -c 20 plugin_logs.arm64 | od -An -tx1 | tr -d ' \n') in
363 7f454c46*e500b700*|7f454c46*b700*) pass "arm64 artifact is an aarch64 ELF" ;;
364 7f454c46*)
365 if od -An -tx1 -j18 -N2 plugin_logs.arm64 | tr -d ' \n' | grep -q 'b7'; then
366 pass "arm64 artifact is an aarch64 ELF"
367 else
368 fail "arm64 artifact is not aarch64"
369 fi ;;
370 *) fail "arm64 artifact is not ELF" ;;
371 esac
372else
373 echo " skip arm64 (not built)"
374fi
375if [ -f plugin_logs.exe ]; then
376 MAGIC=$(head -c 2 plugin_logs.exe)
377 [ "$MAGIC" = "MZ" ] && pass "windows artifact has MZ header" || fail "windows artifact missing MZ"
378 SZ=$(wc -c < plugin_logs.exe | tr -d ' ')
379 [ "$SZ" -gt 20000 ] && pass "windows artifact is not an error page ($SZ bytes)" || fail "windows artifact suspiciously small ($SZ bytes)"
380else
381 echo " skip windows PE (not built)"
382fi
383if [ -f plugin_logs.macos-arm64 ]; then
384 case $(head -c 4 plugin_logs.macos-arm64 | od -An -tx1 | tr -d ' \n') in
385 cffaedfe|cefaedfe) pass "macos-arm64 artifact is Mach-O" ;;
386 *) fail "macos-arm64 artifact is not Mach-O" ;;
387 esac
388else
389 echo " skip macos-arm64 (not built)"
390fi
391if [ -f plugin_logs.macos-x86_64 ]; then
392 case $(head -c 4 plugin_logs.macos-x86_64 | od -An -tx1 | tr -d ' \n') in
393 cffaedfe|cefaedfe) pass "macos-x86_64 artifact is Mach-O" ;;
394 *) fail "macos-x86_64 artifact is not Mach-O" ;;
395 esac
396else
397 echo " skip macos-x86_64 (not built)"
398fi
399
400# ---------------------------------------------------------------- history audit
401section "git history secret & LAN audit"
402if git rev-parse --git-dir >/dev/null 2>&1; then
403 ALL="$TMP/history.txt"
404 # Bookkeeping lines of this audit are excluded so the detector cannot flag
405 # itself. Detector literals are also assembled from fragments below.
406 git log -p --all 2>/dev/null \
407 | grep -v '^Author: ' \
408 | grep -vE 'audit "|HITS=|grep -E|scan "' \
409 > "$ALL" || : > "$ALL"
410
411 audit() { # audit <label> <regex>
412 H=$(grep -Eo "$2" "$ALL" 2>/dev/null | sort -u | head -3 || true)
413 if [ -n "$H" ]; then
414 fail "history: $1"; printf '%s\n' "$H" | sed 's/^/ /'
415 else
416 pass "history clean: $1"
417 fi
418 }
419 audit "LAN 192.168.x" '192\.168\.[0-9]+\.[0-9]+'
420 audit "private 10.x" '\b10\.[0-9]+\.[0-9]+\.[0-9]+'
421 audit "private 172.16-31.x" '172\.(1[6-9]|2[0-9]|3[01])\.[0-9]+\.[0-9]+'
422 audit "GitHub PAT" 'ghp_[A-Za-z0-9]{36}'
423 audit "HuggingFace token" 'hf_[A-Za-z0-9]{30,}'
424 audit "embedded git creds" 'scorpioxinc:[A-Za-z0-9]{20,}'
425 PK2="pico""bot"; WT=".work""trees"
426 audit "fleet path" "/codebases/${PK2}|${WT}/"
427 audit "internal hostname" 'intel-ultra''2|macmini''2018i5|laza''rus'
428else
429 echo " skip history audit (not a git checkout)"
430fi
431
432# ---------------------------------------------------------------- summary
433printf '\n%s== summary ==%s\n' "$C_B" "$C_0"
434printf ' passed: %d\n' "$PASS"
435printf ' failed: %d\n' "$FAIL"
436if [ "$FAIL" -ne 0 ]; then
437 printf ' %sRESULT: FAILED%s\n' "$C_BAD" "$C_0"
438 exit 1
439fi
440printf ' %sRESULT: ALL PASSED%s\n' "$C_OK" "$C_0"
441exit 0