import assert from 'node:assert/strict'; import fs from 'node:fs'; import path from 'node:path'; const repoRoot = process.cwd(); const scriptPath = path.join(repoRoot, 'scripts', 'run-docker-4c16g-benchmark.js'); const runbookPath = path.join(repoRoot, 'docs', 'refactor', 'performance-benchmark-runbook.md'); const readmePath = path.join(repoRoot, 'README.md'); const script = fs.readFileSync(scriptPath, 'utf8'); const runbook = fs.readFileSync(runbookPath, 'utf8'); const readme = fs.readFileSync(readmePath, 'utf8'); assert.match(script, /docker-4c16g-resource-evidence-\$\{shanghaiStamp\(\)\}\.json/, 'benchmark script should write resource evidence JSON'); assert.match(script, /BENCHMARK_LIMIT_DB_RESOURCES/, 'benchmark script should expose explicit DB resource limiting'); assert.match(script, /BENCHMARK_KEEP_DB_LIMIT/, 'benchmark script should support keeping DB limits only when requested'); assert.match(script, /dockerJson\(\['info', '--format', '\{\{json \.\}\}'\]\)/, 'benchmark script should record Docker Desktop resources'); assert.match(script, /inspectContainer\(composeServiceContainerId\('api'\)\)/, 'benchmark script should inspect the API container after compose starts'); assert.match(script, /inspectContainer\(dbContainerName\)/, 'benchmark script should inspect the Supabase DB container'); assert.match(script, /dockerHostRestoreLimit/, 'benchmark script should restore originally-unlimited DB containers to Docker host limits'); assert.match(script, /restoreDbLimit\(dbRestore, resourceEvidence\)/, 'benchmark script should restore DB resource limits by default'); assert.match(script, /restoreLimit = restore/, 'benchmark script should record the DB restore strategy in evidence'); assert.match(script, /readBenchmarkSummary\(report\)/, 'benchmark script should attach benchmark summaries to resource evidence'); assert.match(runbook, /docker-4c16g-resource-evidence-\*\.json\/md/, 'runbook should document the resource evidence artifact'); assert.match(runbook, /BENCHMARK_LIMIT_DB_RESOURCES="true"/, 'runbook should document explicit DB resource limiting'); assert.match(runbook, /默认会在结束后恢复 DB 容器原始限制/, 'runbook should document DB limit restoration'); assert.match(runbook, /不能替代目标云服务器正式压测证据/, 'runbook should keep local benchmark scope explicit'); assert.match(readme, /docker-4c16g-resource-evidence-\*\.json\/md/, 'README should mention resource evidence artifacts'); assert.match(readme, /BENCHMARK_LIMIT_DB_RESOURCES=true/, 'README should mention optional DB resource limiting'); assert.match(readme, /正式容量承诺仍要在目标 4 核 16G 云服务器复跑/, 'README should avoid overstating local Docker capacity'); console.log('[PASS] docker benchmark resource evidence guardrails');