verify-trial-local.mjs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /** 本地试用容器实测;只操作本轮记录的独立 Docker 名称,不删除旧资产。 */
  2. import { recordProgress } from './lib/project-recovery.mjs';
  3. import fs from 'node:fs';
  4. import path from 'node:path';
  5. import assert from 'node:assert/strict';
  6. import { spawnSync } from 'node:child_process';
  7. import { validatedPromptInputs } from './lib/onboarding-input.mjs';
  8. const arg = (name, fallback) => process.argv.find(x => x.startsWith(`--${name}=`))?.slice(name.length + 3) ?? fallback;
  9. const stage = arg('stage', 'status');
  10. const out = path.resolve(arg('out', 'test-results/new-account-20261128'));
  11. const privateDir = path.resolve(arg('private-dir', '.local-backup/new-account-20261128'));
  12. const packageRoot = path.resolve(arg('package-dir', path.join(out, 'onboarding-package')));
  13. const file = path.join(out, 'state.json');
  14. let state, env;
  15. const lockFile = path.join(out, 'runner.lock');
  16. const lock = fs.openSync(lockFile, 'wx');
  17. fs.writeFileSync(lock, JSON.stringify({ pid: process.pid, stage: `docker-${stage}`, at: new Date().toISOString() }));
  18. const save = () => { fs.writeFileSync(file + '.next', JSON.stringify(state, null, 2) + '\n'); fs.renameSync(file + '.next', file); };
  19. const note = text => recordProgress(process.cwd(), `[${out}] ${text}`);
  20. const docker = (args, input, allowFailure = false) => {
  21. const r = spawnSync('docker', args, { input, encoding: 'utf8', timeout: 90000, maxBuffer: 4 * 1024 * 1024 });
  22. if (!allowFailure && (r.error || r.status !== 0)) throw Error(`Docker ${args[0]} 失败,exit=${r.status}:${r.stderr?.slice(-600) ?? r.error?.message}`);
  23. return r;
  24. };
  25. const redact = text => ['MATRIX_PASSWORD', 'FMODE_SESSION_TOKEN'].reduce((text, key) => env?.[key] ? text.split(env[key]).join(`<${key}>`) : text, text);
  26. const snapshot = name => {
  27. const r = docker(['inspect', name], undefined, true);
  28. if (r.status !== 0) return { exists: false, name };
  29. const data = JSON.parse(r.stdout)[0];
  30. const result = { exists: true, name, id: data.Id, state: data.State, image: data.Image,
  31. mounts: data.Mounts.map(x => ({ name: x.Name, destination: x.Destination })),
  32. configuredEnvKeys: data.Config.Env.map(x => x.split('=')[0]) };
  33. const logs = docker(['logs', '--tail', '200', name], undefined, true);
  34. const suffix = stage === 'resume-candidate' ? '-resume-20261129' : '';
  35. fs.writeFileSync(path.join(privateDir, `${name}${suffix}.raw.log`), logs.stdout + logs.stderr);
  36. fs.writeFileSync(path.join(out, `${name}${suffix}.log`), redact(logs.stdout + logs.stderr));
  37. fs.writeFileSync(path.join(out, `${name}${suffix}.inspect.json`), JSON.stringify(result, null, 2));
  38. return result;
  39. };
  40. try {
  41. state = JSON.parse(fs.readFileSync(file));
  42. env = JSON.parse(fs.readFileSync(path.join(privateDir, 'trial-env.json')));
  43. assert.equal(env.AGENT_ID, state.trial?.agentId, '提示词身份与本轮账本不一致');
  44. if (stage === 'status') {
  45. const names = Object.values(state.actions).filter(a => a.kind === 'trial-local').map(a => a.target);
  46. for (const name of names) console.log(JSON.stringify(snapshot(name), null, 2));
  47. } else if (stage === 'prompt-fresh') {
  48. assert.ok(!state.actions.localPromptFresh?.attempted, '新版提示词从零安装已有动作记录,先只读核实,禁止重复建卷或启动');
  49. assert.ok(state.actions.trialPromptRefresh?.confirmedAt && state.actions.cloudPrompt?.confirmedAt, '先完成部署后APK真实提示词回验');
  50. const bundle = JSON.parse(fs.readFileSync('cloud/onboarding/bundle.json'));
  51. assert.equal(state.trial.updatedInstruction.bundleSha256, bundle.sha256);
  52. const instruction = fs.readFileSync(path.join(privateDir, 'trial-instruction-updated.md'), 'utf8');
  53. const savedEnv = JSON.parse(fs.readFileSync(path.join(privateDir, 'trial-env-updated.json')));
  54. const captured = validatedPromptInputs(instruction, state.trial.updatedInstruction, savedEnv, bundle);
  55. const installScript = captured.script;
  56. env = captured.env;
  57. assert.equal(env.AGENT_ID, state.trial.agentId);
  58. assert.equal(env.MATRIX_USER_ID, state.trial.agentMxId);
  59. const source = state.actions.localCandidate;
  60. const before = snapshot(source.target);
  61. assert.equal(before.id, source.containerId, '只能停止本轮原候选');
  62. assert.equal(snapshot(state.actions.localRaw.target).state.Running, false, '原raw必须保持停止');
  63. const name = 'fmode-trial-prompt-' + env.AGENT_ID.replace(/^agent-node-app-/, '') + '-' + bundle.sha256.slice(0, 8);
  64. const volume = name + '-data';
  65. assert.equal(docker(['ps', '-a', '--filter', `name=^/${name}$`, '--format', '{{.Names}}']).stdout.trim(), '');
  66. assert.notEqual(docker(['volume', 'inspect', volume], undefined, true).status, 0);
  67. const modelFile = path.join(privateDir, 'test-model-config.yaml');
  68. assert.ok(fs.existsSync(modelFile), '缺少显式可用模型前提,不能用额外补丁代替');
  69. const runtimeEnv = Object.fromEntries(Object.entries(env).filter(([key]) => /^(HERMES_|MATRIX_|AGENT_|FMODE_)/.test(key) || ['TZ', 'RES_OPTIONS'].includes(key)));
  70. for (const [key, value] of Object.entries(runtimeEnv)) assert.ok(/^[A-Z][A-Z0-9_]*$/.test(key) && typeof value === 'string' && value && !/[\r\n]/.test(value));
  71. const envText = Object.entries(runtimeEnv).map(([key, value]) => key + '=' + value).join('\n') + '\n';
  72. const envFile = path.join(privateDir, 'trial-prompt-fresh-runtime.env');
  73. fs.writeFileSync(envFile, envText, { flag: 'wx' });
  74. state.actions.localPromptFresh = { attempted: true, at: new Date().toISOString(), kind: 'trial-local', target: name, volume, agentId: env.AGENT_ID,
  75. bundleSha256: bundle.sha256, sourceCandidate: source.target, originalCandidateId: before.id, phase: 'before-original-stop-and-volume-create',
  76. instructionSha256: state.trial.updatedInstruction.instructionSha256, modelPrerequisite: 'private test-model-config.yaml; not included in bundle' };
  77. save(); note(`准备停止原候选${source.target}并保留原卷;新隔离卷${volume},新实例${name}。严格执行APK捕获的下载/校验/安装Python程序,模型为显式前提,连续安装两次仅验证幂等,不同时运行相同Matrix身份。`);
  78. if (before.state.Running) docker(['stop', '--time', '15', source.target]);
  79. assert.equal(snapshot(source.target).state.Running, false);
  80. state.actions.localPromptFresh.phase = 'original-stopped-before-volume-create'; save();
  81. docker(['volume', 'create', volume]);
  82. state.actions.localPromptFresh.phase = 'fresh-volume-before-real-prompt-install'; save();
  83. const setup = "import os,shutil,base64\nfrom pathlib import Path\np=Path('/opt/data')\nassert not (p/'config.yaml').exists(), 'fresh volume must not contain a prior config'\nshutil.copyfile('/tmp/test-model.yaml',p/'config.yaml')\nos.chown(p/'config.yaml',10000,10000)\n(p/'.fmode-onboarding.env').write_bytes(base64.b64decode('" + Buffer.from(envText).toString('base64') + "'))\nos.chmod(p/'.fmode-onboarding.env',0o600)\nos.chown(p/'.fmode-onboarding.env',10000,10000)\n";
  84. const installed = docker(['run', '--rm', '-i', '--name', name + '-install', '--env-file', envFile,
  85. '--mount', `type=volume,source=${volume},target=/opt/data`, '--mount', `type=bind,source=${modelFile},target=/tmp/test-model.yaml,readonly`,
  86. '--entrypoint', '/opt/hermes/.venv/bin/python', bundle.image, '-B', '-'], setup + installScript + '\n' + installScript + '\n');
  87. fs.writeFileSync(path.join(out, 'prompt-fresh-install-v101.log'), installed.stdout + installed.stderr, { flag: 'wx' });
  88. const installs = installed.stdout.split(/\r?\n/).filter(line => line.startsWith('{')).map(line => JSON.parse(line));
  89. assert.equal(installs.length, 2, '必须有首次安装及重复安装两个真实回执');
  90. assert.equal(installs[0].version, bundle.version); assert.equal(installs[1].version, bundle.version);
  91. assert.deepEqual(installs[1].changed, [], '相同提示词重复安装仍有变更,幂等未通过');
  92. state.actions.localPromptFresh.installReceipts = installs; state.actions.localPromptFresh.phase = 'prompt-installed-twice-before-start'; save();
  93. const started = docker(['run', '-d', '--name', name, '--hostname', env.AGENT_ID, '--env-file', envFile,
  94. '--mount', `type=volume,source=${volume},target=/opt/data`, '--memory', '1536m', '--cpus', '1.5', '--pids-limit', '512', '--restart', 'no',
  95. '--entrypoint', '/opt/data/.fmode-media-patch/entry.sh', bundle.image, 'gateway', 'run']);
  96. state.actions.localPromptFresh.containerId = started.stdout.trim(); state.actions.localPromptFresh.phase = 'started-awaiting-platform-verification';
  97. state.assets.push({ kind: 'local-docker-container', name, volume, agentId: env.AGENT_ID, owner: state.userId }); save();
  98. await new Promise(resolve => setTimeout(resolve, 8000));
  99. const after = snapshot(name); assert.equal(after.state.Running, true); assert.equal(after.id, state.actions.localPromptFresh.containerId);
  100. state.actions.localPromptFresh.confirmedAt = new Date().toISOString(); state.actions.localPromptFresh.receipt = { id: after.id, state: after.state, mounts: after.mounts, installs }; save();
  101. note(`真实APK提示词已在新隔离卷首次安装并幂等复验成功,${name}运行;原候选与raw停止、旧卷保留。此回执只确认安装/启动,后续真实首报/通信/成果另验。`);
  102. console.log(JSON.stringify({ name, volume, version: bundle.version, secondInstallChanges: installs[1].changed, running: after.state.Running }));
  103. } else if (stage === 'resume-candidate') {
  104. const source = state.actions.localCandidate;
  105. assert.ok(source?.containerId && source.target, '缺少原候选实例回执,不能新建冒充恢复');
  106. const key = 'candidateResume_20261129';
  107. assert.ok(!state.actions[key]?.attempted, '恢复启动已有动作,先只读核实,不盲重试');
  108. const before = snapshot(source.target);
  109. assert.equal(before.id, source.containerId, '候选实例 ID 与原回执不符');
  110. assert.equal(before.state.Running, false, '实例已经运行,无需再次启动');
  111. const raw = snapshot(state.actions.localRaw.target);
  112. assert.equal(raw.state.Running, false, '原始实例必须保持停止,禁止同身份并发');
  113. const expectedVolume = source.volume;
  114. assert.ok(before.mounts.some(x => x.name === expectedVolume && x.destination === '/opt/data'), '原数据卷挂载不符');
  115. state.actions[key] = { attempted: true, at: new Date().toISOString(), target: source.target, containerId: before.id, volume: expectedVolume, phase: 'before-start' };
  116. save(); note(`准备仅恢复原候选实例 ${source.target},ID 与原数据卷已核对;原始实例保持停止,不创建新资产。`);
  117. docker(['start', source.target]);
  118. state.actions[key].phase = 'started-awaiting-inspection'; save();
  119. await new Promise(resolve => setTimeout(resolve, 8000));
  120. const after = snapshot(source.target);
  121. assert.equal(after.id, source.containerId); assert.equal(after.state.Running, true);
  122. state.actions[key].confirmedAt = new Date().toISOString(); state.actions[key].receipt = { id: after.id, state: after.state, mounts: after.mounts }; save();
  123. note('原候选实例已恢复 running,原数据卷未重建;尚须核对真实心跳、消息与历史。');
  124. console.log(JSON.stringify(state.actions[key].receipt));
  125. } else if (stage === 'update-candidate') {
  126. const source = state.actions.localCandidate;
  127. assert.ok(source?.containerId && source.target, '候选实例缺少创建回执');
  128. const receipt = JSON.parse(fs.readFileSync(path.join(packageRoot, 'receipt.json')));
  129. const key = 'candidateUpdate_' + receipt.sha256.slice(0, 16);
  130. assert.ok(!state.actions[key]?.attempted, '该版本更新已有记录,先 status 核实');
  131. const before = snapshot(source.target);
  132. assert.equal(before.id, source.containerId, '候选实例身份发生变化');
  133. state.actions[key] = { attempted: true, at: new Date().toISOString(), target: source.target, bundleSha256: receipt.sha256, phase: 'before-stop' };
  134. save(); note(`准备仅更新候选实例 ${source.target} 至接入包 ${receipt.sha256};先停止,再在离线初始化进程中安装,保留模型和历史。`);
  135. if (before.state.Running) docker(['stop', '--time', '15', source.target]);
  136. state.actions[key].phase = 'stopped-before-install'; save();
  137. const packageDir = path.join(packageRoot, 'package');
  138. const modelFile = path.join(privateDir, 'test-model-config.yaml');
  139. const bootstrap = "import os,sys,json,yaml;from pathlib import Path;p=Path('/opt/data/config.yaml');cfg=yaml.safe_load(p.read_text());fixture=yaml.safe_load(Path('/tmp/test-model.yaml').read_text());assert cfg['model']==fixture['model'],'test model configuration unexpectedly changed';cfg.setdefault('_config_version',fixture['_config_version']);p.write_text(yaml.safe_dump(cfg,allow_unicode=True));os.chown(p,10000,10000);sys.path.insert(0,'/candidate');from install import install;print(json.dumps(install(Path('/candidate'),Path('/opt/data'),dict(os.environ)),ensure_ascii=False))";
  140. const installed = docker(['run', '--rm', '--name', source.target + '-update', '--network', 'none', '--env-file', path.join(privateDir, 'trial-runtime.env'),
  141. '--mount', `type=volume,source=${source.volume},target=/opt/data`, '--mount', `type=bind,source=${packageDir},target=/candidate,readonly`,
  142. '--mount', `type=bind,source=${modelFile},target=/tmp/test-model.yaml,readonly`, '--entrypoint', '/opt/hermes/.venv/bin/python',
  143. 'fmode/agent-node:0.21.3', '-B', '-c', bootstrap]);
  144. fs.writeFileSync(path.join(out, `${key}-install.json`), installed.stdout);
  145. state.actions[key].phase = 'installed-before-start'; save();
  146. docker(['start', source.target]);
  147. state.actions[key].phase = 'restarted-awaiting-inspection'; save();
  148. await new Promise(resolve => setTimeout(resolve, 8000));
  149. const result = snapshot(source.target);
  150. state.actions[key].confirmedAt = new Date().toISOString(); state.actions[key].receipt = result.state;
  151. state.actions.localCandidate.bundleSha256 = receipt.sha256; save();
  152. note(`候选实例更新后状态 ${result.state.Status};指定成果 hooks 已登记许可,图文合并组件已纳入启用清单;继续真实消息和文件验收。`);
  153. console.log(JSON.stringify({ name: source.target, updated: receipt.sha256, state: result.state }, null, 2));
  154. } else if (stage === 'candidate') {
  155. assert.ok(!state.actions.localCandidate?.attempted, '修复版容器已有创建记录,先 status 核实');
  156. assert.equal(snapshot(state.actions.localRaw.target).state.Running, false, '原始实例必须先停止,避免相同 Matrix 身份并发');
  157. const name = 'fmode-trial-local-' + env.AGENT_ID.replace(/^agent-node-app-/, '') + '-candidate';
  158. const volume = name + '-data';
  159. const packageDir = path.join(packageRoot, 'package');
  160. const modelFile = path.join(privateDir, 'test-model-config.yaml');
  161. assert.ok(fs.existsSync(modelFile), '本地测试需先准备明确的模型前提配置');
  162. assert.equal(docker(['ps', '-a', '--filter', `name=^/${name}$`, '--format', '{{.Names}}']).stdout.trim(), '');
  163. assert.notEqual(docker(['volume', 'inspect', volume], undefined, true).status, 0);
  164. const receipt = JSON.parse(fs.readFileSync(path.join(packageRoot, 'receipt.json')));
  165. state.actions.localCandidate = { attempted: true, at: new Date().toISOString(), kind: 'trial-local', target: name, volume,
  166. agentId: env.AGENT_ID, phase: 'before-volume-create', bundleSha256: receipt.sha256, modelPrerequisite: 'private test-model-config.yaml, not distributed' };
  167. save(); note(`准备创建隔离候选实例 ${name} 与卷 ${volume},使用接入包 ${receipt.sha256};模型配置是显式测试前提,仅在私有目录,不进入接入包。原试用实例已停止。`);
  168. const completeEnv = { ...env, HERMES_HOME: '/opt/data', HERMES_DASHBOARD: '0', TZ: 'Asia/Shanghai', RES_OPTIONS: 'single-request' };
  169. const envFile = path.join(privateDir, 'trial-runtime.env');
  170. fs.writeFileSync(envFile, Object.entries(completeEnv).map(([k, v]) => `${k}=${v}`).join('\n') + '\n');
  171. docker(['volume', 'create', volume]);
  172. state.actions.localCandidate.phase = 'volume-created-before-model-and-bridge-install'; save();
  173. const bootstrap = "import os,shutil,sys,json;from pathlib import Path;shutil.copyfile('/tmp/test-model.yaml','/opt/data/config.yaml');os.chown('/opt/data/config.yaml',10000,10000);sys.path.insert(0,'/candidate');from install import install;print(json.dumps(install(Path('/candidate'),Path('/opt/data'),dict(os.environ)),ensure_ascii=False))";
  174. const installed = docker(['run', '--rm', '--name', name + '-install', '--network', 'none', '--env-file', envFile,
  175. '--mount', `type=volume,source=${volume},target=/opt/data`, '--mount', `type=bind,source=${packageDir},target=/candidate,readonly`,
  176. '--mount', `type=bind,source=${modelFile},target=/tmp/test-model.yaml,readonly`, '--entrypoint', '/opt/hermes/.venv/bin/python',
  177. 'fmode/agent-node:0.21.3', '-B', '-c', bootstrap]);
  178. fs.writeFileSync(path.join(out, 'candidate-install.json'), installed.stdout);
  179. state.actions.localCandidate.phase = 'model-prerequisite-and-bridge-installed'; save();
  180. const started = docker(['run', '-d', '--name', name, '--hostname', env.AGENT_ID, '--env-file', envFile,
  181. '--mount', `type=volume,source=${volume},target=/opt/data`, '--memory', '1536m', '--cpus', '1.5', '--pids-limit', '512',
  182. '--restart', 'no', '--entrypoint', '/opt/data/.fmode-media-patch/entry.sh', 'fmode/agent-node:0.21.3', 'gateway', 'run']);
  183. state.actions.localCandidate.containerId = started.stdout.trim(); state.actions.localCandidate.phase = 'started-awaiting-inspection'; save();
  184. state.assets.push({ kind: 'local-docker-container', name, volume, agentId: env.AGENT_ID, owner: state.userId }); save();
  185. await new Promise(resolve => setTimeout(resolve, 8000));
  186. const result = snapshot(name);
  187. state.actions.localCandidate.confirmedAt = new Date().toISOString(); state.actions.localCandidate.receipt = result; save();
  188. note(`候选接入包已安装并启动,Docker 实际状态 ${result.state.Status};待核实插件加载、真实平台首报和 App 使用,不按 running 判成功。`);
  189. console.log(JSON.stringify({ name, state: result.state, bundleSha256: receipt.sha256 }, null, 2));
  190. } else if (stage === 'stop-raw') {
  191. const source = state.actions.localRaw;
  192. assert.ok(source?.containerId && source?.target, '缺少本轮原始实测容器回执');
  193. assert.ok(!state.actions.localRawStop?.attempted, '停止动作已有记录,先 status 核实');
  194. const before = snapshot(source.target);
  195. assert.equal(before.id, source.containerId, '目标实例不是本轮创建的容器');
  196. state.actions.localRawStop = { attempted: true, at: new Date().toISOString(), target: source.target, before: before.state.Status };
  197. save(); note(`准备停止本轮原始实测容器 ${source.target},保留容器、数据卷与日志;不操作既有容器。`);
  198. docker(['stop', '--time', '15', source.target]);
  199. const result = snapshot(source.target);
  200. assert.equal(result.state.Running, false);
  201. state.actions.localRawStop.confirmedAt = new Date().toISOString(); state.actions.localRawStop.receipt = result.state; save();
  202. note(`原始实测容器已停止;已确认提示词未提供接入插件,平台无该容器心跳;默认仪表盘认证失败反复重启。原日志及数据保留,接下来只修独立接入路径。`);
  203. console.log(JSON.stringify({ stopped: source.target, running: result.state.Running }));
  204. } else if (stage === 'raw') {
  205. assert.ok(!state.actions.localRaw?.attempted, '原提示词实测已登记,先 status 核实,不能重复启动');
  206. const name = 'fmode-trial-local-' + env.AGENT_ID.replace(/^agent-node-app-/, '') + '-raw';
  207. const volume = name + '-data';
  208. assert.equal(docker(['ps', '-a', '--filter', `name=^/${name}$`, '--format', '{{.Names}}']).stdout.trim(), '', '同名容器已存在');
  209. assert.notEqual(docker(['volume', 'inspect', volume], undefined, true).status, 0, '同名数据卷已存在');
  210. state.actions.localRaw = { attempted: true, at: new Date().toISOString(), kind: 'trial-local', target: name, volume, agentId: env.AGENT_ID, phase: 'before-volume-create', prompt: 'original' };
  211. save(); note(`准备按原提示词的 .env + Docker 环境变量方式启动 ${name},新数据卷 ${volume};仅使用本轮试用身份,可能产生网关上线事件。`);
  212. const envText = Object.entries(env).map(([key, value]) => {
  213. assert.match(key, /^[A-Z][A-Z0-9_]*$/); assert.ok(!/[\r\n]/.test(value)); return `${key}=${value}`;
  214. }).join('\n') + '\n';
  215. const envFile = path.join(privateDir, 'trial-original.env');
  216. fs.writeFileSync(envFile, envText);
  217. docker(['volume', 'create', volume]);
  218. state.actions.localRaw.phase = 'volume-created'; save();
  219. docker(['run', '--rm', '-i', '--name', name + '-write-env', '--network', 'none', '--mount', `type=volume,source=${volume},target=/opt/data`, '--entrypoint', '/bin/sh', 'fmode/agent-node:0.21.3', '-c', 'umask 077; cat > /opt/data/.env; chown 10000:10000 /opt/data/.env'], envText);
  220. state.actions.localRaw.phase = 'env-written-before-start'; save();
  221. const run = docker(['run', '-d', '--name', name, '--hostname', env.AGENT_ID,
  222. '--env-file', envFile, '--mount', `type=volume,source=${volume},target=/opt/data`,
  223. '--memory', '1536m', '--cpus', '1.5', '--pids-limit', '512', '--restart', 'no',
  224. 'fmode/agent-node:0.21.3', 'gateway', 'run']);
  225. state.actions.localRaw.containerId = run.stdout.trim(); state.actions.localRaw.phase = 'started-awaiting-inspection'; save();
  226. await new Promise(resolve => setTimeout(resolve, 7000));
  227. const result = snapshot(name);
  228. state.actions.localRaw.confirmedAt = new Date().toISOString(); state.actions.localRaw.receipt = result; save();
  229. state.assets.push({ kind: 'local-docker-container', name, volume, agentId: env.AGENT_ID, owner: state.userId }); save();
  230. note(`原提示词实测容器已创建并回读:${result.state.Status},退出码 ${result.state.ExitCode};日志 ${path.relative(process.cwd(), out)}/${name}.log;此记录仅确认实际动作,不表示接入通过。`);
  231. console.log(JSON.stringify({ name, state: result.state, log: `${name}.log` }, null, 2));
  232. } else throw Error('未知本地试用阶段:' + stage);
  233. } catch (error) {
  234. if (state) { state.lastFailure = { stage: 'docker-' + stage, message: redact(error.message), at: new Date().toISOString() }; save(); }
  235. note(`未完成:${redact(error.message)};先只读检查,不重复创建。`);
  236. throw error;
  237. } finally { fs.closeSync(lock); fs.unlinkSync(lockFile); }