跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

control-upgrade-smoke.mjs

53 行 · 3.2 KB历史下载
1// Run only with disposable builds. Every service uses a newly created profile.
2// Usage: node scripts/control-upgrade-smoke.mjs <legacy-cage> <current-cage> <different-build-cage>
3import assert from "node:assert/strict";
4import { spawn, execFile } from "node:child_process";
5import { promisify } from "node:util";
6import { mkdtemp, readFile, rm } from "node:fs/promises";
7import { tmpdir } from "node:os";
8import path from "node:path";
9
10const runFile = promisify(execFile);
11const [legacy, current, next] = process.argv.slice(2).map((file) => path.resolve(file));
12assert(legacy && current && next, "Pass three cage executables");
13const profile = await mkdtemp(path.join(tmpdir(), "cage-control-upgrade-"));
14const env = { ...process.env, CLAUDE_CAGE_CONFIG: path.join(profile, "config.json") };
15const call = async (binary, ...args) => {
16 const { stdout } = await runFile(binary, [...args, "--json"], { env, timeout: 150_000, maxBuffer: 512 * 1024 });
17 return JSON.parse(stdout);
18};
19const record = async (entry = false) => JSON.parse(await readFile(path.join(profile, entry ? "desktop-entry" : ".", "control.json"), "utf8"));
20const wait = async (test) => {
21 for (let i = 0; i < 100; i++) {
22 try { if (await test()) return; } catch {}
23 await new Promise((resolve) => setTimeout(resolve, 100));
24 }
25 throw new Error("Timed out waiting for the disposable controller");
26};
27const old = spawn(legacy, ["serve"], { cwd: profile, env, stdio: "ignore" });
28try {
29 await wait(async () => (await record()).pid === old.pid);
30 assert.equal((await call(current, "desktop")).status, "ready", "Chooser can open without taking over the older workload");
31 assert.equal((await record()).pid, old.pid);
32 assert.equal((await call(current, "desktop", "--existing")).status, "existing");
33 assert.equal((await call(current, "prepare-update")).status, "stop_required");
34 assert.equal((await call(current, "prepare-update", "--stop")).status, "prepared");
35 await wait(() => old.exitCode !== null || old.signalCode !== null);
36 assert.equal((await call(current, "desktop")).status, "ready");
37 const first = await record(true);
38 assert.equal((await call(current, "desktop")).status, "ready");
39 assert.equal((await record(true)).pid, first.pid, "Same build must reuse its controller");
40 assert.equal((await call(next, "desktop")).status, "ready");
41 const replacement = await record(true);
42 assert.notEqual(replacement.pid, first.pid, "Different build must replace an idle controller");
43 assert.notEqual(replacement.controller.build, first.controller.build);
44 assert.equal(replacement.controller.version, first.controller.version, "Exercise same-version distinct builds");
45 assert.equal((await call(next, "prepare-update")).status, "prepared");
46 console.log("PASS: legacy requires explicit stop, verified legacy migration, same-build reuse, same-version build replacement, and graceful shutdown");
47} finally {
48 // Only this fresh profile is addressed. Never target the user's normal profile.
49 await call(current, "prepare-update", "--stop").catch(() => {});
50 if (old.exitCode === null && old.signalCode === null) old.kill("SIGTERM");
51 await rm(profile, { recursive: true, force: true });
52 await rm(profile + "-workspace", { recursive: true, force: true });
53}