#!/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" \ pnpm --filter @faunosteo/supabase test:e2e