AccessibilityToolkit / scripts /smoke_test.sh
Claude
Add four accessibility checks/tools (now 14 tools)
e553423 unverified
Raw History Blame Contribute Delete
4.27 kB
#!/usr/bin/env bash
# HTTP smoke test for the PPTX/PDF tools web app.
#
# Exercises the live API against a running server. Dependency-light: needs
# only bash, curl, and python3 (stdlib) for JSON assertions.
#
# Usage:
# scripts/smoke_test.sh [BASE_URL]
# Default BASE_URL: http://localhost:8000
set -euo pipefail
BASE_URL="${1:-http://localhost:8000}"
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
FIX="$ROOT/tests/fixtures"
TMP="$(mktemp -d)"
trap 'rm -rf "$TMP"' EXIT
pass=0
fail=0
ok() { echo " PASS: $1"; pass=$((pass + 1)); }
bad() { echo " FAIL: $1"; fail=$((fail + 1)); }
# jget FILE KEY -> prints value of top-level JSON key (or "" if missing)
jget() { python3 -c "import json,sys; print(json.load(open(sys.argv[1])).get(sys.argv[2],''))" "$1" "$2"; }
echo "Smoke testing $BASE_URL"
# 1. Health ----------------------------------------------------------
code="$(curl -s -o "$TMP/health.json" -w '%{http_code}' "$BASE_URL/api/health")"
[ "$code" = "200" ] && [ "$(jget "$TMP/health.json" status)" = "ok" ] \
&& ok "health" || bad "health (HTTP $code)"
# 2. Tool list -------------------------------------------------------
code="$(curl -s -o "$TMP/tools.json" -w '%{http_code}' "$BASE_URL/api/tools")"
count="$(python3 -c "import json;print(len(json.load(open('$TMP/tools.json'))['tools']))" 2>/dev/null || echo 0)"
[ "$code" = "200" ] && [ "$count" = "14" ] \
&& ok "tools list (14 tools)" || bad "tools list (HTTP $code, count $count)"
# 3. PPTX tool that produces a file: convert_caps + download ---------
code="$(curl -s -o "$TMP/cc.json" -w '%{http_code}' \
-F "files=@$FIX/sample.pptx" -F "keep=API" "$BASE_URL/api/run/convert_caps")"
rid="$(jget "$TMP/cc.json" result_id)"
if [ "$code" = "200" ] && [ "$(jget "$TMP/cc.json" output_produced)" = "True" ] && [ -n "$rid" ]; then
dcode="$(curl -s -o "$TMP/out.pptx" -w '%{http_code}' "$BASE_URL/api/result/$rid")"
sz=$(wc -c < "$TMP/out.pptx")
[ "$dcode" = "200" ] && [ "$sz" -gt 1000 ] \
&& ok "convert_caps run + download ($sz bytes)" || bad "convert_caps download (HTTP $dcode, $sz bytes)"
else
bad "convert_caps run (HTTP $code)"
fi
# 4. PDF tool that produces a file: clear_pdf_metadata --------------
code="$(curl -s -o "$TMP/pm.json" -w '%{http_code}' \
-F "files=@$FIX/sample.pdf" "$BASE_URL/api/run/clear_pdf_metadata")"
rid="$(jget "$TMP/pm.json" result_id)"
if [ "$code" = "200" ] && [ -n "$rid" ]; then
dcode="$(curl -s -o "$TMP/out.pdf" -w '%{http_code}' "$BASE_URL/api/result/$rid")"
[ "$dcode" = "200" ] && ok "clear_pdf_metadata run + download" \
|| bad "clear_pdf_metadata download (HTTP $dcode)"
else
bad "clear_pdf_metadata run (HTTP $code)"
fi
# 5. Preview path (report-only, no file) -----------------------------
code="$(curl -s -o "$TMP/ro.json" -w '%{http_code}' \
-F "files=@$FIX/sample.pdf" -F "report_only=true" -F "to=en-US" \
"$BASE_URL/api/run/fix_pdf_lang_tags")"
[ "$code" = "200" ] && [ "$(jget "$TMP/ro.json" output_produced)" = "False" ] \
&& ok "fix_pdf_lang_tags preview (no file)" || bad "lang preview (HTTP $code)"
# 6. Wrong file type is rejected -------------------------------------
code="$(curl -s -o /dev/null -w '%{http_code}' \
-F "files=@$FIX/sample.pdf" "$BASE_URL/api/run/convert_caps")"
[ "$code" = "400" ] && ok "wrong file type rejected (400)" \
|| bad "wrong file type (expected 400, got $code)"
# 7. Batch: two PDFs -> zip ------------------------------------------
code="$(curl -s -o "$TMP/batch.json" -w '%{http_code}' \
-F "files=@$FIX/sample.pdf" -F "files=@$FIX/sample.pdf" \
"$BASE_URL/api/run/clear_pdf_metadata")"
rid="$(jget "$TMP/batch.json" result_id)"
fcount="$(jget "$TMP/batch.json" file_count)"
if [ "$code" = "200" ] && [ "$(jget "$TMP/batch.json" download_name)" != "" ] && [ -n "$rid" ]; then
curl -s -o "$TMP/out.zip" "$BASE_URL/api/result/$rid"
entries="$(python3 -c "import zipfile;print(len(zipfile.ZipFile('$TMP/out.zip').namelist()))" 2>/dev/null || echo 0)"
[ "$fcount" = "2" ] && [ "$entries" = "2" ] \
&& ok "batch clear_pdf_metadata (zip, $entries entries)" \
|| bad "batch (file_count $fcount, zip entries $entries)"
else
bad "batch clear_pdf_metadata (HTTP $code)"
fi
echo
echo "Smoke test: $pass passed, $fail failed."
[ "$fail" -eq 0 ]