steelbot/scripts/e2e-test.sh
caelum0x 4b2262e406 feat: Steelbot — autonomous AI agent with USDC wallet on Base
Synthesis Hackathon submission. Built on IronClaw fork.

26 tools: Locus payments (6), Uniswap DeFi (3), onchain reads (3),
security scanning (2), wallet analytics (3), OpenRouter LLM (2),
self-hosted scraping (3), portfolio (2), synthesis (2).

3 defense hooks: spending limits ($5/tx, $25/session), contract guard
(SCONE-bench vulnerability patterns), credential guard (blocks private
key/seed phrase leaks).

Payment system (Polar.sh), landing page, license key gating (Free/Pro/
Unlimited tiers), brand rename from IronClaw to Steelbot.

9,669 lines of code. 3,665 tests passing. Zero clippy warnings.
Real USDC transactions on Base chain.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-22 01:53:00 +03:00

447 lines
16 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# ──────────────────────────────────────────────────────────────────────────────
# Steelbot / IronClaw — End-to-end integration test suite
#
# Usage: ./scripts/e2e-test.sh
#
# Tests the full stack: build, server startup, public routes, auth-protected
# routes, payment API, marketplace API, and CLI commands. Requires only curl
# and a working Rust toolchain — no external services needed.
# ──────────────────────────────────────────────────────────────────────────────
set -euo pipefail
# ── Colors ────────────────────────────────────────────────────────────────────
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
RESET='\033[0m'
# ── Counters ──────────────────────────────────────────────────────────────────
PASS=0
FAIL=0
SKIP=0
TOTAL=0
# ── Config ────────────────────────────────────────────────────────────────────
# Pick a random port between 10000–60000 to avoid conflicts.
PORT=$((RANDOM % 50000 + 10000))
BASE_URL="http://127.0.0.1:${PORT}"
AUTH_TOKEN="e2e-test-token-$(date +%s)"
SERVER_PID=""
PROJECT_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
BINARY="${PROJECT_ROOT}/target/release/ironclaw"
MAX_WAIT=60 # seconds to wait for server health
LOG_FILE="${PROJECT_ROOT}/target/e2e-test-server.log"
# ── Helpers ───────────────────────────────────────────────────────────────────
log_header() {
echo -e "\n${CYAN}${BOLD}━━━ $1 ━━━${RESET}"
}
log_test() {
TOTAL=$((TOTAL + 1))
echo -ne " ${BOLD}[$TOTAL]${RESET} $1 ... "
}
pass() {
PASS=$((PASS + 1))
echo -e "${GREEN}PASS${RESET}"
}
fail() {
FAIL=$((FAIL + 1))
echo -e "${RED}FAIL${RESET}"
if [ -n "${1:-}" ]; then
echo -e " ${RED}→ $1${RESET}"
fi
}
skip() {
SKIP=$((SKIP + 1))
echo -e "${YELLOW}SKIP${RESET}"
if [ -n "${1:-}" ]; then
echo -e " ${YELLOW}→ $1${RESET}"
fi
}
cleanup() {
echo ""
if [ -n "$SERVER_PID" ] && kill -0 "$SERVER_PID" 2>/dev/null; then
echo -e "${CYAN}Stopping server (PID $SERVER_PID)...${RESET}"
kill "$SERVER_PID" 2>/dev/null || true
wait "$SERVER_PID" 2>/dev/null || true
fi
}
trap cleanup EXIT INT TERM
# ── 1. Build ──────────────────────────────────────────────────────────────────
log_header "1/8 Build Check"
log_test "cargo build --release"
if cargo build --release --manifest-path "${PROJECT_ROOT}/Cargo.toml" 2>&1; then
pass
else
fail "Build failed — cannot continue"
exit 1
fi
if [ ! -x "$BINARY" ]; then
echo -e "${RED}Binary not found at $BINARY${RESET}"
exit 1
fi
# ── 2. Start Server ──────────────────────────────────────────────────────────
log_header "2/8 Server Startup"
mkdir -p "$(dirname "$LOG_FILE")"
echo -e " Starting server on port ${PORT}..."
# Minimal env: disable everything except the web gateway.
env \
GATEWAY_HOST="127.0.0.1" \
GATEWAY_PORT="$PORT" \
GATEWAY_AUTH_TOKEN="$AUTH_TOKEN" \
HEARTBEAT_ENABLED="false" \
TELEMETRY_ENABLED="false" \
SANDBOX_ENABLED="false" \
RUST_LOG="ironclaw=warn" \
"$BINARY" run \
> "$LOG_FILE" 2>&1 &
SERVER_PID=$!
# ── 3. Wait for health ───────────────────────────────────────────────────────
log_test "Waiting for /api/health (max ${MAX_WAIT}s)"
elapsed=0
healthy=false
while [ $elapsed -lt $MAX_WAIT ]; do
if curl -sf "${BASE_URL}/api/health" > /dev/null 2>&1; then
healthy=true
break
fi
# Check server is still alive
if ! kill -0 "$SERVER_PID" 2>/dev/null; then
fail "Server exited prematurely — check $LOG_FILE"
echo -e "\n${RED}Last 20 lines of server log:${RESET}"
tail -20 "$LOG_FILE" 2>/dev/null || true
exit 1
fi
sleep 1
elapsed=$((elapsed + 1))
done
if $healthy; then
pass
else
fail "Server did not become healthy within ${MAX_WAIT}s"
echo -e "\n${RED}Last 20 lines of server log:${RESET}"
tail -20 "$LOG_FILE" 2>/dev/null || true
exit 1
fi
# ── Helper: HTTP assertions ──────────────────────────────────────────────────
# assert_status URL EXPECTED_STATUS [EXTRA_CURL_ARGS...]
assert_status() {
local url="$1" expected="$2"
shift 2
local status
status=$(curl -s -o /dev/null -w "%{http_code}" "$@" "$url" 2>/dev/null) || true
if [ "$status" = "$expected" ]; then
return 0
else
return 1
fi
}
# assert_body_contains URL SUBSTRING [EXTRA_CURL_ARGS...]
assert_body_contains() {
local url="$1" substring="$2"
shift 2
local body
body=$(curl -sL "$@" "$url" 2>/dev/null) || true
if echo "$body" | grep -qi "$substring"; then
return 0
else
return 1
fi
}
# ── 4. Public Routes ─────────────────────────────────────────────────────────
log_header "3/8 Public Routes"
# GET / → 200, contains "Steelbot"
log_test "GET / → 200, body contains 'Steelbot'"
if assert_status "${BASE_URL}/" "200" && assert_body_contains "${BASE_URL}/" "Steelbot"; then
pass
else
fail "Landing page did not return 200 or missing 'Steelbot'"
fi
# GET /docs → 200, contains "Documentation"
log_test "GET /docs → 200, body contains 'Documentation'"
if assert_status "${BASE_URL}/docs" "200" && assert_body_contains "${BASE_URL}/docs" "Documentation"; then
pass
else
fail "Docs page did not return 200 or missing 'Documentation'"
fi
# GET /pricing → 301 redirect to /#pricing
log_test "GET /pricing → 308 permanent redirect"
status=$(curl -s -o /dev/null -w "%{http_code}" --max-redirs 0 "${BASE_URL}/pricing" 2>/dev/null) || true
location=$(curl -s -D - -o /dev/null --max-redirs 0 "${BASE_URL}/pricing" 2>/dev/null | grep -i "^location:" | tr -d '\r' | awk '{print $2}') || true
if [ "$status" = "308" ] && echo "$location" | grep -q "/#pricing"; then
pass
else
fail "Expected 308 redirect to /#pricing, got status=$status location=$location"
fi
# GET /api/health → 200, JSON with "status"
log_test "GET /api/health → 200, JSON has 'status'"
health_body=$(curl -sf "${BASE_URL}/api/health" 2>/dev/null) || true
if echo "$health_body" | grep -q '"status"'; then
pass
else
fail "Health endpoint missing 'status' field"
fi
# Verify health JSON contains "healthy"
log_test "GET /api/health → status is 'healthy'"
if echo "$health_body" | grep -q '"healthy"'; then
pass
else
fail "Health status is not 'healthy'"
fi
# ── 5. Auth-protected Routes ─────────────────────────────────────────────────
log_header "4/8 Auth-Protected Routes"
AUTH_HEADER="Authorization: Bearer ${AUTH_TOKEN}"
# /app is a static route (no auth middleware) — verify it loads
log_test "GET /app → 200"
if assert_status "${BASE_URL}/app" "200"; then
pass
else
status=$(curl -s -o /dev/null -w "%{http_code}" "${BASE_URL}/app" 2>/dev/null) || true
fail "Expected 200, got $status"
fi
# GET /app body contains HTML
log_test "GET /app body contains HTML content"
if assert_body_contains "${BASE_URL}/app" "<html"; then
pass
else
fail "App page missing HTML content"
fi
# Protected API endpoint without auth → 401
log_test "GET /api/chat/history without auth → 401"
if assert_status "${BASE_URL}/api/chat/history" "401"; then
pass
else
status=$(curl -s -o /dev/null -w "%{http_code}" "${BASE_URL}/api/chat/history" 2>/dev/null) || true
fail "Expected 401, got $status"
fi
# GET /admin/dashboard → 200 or 503 (telemetry disabled)
log_test "GET /admin/dashboard → 200 or 503"
status=$(curl -s -o /dev/null -w "%{http_code}" -H "$AUTH_HEADER" "${BASE_URL}/admin/dashboard" 2>/dev/null) || true
if [ "$status" = "200" ] || [ "$status" = "503" ]; then
pass
else
fail "Expected 200 or 503, got $status"
fi
# If 503, verify the telemetry-disabled message
if [ "$status" = "503" ]; then
log_test "GET /admin/dashboard → 503 body mentions telemetry"
if assert_body_contains "${BASE_URL}/admin/dashboard" "Telemetry" -H "$AUTH_HEADER"; then
pass
else
fail "503 page missing telemetry message"
fi
fi
# ── 6. Payment API ───────────────────────────────────────────────────────────
log_header "5/8 Payment API"
# POST /api/payments/license/validate — test with a fake key
log_test "POST /api/payments/license/validate → 200"
pay_status=$(curl -s -o /dev/null -w "%{http_code}" \
-X POST \
-H "Content-Type: application/json" \
-d '{"key":"SB-PRO-00000000-0000-0000-0000-000000000000-test","email":"test@example.com"}' \
"${BASE_URL}/api/payments/license/validate" 2>/dev/null) || true
if [ "$pay_status" = "200" ]; then
pass
else
fail "Expected 200, got $pay_status"
fi
# Verify the response has the expected shape
log_test "POST /api/payments/license/validate → JSON has 'valid' field"
pay_body=$(curl -s \
-X POST \
-H "Content-Type: application/json" \
-d '{"key":"SB-PRO-00000000-test","email":"test@example.com"}' \
"${BASE_URL}/api/payments/license/validate" 2>/dev/null) || true
if echo "$pay_body" | grep -q '"valid"'; then
pass
else
fail "Response missing 'valid' field: $pay_body"
fi
# Fake key should not validate
log_test "Fake license key → valid=false"
if echo "$pay_body" | grep -q '"valid":false'; then
pass
else
fail "Fake key should not validate: $pay_body"
fi
# ── 7. Marketplace API ───────────────────────────────────────────────────────
log_header "6/8 Marketplace API"
# GET /api/marketplace/search?q=test → 200 (requires auth)
log_test "GET /api/marketplace/search?q=test → 200"
mkt_status=$(curl -s -o /dev/null -w "%{http_code}" \
-H "$AUTH_HEADER" \
"${BASE_URL}/api/marketplace/search?q=test" 2>/dev/null) || true
if [ "$mkt_status" = "200" ]; then
pass
else
fail "Expected 200, got $mkt_status"
fi
# GET /api/marketplace/browse?category=utility → 200
log_test "GET /api/marketplace/browse?category=utility → 200"
mkt_browse_status=$(curl -s -o /dev/null -w "%{http_code}" \
-H "$AUTH_HEADER" \
"${BASE_URL}/api/marketplace/browse?category=utility" 2>/dev/null) || true
if [ "$mkt_browse_status" = "200" ]; then
pass
else
fail "Expected 200, got $mkt_browse_status"
fi
# Verify marketplace search returns valid JSON
log_test "GET /api/marketplace/search → valid JSON array"
mkt_body=$(curl -s -H "$AUTH_HEADER" \
"${BASE_URL}/api/marketplace/search?q=test" 2>/dev/null) || true
if echo "$mkt_body" | python3 -c "import sys,json; json.load(sys.stdin)" 2>/dev/null; then
pass
else
# Fall back — some responses wrap in an object
if echo "$mkt_body" | grep -qE '^\[|^\{'; then
pass
else
fail "Response is not valid JSON: $mkt_body"
fi
fi
# ── 8. CLI Commands ──────────────────────────────────────────────────────────
log_header "7/8 CLI Commands"
# ironclaw --help
log_test "ironclaw --help → shows usage"
help_output=$("$BINARY" --help 2>&1) || true
if echo "$help_output" | grep -qi "ironclaw\|usage\|command"; then
pass
else
fail "Help output missing expected text"
fi
# ironclaw status
log_test "ironclaw status → runs without crash"
if "$BINARY" status 2>&1 | head -5 > /dev/null; then
pass
else
# status may fail if no server is configured for it, but it should not crash
skip "status command unavailable"
fi
# ── 9. Additional Endpoint Checks ────────────────────────────────────────────
log_header "8/8 Additional Checks"
# GET /style.css → 200
log_test "GET /style.css → 200"
if assert_status "${BASE_URL}/style.css" "200"; then
pass
else
fail "CSS file not served"
fi
# GET /app.js → 200
log_test "GET /app.js → 200"
if assert_status "${BASE_URL}/app.js" "200"; then
pass
else
fail "JS file not served"
fi
# GET /favicon.ico → 200
log_test "GET /favicon.ico → 200"
if assert_status "${BASE_URL}/favicon.ico" "200"; then
pass
else
fail "Favicon not served"
fi
# GET /api/gateway/status → 200 (protected)
log_test "GET /api/gateway/status → 200 (with auth)"
gw_status=$(curl -s -o /dev/null -w "%{http_code}" \
-H "$AUTH_HEADER" \
"${BASE_URL}/api/gateway/status" 2>/dev/null) || true
if [ "$gw_status" = "200" ]; then
pass
else
fail "Expected 200, got $gw_status"
fi
# Unauthenticated protected route → 401
log_test "GET /api/gateway/status without auth → 401"
unauth_status=$(curl -s -o /dev/null -w "%{http_code}" \
"${BASE_URL}/api/gateway/status" 2>/dev/null) || true
if [ "$unauth_status" = "401" ]; then
pass
else
fail "Expected 401, got $unauth_status"
fi
# POST /api/scrape without auth → 401
log_test "POST /api/scrape without auth → 401"
scrape_status=$(curl -s -o /dev/null -w "%{http_code}" \
-X POST \
-H "Content-Type: application/json" \
-d '{"url":"https://example.com"}' \
"${BASE_URL}/api/scrape" 2>/dev/null) || true
if [ "$scrape_status" = "401" ]; then
pass
else
fail "Expected 401, got $scrape_status"
fi
# ── Report ────────────────────────────────────────────────────────────────────
echo ""
echo -e "${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${RESET}"
echo -e "${BOLD} E2E Test Report${RESET}"
echo -e "${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${RESET}"
echo -e " Total: ${TOTAL}"
echo -e " ${GREEN}Passed: ${PASS}${RESET}"
echo -e " ${RED}Failed: ${FAIL}${RESET}"
echo -e " ${YELLOW}Skipped: ${SKIP}${RESET}"
echo -e "${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${RESET}"
if [ "$FAIL" -gt 0 ]; then
echo -e "\n${RED}${BOLD}RESULT: FAILED${RESET} ($FAIL failures)"
echo -e "Server log: $LOG_FILE"
exit 1
else
echo -e "\n${GREEN}${BOLD}RESULT: ALL TESTS PASSED${RESET}"
exit 0
fi