跳到主要内容

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

浏览文件

offline-quit-smoke.mjs

51 行 · 2.0 KB历史下载
1import assert from "node:assert/strict";
2import { createWorkbench } from "./workbench-fixture.mjs";
3
4const calls = [];
5const view = {
6 mode: "local", desktop_gateway: true, connection_id: "test-local-view",
7 connection: { state: "connected" },
8};
9const { page, browser, errors } = await createWorkbench({
10 clientContext: view,
11 nativeRequest: async (request) => { calls.push(request); return null; },
12});
13const quit = () => page.evaluate(() => window.cageNativeAction("quit"));
14const exits = () => calls.filter(({ action }) => action === "quitNow").length;
15const refused = (route) => route.abort("connectionrefused");
16const stops = [];
17page.on("request", (request) => {
18 if (new URL(request.url()).pathname === "/api/stop") stops.push(request);
19});
20try {
21 await page.exposeFunction("testDesktopExits", exits);
22 // Lose the gateway while the workbench still shows the previous environment.
23 await page.route("**/api/**", refused);
24 await page.locator(".connection-banner").waitFor();
25 await quit();
26 const dialog = page.getByRole("dialog", { name: "退出 Cage" });
27 await dialog.getByRole("button", { name: "取消" }).click();
28 assert.equal(exits(), 0);
29 await quit();
30 await dialog.getByRole("button", { name: "仅退出桌面应用" }).click();
31 await page.waitForFunction(async () => (await window.testDesktopExits()) === 1, null, { timeout: 5000 });
32 assert.equal(exits(), 1);
33
34 // Initial context cannot be loaded on reopening the page.
35 await page.reload();
36 await page.getByRole("alert").getByRole("button", { name: "重新连接" }).waitFor();
37 await quit();
38 assert.equal(exits(), 2);
39
40 // Gateway is alive, but its selected CLI controller has exited.
41 view.connection = { state: "failed", error_code: "connection_lost" };
42 await page.unroute("**/api/**", refused);
43 await page.reload();
44 await page.getByRole("heading", { name: "重新连接本机工作台" }).waitFor();
45 await quit();
46 assert.equal(exits(), 3);
47 assert.equal(stops.length, 0);
48 assert.deepEqual(errors, []);
49} finally {
50 await browser.close();
51}