跳到主要内容

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

浏览文件

terminal-startup-smoke.mjs

74 行 · 4.6 KB历史下载
1import assert from "node:assert/strict";
2import { createWorkbench } from "./workbench-fixture.mjs";
3
4const warning = "WARNING: Loading development channels\r\nChannels: server:cage\r\n1. I am using this for local development\r\nEnter to confirm";
5for (const platform of ["darwin", "windows", "linux"]) {
6 const fixture = await createWorkbench({
7 mockWebSockets: false,
8 clientContext: { mode: "local", connection_id: "local", client_platform: platform, server_platform: platform, connection: { state: "disconnected" } },
9 beforeNavigate: page => page.clock.install(),
10 });
11 const { page, state } = fixture;
12 let terminalSocket;
13 const inputs = [];
14 try {
15 await page.route("**/api/terminals", route => {
16 if (route.request().method() !== "POST") return route.fallback();
17 const tab = { id: "startup-test", title: "Claude 1", kind: "claude", workspace: state.settings.workspace, cli_session_id: "fixture-cli", cli_starting: true };
18 state.terminals = [tab];
19 return route.fulfill({ json: tab });
20 });
21 await page.routeWebSocket("**/api/**", socket => {
22 if (!socket.url().includes("/terminals/")) return socket.close();
23 terminalSocket = socket;
24 socket.onMessage(message => { const value = JSON.parse(message); if (value.type === "input") inputs.push(value.data); });
25 socket.send(JSON.stringify({ type: "cli-startup", pending: true }));
26 socket.send(Buffer.from(warning.slice(0, 22)));
27 socket.send(Buffer.from(warning.slice(22)));
28 });
29 await page.reload();
30 await page.getByRole("button", { name: "启动 Cage 环境", exact: true }).click();
31 await page.getByRole("button", { name: "新建终端", exact: true }).first().click();
32 await page.getByRole("menuitem", { name: /Claude/ }).first().click();
33 await page.getByText("正在准备 Claude 会话…", { exact: true }).waitFor();
34 await page.waitForFunction(() => document.querySelector(".xterm-rows")?.textContent.includes("Loading development channels"));
35 assert.equal(await page.locator(".terminal-host").isVisible(), false);
36 await page.evaluate(() => {
37 window.startupFlashes = [];
38 const observer = new MutationObserver(() => {
39 const host = document.querySelector(".terminal-host");
40 const text = host?.querySelector(".xterm-rows")?.textContent || "";
41 if (host && getComputedStyle(host).visibility === "visible" && text.includes("Loading development channels")) window.startupFlashes.push(text.slice(0, 250));
42 });
43 observer.observe(document.querySelector(".terminal-view"), { childList: true, subtree: true, attributes: true });
44 });
45 terminalSocket.send(JSON.stringify({ type: "cli-startup", pending: false }));
46 await page.clock.runFor(120);
47 assert.equal(await page.locator(".terminal-host").isVisible(), false, "channel registration must not expose the previous warning screen");
48 await page.clock.resume();
49 terminalSocket.send(Buffer.from("\x1b[2J\x1b[HWelcome to Claude\r\n> "));
50 await page.locator(".terminal-host").waitFor({ state: "visible" });
51 assert.deepEqual(await page.evaluate(() => window.startupFlashes), []);
52 assert.deepEqual(inputs, [], "presentation never confirms tools or other prompts");
53 await page.keyboard.type("hello");
54 await page.waitForFunction(() => document.querySelector(".xterm-helper-textarea") === document.activeElement);
55
56 // A new attachment can be waiting for login. It must become interactive
57 // without channel readiness, and the user can reveal it immediately.
58 terminalSocket.close();
59 await page.getByRole("button", { name: "重新连接", exact: true }).click();
60 await page.getByText("正在准备 Claude 会话…", { exact: true }).waitFor();
61 terminalSocket.send(Buffer.from("\x1b[2J\x1b[HSelect login method\r\n1. Claude account"));
62 await page.clock.fastForward(8100);
63 await page.clock.resume();
64 await page.locator(".terminal-host").waitFor({ state: "visible" });
65 assert.ok((await page.locator(".xterm-rows").textContent()).includes("Select login method"));
66 terminalSocket.close();
67 await page.getByRole("button", { name: "重新连接", exact: true }).click();
68 await page.getByText("正在准备 Claude 会话…", { exact: true }).waitFor();
69 await page.getByRole("button", { name: "显示启动过程", exact: true }).click();
70 await page.locator(".terminal-host").waitFor({ state: "visible" });
71 assert.deepEqual(fixture.errors, []);
72 console.log(`PASS: ${platform} hides split confirmation output, waits for repaint, restores focus, and exposes stalled/login output`);
73 } finally { await fixture.browser.close(); }
74}