feat(acceptance): 建立同构验收与弹性容量体系

实现本地三节点 K3s 同构环境、脱敏生产快照、Gemini 图片和多参考图视频协议模拟、统一验收报告及故障注入。\n\n新增 Worker 容量控制器、资源与连接预算、任务恢复保护,并将生产验收拆分为 validation 执行和人工 CAS 放量。\n\n验证包括 Go 全量测试、PostgreSQL HTTP 集成测试、go vet、OpenAPI、ShellCheck、前端检查、迁移及发布脚本测试。
This commit is contained in:
2026-07-31 18:02:24 +08:00
parent 93d36d0e55
commit e05922b0f4
94 changed files with 12379 additions and 826 deletions
+124
View File
@@ -0,0 +1,124 @@
import assert from 'node:assert/strict';
import { execFileSync } from 'node:child_process';
import { mkdtempSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
const root = resolve(import.meta.dirname, '../..');
const temporary = mkdtempSync(join(tmpdir(), 'easyai-acceptance-report-'));
const reports = join(temporary, 'reports');
mkdirSync(reports);
const releaseSha = 'a'.repeat(40);
const digest = `sha256:${'b'.repeat(64)}`;
const configHash = 'c'.repeat(64);
const snapshotHash = 'd'.repeat(64);
const runID = '00000000-0000-4000-8000-000000000001';
const writeJSON = (path, value) => writeFileSync(path, `${JSON.stringify(value)}\n`, { mode: 0o600 });
const runtime = join(temporary, 'runtime.json');
const snapshot = join(temporary, 'snapshot.json');
const artifact = join(temporary, 'artifact.json');
const output = join(temporary, 'acceptance-report.json');
const partialOutput = join(temporary, 'acceptance-report.partial.json');
const productionPartial = join(temporary, 'production-summary.partial.json');
const mergedPartialOutput = join(temporary, 'acceptance-report.production-partial.json');
writeJSON(runtime, {
schemaVersion: 'acceptance-runtime/v1',
runId: runID,
releaseSha,
apiImageDigest: digest,
workerImageDigest: digest,
snapshotConfigHash: configHash,
snapshotSha256: snapshotHash,
apiKeys: ['must-not-be-copied'],
runToken: 'must-not-be-copied'
});
writeJSON(snapshot, {
schemaVersion: 'acceptance-snapshot/v1',
source: { releaseSha: 'e'.repeat(40), configHash },
snapshotSha256: snapshotHash
});
writeJSON(artifact, {
schemaVersion: 'acceptance-artifact-smoke/v1',
releaseSha,
apiImageDigest: digest,
passed: true,
secretSafe: true
});
writeJSON(join(reports, 'load.json'), {
schemaVersion: 'acceptance-load-report/v1',
profile: 'simulated-smoke',
passed: true,
secretSafe: true,
phases: [],
startedAt: '2026-01-01T00:00:00Z',
finishedAt: '2026-01-01T00:01:00Z'
});
execFileSync('node', [
join(root, 'scripts/acceptance/report.mjs'),
'build-local',
'--runtime', runtime,
'--snapshot', snapshot,
'--reports', reports,
'--artifact', artifact,
'--api-digest', digest,
'--certified-profile', 'P24',
'--output', output
]);
const report = JSON.parse(readFileSync(output, 'utf8'));
assert.equal(report.schemaVersion, 'acceptance-report/v1');
assert.equal(report.stages.localNative.status, 'passed');
assert.equal(report.stages.amd64Artifact.status, 'passed');
assert.equal(report.promotion.ready, false);
assert.equal(readFileSync(output, 'utf8').includes('must-not-be-copied'), false);
execFileSync('node', [join(root, 'scripts/acceptance/report.mjs'), 'validate', '--input', output]);
execFileSync('node', [
join(root, 'scripts/acceptance/report.mjs'),
'build-local-partial',
'--runtime', runtime,
'--snapshot', snapshot,
'--reports', reports,
'--certified-profile', 'P24',
'--failure-phase', 'capacity_p28_round_2',
'--output', partialOutput
]);
const partialReport = JSON.parse(readFileSync(partialOutput, 'utf8'));
assert.equal(partialReport.stages.localNative.status, 'failed');
assert.equal(partialReport.stages.localNative.failurePhase, 'capacity_p28_round_2');
assert.equal(partialReport.stages.amd64Artifact.status, 'not-run');
assert.equal(partialReport.promotion.ready, false);
assert.equal(readFileSync(partialOutput, 'utf8').includes('must-not-be-copied'), false);
execFileSync('node', [join(root, 'scripts/acceptance/report.mjs'), 'validate', '--input', partialOutput]);
writeJSON(productionPartial, {
releaseSha,
apiImageDigest: digest,
snapshotConfigHash: configHash,
snapshotSha256: snapshotHash,
stableCapacityProfile: 'P24',
realCanaryPassed: false,
gates: [
{
id: 'workflow_interrupted',
passed: false,
detail: 'production acceptance interrupted by signal'
}
],
passed: false
});
execFileSync('node', [
join(root, 'scripts/acceptance/report.mjs'),
'merge-production',
'--local-report', output,
'--production-summary', productionPartial,
'--output', mergedPartialOutput
]);
const mergedPartial = JSON.parse(readFileSync(mergedPartialOutput, 'utf8'));
assert.equal(mergedPartial.stages.onlineSimulation.status, 'failed');
assert.equal(mergedPartial.stages.realCanary.status, 'failed');
assert.equal(mergedPartial.promotion.ready, false);
assert.equal(mergedPartial.promotion.trafficMode, 'validation');
assert.equal(mergedPartial.gates.at(-1).id, 'workflow_interrupted');
execFileSync('node', [join(root, 'scripts/acceptance/report.mjs'), 'validate', '--input', mergedPartialOutput]);
+14
View File
@@ -117,6 +117,7 @@ RELEASE_SOURCE_SHA=$source_sha \
RELEASE_BASE_SHA=$base_sha \
RELEASE_COMPONENTS=api \
RELEASE_MIGRATIONS_CHANGED=false \
RELEASE_MIGRATION_VERSION=0097_worker_runtime_owner_index \
RELEASE_API_IMAGE=$api_image \
RELEASE_WEB_IMAGE=$web_image \
RELEASE_BUILD_COMPLETED_AT=2026-07-22T00:00:00Z \
@@ -129,6 +130,7 @@ RELEASE_SOURCE_SHA=$source_sha \
RELEASE_BASE_SHA='' \
RELEASE_COMPONENTS=api \
RELEASE_MIGRATIONS_CHANGED=true \
RELEASE_MIGRATION_VERSION=0097_worker_runtime_owner_index \
RELEASE_API_IMAGE=$api_image \
RELEASE_WEB_IMAGE=$web_image \
RELEASE_BUILD_COMPLETED_AT=2026-07-22T00:00:00Z \
@@ -143,6 +145,17 @@ RELEASE_DEPLOY_DURATION_SECONDS=17 \
RELEASE_DEPLOY_ACTION=deploy \
node "$root/scripts/release-manifest.mjs" record-deployment "$manifest" "$recorded" >/dev/null
node "$root/scripts/release-manifest.mjs" validate "$recorded" >/dev/null
certified=$tmp/certified.json
RELEASE_CERTIFIED_AT=2026-07-22T00:02:00Z \
RELEASE_ACCEPTANCE_RUN_ID=11111111-1111-4111-8111-111111111111 \
RELEASE_CONFIG_HASH=$(printf '3%.0s' {1..64}) \
RELEASE_CAPACITY_PROFILE=P24 \
RELEASE_WORKER_INSTANCE_SLOTS=24 \
RELEASE_WORKER_MAX_REPLICAS_NINGBO=1 \
RELEASE_WORKER_MAX_REPLICAS_HONGKONG=2 \
node "$root/scripts/release-manifest.mjs" record-certification "$recorded" "$certified" >/dev/null
node "$root/scripts/release-manifest.mjs" validate "$certified" >/dev/null
[[ $(node "$root/scripts/release-manifest.mjs" get "$certified" certification.capacityProfile) == P24 ]]
sensitive=$tmp/sensitive.json
node -e 'const fs=require("fs"); const value=JSON.parse(fs.readFileSync(process.argv[1])); value.accessToken="forbidden"; fs.writeFileSync(process.argv[2], JSON.stringify(value))' "$manifest" "$sensitive"
@@ -234,6 +247,7 @@ RELEASE_SOURCE_SHA=cccccccccccccccccccccccccccccccccccccccc \
RELEASE_BASE_SHA=dddddddddddddddddddddddddddddddddddddddd \
RELEASE_COMPONENTS=web \
RELEASE_MIGRATIONS_CHANGED=false \
RELEASE_MIGRATION_VERSION=0097_worker_runtime_owner_index \
RELEASE_API_IMAGE=$api_image \
RELEASE_WEB_IMAGE=$web_image \
RELEASE_BUILD_COMPLETED_AT=2026-07-22T00:02:00Z \