跳到主要内容

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

浏览文件

input-paste-order-smoke.mjs

64 行 · 3.1 KB历史下载
1import assert from "node:assert/strict";
2import { createWorkbench } from "./workbench-fixture.mjs";
3import { startDisplay } from "./rfb-wire-fixture.mjs";
4
5const display = await startDisplay(process.env.CAGE_UI_URL || "http://127.0.0.1:5198", { sharedClipboard: true });
6let context = "a".repeat(32);
7const { browser, page, errors } = await createWorkbench({
8 mockWebSockets: false, url: display.url,
9 nativeRequest: request => {
10 if (request.action === "clipboardRevision") return 1;
11 if (request.action === "clipboardSyncRead") return { text: "synthetic shared clipboard", revision: 1 };
12 return true;
13 },
14 async beforeNavigate(page, state) {
15 state.status.ready = state.status.vm_running = true;
16 await page.route("**/api/claude-desktop", route => route.fulfill({ json: { installed: true, running: true, managed: true } }));
17 await page.route("**/api/input", route => route.fulfill({ json: { available: true, context, rect: [20, 20, 1, 24] } }));
18 },
19});
20page.setDefaultTimeout(10000);
21async function until(predicate) {
22 for (let attempt = 0; attempt < 200; attempt++) {
23 if (predicate()) return;
24 await page.waitForTimeout(20);
25 }
26 assert(predicate(), "expected RFB input did not arrive");
27}
28async function delaySync() {
29 await page.evaluate(() => {
30 window.pendingSync = false;
31 window.cageSyncClipboard = () => new Promise(resolve => {
32 window.pendingSync = true;
33 window.releaseSync = resolve;
34 });
35 });
36}
37try {
38 await page.getByRole("button", { name: "Claude Desktop", exact: true }).click();
39 await page.getByText("正在连接画面", { exact: true }).waitFor({ state: "hidden" });
40 await page.waitForFunction(() => window.cageSharedClipboardActive === true);
41 await page.locator(".remote-canvas canvas").click({ position: { x: 40, y: 40 } });
42 display.stats.keys.length = 0;
43 await delaySync();
44 await page.keyboard.press("Meta+v");
45 await page.waitForFunction(() => window.pendingSync);
46 await page.keyboard.press("Enter");
47 assert(!display.stats.keys.some(key => key.symbol === 118 || key.symbol === 0xff0d));
48 await page.evaluate(() => window.releaseSync());
49 await until(() => display.stats.keys.some(key => key.symbol === 0xff0d && !key.down));
50 const ordered = display.stats.keys.map(key => [key.symbol, key.down]);
51 assert(ordered.findIndex(([symbol, down]) => symbol === 118 && down) < ordered.findIndex(([symbol, down]) => symbol === 0xff0d && down));
52
53 display.stats.keys.length = 0;
54 await delaySync();
55 await page.keyboard.press("Meta+v");
56 await page.waitForFunction(() => window.pendingSync);
57 context = "b".repeat(32);
58 await page.keyboard.press("Enter");
59 await page.evaluate(() => window.releaseSync());
60 await page.getByText("粘贴位置已切换,请回到原输入位置重试", { exact: true }).waitFor();
61 assert(!display.stats.keys.some(key => key.symbol === 118 || key.symbol === 0xff0d));
62 assert.deepEqual(errors, []);
63 console.log(JSON.stringify({ result: "PASS", checks: ["shared clipboard gate reserves the real RFB queue", "paste precedes Enter", "focus change cancels paste and queued Enter"], wire: ordered }));
64} finally { await browser.close(); await display.close(); }