跳到主要内容

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

浏览文件

archive-contention-smoke.mjs

54 行 · 2.8 KB历史下载
1// Real archive/catalog/terminal handlers; only unrelated workbench services use fixtures.
2import assert from "node:assert/strict";
3import { createWorkbench } from "./workbench-fixture.mjs";
4
5let input = "";
6for await (const chunk of process.stdin) input += chunk;
7const fixture = JSON.parse(input);
8const forward = async route => {
9 const request = route.request();
10 const url = new URL(request.url());
11 const response = await fetch(fixture.origin + url.pathname + url.search, {
12 method: request.method(),
13 headers: { Origin: fixture.origin, Cookie: fixture.cookie, "Content-Type": "application/json" },
14 body: request.postData() || undefined,
15 });
16 return route.fulfill({ status: response.status, contentType: response.headers.get("Content-Type"), body: await response.text() });
17};
18const { page, browser, errors } = await createWorkbench({
19 url: process.env.CAGE_UI_URL || fixture.origin,
20 cliRequest: forward,
21 beforeNavigate: async (page, state) => {
22 state.settings.workspace = fixture.workspace;
23 Object.assign(state.status, { ready: true, vm_running: true, projects: [fixture.workspace], environment_directory: fixture.workspace });
24 await page.route("**/api/terminals", forward);
25 },
26});
27try {
28 const actions = page.getByRole("group", { name: `${fixture.title} 的操作`, exact: true, includeHidden: true });
29 await page.locator(".sidebar-tab").filter({ has: actions }).hover();
30 await actions.getByRole("button", { name: "归档", exact: true }).hover();
31 await actions.locator(".terminal-action-label").filter({ hasText: /^归档$/ }).click();
32 const dialog = page.getByRole("dialog", { name: "归档这段会话?", exact: true });
33 await dialog.getByRole("button", { name: "归档会话", exact: true }).click();
34 const pending = dialog.getByRole("button", { name: "正在归档…", exact: true });
35 await pending.waitFor();
36 assert.equal(await pending.isDisabled(), true);
37 await page.keyboard.press("Enter");
38 await page.keyboard.press("Escape");
39 assert.equal(await dialog.isVisible(), true);
40 await fetch(fixture.origin + "/fixture/release-operation", { method: "POST" });
41 await dialog.waitFor({ state: "hidden" });
42 await actions.waitFor({ state: "hidden" });
43 // Reload fetches the durable catalog again through the real backend.
44 const reloadedSessions = page.waitForResponse(response => new URL(response.url()).pathname === "/api/cli/sessions");
45 await page.reload();
46 await page.getByRole("button", { name: "打开浏览器", exact: true }).waitFor();
47 await reloadedSessions;
48 assert.equal(await actions.count(), 0);
49 assert.deepEqual(errors, []);
50 console.log(`${process.env.CAGE_TEST_BROWSER}: UI archive waited for the environment operation, submitted once, removed the row, retained history and survived reload`);
51} finally {
52 await fetch(fixture.origin + "/fixture/release-operation", { method: "POST" });
53 await browser.close();
54}