跳到主要内容

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

浏览文件

split-tabs-smoke.mjs

99 行 · 5.8 KB历史下载
1// Exercise the actual pointer paths in an isolated workbench.
2import assert from "node:assert/strict";
3import { createWorkbench } from "./workbench-fixture.mjs";
4
5const { page, state, browser, errors } = await createWorkbench();
6try {
7 await page.getByRole("button", { name: "启动 Cage 环境", exact: true }).click();
8 await page.getByRole("heading", { name: "Cage 环境已就绪" }).waitFor();
9 await page.getByRole("button", { name: "打开浏览器", exact: true }).click();
10 await page.getByRole("tablist", { name: "浏览器标签页" }).waitFor();
11 await page.getByRole("button", { name: "新建网页", exact: true }).click();
12 const workspace = page.locator("main.workspace");
13 const tabs = page.locator(".browser-tabs [role=tab]");
14 const first = state.tabs[0].id;
15 const second = state.tabs[1].id;
16 async function drag(tab, fraction, cancel = false) {
17 await tab.click({ trial: true });
18 const from = await tab.boundingBox();
19 const to = await workspace.boundingBox();
20 await page.mouse.move(from.x + from.width / 2, from.y + from.height / 2);
21 await page.mouse.down();
22 await page.mouse.move(to.x + fraction * to.width, to.y + to.height / 2, { steps: 6 });
23 await workspace.locator(fraction < 0.5 ? ".split-drop.split-left" : ".split-drop.split-right").waitFor();
24 if (cancel) await page.keyboard.press("Escape");
25 await page.mouse.up();
26 await workspace.locator(".split-drop").waitFor({ state: "hidden" });
27 }
28
29 // Reordering inside the strip must still work independently of pane drops.
30 await page.waitForFunction(() => {
31 const list = [...document.querySelectorAll(".browser-tab")];
32 return list.length === 2 && list.every(tab => tab.getBoundingClientRect().width >= 100);
33 });
34 const start = await tabs.first().boundingBox();
35 const end = await tabs.last().boundingBox();
36 await page.mouse.move(start.x + start.width / 2, start.y + start.height / 2);
37 await page.mouse.down();
38 await page.mouse.move(end.x + end.width - 3, end.y + end.height / 2, { steps: 10 });
39 await page.mouse.up();
40 await page.waitForFunction(id => document.querySelector(".browser-tab").dataset.tabId === id, second);
41 const firstTab = page.locator(`.browser-tab[data-tab-id="${first}"] [role=tab]`);
42 await drag(firstTab, 0.25, true);
43 assert.equal(await workspace.locator(".browser-header-cell").count(), 1);
44 await drag(firstTab, 0.75);
45 const cells = workspace.locator(".browser-header-cell");
46 const left = cells.first(), right = cells.last();
47 await right.locator(`[data-browser-tab="${first}"]`).waitFor();
48 await left.locator(`[data-browser-tab="${second}"]`).waitFor();
49 await workspace.locator(".remote-view:not(.concealed)").waitFor();
50 const surface = await workspace.locator(".remote-view:not(.concealed)").boundingBox();
51 const box = await workspace.boundingBox();
52 assert.equal(Math.round(surface.width), Math.round(box.width));
53 assert.ok(state.split.left === second && state.split.right === first);
54 const leftAddress = left.getByRole("textbox", { name: "网页地址或搜索" });
55 await leftAddress.fill("https://example.com/left");
56 await leftAddress.press("Enter");
57 assert.equal(state.requests.filter(r => r.path === "/browser/navigate").at(-1).body.id, second);
58 assert.equal(await right.getByRole("textbox", { name: "网页地址或搜索" }).inputValue(), state.tabs.find(t => t.id === first).url);
59 await left.getByRole("button", { name: "退出分屏" }).click();
60 assert.equal(await tabs.count(), 2);
61 await page.waitForFunction(() => document.querySelectorAll(".browser-header-cell").length === 1);
62
63 await drag(firstTab, 0.25);
64 await left.locator(`[data-browser-tab="${first}"]`).waitFor();
65 await page.locator(`.browser-tab[data-tab-id="${first}"] .tab-close`).click();
66 await page.waitForFunction(() => !document.querySelector(".workspace-split"));
67 await page.setViewportSize({ width: 820, height: 558 });
68 const term = { id: "split-term", title: "分屏终端", workspace: state.settings.workspace };
69 state.terminals.push(term);
70 const terminal = page.getByRole("tab", { name: term.title, exact: true });
71 await terminal.waitFor();
72 const connections = state.terminalConnections;
73 await drag(terminal, 0.75);
74 const terminalRight = workspace.locator(".terminal-lane.split-right:visible");
75 await terminalRight.getByText(term.title, { exact: true }).waitFor();
76 const browserBox = await workspace.locator(".browser-lane .browser-chrome").boundingBox();
77 const terminalBox = await terminalRight.locator("header").boundingBox();
78 assert.ok(browserBox.x + browserBox.width <= terminalBox.x + 1);
79 assert.ok((await terminalRight.locator(".terminal-view").boundingBox()).y <
80 (await workspace.locator(".browser-lane .remote-view").boundingBox()).y);
81 await workspace.locator(".browser-chrome .address-bar input").click();
82 await terminalRight.locator("textarea.xterm-helper-textarea").click({ force: true });
83 assert.equal(await workspace.locator(".browser-chrome").count(), 1);
84 assert.equal(state.terminalConnections, connections);
85 const secondTerm = { ...term, id: "split-term-2", title: "第二个终端" };
86 state.terminals.push(secondTerm);
87 const secondTerminal = page.getByRole("tab", { name: secondTerm.title, exact: true });
88 await secondTerminal.waitFor();
89 await drag(secondTerminal, 0.25);
90 await workspace.locator(".terminal-lane.split-left:visible").getByText(secondTerm.title, { exact: true }).waitFor();
91 await terminalRight.getByText(term.title, { exact: true }).waitFor();
92 assert.equal(await workspace.getByRole("tablist").count(), 0);
93 assert.equal(await workspace.locator(".terminal-chrome:visible").count(), 2);
94 assert.equal(await workspace.locator(".terminal-view:not(.concealed)").count(), 2);
95 assert.deepEqual(errors, []);
96 console.log("Passed: cancel, left/right drops, pane focus, native split, independent headers and navigation, exit, close and terminal continuity");
97} finally {
98 await browser.close();
99}