#!/usr/bin/env bash
set -euo pipefail

export PLAYWRIGHT_STAGING=1
export PLAYWRIGHT_SKIP_WEBSERVER=1
export PLAYWRIGHT_FULL_SUITE=1

: "${PLAYWRIGHT_BASE_URL:?PLAYWRIGHT_BASE_URL is required}"
: "${STAGING_E2E_SECRET:?STAGING_E2E_SECRET is required}"
: "${PLAYWRIGHT_STAGING_EMAIL:?PLAYWRIGHT_STAGING_EMAIL is required}"
: "${PLAYWRIGHT_STAGING_PORTAL_SLUG:?PLAYWRIGHT_STAGING_PORTAL_SLUG is required}"

mkdir -p docs/e2e

echo "Running staging health pre-check via Playwright global setup..."
npx playwright test staging-verification.spec.ts --grep "00 health pre-check" --project=staging

echo "Running full staging verification suite..."
npx playwright test staging-verification.spec.ts --project=staging

echo "Artifacts written to docs/e2e/"
