#!/usr/bin/env bash # ═══════════════════════════════════════════════ # Surface Test Runner — CI Entrypoint # ═══════════════════════════════════════════════ # # Authenticates as admin, navigates to the test-runners surface # via Playwright, runs all test suites, and asserts zero failures. # # Prerequisites: # - Server running at $SERVER_URL (default: http://localhost:3000) # - npx playwright install chromium # - ADMIN_USER / ADMIN_PASS env vars (default: admin/admin) # # Exit codes: 0 = all tests passed, 1 = failures detected set -euo pipefail SERVER_URL="${SERVER_URL:-http://localhost:3000}" ADMIN_USER="${ADMIN_USER:-admin}" ADMIN_PASS="${ADMIN_PASS:-admin}" RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' echo -e "${YELLOW}═══ Surface Test Runner ═══${NC}" echo " Server: ${SERVER_URL}" # ── Authenticate ───────────────────────────── echo -e "${YELLOW}Authenticating...${NC}" TOKEN=$(curl -sf -X POST "${SERVER_URL}/api/v1/auth/login" \ -H "Content-Type: application/json" \ -d "{\"login\":\"${ADMIN_USER}\",\"password\":\"${ADMIN_PASS}\"}" \ | node -e "process.stdin.resume(); let d=''; process.stdin.on('data',c=>d+=c); process.stdin.on('end',()=>{try{console.log(JSON.parse(d).token)}catch(e){process.exit(1)}})") if [ -z "$TOKEN" ]; then echo -e "${RED}Failed to authenticate${NC}" exit 1 fi echo -e "${GREEN}Authenticated${NC}" # ── Run via Playwright ─────────────────────── echo -e "${YELLOW}Running surface tests via Playwright...${NC}" node "$(dirname "$0")/surface-test-driver.js" \ --server="${SERVER_URL}" \ --token="${TOKEN}" EXIT_CODE=$? if [ $EXIT_CODE -eq 0 ]; then echo -e "${GREEN}═══ All surface tests passed ═══${NC}" else echo -e "${RED}═══ Surface tests FAILED ═══${NC}" fi exit $EXIT_CODE