2026-10-08 10:06:44 +08:00
|
|
|
param(
|
|
|
|
|
[string[]]$Packages = @('onboarding','devicereset','opsdevice','hardwareprovision','idempotency','httpapi','orchestration','saas','outbox','privacy'),
|
|
|
|
|
[switch]$VerboseTests,
|
|
|
|
|
[string]$OutputDirectory = '.tmp-onboarding'
|
|
|
|
|
)
|
2026-09-12 08:57:29 +08:00
|
|
|
$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()
|
2026-10-08 10:06:44 +08:00
|
|
|
$taskPreviousDatabase = $env:TEST_DATABASE_URL
|
|
|
|
|
$taskPreviousRedis = $env:TEST_REDIS_ADDR
|
|
|
|
|
New-Item -ItemType Directory -Force -Path $OutputDirectory | Out-Null
|
2026-09-12 08:57:29 +08:00
|
|
|
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)
|
2026-10-08 10:06:44 +08:00
|
|
|
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 (Join-Path $OutputDirectory 'migration-validation.log')
|
2026-09-12 08:57:29 +08:00
|
|
|
if($LASTEXITCODE -ne 0){throw 'Migration validation failed'}
|
2026-10-08 10:06:44 +08:00
|
|
|
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 (Join-Path $OutputDirectory 'seed-validation.log')
|
2026-09-12 08:57:29 +08:00
|
|
|
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'
|
2026-10-08 10:06:44 +08:00
|
|
|
$taskGoArgs = @('test', '-count=1', '-p', '1')
|
|
|
|
|
if ($VerboseTests) { $taskGoArgs += '-v' }
|
|
|
|
|
$taskGoArgs += "./internal/$taskPackage"
|
|
|
|
|
go @taskGoArgs 2>&1 | Tee-Object (Join-Path $OutputDirectory "integration-$taskPackage.log")
|
2026-09-12 08:57:29 +08:00
|
|
|
if($LASTEXITCODE -ne 0){throw "Integration failed: $taskPackage"}
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
2026-10-08 10:06:44 +08:00
|
|
|
$env:TEST_DATABASE_URL = $taskPreviousDatabase
|
|
|
|
|
$env:TEST_REDIS_ADDR = $taskPreviousRedis
|
2026-09-12 08:57:29 +08:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|