#!/usr/bin/env bash # e2e_api.sh — Suite end-to-end de la API HTTP de navegator_dashboard. # # Asume que `navegator_dashboard.exe` esta corriendo con la API en 127.0.0.1:19333. # Si no esta, lanza la app primero (no la mata al final — dejarla viva para iterar). # # Cubre: # 1. /health responde OK # 2. /browsers retorna JSON array # 3. POST /spawn lanza chrome.exe + retorna {ok:true,pid,port} # 4. CDP responde en el puerto retornado # 5. cdp-cli puede navegar/evaluar sobre la instancia # 6. /browsers ahora contiene la instancia (1 entrada por chrome master, no N) # 7. POST /kill mata la instancia # 8. CDP deja de responder # 9. /browsers vuelve a no contenerla # # Exit 0 en exito, !=0 en fallo. Cada paso imprime "OK" o "FAIL: ..." a stderr. set -euo pipefail API="${NAVD_API:-http://127.0.0.1:19333}" EXE="${NAVD_EXE:-/mnt/c/Users/lucas/Desktop/apps/navegator_dashboard/navegator_dashboard.exe}" CDP_CLI="${NAVD_CDP_CLI:-/home/lucas/fn_registry/projects/osint_graph/apps/graph_explorer/cdp-cli/cdp-cli}" PROFILE="e2e_$(date +%s)" PORT=19299 failures=0 step() { echo; echo "==[ $1 ]==" >&2; } ok() { echo " OK: $1" >&2; } fail() { echo " FAIL: $1" >&2; failures=$((failures + 1)); } # --------------------------------------------------------- step "0. dashboard reachable" # --------------------------------------------------------- if ! curl -sf --max-time 2 "$API/health" >/dev/null 2>&1; then if [[ -x "$EXE" ]]; then echo " app no responde, lanzando $EXE..." >&2 powershell.exe -NoProfile -Command "Start-Process -FilePath '$(wslpath -w "$EXE" 2>/dev/null || echo "$EXE")'" >/dev/null 2>&1 || true for _ in $(seq 1 20); do if curl -sf --max-time 1 "$API/health" >/dev/null 2>&1; then break; fi sleep 0.5 done fi fi if curl -sf --max-time 2 "$API/health" >/dev/null 2>&1; then ok "dashboard up" else fail "dashboard no responde en $API/health" exit 1 fi # --------------------------------------------------------- step "1. /health" # --------------------------------------------------------- body="$(curl -sf --max-time 2 "$API/health")" echo " body: $body" >&2 [[ "$body" == *'"ok":true'* ]] && ok "/health responde ok=true" || fail "/health body inesperado" # --------------------------------------------------------- step "2. /browsers (initial)" # --------------------------------------------------------- body="$(curl -sf --max-time 2 "$API/browsers")" echo " body: $body" >&2 [[ "$body" == \[* ]] && ok "/browsers retorna array" || fail "/browsers no retorna JSON array" # --------------------------------------------------------- step "3. POST /spawn" # --------------------------------------------------------- body="$(curl -sf --max-time 10 -X POST "$API/spawn?profile=$PROFILE&port=$PORT")" echo " body: $body" >&2 if [[ "$body" == *'"ok":true'* ]]; then ok "/spawn launched" SPAWNED_PID="$(echo "$body" | sed -nE 's/.*"pid":([0-9]+).*/\1/p')" echo " pid=$SPAWNED_PID port=$PORT profile=$PROFILE" >&2 else fail "/spawn fallo" exit 1 fi # --------------------------------------------------------- step "4. CDP responde en puerto $PORT" # --------------------------------------------------------- ok_cdp="" for _ in $(seq 1 20); do if curl -sf --max-time 1 "http://127.0.0.1:$PORT/json/version" >/dev/null 2>&1; then ok_cdp=1; break fi sleep 0.5 done if [[ -n "$ok_cdp" ]]; then browser="$(curl -sf "http://127.0.0.1:$PORT/json/version" 2>/dev/null | grep -i '"Browser"' | head -1 | tr -d '\r' || true)" ok "CDP up —${browser}" else fail "CDP no responde en $PORT" fi # --------------------------------------------------------- step "5. cdp-cli navigate + evaluate" # --------------------------------------------------------- if [[ -x "$CDP_CLI" ]]; then "$CDP_CLI" navigate --port "$PORT" --url "data:text/html,