Files
httptoolkit/scripts/smoke.sh
T
shihaam 6768b0a5b2
Build & Release binary / build (push) Successful in 26m20s
build works now
2026-08-22 16:14:56 +05:00

70 lines
2.7 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Smoke test: launch the built binary and verify it actually serves the UI and
# starts the backend. Fails loudly (non-zero) if a native module won't load or
# the server never comes up - this is the main guard for the single-file build.
#
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
BIN="${1:-dist/httptoolkit}"
PORT="${PORT:-8099}"
SERVER_PORT="${SERVER_PORT:-45457}"
echo "==> --help must exit 0"
"$BIN" --help
echo "==> launching $BIN on port $PORT"
"$BIN" --port "$PORT" --server-port "$SERVER_PORT" --no-open &
PID=$!
trap 'kill "$PID" 2>/dev/null || true' EXIT
# Wait up to ~30s for the UI port to answer:
ok=0
for _ in $(seq 1 60); do
if curl -fsS "http://127.0.0.1:${PORT}/" -o /tmp/htk-index.html 2>/dev/null; then
ok=1; break
fi
if ! kill -0 "$PID" 2>/dev/null; then
echo "!! binary exited early"; exit 1
fi
sleep 0.5
done
[ "$ok" = 1 ] || { echo "!! UI never responded on :$PORT"; exit 1; }
echo "==> UI responded; checking it looks like the HTK app"
grep -qi 'httptoolkit\|<div id="app"\|<title' /tmp/htk-index.html \
|| { echo "!! served index.html doesn't look like the UI"; exit 1; }
# The WebSocket/subscription path is where bun's built-in `ws` shim used to kill
# the server, and no amount of HTTP probing reaches it. Needs node + the server's
# node_modules for the mockttp client, so it's skipped in the self-containment
# run (where the source tree is deliberately hidden).
if [ "${WS_CHECK:-0}" = "1" ]; then
MOCKTTP_PORT="${MOCKTTP_PORT:-45456}"
NM="$ROOT/httptoolkit-server/node_modules"
if [ -d "$NM" ] && command -v node > /dev/null; then
echo "==> checking admin WebSocket + subscription stream on :$MOCKTTP_PORT"
NODE_PATH="$NM" node "$ROOT/scripts/ws-check.js" \
"http://127.0.0.1:${MOCKTTP_PORT}" "http://localhost:${PORT}" \
|| { echo "!! admin WebSocket check failed"; exit 1; }
# That check is only meaningful if it didn't take the server down with it:
kill -0 "$PID" 2>/dev/null || { echo "!! binary died during WebSocket check"; exit 1; }
else
echo "==> SKIP WebSocket check (needs node + httptoolkit-server/node_modules)"
fi
fi
echo "==> checking management API is listening on :$SERVER_PORT"
# corsGate rejects requests without an allowed Origin with a JSON 403 - that's a
# *successful* connection (the server is up), which is all we need to confirm.
code=$(curl -s -o /dev/null -w '%{http_code}' \
-H 'Origin: http://localhost:'"$PORT" \
"http://127.0.0.1:${SERVER_PORT}/" || true)
echo " management API HTTP status: $code"
[ -n "$code" ] && [ "$code" != "000" ] \
|| { echo "!! management API not reachable"; exit 1; }
echo "==> SMOKE TEST PASSED"