test(supabase): V1-2.3 verification worker end to end on the sandbox

This commit is contained in:
bchanot committed 2026-11-01 17:34:33 +01:00
1 parent 13fe98ca0d
commit 5afb34ed0f
2 files changed
+548 -2

No files matched your search

+67 -2
View File
@@ -14,6 +14,9 @@
# pnpm db:sandbox types [--check] generated types (write, or diff with the committed file)
# pnpm db:sandbox test packages/supabase/tests/sandbox (HTTP, concurrency)
# pnpm db:sandbox e2e-shell [args] = pnpm e2e:shell: the /app shell in Chromium (apps/app/e2e); args go to Playwright (a spec file, --grep)
# pnpm db:sandbox verify-e2e [args] the sheet verification worker against the sandbox: an
# unpublished gateway, the worker container, then
# tests/sandbox/sheet-verification.sandbox.ts (args go to vitest)
# pnpm db:sandbox sql psql as postgres on stdin
# pnpm db:sandbox down
#
@@ -36,6 +39,10 @@ AUTH=faunosteo_dbsandbox_auth
REST=faunosteo_dbsandbox_rest
STORAGE=faunosteo_dbsandbox_storage
MAIL=faunosteo_dbsandbox_mail
GATEWAY=faunosteo_dbsandbox_gateway
WORKER=faunosteo_dbsandbox_worker_verify
GATEWAY_IMAGE=nginx:1.31-alpine
WORKER_IMAGE=faunosteo_worker:dev
PORT_DB=57432 PORT_AUTH=57999 PORT_REST=57300 PORT_STORAGE=57500 PORT_MAIL=57025
STATE="${FAUNOSTEO_SANDBOX_DIR:-$HOME/.cache/faunosteo-db-sandbox}"
SECRETS="$STATE/secrets.sh"
@@ -219,7 +226,7 @@ cmd_up() {
}
cmd_down() {
docker rm -f "$REST" "$STORAGE" "$AUTH" "$MAIL" "$DB" >/dev/null 2>&1 || true
docker rm -f "$WORKER" "$GATEWAY" "$REST" "$STORAGE" "$AUTH" "$MAIL" "$DB" >/dev/null 2>&1 || true
docker network rm "$NET" >/dev/null 2>&1 || true
rm -f "$SECRETS" "$STATE/db.env" "$STATE/auth.env" "$STATE/storage.env" "$STATE/rest.env" "$STATE/service-header"
echo "== sandbox removed"
@@ -234,6 +241,63 @@ with_sandbox_env() (
"$@"
)
# The Kong routes the worker calls (/rest/v1/, /storage/v1/), on the sandbox
# network only: no host port is published.
GATEWAY_CONF='server {
listen 8000;
client_max_body_size 8m;
proxy_http_version 1.1;
location /rest/v1/ { proxy_pass http://'"$REST"':3000/; }
location /storage/v1/ { proxy_pass http://'"$STORAGE"':5000/; }
location / { return 404; }
}'
# The worker's JSON lines hold no secret by design (crates/worker log allowlist);
# they are printed only after checking that neither key appears in them.
print_worker_log() {
local lines
lines="$(docker logs "$WORKER" 2>&1)" || return 0
case "$lines" in
*"$SB_SERVICE_KEY"* | *"$SB_ANON_KEY"*) echo "== worker log withheld: it contains a key" ;;
*) echo "== worker log"; printf '%s\n' "$lines" ;;
esac
}
verify_cleanup() {
[ -n "${verify_env:-}" ] && rm -f "$verify_env"
print_worker_log
docker rm -f "$WORKER" "$GATEWAY" >/dev/null 2>&1 || true
}
cmd_verify_e2e() {
load_secrets
docker image inspect "$WORKER_IMAGE" >/dev/null 2>&1 || die "$WORKER_IMAGE missing (pnpm worker:image)"
docker rm -f "$WORKER" "$GATEWAY" >/dev/null 2>&1 || true
trap verify_cleanup EXIT
docker run -d --name "$GATEWAY" --network "$NET" --security-opt no-new-privileges:true \
--entrypoint sh "$GATEWAY_IMAGE" -c 'printf "%s\n" "$0" > /etc/nginx/conf.d/default.conf && exec nginx -g "daemon off;"' \
"$GATEWAY_CONF" >/dev/null
wait_for "gateway" docker exec "$GATEWAY" wget -q -O /dev/null http://127.0.0.1:8000/rest/v1/
# The service key reaches the container through a 600 file removed once it started.
verify_env="$(umask 077; mktemp "$STATE/worker-verify.XXXXXX")"
printf 'SUPABASE_URL=http://%s:8000\nSUPABASE_SERVICE_ROLE_KEY=%s\nWORKER_ID=sandbox-verify\nWORKER_POLL_SECONDS=1\n' \
"$GATEWAY" "$SB_SERVICE_KEY" > "$verify_env"
docker run -d --name "$WORKER" --network "$NET" --env-file "$verify_env" \
--read-only --cap-drop ALL --security-opt no-new-privileges:true \
--memory 512m --cpus 1 --pids-limit 64 --user nonroot \
"$WORKER_IMAGE" run --jobs sheet-verify >/dev/null
rm -f "$verify_env"; verify_env=
for _ in $(seq 1 30); do
docker logs "$WORKER" 2>&1 | grep -q '"event":"worker_start"' && break
[ "$(docker inspect -f '{{.State.Running}}' "$WORKER")" = true ] || die "worker exited before worker_start"
sleep 1
done
docker logs "$WORKER" 2>&1 | grep -q '"event":"worker_start"' || die "timeout waiting for worker_start"
echo "== worker up ($WORKER_IMAGE, run --jobs sheet-verify, via $GATEWAY)"
SANDBOX_VERIFY_WORKER="$WORKER" with_sandbox_env node_modules/.bin/pnpm --filter @faunosteo/supabase \
test:sandbox tests/sandbox/sheet-verification.sandbox.ts "$@"
}
case "${1:-}" in
up) shift; cmd_up "$@" ;;
down) cmd_down ;;
@@ -248,6 +312,7 @@ case "${1:-}" in
fi ;;
test) shift; load_secrets; with_sandbox_env node_modules/.bin/pnpm --filter @faunosteo/supabase test:sandbox "$@" ;;
e2e-shell) shift; load_secrets; with_sandbox_env node_modules/.bin/pnpm --filter @faunosteo/app e2e:shell "$@" ;;
verify-e2e) shift; cmd_verify_e2e "$@" ;;
sql) load_secrets; sb_psql ;;
*) sed -n '2,23p' "$0"; exit 1 ;;
*) sed -n '2,26p' "$0"; exit 1 ;;
esac