#!/usr/bin/env bash set -euo pipefail BASE_URL="${STORYFORGE_PUBLIC_BASE_URL:-https://storyforge.hyzq.net}" CURL_MAX_TIME="${STORYFORGE_PUBLIC_CURL_MAX_TIME:-60}" need_cmd() { if ! command -v "$1" >/dev/null 2>&1; then echo "missing required command: $1" >&2 exit 1 fi } need_cmd curl need_cmd python3 need_cmd rg curl_fetch() { curl -fsS --max-time "$CURL_MAX_TIME" "$@" } tmp_dir="$(mktemp -d)" trap 'rm -rf "$tmp_dir"' EXIT health_file="$tmp_dir/health.json" html_file="$tmp_dir/index.html" js_file="$tmp_dir/app.js" openapi_file="$tmp_dir/openapi.json" asr_url_file="$tmp_dir/asr-url.txt" asr_wav="$tmp_dir/asr.wav" asr_result="$tmp_dir/asr.json" echo "[1/4] check public healthz" curl_fetch "$BASE_URL/healthz" >"$health_file" python3 - "$health_file" "$asr_url_file" <<'PY' import json import pathlib import sys payload = json.loads(pathlib.Path(sys.argv[1]).read_text()) status = str(payload.get("status") or "").lower() if status != "ok": raise SystemExit(f"unexpected health status: {status!r}") asr_url = str(payload.get("asrHttpBaseUrl") or "").strip() pathlib.Path(sys.argv[2]).write_text(asr_url, encoding="utf-8") print("healthz ok") PY echo "[2/5] check public ASR transcribe" python3 - "$asr_wav" <<'PY' import math import struct import sys import wave path = sys.argv[1] sample_rate = 16000 duration = 0.25 freq = 440.0 samples = int(sample_rate * duration) with wave.open(path, "wb") as handle: handle.setnchannels(1) handle.setsampwidth(2) handle.setframerate(sample_rate) for i in range(samples): value = int(16000 * math.sin(2 * math.pi * freq * (i / sample_rate))) handle.writeframes(struct.pack(""$asr_result" python3 - "$asr_result" <<'PY' import json import pathlib import sys payload = json.loads(pathlib.Path(sys.argv[1]).read_text()) if "duration_ms" not in payload: raise SystemExit("missing duration_ms") if "success" not in payload: raise SystemExit("missing success flag") print("asr transcribe ok") PY ;; esac echo "[3/5] check public index" curl_fetch "$BASE_URL/" >"$html_file" rg -q "StoryForge" "$html_file" echo "index ok" echo "[4/5] check deployed web bundle" curl_fetch "$BASE_URL/assets/app.js" >"$js_file" rg -q "select-platform" "$js_file" rg -q "trackingCursorMap" "$js_file" rg -q "renderPlatformSwitchChips" "$js_file" echo "bundle ok" echo "[5/5] check public openapi routes" curl_fetch "$BASE_URL/openapi.json" >"$openapi_file" for route in \ '"/v2/xiaohongshu/accounts"' \ '"/v2/bilibili/accounts"' \ '"/v2/kuaishou/accounts"' \ '"/v2/wechat_video/accounts"' \ '"/v2/platform-agents"' \ '"/v2/tenant/quota"' do rg -q "$route" "$openapi_file" done echo "openapi ok" echo "public smoke passed: $BASE_URL"