Files
faunosteo/scripts/avatar-e2e.sh
T
bchanot 2a84e3702e test(supabase): avatar suite on the sandbox, per-run sandbox passwords
pnpm db:sandbox avatar-e2e runs tests/e2e/avatar-flow.e2e.ts with the real
worker (default mode) on the throwaway stack; the suite now requires its
database container by name, makes both accounts per run and expedites only
its own purges. Throwaway sandbox accounts get random passwords per run.
2026-11-01 21:02:59 +01:00

60 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Real-stack end-to-end run of the avatar flow (docs/development/STORAGE.md §6):
# starts the worker container against the local Supabase stack with a fast sweep
# and no quarantine grace, runs packages/supabase/tests/e2e, stops the container.
# Needs: `pnpm db:start` done, Docker, the worker image (`pnpm worker:image`,
# built here when absent). The keys come from `supabase status`; the service key
# reaches the container through a 600-mode temporary env file, never the command line.
set -euo pipefail
cd "$(dirname "$0")/.."
network="${SUPABASE_NETWORK:-supabase_network_faunosteo}"
kong="${SUPABASE_INTERNAL_URL:-http://supabase_kong_faunosteo:8000}"
image="${WORKER_IMAGE:-faunosteo_worker:dev}"
name="faunosteo_worker_e2e"
. scripts/dev-env.sh
status="$(node_modules/.bin/supabase status -o env 2>/dev/null)" \
|| { echo "avatar-e2e: the local stack is not running (pnpm db:start)" >&2; exit 1; }
value() { printf '%s\n' "$status" | sed -n "s/^$1=\"\(.*\)\"$/\1/p"; }
api_url="$(value API_URL)"
anon_key="$(value ANON_KEY)"
service_key="$(value SERVICE_ROLE_KEY)"
[ -n "$api_url" ] && [ -n "$anon_key" ] && [ -n "$service_key" ] \
|| { echo "avatar-e2e: could not read the keys from supabase status" >&2; exit 1; }
if ! docker image inspect "$image" >/dev/null 2>&1; then
echo "== building $image"
docker build -f crates/worker/Dockerfile -t "$image" .
fi
env_file="$(mktemp)"
chmod 600 "$env_file"
cleanup() {
echo "== worker log (last lines)"
docker logs --tail 40 "$name" 2>/dev/null || true
docker rm -f "$name" >/dev/null 2>&1 || true
rm -f "$env_file"
}
trap cleanup EXIT
{
echo "SUPABASE_URL=$kong"
echo "SUPABASE_SERVICE_ROLE_KEY=$service_key"
echo "WORKER_ID=e2e"
echo "WORKER_POLL_SECONDS=1"
echo "WORKER_SWEEP_SECONDS=5"
echo "WORKER_QUARANTINE_GRACE_SECONDS=0"
} > "$env_file"
docker rm -f "$name" >/dev/null 2>&1 || true
echo "== starting $name on $network"
docker run -d --name "$name" --read-only --cap-drop ALL \
--security-opt no-new-privileges:true --memory 512m --cpus 1 --pids-limit 64 \
--network "$network" --env-file "$env_file" "$image" run >/dev/null
echo "== e2e suite"
SUPABASE_URL="$api_url" SUPABASE_ANON_KEY="$anon_key" SUPABASE_SERVICE_ROLE_KEY="$service_key" \
AVATAR_E2E_DB_CONTAINER="${AVATAR_E2E_DB_CONTAINER:-supabase_db_faunosteo}" \
pnpm --filter @faunosteo/supabase test:e2e