跳到主要内容

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

浏览文件

desktop-focus-smoke.mjs

44 行 · 2.1 KB历史下载
1// Isolated UI test: notifications use the production SSE consumer, without
2// accessing the user's browser, login URL, or running desktop application.
3import assert from "node:assert/strict";
4import { createWorkbench } from "./workbench-fixture.mjs";
5
6const { browser, page, state, errors } = await createWorkbench();
7try {
8 await page.addInitScript(() => {
9 window.EventSource = class extends EventTarget {
10 constructor() {
11 super();
12 window.testBrowserEvents = this;
13 queueMicrotask(() => this.onopen?.());
14 }
15 close() { if (window.testBrowserEvents === this) window.testBrowserEvents = null; }
16 };
17 });
18 await page.route("**/api/claude-desktop", (route) => route.fulfill({ json: {
19 installed: true, running: true, failed: false, managed: true, version: "fixture",
20 } }));
21 state.status.vm_running = true;
22 state.status.ready = true;
23 await page.reload();
24 await page.getByRole("button", { name: "打开浏览器", exact: true }).click();
25 await page.waitForFunction(() => Boolean(window.testBrowserEvents?.onmessage));
26 const notify = (desktopFocus) => page.evaluate((desktopFocus) => {
27 window.testBrowserEvents.onmessage({ data: JSON.stringify({
28 tabs: [], active: "", downloads: [], uploads: [], desktopFocus,
29 }) });
30 }, desktopFocus);
31 await notify(true);
32 await page.getByRole("region", { name: "Claude Desktop", exact: true }).waitFor();
33 await page.getByRole("button", { name: "关闭应用", exact: true }).waitFor();
34 assert.equal(state.requests.some((r) => r.path === "/claude-desktop/start"), false);
35 await page.getByRole("button", { name: "打开浏览器", exact: true }).click();
36 await notify(false);
37 await page.getByRole("region", { name: "Claude Desktop", exact: true }).waitFor({ state: "hidden" });
38 await notify(true);
39 await page.getByRole("region", { name: "Claude Desktop", exact: true }).waitFor();
40 assert.deepEqual(errors, []);
41 console.log("PASS: callback switches to the running desktop; ordinary snapshots do not reopen it; repeated callbacks work.");
42} finally {
43 await browser.close();
44}