'use strict'; const fs = require('fs'); const os = require('os'); const path = require('path'); const { spawnSync } = require('child_process'); const ROOT = path.resolve(__dirname, '..'); const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'qiwei-release-check-')); const outputsDir = path.join(tempRoot, 'outputs'); const npmCli = process.env.npm_execpath || path.join(path.dirname(process.execPath), 'node_modules', 'npm', 'bin', 'npm-cli.js'); const checks = [ 'check', 'smoke', 'agent:smoke', 'library:smoke', 'excel:smoke', 'outputs:validate', 'install:check', 'package:smoke', 'audit:prod', ]; try { for (const check of checks) { const result = spawnSync(process.execPath, [npmCli, 'run', check], { cwd: ROOT, env: { ...process.env, QIWEI_OUTPUTS_DIR: outputsDir, QIWEI_AGENT_DB_PATH: path.join(outputsDir, 'messages', 'agent-workbench.db'), }, stdio: 'inherit', windowsHide: true, }); if (result.error) throw result.error; if (result.status !== 0) process.exit(result.status || 1); } process.stdout.write(`\n发布检查通过:${checks.length} 组检查均已完成,测试输出已隔离。\n`); } finally { fs.rmSync(tempRoot, { recursive: true, force: true }); }