跳到主要内容

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

浏览文件

macos-first-setup-smoke.mjs

90 行 · 5.1 KB历史下载
1import assert from "node:assert/strict";
2import { createWorkbench } from "./workbench-fixture.mjs";
3for (const failure of ["http", "native"]) {
4 const user = "cage";
5 const permissions = { screen:false, input:false, projects:false, managed_credential:true };
6 const calls = []; let finishFailed = false;
7 const {page, browser, errors} = await createWorkbench({
8 async beforeNavigate(page, state) {
9 Object.assign(state.account, {initial_mac_setup:true, guest_system:"macos", macos_guest_user:user});
10 Object.assign(state.status, {ready:true, vm_running:true});
11 const frame = await page.evaluate(() => {
12 const canvas = document.createElement("canvas");
13 canvas.width = 160; canvas.height = 100;
14 return canvas.toDataURL("image/png").split(",")[1];
15 });
16 await page.route("**/api/macos/first-setup", async r => {
17 const q = r.request().postDataJSON(); calls.push(q.action);
18 if (q.action === "permissions") return r.fulfill({json:permissions});
19 if (q.action === "open") return r.fulfill({json:{session:"setup-fixture"}});
20 if (q.action === "frame") return r.fulfill({json:{image:frame}});
21 if (q.action === "scroll") {
22 assert.equal(q.session,"setup-fixture");
23 assert.ok(Number.isInteger(q.x) && q.x >= 0 && q.x < 1024);
24 assert.ok(Number.isInteger(q.y) && q.y >= 0 && q.y < 640);
25 assert.ok(q.delta_y > 0 && q.delta_y <= 512);
26 }
27 if (q.action === "fill-password") {
28 assert.equal(q.password,undefined,"browser sent a credential");
29 assert.equal(q.session,"setup-fixture");
30 }
31 if (q.action === "finish") {
32 assert.ok(permissions.screen && permissions.input && permissions.projects);
33 if (!finishFailed) {
34 finishFailed=true;
35 return failure === "http"
36 ? r.fulfill({status:409,body:"临时设置账户未关闭,请重试完成设置"})
37 : r.fulfill({json:{error:"未能保存首次设置,请重试"}});
38 }
39 state.account.initial_mac_setup = false; return r.fulfill({json:{closed:true}});
40 }
41 return r.fulfill({json:{}});
42 });
43 },
44 });
45 async function waitCall(action) {
46 for(let i=0; !calls.includes(action) && i<200; i++) await new Promise(resolve=>setTimeout(resolve,20));
47 assert.ok(calls.includes(action),`missing ${action}`);
48 }
49 try {
50 await page.getByRole("dialog",{name:"首次设置虚拟 Mac"}).waitFor();
51 await waitCall("screen");
52 await page.getByRole("dialog",{name:"首次设置虚拟 Mac"}).getByText(/打开 Cage Guest Window 的窗口录制开关/).waitFor();
53 const image = page.getByRole("dialog",{name:"首次设置虚拟 Mac"}).getByRole("img");
54 await image.waitFor();
55 if (process.env.CAGE_INITIALIZATION_EVIDENCE) await page.screenshot({ path: `${process.env.CAGE_INITIALIZATION_EVIDENCE}/setup-window-${failure}.png`, fullPage: true });
56 const box = await image.boundingBox();
57 await page.mouse.move(box.x+box.width/2,box.y+box.height/2);
58 await page.mouse.wheel(0,400);
59 await waitCall("scroll");
60 const tools=page.getByRole("toolbar",{name:"画面工具"});
61 await tools.getByRole("button",{name:"填写授权密码"}).click();
62 await waitCall("fill-password");
63 permissions.screen=true;
64 await waitCall("input");
65 await page.getByRole("dialog",{name:"首次设置虚拟 Mac"}).getByText(/打开 Cage Guest Window 的辅助功能开关/).waitFor();
66 permissions.input=true;
67 await waitCall("projects");
68 await page.getByRole("dialog",{name:"首次设置虚拟 Mac"}).getByText(/打开 macFUSE 和 macFUSE \(local\) 两个开关,用于/).waitFor();
69 assert.ok(!calls.includes("finish"),"finished before filesystem permission");
70 permissions.projects=true;
71 await page.getByRole("button",{name:"返回设置指引"}).click();
72 const retry=page.getByRole("button",{name:"重试完成设置"});
73 await retry.waitFor();
74 await page.getByText("管理员密码与找不到设置页时的帮助",{exact:true}).click();
75 await page.getByRole("button",{name:"重新打开文件系统扩展",exact:true}).click();
76 await page.getByRole("alert").waitFor({state:"hidden"});
77 assert.ok(await retry.isVisible(), "checking permissions hid the completion retry");
78 await retry.click();
79 await page.getByRole("heading",{name:"完成虚拟 Mac 的系统授权"}).waitFor({state:"hidden"});
80 await page.getByRole("complementary", { name: "项目与终端" }).waitFor();
81 await page.evaluate(() => window.cageNativeAction("settings"));
82 await page.getByRole("region", { name: "设置", exact: true }).waitFor();
83 await page.evaluate(() => window.cageNativeAction("quit"));
84 await page.getByRole("dialog", { name: "退出 Cage", exact: true }).getByRole("button", { name: "取消", exact: true }).click();
85 assert.equal(calls.filter(c=>c==="finish").length,2);
86 assert.equal(calls.filter(c=>c==="verify-projects").length,0);
87 assert.deepEqual(errors, []);
88 console.log(user,failure,"automatic setup view, permission progression, credential fill, completion and failure recovery passed");
89 } finally { await browser.close(); }
90}