feat(M01-A): 锁定后端依赖并验证HTTP健康检查

This commit is contained in:
Codex
2026-06-16 20:56:51 +08:00
parent ea884e166f
commit 6114124ecb
4 changed files with 1354 additions and 7 deletions
+50 -1
View File
@@ -23,4 +23,53 @@ if ($LASTEXITCODE -ne 0) {
throw "backend contract test failed"
}
Write-Host "PASS: backend M01-A skeleton check passed."
& npm --prefix backend run build
if ($LASTEXITCODE -ne 0) {
throw "backend build failed"
}
$oldHost = $env:QIPAI_API_HOST
$oldPort = $env:QIPAI_API_PORT
$oldVersion = $env:QIPAI_API_VERSION
$env:QIPAI_API_HOST = "127.0.0.1"
$env:QIPAI_API_PORT = "3101"
$env:QIPAI_API_VERSION = "0.1.0-test"
$server = $null
try {
$server = Start-Process -FilePath node -ArgumentList "dist/server.js" -WorkingDirectory "backend" -PassThru -WindowStyle Hidden
$appHealth = $null
$adminHealth = $null
for ($attempt = 0; $attempt -lt 20; $attempt++) {
try {
$appHealth = Invoke-RestMethod -Uri "http://127.0.0.1:3101/app-api/health" -Headers @{ "x-trace-id" = "codex-health-app" }
$adminHealth = Invoke-RestMethod -Uri "http://127.0.0.1:3101/admin-api/health" -Headers @{ "x-trace-id" = "codex-health-admin" }
break
} catch {
if ($server.HasExited) {
throw "backend server exited before health checks completed"
}
Start-Sleep -Milliseconds 500
}
}
if (-not $appHealth -or -not $adminHealth) {
throw "backend health checks did not respond"
}
if (-not $appHealth.ok -or $appHealth.service -ne "qipai-api" -or $appHealth.traceId -ne "codex-health-app") {
throw "app health response mismatch"
}
if (-not $adminHealth.ok -or $adminHealth.service -ne "qipai-api" -or $adminHealth.traceId -ne "codex-health-admin") {
throw "admin health response mismatch"
}
} finally {
if ($server -and -not $server.HasExited) {
Stop-Process -Id $server.Id -Force
}
$env:QIPAI_API_HOST = $oldHost
$env:QIPAI_API_PORT = $oldPort
$env:QIPAI_API_VERSION = $oldVersion
}
Write-Host "PASS: backend M01-A build and HTTP health checks passed."