feat(M01-A): 锁定后端依赖并验证HTTP健康检查
This commit is contained in:
Generated
+1288
File diff suppressed because it is too large
Load Diff
+11
-4
@@ -3,6 +3,10 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=20.0.0",
|
||||||
|
"npm": ">=10.0.0"
|
||||||
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "tsx watch src/server.ts",
|
"dev": "tsx watch src/server.ts",
|
||||||
"build": "tsc -p tsconfig.json",
|
"build": "tsc -p tsconfig.json",
|
||||||
@@ -10,10 +14,9 @@
|
|||||||
"test": "node tests/backend-contract.test.mjs"
|
"test": "node tests/backend-contract.test.mjs"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fastify/cors": "^9.0.1",
|
"@fastify/cors": "^11.2.0",
|
||||||
"@fastify/rate-limit": "^9.1.0",
|
"@fastify/rate-limit": "^11.0.0",
|
||||||
"fastify": "^4.28.1",
|
"fastify": "^5.8.5",
|
||||||
"kysely": "^0.27.4",
|
|
||||||
"mysql2": "^3.11.3",
|
"mysql2": "^3.11.3",
|
||||||
"pino": "^9.4.0",
|
"pino": "^9.4.0",
|
||||||
"zod": "^3.23.8"
|
"zod": "^3.23.8"
|
||||||
@@ -22,5 +25,9 @@
|
|||||||
"@types/node": "^20.17.6",
|
"@types/node": "^20.17.6",
|
||||||
"tsx": "^4.19.2",
|
"tsx": "^4.19.2",
|
||||||
"typescript": "^5.6.3"
|
"typescript": "^5.6.3"
|
||||||
|
},
|
||||||
|
"overrides": {
|
||||||
|
"fast-uri": "3.1.2",
|
||||||
|
"toad-cache": "3.7.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,13 @@ const root = dirname(dirname(fileURLToPath(import.meta.url)));
|
|||||||
const read = (path) => readFileSync(join(root, path), 'utf8');
|
const read = (path) => readFileSync(join(root, path), 'utf8');
|
||||||
|
|
||||||
const packageJson = JSON.parse(read('package.json'));
|
const packageJson = JSON.parse(read('package.json'));
|
||||||
assert.equal(packageJson.dependencies.fastify.startsWith('^4.'), true);
|
assert.equal(packageJson.engines.node, '>=20.0.0');
|
||||||
|
assert.equal(packageJson.dependencies.fastify.startsWith('^5.'), true);
|
||||||
|
assert.equal(packageJson.dependencies['@fastify/cors'].startsWith('^11.'), true);
|
||||||
|
assert.equal(packageJson.dependencies['@fastify/rate-limit'].startsWith('^11.'), true);
|
||||||
assert.equal(packageJson.dependencies.zod.startsWith('^3.'), true);
|
assert.equal(packageJson.dependencies.zod.startsWith('^3.'), true);
|
||||||
assert.equal(packageJson.dependencies.mysql2.startsWith('^3.'), true);
|
assert.equal(packageJson.dependencies.mysql2.startsWith('^3.'), true);
|
||||||
assert.equal(packageJson.dependencies.kysely.startsWith('^0.'), true);
|
assert.equal(packageJson.dependencies.kysely, undefined);
|
||||||
|
|
||||||
const tsconfig = JSON.parse(read('tsconfig.json'));
|
const tsconfig = JSON.parse(read('tsconfig.json'));
|
||||||
assert.equal(tsconfig.compilerOptions.strict, true);
|
assert.equal(tsconfig.compilerOptions.strict, true);
|
||||||
|
|||||||
@@ -23,4 +23,53 @@ if ($LASTEXITCODE -ne 0) {
|
|||||||
throw "backend contract test failed"
|
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."
|
||||||
|
|||||||
Reference in New Issue
Block a user