跳到主要内容

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

浏览文件

guest-install-smoke.mjs

73 行 · 3.7 KB历史下载
1import assert from "node:assert/strict";
2import { createWorkbench } from "./workbench-fixture.mjs";
3
4for (const [id, name, platform] of [["macos", "macOS", "darwin"], ["windows-11", "Windows 11", "windows"]]) {
5 let submitted;
6 const { page, browser } = await createWorkbench({
7 clientContext: { mode: "local", connection_id: "local", client_platform: platform, server_platform: platform },
8 nativeRequest: ({ action }) => action === "chooseGuestMedia" ? "C:\\media\\Windows11.iso" : null,
9 async beforeNavigate(page, state) {
10 state.status.local_vm_storage = true;
11 await page.route("**/api/environment/guest-systems", r => r.fulfill({ json: { fresh: true, available: true, system: id } }));
12 await page.route("**/api/start", r => {
13 submitted = r.request().postDataJSON();
14 return r.fulfill({ json: { id: "native", running: true, kind: "guest-install" } });
15 });
16 },
17 });
18 try {
19 const picker = page.getByRole("combobox", { name: "客户机系统" });
20 const storage = page.getByRole("button", { name: "选择环境存储位置" });
21 const storageBefore = await storage.boundingBox();
22 await picker.click();
23 const option = page.getByRole("option", { name, exact: true });
24 await option.waitFor();
25 const row = await option.boundingBox(), below = await storage.boundingBox();
26 assert.ok(Math.abs(below.y - storageBefore.y) < 1 && row.height > 0);
27 await picker.press("Escape");
28 assert.equal((await storage.boundingBox()).y, storageBefore.y);
29 await picker.press("Enter"); await picker.press("End"); await picker.press("Enter");
30 const button = page.getByRole("button", { name: "安装客户机" });
31 if (platform === "darwin") {
32 assert.ok(await button.isEnabled());
33 assert.equal(await page.getByLabel("客机账户密码",{exact:true}).count(),0);
34 } else {
35 assert.ok(await button.isDisabled());
36 await page.getByRole("button", { name: "选择本机 ISO" }).click();
37 await page.getByText("C:\\media\\Windows11.iso", { exact: true }).waitFor();
38 await page.getByLabel("ISO 的 SHA-256").fill("a".repeat(64));
39 assert.ok(await button.isDisabled());
40 await page.getByRole("checkbox").check();
41 }
42 await Promise.all([
43 page.waitForResponse(response => response.url().endsWith("/api/start")),
44 button.click(),
45 ]);
46 assert.equal(submitted.guest_system, id);
47 if (platform === "windows") assert.ok(submitted.editor_terms && submitted.sha256.length === 64 && submitted.media.endsWith(".iso"));
48 else assert.equal(submitted.password, undefined);
49 console.log(platform, "inline picker, keyboard, validation and start request passed");
50 } catch (error) {
51 console.error((await page.locator("body").innerText()).slice(-2300));
52 throw error;
53 } finally { await browser.close(); }
54}
55
56{
57 const calls=[];
58 const {page,browser,errors}=await createWorkbench({
59 nativeRequest: message=>{ calls.push(message.action); return null; },
60 async beforeNavigate(page,state) {
61 state.status.local_vm_storage=true;
62 await page.route("**/api/environment/guest-systems",r=>r.fulfill({json:{fresh:false,available:true,system:"macos",pending:{system:"macos",id:"activation-fixture"},activate:true}}));
63 await page.route("**/api/environment/guest-systems/activate",r=>{ calls.push("activate"); return r.fulfill({json:{stopping:true}}); });
64 }
65 });
66 try {
67 for(let i=0; !calls.includes("reconnect") && i<150;i++) await new Promise(resolve=>setTimeout(resolve,20));
68 assert.equal(calls.filter(action=>action==="activate").length,1);
69 assert.equal(calls.filter(action=>action==="reconnect").length,1);
70 assert.deepEqual(errors,[]);
71 console.log("installed guest automatically activated and reconnected");
72 } finally { await browser.close(); }
73}