跳到主要内容

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

浏览文件

terminal-startup-live-smoke.mjs

45 行 · 2.5 KB历史下载
1import assert from "node:assert/strict";
2import { createWorkbench } from "./workbench-fixture.mjs";
3
4const parts = [];
5for await (const chunk of process.stdin) parts.push(chunk);
6const input = JSON.parse(Buffer.concat(parts).toString());
7const fixture = await createWorkbench({
8 url: input.origin,
9 mockWebSockets: false,
10 cliRequest: route => route.continue(),
11 beforeNavigate: page => page.context().addCookies([{ name: input.cookie, value: input.session, url: input.origin }]),
12});
13try {
14 const { page, state } = fixture;
15 await page.route("**/api/terminals**", route => route.continue());
16 state.status.ready = state.status.vm_running = true;
17 state.status.projects = [input.project];
18 state.status.environment_directory = state.settings.workspace = input.project;
19 let output = "";
20 page.on("websocket", socket => {
21 if (!socket.url().includes("/terminals/")) return;
22 socket.on("framereceived", ({ payload }) => { output = (output + payload.toString()).slice(-65536); });
23 });
24 await page.reload();
25 await page.evaluate(() => {
26 window.visibleStartupWarnings = 0;
27 const check = () => {
28 for (const host of document.querySelectorAll(".terminal-host")) {
29 const text = host.querySelector(".xterm-rows")?.textContent.replace(/\s/g, "") || "";
30 if (getComputedStyle(host).visibility === "visible" && text.includes("Loadingdevelopmentchannels")) window.visibleStartupWarnings++;
31 }
32 };
33 new MutationObserver(check).observe(document.body, { attributes: true, childList: true, subtree: true });
34 });
35 await page.getByRole("button", { name: "新建终端", exact: true }).first().click();
36 await page.getByRole("menuitem", { name: "Claude 终端", exact: true }).click();
37 await page.getByText("正在准备 Claude 会话…", { exact: true }).waitFor();
38 await page.locator(".terminal-host").waitFor({ state: "visible" });
39 await page.waitForFunction(() => document.querySelector(".xterm-rows")?.textContent.includes("Claude Code"));
40 const text = output.replace(/\x1b\[[0-?]*[ -/]*[@-~]|\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/g, "").replace(/\s/g, "");
41 assert.ok(text.includes("Loadingdevelopmentchannels"), "the genuine CLI confirmation must still exist in the raw output");
42 assert.equal(await page.evaluate(() => window.visibleStartupWarnings), 0, "the genuine startup confirmation flashed on screen");
43 assert.deepEqual(fixture.errors, []);
44 console.log("PASS: genuine Claude Code, isolated SSH/PTY and product WebSocket reach the desktop session without displaying the channel confirmation");
45} finally { await fixture.browser.close(); }