跳到主要内容

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

浏览文件

packaged-startup-smoke.mjs

66 行 · 4.4 KB历史下载
1import assert from "node:assert/strict";
2import { randomBytes } from "node:crypto";
3import fs from "node:fs/promises";
4import os from "node:os";
5import path from "node:path";
6import { execFile } from "node:child_process";
7import { promisify } from "node:util";
8import { createRequire } from "node:module";
9
10const run = promisify(execFile);
11const target = process.argv[2];
12assert.ok(path.isAbsolute(target || ""), "supply an absolute Cage.app or full Cage helper path");
13const packaged = target.endsWith(".app");
14const cage = packaged ? path.join(target, "Contents/Resources/cage") : target;
15const evidence = process.env.CAGE_REMOTE_QA_DIR;
16if (evidence) await fs.mkdir(evidence, { recursive: true });
17const profile = await fs.mkdtemp(path.join(os.tmpdir(), "cage-packaged-"));
18const env = { ...process.env, CLAUDE_CAGE_CONFIG: path.join(profile, "config.json") };
19const require = createRequire(import.meta.url);
20const { chromium } = require(process.env.CAGE_PLAYWRIGHT_MODULE || "playwright");
21let browser;
22try {
23 const { stdout } = await run(cage, ["desktop", "--json"], { env });
24 const entry = JSON.parse(stdout);
25 assert.equal(entry.status, "ready");
26 assert.equal(entry.controller.version, (await fs.readFile(new URL("../../VERSION", import.meta.url), "utf8")).trim());
27 browser = await chromium.launch({ headless: true, executablePath: process.env.CAGE_TEST_BROWSER_PATH });
28 const page = await browser.newPage();
29 const errors = [];
30 page.on("pageerror", (error) => errors.push(error.message));
31 await page.goto(entry.url);
32 await page.getByRole("heading", { name: "注册 Cage 账户", exact: true }).waitFor();
33 await page.getByLabel("用户名",{exact:true}).waitFor();
34 const initial = await page.evaluate(async () => (await fetch("/api/client/local-status")).json());
35 assert.ok(initial.known && initial.service_running && !initial.running, "opening the local home must not boot the VM");
36 assert.equal(await page.getByRole("heading",{name:"选择工作环境"}).count(),0);
37 if (evidence) await page.screenshot({ path:path.join(evidence,"desktop-first-open.png") });
38 const password = randomBytes(24).toString("base64url");
39 await page.getByLabel("用户名",{exact:true}).fill("packaged_smoke");
40 await page.getByLabel("设置密码",{exact:true}).fill(password);
41 await page.getByLabel("确认密码",{exact:true}).fill(password);
42 const statusResponse = page.waitForResponse((response) => response.url().endsWith("/api/status") && response.ok());
43 await page.getByRole("button",{name:"创建本地账户",exact:true}).click();
44 const status = await (await statusResponse).json();
45 assert.equal(status.vm_running, false);
46 await page.getByRole("heading", { name: "为 Cage 准备独立环境", exact: true }).waitFor();
47 const nav = page.getByRole("navigation", {name:"主导航"});
48 assert.equal(await nav.count(), 0, "fresh profile must not mount workbench navigation");
49 await page.getByRole("button",{name:"只连接 SSH 主机",exact:true}).click();
50 await page.getByRole("complementary",{name:"SSH 主机"}).waitFor();
51 if (evidence) await page.screenshot({ path:path.join(evidence,"local-ssh-sidebar.png") });
52 await page.getByRole("button",{name:"返回工作台侧栏"}).click();
53 assert.equal(new URL(page.url()).hash, "", "launch ticket was not removed");
54 await page.getByRole("button", { name: "下一步:配置代理", exact: true }).click();
55 await page.getByRole("heading",{name:"连接你的网络代理",exact:true}).waitFor();
56 assert.ok(await page.getByRole("button",{name:"开始安装",exact:true}).isDisabled(), "proxy must be applied before installation");
57 await page.getByText("添加来源", { exact: true }).first().waitFor();
58 if(evidence) await page.screenshot({ path:path.join(evidence,"initialization-proxy.png") });
59 assert.deepEqual(errors, []);
60 console.log(JSON.stringify({ checks: ["standalone initialization after account setup", "VM stopped throughout", "no workbench navigation before initialization", "SSH-only alternative", "proxy required before installation", packaged ? "packaged helper bootstrap" : "development helper bootstrap", "real session and APIs", "embedded production UI loaded", "private profile onboarding", "launch ticket removed"], version: entry.controller.version }));
61} finally {
62 await browser?.close();
63 await run(cage, ["prepare-update", "--json"], { env });
64 await fs.rm(profile, { recursive: true, force: true });
65 await fs.rm(profile + "-workspace", { recursive: true, force: true });
66}