#!/usr/bin/env bash # acceptance-test.sh — Full boot cycle acceptance test for OSVauco OPAX set -euo pipefail # --- Configuration & Helpers --- ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.." # Default to no cleanup CLEANUP=false # Parse command-line arguments for arg in "$@" do case $arg in --cleanup) CLEANUP=true shift # Remove --cleanup from processing ;; esac done echo_step() { echo "" echo "==================================================================" echo "=> $1" echo "==================================================================" } # --- Main Test Flow --- # Step 1: Source environment variables if .env file exists echo_step "Loading environment..." if [ -f "$ROOT_DIR/.env" ]; then source "$ROOT_DIR/.env" echo ".env file loaded." else echo "WARNING: .env file not found. Script may fail if required variables are not set." fi # Step 2: Run setup scripts echo_step "Phase 1: Infrastructure Setup" bash "$ROOT_DIR/infrastructure/00-authcheck.sh" bash "$ROOT_DIR/infrastructure/01-setupenv.sh" bash "$ROOT_DIR/infrastructure/07-rag-setup.sh" bash "$ROOT_DIR/infrastructure/08-memorybank-setup.sh" bash "$ROOT_DIR/infrastructure/04-observability-setup.sh" bash "$ROOT_DIR/infrastructure/11-billing-iam-hardening.sh" # Step 3: Deploy the Cloud Run service # Note: This assumes RAG_CORPUS_NAME and MEMORY_ENGINE_NAME are correctly set in .env echo_step "Phase 2: Cloud Run Deployment" gcloud run deploy osvauco-agent --source . --region europe-west1 --project "${GCLOUD_PROJECT_ID?GCLOUD_PROJECT_ID not set}" --set-secrets "RAG_CORPUS=${RAG_CORPUS_NAME?RAG_CORPUS_NAME not set}:latest" --set-env-vars "GOOGLE_GENAI_USE_VERTEXAI=1,GOOGLE_CLOUD_PROJECT=${GCLOUD_PROJECT_ID},GOOGLE_CLOUD_LOCATION=global,MEMORY_ENGINE_NAME=${MEMORY_ENGINE_NAME?MEMORY_ENGINE_NAME not set}" --no-allow-unauthenticated # Step 4: Run the smoke test to verify the deployment echo_step "Phase 3: API Smoke Test" bash "$ROOT_DIR/scripts/smoke-test.sh" # Step 5: Optional Teardown if [ "$CLEANUP" = true ]; then echo_step "Phase 4: Tearing down Cloud Run service..." bash "$ROOT_DIR/infrastructure/03-teardown.sh" echo "Teardown complete." else echo_step "Skipping teardown. Run 'bash infrastructure/03-teardown.sh' manually to clean up." fi echo "" echo "==================================================================" echo "✅✅✅ Acceptance Test Completed Successfully ✅✅✅" echo "=================================================================="