| 1 | #!/bin/sh |
| 2 | # tests/run.sh - offline assertion suite for plugin_sessionstats. |
| 3 | # |
| 4 | # Everything here runs against synthetic session fixtures in a throwaway |
| 5 | # directory, so no real ~/.scorpiox/sessions is touched and no network, shell |
| 6 | # tool or real clock is involved. Every timestamp is fixed, so the expected |
| 7 | # durations are exact. |
| 8 | # |
| 9 | # Usage: sh tests/run.sh [path-to-binary] |
| 10 | # Exit: 0 when every assertion passes. |
| 11 | |
| 12 | set -u |
| 13 | |
| 14 | ROOT=$(cd "$(dirname "$0")/.." && pwd) |
| 15 | BIN=${1:-"$ROOT/plugin_sessionstats"} |
| 16 | [ -x "$BIN" ] || { echo "binary not built: $BIN" >&2; exit 1; } |
| 17 | |
| 18 | TMP=$(mktemp -d "${TMPDIR:-/tmp}/sx_sessionstats_XXXXXX") |
| 19 | trap 'rm -rf "$TMP"' EXIT |
| 20 | |
| 21 | PASS=0 |
| 22 | FAIL=0 |
| 23 | ok() { PASS=$((PASS+1)); } |
| 24 | bad() { FAIL=$((FAIL+1)); printf ' FAIL %s\n' "$1"; } |
| 25 | check() { # check <label> <actual> <expected> |
| 26 | if [ "$2" = "$3" ]; then ok; else bad "$1 (got '$2', want '$3')"; fi |
| 27 | } |
| 28 | |
| 29 | # ---------------------------------------------------------------- fixtures |
| 30 | S="$TMP/sessions" |
| 31 | mkdir -p "$S/s1" "$S/s2" "$S/s3" |
| 32 | |
| 33 | # --- s1: two complete runs, three tool kinds, a profile and a model |
| 34 | cat > "$S/s1/meta.json" <<'EOF' |
| 35 | { |
| 36 | "id": "2026_01_01_quiet_curie", |
| 37 | "thread_guid": "11111111-2222-3333-4444-555555555555", |
| 38 | "start_time": "2026-01-01 10:00:00", |
| 39 | "start_epoch": 1767261600, |
| 40 | "model": "alpha-1", |
| 41 | "provider": "openai", |
| 42 | "profile": "profile-alpha", |
| 43 | "cwd": "/work/alpha" |
| 44 | } |
| 45 | EOF |
| 46 | cat > "$S/s1/stats.json" <<'EOF' |
| 47 | { |
| 48 | "model": "alpha-1", |
| 49 | "branch": "main", |
| 50 | "input_tokens": 1000, |
| 51 | "output_tokens": 250, |
| 52 | "cache_read_tokens": 800, |
| 53 | "cache_creation_tokens": 50 |
| 54 | } |
| 55 | EOF |
| 56 | cat > "$S/s1/events.jsonl" <<'EOF' |
| 57 | {"ts":"2026-01-01 10:00:00","event":"session_start","model":"alpha-1","provider":"openai","profile":"profile-alpha"} |
| 58 | {"ts":"2026-01-01 10:00:05","event":"user_message","len":10} |
| 59 | {"ts":"2026-01-01 10:00:05","event":"agent_run_start","msg_len":10} |
| 60 | {"ts":"2026-01-01 10:00:15","event":"tool_use","tool":"Bash","input_len":12} |
| 61 | {"ts":"2026-01-01 10:00:20","event":"tool_use","tool":"Bash","input_len":20} |
| 62 | {"ts":"2026-01-01 10:00:30","event":"tool_use","tool":"Read","input_len":5} |
| 63 | {"ts":"2026-01-01 10:00:35","event":"agent_idle"} |
| 64 | {"ts":"2026-01-01 10:05:00","event":"user_message","len":8} |
| 65 | {"ts":"2026-01-01 10:05:00","event":"agent_run_start","msg_len":8} |
| 66 | {"ts":"2026-01-01 10:05:25","event":"tool_use","tool":"Write","input_len":9} |
| 67 | {"ts":"2026-01-01 10:05:40","event":"agent_complete"} |
| 68 | EOF |
| 69 | # run 1 = 10:00:05 -> 10:00:35 = 30s; run 2 = 10:05:00 -> 10:05:40 = 40s |
| 70 | # active = 70s, wall = 10:00:00 -> 10:05:40 = 340s, idle = 270s |
| 71 | |
| 72 | # --- s2: still running (open run + thinking marker), different profile |
| 73 | cat > "$S/s2/meta.json" <<'EOF' |
| 74 | { |
| 75 | "id": "2026_01_02_bold_lovelace", |
| 76 | "start_time": "2026-01-02 08:00:00", |
| 77 | "model": "beta-2", |
| 78 | "provider": "anthropic", |
| 79 | "profile": "profile-beta", |
| 80 | "cwd": "/work/beta" |
| 81 | } |
| 82 | EOF |
| 83 | cat > "$S/s2/events.jsonl" <<'EOF' |
| 84 | {"ts":"2026-01-02 08:00:00","event":"session_start","model":"beta-2","provider":"anthropic","profile":"profile-beta"} |
| 85 | {"ts":"2026-01-02 08:00:10","event":"user_message","len":5} |
| 86 | {"ts":"2026-01-02 08:00:10","event":"agent_run_start","msg_len":5} |
| 87 | {"ts":"2026-01-02 08:01:00","event":"tool_use","tool":"Bash","input_len":7} |
| 88 | {"ts":"2026-01-02 08:01:10","event":"api_response","turn":1} |
| 89 | EOF |
| 90 | : > "$S/s2/thinking" |
| 91 | # run still open at last event: active = 08:00:10 -> 08:01:10 = 60s, wall = 70s |
| 92 | |
| 93 | # --- s3: metadata only, no events at all (degenerate but must not crash) |
| 94 | cat > "$S/s3/meta.json" <<'EOF' |
| 95 | { |
| 96 | "id": "2026_01_03_empty_nash", |
| 97 | "start_time": "2026-01-03 00:00:00", |
| 98 | "start_epoch": 1767398400 |
| 99 | } |
| 100 | EOF |
| 101 | |
| 102 | run() { # run <query-string> [extra env assignments via args 2..] |
| 103 | qs="$1"; shift |
| 104 | env SX_SESSIONS_DIR="$S" QUERY_STRING="$qs" "$@" "$BIN" 2>/dev/null |
| 105 | } |
| 106 | |
| 107 | jsoncheck() { # jsoncheck <label> <json-file> <python-expression on d> <expected> |
| 108 | label="$1"; file="$2"; expr="$3"; want="$4" |
| 109 | got=$(python3 - "$file" "$expr" <<'PY' |
| 110 | import json, sys |
| 111 | d = json.load(open(sys.argv[1])) |
| 112 | try: |
| 113 | v = eval(sys.argv[2], {"d": d, "len": len, "sum": sum, "sorted": sorted}) |
| 114 | except Exception as e: |
| 115 | v = "ERR:%s" % e |
| 116 | print(v) |
| 117 | PY |
| 118 | ) |
| 119 | check "$label" "$got" "$want" |
| 120 | } |
| 121 | |
| 122 | echo "== meta mode" |
| 123 | out=$("$BIN" --meta) |
| 124 | check "--meta exact JSON" "$out" '{"name":"sessions","desc":"Turn metrics"}' |
| 125 | out=$(SX_PLUGIN_META=1 "$BIN") |
| 126 | check "SX_PLUGIN_META=1 exact JSON" "$out" '{"name":"sessions","desc":"Turn metrics"}' |
| 127 | check "meta name is other field free" "$(printf '%s' "$out" | python3 -c 'import json,sys;d=json.load(sys.stdin);print(len(d))')" "2" |
| 128 | check "meta name length <= 2 words" "$(printf '%s' "$out" | python3 -c 'import json,sys;print(len(json.load(sys.stdin)["name"].split()))')" "1" |
| 129 | check "meta desc length <= 15" "$(printf '%s' "$out" | python3 -c 'import json,sys;print(len(json.load(sys.stdin)["desc"])<=15)')" "True" |
| 130 | |
| 131 | echo "== auth gate" |
| 132 | code=$(BOT_PASSWORD=pw SX_SESSIONS_DIR="$S" QUERY_STRING=action=summary "$BIN" | head -1 | tr -d '\r') |
| 133 | check "401 without credential" "$code" "Status: 401 Unauthorized" |
| 134 | code=$(BOT_PASSWORD=pw HTTP_X_BOT_PASSWORD=pw SX_SESSIONS_DIR="$S" QUERY_STRING=action=summary "$BIN" | head -1 | cut -c1-12) |
| 135 | check "header credential accepted" "$code" "Content-Type" |
| 136 | code=$(BOT_PASSWORD=pw HTTP_AUTHORIZATION="Bearer pw" SX_SESSIONS_DIR="$S" QUERY_STRING=action=summary "$BIN" | head -1 | cut -c1-12) |
| 137 | check "bearer credential accepted" "$code" "Content-Type" |
| 138 | code=$(BOT_PASSWORD=pw SX_SESSIONS_DIR="$S" QUERY_STRING='action=summary&pwd=pw' "$BIN" | head -1 | cut -c1-12) |
| 139 | check "query credential accepted" "$code" "Content-Type" |
| 140 | code=$(BOT_PASSWORD=pw SX_SESSIONS_DIR="$S" "$BIN" --meta | cut -c1-10) |
| 141 | check "--meta stays unauthenticated" "$code" '{"name":"s' |
| 142 | code=$(BOT_PASSWORD=pw SX_SESSIONS_DIR="$S" QUERY_STRING=action=summary "$BIN" | tail -1) |
| 143 | check "401 body is JSON error" "$code" '{"ok":false,"error":"invalid node password"}' |
| 144 | |
| 145 | echo "== summary shape" |
| 146 | run 'action=summary' > "$TMP/sum.json" |
| 147 | last=$(tail -1 "$TMP/sum.json") |
| 148 | check "summary has no Content-Length" "$(printf '%s' "$last" | grep -c 'Content-Length')" "0" |
| 149 | printf '%s' "$last" > "$TMP/sum.body.json" |
| 150 | jsoncheck "ok" "$TMP/sum.body.json" 'd["ok"]' "True" |
| 151 | jsoncheck "plugin id" "$TMP/sum.body.json" 'd["plugin"]' "plugin_sessionstats" |
| 152 | jsoncheck "version" "$TMP/sum.body.json" 'd["version"]' "1.0.1" |
| 153 | jsoncheck "root_found" "$TMP/sum.body.json" 'd["root_found"]' "True" |
| 154 | jsoncheck "session count" "$TMP/sum.body.json" 'd["count"]' "3" |
| 155 | jsoncheck "active_now" "$TMP/sum.body.json" 'd["active_now"]' "1" |
| 156 | jsoncheck "turns total" "$TMP/sum.body.json" 'd["turns"]' "3" |
| 157 | jsoncheck "tool events" "$TMP/sum.body.json" 'd["tool_events"]' "5" |
| 158 | jsoncheck "total sec" "$TMP/sum.body.json" 'd["total_sec"]' "410" |
| 159 | jsoncheck "active sec" "$TMP/sum.body.json" 'd["active_sec"]' "130" |
| 160 | jsoncheck "idle sec" "$TMP/sum.body.json" 'd["idle_sec"]' "280" |
| 161 | jsoncheck "idle+active=total" "$TMP/sum.body.json" 'd["idle_sec"]+d["active_sec"]==d["total_sec"]' "True" |
| 162 | jsoncheck "duty pct" "$TMP/sum.body.json" 'round(d["duty_cycle_pct"],2)' "31.71" |
| 163 | jsoncheck "total_fmt" "$TMP/sum.body.json" 'd["total_fmt"]' "06m 50s" |
| 164 | jsoncheck "active_fmt" "$TMP/sum.body.json" 'd["active_fmt"]' "02m 10s" |
| 165 | jsoncheck "idle_fmt" "$TMP/sum.body.json" 'd["idle_fmt"]' "04m 40s" |
| 166 | jsoncheck "sessions array length" "$TMP/sum.body.json" 'len(d["sessions"])' "3" |
| 167 | jsoncheck "profiles present" "$TMP/sum.body.json" 'len(d["profiles"])' "3" |
| 168 | jsoncheck "models present" "$TMP/sum.body.json" 'len(d["models"])' "3" |
| 169 | jsoncheck "profile alpha leads" "$TMP/sum.body.json" 'd["profiles"][0]["profile"]' "profile-alpha" |
| 170 | jsoncheck "profile alpha active" "$TMP/sum.body.json" 'd["profiles"][0]["active_sec"]' "70" |
| 171 | jsoncheck "profile beta active" "$TMP/sum.body.json" 'd["profiles"][1]["active_sec"]' "60" |
| 172 | jsoncheck "profile alpha sessions" "$TMP/sum.body.json" 'd["profiles"][0]["sessions"]' "1" |
| 173 | jsoncheck "unknown profile bucket" "$TMP/sum.body.json" 'd["profiles"][2]["profile"]' "unknown" |
| 174 | jsoncheck "model alpha leads" "$TMP/sum.body.json" 'd["models"][0]["model"]' "alpha-1" |
| 175 | |
| 176 | echo "== summary is sorted newest first" |
| 177 | jsoncheck "first session is s2" "$TMP/sum.body.json" 'd["sessions"][0]["id"]' "2026_01_02_bold_lovelace" |
| 178 | jsoncheck "second session is s1" "$TMP/sum.body.json" 'd["sessions"][1]["id"]' "2026_01_01_quiet_curie" |
| 179 | |
| 180 | echo "== per-session numbers (s1)" |
| 181 | cat > "$TMP/py_s1.py" <<'PY' |
| 182 | import json,sys |
| 183 | d=json.load(open(sys.argv[1])) |
| 184 | for s in d["sessions"]: |
| 185 | if s["dir"]=="s1": |
| 186 | print(s["total_sec"], s["active_sec"], s["idle_sec"], s["turns"], |
| 187 | s["duty_cycle_pct"], s["model"], s["profile"], s["branch"], |
| 188 | s["tokens"]["in"], s["tokens"]["out"], s["tokens"]["cache_read"], |
| 189 | s["tokens"]["cache_write"]) |
| 190 | PY |
| 191 | got=$(python3 "$TMP/py_s1.py" "$TMP/sum.body.json") |
| 192 | check "s1 numbers" "$got" "340 70 270 2 20.59 alpha-1 profile-alpha main 1000 250 800 50" |
| 193 | |
| 194 | cat > "$TMP/py_s1tools.py" <<'PY' |
| 195 | import json,sys |
| 196 | d=json.load(open(sys.argv[1])) |
| 197 | for s in d["sessions"]: |
| 198 | if s["dir"]=="s1": |
| 199 | print(" ".join("%s=%d"%(t["name"],t["calls"]) for t in s["tools"])) |
| 200 | PY |
| 201 | got=$(python3 "$TMP/py_s1tools.py" "$TMP/sum.body.json") |
| 202 | check "s1 tools sorted by calls" "$got" "Bash=2 Read=1 Write=1" |
| 203 | |
| 204 | cat > "$TMP/py_s1id.py" <<'PY' |
| 205 | import json,sys |
| 206 | d=json.load(open(sys.argv[1])) |
| 207 | for s in d["sessions"]: |
| 208 | if s["dir"]=="s1": |
| 209 | print(s["id"], s["start_time"], s["is_active"], s["avg_turn_sec"]) |
| 210 | PY |
| 211 | got=$(python3 "$TMP/py_s1id.py" "$TMP/sum.body.json") |
| 212 | check "s1 identity fields" "$got" "2026_01_01_quiet_curie 2026-01-01 10:00:00 False 35.0" |
| 213 | |
| 214 | echo "== per-session numbers (s2, still running)" |
| 215 | cat > "$TMP/py_s2.py" <<'PY' |
| 216 | import json,sys |
| 217 | d=json.load(open(sys.argv[1])) |
| 218 | for s in d["sessions"]: |
| 219 | if s["dir"]=="s2": |
| 220 | print(s["total_sec"], s["active_sec"], s["idle_sec"], s["turns"], s["is_active"]) |
| 221 | PY |
| 222 | got=$(python3 "$TMP/py_s2.py" "$TMP/sum.body.json") |
| 223 | check "s2 numbers" "$got" "70 60 10 1 True" |
| 224 | |
| 225 | echo "== degenerate session (metadata only)" |
| 226 | cat > "$TMP/py_s3.py" <<'PY' |
| 227 | import json,sys |
| 228 | d=json.load(open(sys.argv[1])) |
| 229 | for s in d["sessions"]: |
| 230 | if s["dir"]=="s3": |
| 231 | print(s["total_sec"], s["active_sec"], s["turns"], s["is_active"]) |
| 232 | PY |
| 233 | got=$(python3 "$TMP/py_s3.py" "$TMP/sum.body.json") |
| 234 | check "s3 numbers" "$got" "0 0 0 False" |
| 235 | |
| 236 | echo "== action=session" |
| 237 | run 'action=session&sid=s1' | tail -1 > "$TMP/one.json" |
| 238 | jsoncheck "session ok" "$TMP/one.json" 'd["ok"]' "True" |
| 239 | jsoncheck "session id" "$TMP/one.json" 'd["session"]["id"]' "2026_01_01_quiet_curie" |
| 240 | jsoncheck "session active" "$TMP/one.json" 'd["session"]["active_sec"]' "70" |
| 241 | jsoncheck "session tools" "$TMP/one.json" 'len(d["session"]["tools"])' "3" |
| 242 | jsoncheck "session summary block" "$TMP/one.json" 'd["summary"]["turns"]' "2" |
| 243 | run 'action=session&sid=2026_01_02_bold_lovelace' | tail -1 > "$TMP/one2.json" |
| 244 | jsoncheck "session by full id" "$TMP/one2.json" 'd["session"]["dir"]' "s2" |
| 245 | run 'action=session&sid=nope' | tail -1 > "$TMP/one3.json" |
| 246 | jsoncheck "unknown session ok=false" "$TMP/one3.json" 'd["ok"]' "False" |
| 247 | jsoncheck "unknown session error" "$TMP/one3.json" 'd["error"]' "session not found" |
| 248 | run 'action=session' | tail -1 > "$TMP/one4.json" |
| 249 | jsoncheck "missing sid error" "$TMP/one4.json" 'd["error"]' "missing sid parameter" |
| 250 | run 'action=session&id=s1' | tail -1 > "$TMP/one5.json" |
| 251 | jsoncheck "id= alias accepted" "$TMP/one5.json" 'd["session"]["dir"]' "s1" |
| 252 | run 'action=session&sid=%73%31' | tail -1 > "$TMP/one6.json" |
| 253 | jsoncheck "percent-decoded sid" "$TMP/one6.json" 'd["session"]["dir"]' "s1" |
| 254 | |
| 255 | echo "== format=json" |
| 256 | run 'format=json' | tail -1 > "$TMP/fmt.json" |
| 257 | jsoncheck "format=json returns summary" "$TMP/fmt.json" 'd["count"]' "3" |
| 258 | jsoncheck "format=json ok" "$TMP/fmt.json" 'd["ok"]' "True" |
| 259 | |
| 260 | echo "== unknown action falls back to the summary" |
| 261 | run 'action=whatever' | tail -1 > "$TMP/unk.json" |
| 262 | jsoncheck "unknown action still JSON" "$TMP/unk.json" 'd["ok"]' "True" |
| 263 | |
| 264 | echo "== html" |
| 265 | run 'embed=1' > "$TMP/html.txt" |
| 266 | head -1 "$TMP/html.txt" | grep -q 'Content-Type: text/html' && ok || bad "html content type" |
| 267 | grep -q '<!DOCTYPE html>' "$TMP/html.txt" && ok || bad "html doctype" |
| 268 | grep -q 'Session Analytics' "$TMP/html.txt" && ok || bad "html title" |
| 269 | grep -q "id='kSessions'" "$TMP/html.txt" && ok || bad "kpi card sessions" |
| 270 | grep -q "id='railOn'" "$TMP/html.txt" && ok || bad "active rail" |
| 271 | grep -q "id='profBars'" "$TMP/html.txt" && ok || bad "profile bars" |
| 272 | grep -q "id='modelBars'" "$TMP/html.txt" && ok || bad "model bars" |
| 273 | grep -q "id='tbody'" "$TMP/html.txt" && ok || bad "session table" |
| 274 | grep -q "btnTheme" "$TMP/html.txt" && ok || bad "theme toggle" |
| 275 | grep -q "prefers-color-scheme" "$TMP/html.txt" && ok || bad "dark/light support" |
| 276 | grep -q 'theme=(light|dark)' "$TMP/html.txt" && ok || bad "theme: reads ?theme= before paint" |
| 277 | grep -q "d.type==='sx-theme'" "$TMP/html.txt" && ok || bad "theme: listens for sx-theme" |
| 278 | grep -q "sx-theme-request" "$TMP/html.txt" && ok || bad "theme: asks the host for the theme" |
| 279 | grep -q -- "--bg-card" "$TMP/html.txt" && ok || bad "theme: bot token --bg-card" |
| 280 | grep -q -- "--surface-2" "$TMP/html.txt" && ok || bad "theme: bot token --surface-2" |
| 281 | grep -q -- "--text-2" "$TMP/html.txt" && ok || bad "theme: bot token --text-2" |
| 282 | grep -q "embed-hide" "$TMP/html.txt" && ok || bad "theme: toggle hidden when embedded" |
| 283 | grep -q 'Scorpio'"X Bot" "$TMP/html.txt" && bad "theme: no retired brand casing" || ok |
| 284 | grep -q "0d0d0f" "$TMP/html.txt" && bad "theme: no private palette 0d0d0f" || ok |
| 285 | grep -q "18181b" "$TMP/html.txt" && bad "theme: no private palette 18181b" || ok |
| 286 | grep -q "max-width:400px" "$TMP/html.txt" && ok || bad "narrow breakpoint" |
| 287 | grep -q "plugin_sessionstats?action=" "$TMP/html.txt" && ok || bad "direct plugin route" |
| 288 | grep -q "plugins?plugin=" "$TMP/html.txt" && ok || bad "hub proxy route" |
| 289 | grep -q "bot_active_pwd" "$TMP/html.txt" && ok || bad "pwd bootstrap" |
| 290 | grep -q "X-Bot-Password" "$TMP/html.txt" && ok || bad "pwd header" |
| 291 | grep -qi 'content-length' "$TMP/html.txt" && bad "html must not emit Content-Length" || ok |
| 292 | |
| 293 | echo "== initial id is injected and escaped" |
| 294 | run 'id=s1' > "$TMP/html2.txt" |
| 295 | grep -q "q.get('id')||'s1'" "$TMP/html2.txt" && ok || bad "initial id injected" |
| 296 | mkdir -p "$S/bad'name" |
| 297 | run "id=x%27y" > "$TMP/html3.txt" |
| 298 | grep -q "q.get('id')||'x\\\\'y'" "$TMP/html3.txt" && ok || bad "single quote escaped in initial id" |
| 299 | rm -rf "$S/bad'name" |
| 300 | |
| 301 | echo "== missing sessions root" |
| 302 | out=$(SX_SESSIONS_DIR="$TMP/does-not-exist" QUERY_STRING='action=summary' "$BIN" | tail -1) |
| 303 | printf '%s' "$out" > "$TMP/noroot.json" |
| 304 | jsoncheck "root_found false" "$TMP/noroot.json" 'd["root_found"]' "False" |
| 305 | jsoncheck "empty summary ok" "$TMP/noroot.json" 'd["ok"]' "True" |
| 306 | jsoncheck "zero sessions" "$TMP/noroot.json" 'd["count"]' "0" |
| 307 | jsoncheck "empty profiles" "$TMP/noroot.json" 'd["profiles"]' "[]" |
| 308 | |
| 309 | echo "== the root must be a directory, not any openable path" |
| 310 | : > "$TMP/notadir" |
| 311 | out=$(SX_SESSIONS_DIR="$TMP/notadir" QUERY_STRING='action=summary' "$BIN" | tail -1) |
| 312 | printf '%s' "$out" > "$TMP/notadir.json" |
| 313 | jsoncheck "file root rejected" "$TMP/notadir.json" 'd["root_found"]' "False" |
| 314 | |
| 315 | echo "== read-only guarantee" |
| 316 | before=$(find "$S" -type f | wc -l | tr -d ' ') |
| 317 | run 'action=summary' >/dev/null |
| 318 | run 'action=session&sid=s1' >/dev/null |
| 319 | run 'embed=1' >/dev/null |
| 320 | after=$(find "$S" -type f | wc -l | tr -d ' ') |
| 321 | check "no files created" "$after" "$before" |
| 322 | diff -r "$S" "$S" >/dev/null 2>&1 && ok || bad "fixture tree unchanged" |
| 323 | |
| 324 | echo "== no emoji anywhere in the source" |
| 325 | if grep -qP '[\x{1F300}-\x{1FAFF}\x{2600}-\x{27BF}]' "$ROOT/src/plugin_sessionstats.c" 2>/dev/null; then |
| 326 | bad "source contains emoji" |
| 327 | else |
| 328 | ok |
| 329 | fi |
| 330 | |
| 331 | echo "== no private addresses or credentials in the whole history" |
| 332 | HIST="$TMP/history.txt" |
| 333 | git -C "$ROOT" log -p --all 2>/dev/null \ |
| 334 | | grep -v '^Author: ' \ |
| 335 | | grep -vE 'scan "|audit "|HITS=|grep -E|P_ROOT=|P_WT=|PK="' > "$HIST" || : > "$HIST" |
| 336 | check "no 192.168 in history" "$(grep -Eco '192\.168\.[0-9]+\.[0-9]+' "$HIST" || true)" "0" |
| 337 | check "no 10.x private range" "$(grep -Eco '(^|[^0-9.])10\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' "$HIST" || true)" "0" |
| 338 | check "no 172.16-31 range" "$(grep -Eco '172\.(1[6-9]|2[0-9]|3[01])\.[0-9]+\.[0-9]+' "$HIST" || true)" "0" |
| 339 | check "no ghp_ token" "$(grep -Eco 'ghp_[A-Za-z0-9]{20,}' "$HIST" || true)" "0" |
| 340 | check "no hf_ token" "$(grep -Eco 'hf_[A-Za-z0-9]{20,}' "$HIST" || true)" "0" |
| 341 | check "no internal hostnames" "$(grep -Eco 'intel-ultra'"2"'|INTERNAL_HOST_B|INTERNAL_HOST_C' "$HIST" || true)" "0" |
| 342 | check "no default password" "$(grep -Eco 'Xboxone'0909'|TESTPW' "$HIST" || true)" "0" |
| 343 | |
| 344 | echo "== Windows artifact shape (when the cross build exists)" |
| 345 | if [ -f "$ROOT/plugin_sessionstats.exe" ]; then |
| 346 | check "windows artifact starts with MZ" "$(head -c 2 "$ROOT/plugin_sessionstats.exe")" "MZ" |
| 347 | else |
| 348 | echo " skip (plugin_sessionstats.exe not built)" |
| 349 | fi |
| 350 | |
| 351 | echo "== musl artifact shape (when the static build exists)" |
| 352 | if [ -f "$ROOT/plugin_sessionstats.musl" ]; then |
| 353 | check "musl artifact is a static ELF" "$(head -c 4 "$ROOT/plugin_sessionstats.musl" | od -An -c | tr -d ' \n')" '177ELF' |
| 354 | else |
| 355 | echo " skip (plugin_sessionstats.musl not built)" |
| 356 | fi |
| 357 | |
| 358 | echo |
| 359 | printf ' %d passed, %d failed\n' "$PASS" "$FAIL" |
| 360 | [ "$FAIL" -eq 0 ] || exit 1 |