← back to Ios Fleet Recording Qa
selftest.sh
68 lines
#!/usr/bin/env bash
# selftest.sh — builds synthetic fixtures and asserts the recording-qa verdict matrix.
# Requires: ffmpeg, ffprobe, tesseract, python3+PIL. $0, no network.
set -uo pipefail
cd "$(dirname "$0")"
QA="./recording-qa.sh"
T=$(mktemp -d); trap 'rm -rf "$T"' EXIT
python3 - "$T" <<'PY'
import sys, os
from PIL import Image, ImageDraw, ImageFont
T=sys.argv[1]
def frame(txt,out):
im=Image.new("RGB",(1080,1920),"white"); d=ImageDraw.Draw(im)
try: f=ImageFont.truetype("/System/Library/Fonts/Supplemental/Arial.ttf",72)
except Exception: f=ImageFont.load_default()
d.multiline_text((90,880),txt,fill="black",font=f); im.save(out)
frame("Contact test@evil.com", os.path.join(T,"pii.png"))
frame("Opportunities\nListing Settings", os.path.join(T,"clean.png"))
frame("Username\ndemo_reviewer\nhttps://api.agentabrams.com", os.path.join(T,"cred.png"))
PY
ffmpeg -y -loglevel error -f lavfi -i color=c=black:s=1080x1920:d=5 -pix_fmt yuv420p "$T/A.mov"
ffmpeg -y -loglevel error -loop 1 -i "$T/pii.png" -t 25 -r 5 -pix_fmt yuv420p "$T/B.mov"
ffmpeg -y -loglevel error -loop 1 -i "$T/clean.png" -t 25 -r 5 -pix_fmt yuv420p "$T/C.mov"
ffmpeg -y -loglevel error -loop 1 -i "$T/cred.png" -t 25 -r 5 -pix_fmt yuv420p "$T/D_cred.mov"
cp "$T/C.mov" "$T/E_simulator.mov"
v(){ "$QA" --json "$1" 2>/dev/null | sed 's/.*"verdict":"//;s/".*//'; }
fail=0
assert(){ local got want; got=$(v "$1"); want="$2"
if [ "$got" = "$want" ]; then echo "PASS $(basename "$1") -> $got"
else echo "FAIL $(basename "$1") -> got=$got want=$want"; fail=1; fi; }
assert "$T/A.mov" TECH_FAIL
assert "$T/B.mov" PRIVACY_FLAGGED
assert "$T/C.mov" TECH_PASS_PRIVACY_PENDING
assert "$T/E_simulator.mov" REJECTED_NOT_DEVICE
# --approve refuses a PII clip
# credential lens (added with a507... a23289a, previously UNTESTED — TK-11155).
# It WARNS by design (Apple 2.1 #4 asks for demo credentials) so the verdict must
# stay TECH_PASS_PRIVACY_PENDING; what we prove is that the lens actually fires,
# and — the half that matters — that it does NOT fire on a clean clip.
credout=$("$QA" "$T/D_cred.mov" 2>&1)
if printf '%s' "$credout" | grep -q '🔑 CRED'; then
echo "PASS D_cred.mov -> credential lens FIRED ($(printf '%s' "$credout" | grep -c '🔑 CRED') hit(s))"
else
echo "FAIL D_cred.mov -> credential lens did NOT fire"; fail=1
fi
if printf '%s' "$credout" | grep -q 'TECH_PASS_PRIVACY_PENDING'; then
echo "PASS D_cred.mov -> still WARN, not a hard fail (by design)"
else
echo "FAIL D_cred.mov -> credential visibility hard-failed; it must only WARN"; fail=1
fi
if "$QA" "$T/C.mov" 2>&1 | grep -q '🔑 CRED'; then
echo "FAIL C.mov -> credential lens FALSE POSITIVE on a clean clip"; fail=1
else
echo "PASS C.mov -> credential lens silent on a clean clip (no false positive)"
fi
"$QA" --approve "$T/B.mov" >/dev/null 2>&1 && { echo "FAIL --approve accepted a PII clip"; fail=1; } || echo "PASS --approve refused the PII clip"
# approve the clean clip -> READY
"$QA" --approve "$T/C.mov" >/dev/null 2>&1
assert "$T/C.mov" READY_TO_SEND
[ "$fail" -eq 0 ] && echo "ALL PASS" || echo "SOME FAILED"
exit $fail