param([string[]]$Packages = @('onboarding','devicereset','opsdevice','hardwareprovision','idempotency','httpapi','orchestration','saas','outbox','privacy')) $ErrorActionPreference='Continue' Set-Location (Split-Path $PSScriptRoot -Parent) $taskTemplate='codex_onboarding_template_'+[Guid]::NewGuid().ToString('N').Substring(0,12) $taskDatabases=[System.Collections.Generic.List[string]]::new() New-Item -ItemType Directory -Force -Path '.tmp-onboarding' | Out-Null try { docker compose exec -T postgres psql -U voice -d postgres -v ON_ERROR_STOP=1 -c "CREATE DATABASE $taskTemplate" | Out-Null if($LASTEXITCODE -ne 0){throw 'Test database creation failed'} $taskDatabases.Add($taskTemplate) docker compose run --rm --no-deps migrate -path=/migrations "-database=postgres://voice:voice_dev_only@postgres:5432/$taskTemplate`?sslmode=disable" up 2>&1 | Out-File '.tmp-onboarding/migration-validation.log' if($LASTEXITCODE -ne 0){throw 'Migration validation failed'} docker compose run --rm --no-deps -e PGPASSWORD=voice_dev_only seed psql -h postgres -U voice -d $taskTemplate -v ON_ERROR_STOP=1 -f /fixtures/local_seed.sql 2>&1 | Out-File '.tmp-onboarding/seed-validation.log' if($LASTEXITCODE -ne 0){throw 'Seed validation failed'} foreach($taskPackage in $Packages) { if($taskPackage -notmatch '^[a-z]+$'){throw 'Invalid package'} $taskDatabase='codex_onboarding_test_'+[Guid]::NewGuid().ToString('N').Substring(0,12) docker compose exec -T postgres psql -U voice -d postgres -v ON_ERROR_STOP=1 -c "CREATE DATABASE $taskDatabase TEMPLATE $taskTemplate" | Out-Null if($LASTEXITCODE -ne 0){throw 'Package database creation failed'} $taskDatabases.Add($taskDatabase) $env:TEST_DATABASE_URL="postgres://voice:voice_dev_only@127.0.0.1:55432/$taskDatabase`?sslmode=disable" $env:TEST_REDIS_ADDR='127.0.0.1:56379' go test -count=1 -p 1 "./internal/$taskPackage" 2>&1 | Tee-Object ".tmp-onboarding/integration-$taskPackage.log" if($LASTEXITCODE -ne 0){throw "Integration failed: $taskPackage"} } } finally { Remove-Item Env:TEST_DATABASE_URL -ErrorAction SilentlyContinue foreach($taskDatabase in $taskDatabases) { # Only databases created by this invocation can be removed. if($taskDatabase -match '^codex_onboarding_(template|test)_[0-9a-f]{12}$'){ docker compose exec -T postgres psql -U voice -d postgres -c "DROP DATABASE $taskDatabase WITH (FORCE)" | Out-Null } } }