跳到主要内容

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

浏览文件

recovery-ui-smoke.mjs

101 行 · 7.2 KB历史下载
1import assert from "node:assert/strict";
2import fs from "node:fs/promises";
3import { join } from "node:path";
4import { smokeCaptureDirectory } from "./smoke-captures.mjs";
5import { createWorkbench } from "./workbench-fixture.mjs";
6
7const output = await smokeCaptureDirectory("recovery-ui");
8const calls = [];
9let update = { phase: "available", currentVersion: "0.2.0-alpha.1", latestVersion: "0.2.0-alpha.2", message: "发现新版本,可下载更新", retryable: true };
10const fixture = await createWorkbench({ nativeRequest: async (body) => {
11 calls.push(body);
12 if (body.action === "workbenchReady") return true;
13 if (body.action !== "appUpdate") return null;
14 if (body.operation === "install") update = { ...update, phase: "downloading", receivedBytes: 50, totalBytes: 100, message: "正在下载更新" };
15 if (body.operation === "cancel") update = { ...update, phase: "available", message: "更新已暂停,可稍后继续" };
16 return update;
17} });
18const { browser, page, state, errors } = fixture;
19const checks = [];
20try {
21 await page.getByRole("button", { name: "下载更新", exact: true }).waitFor();
22 const button = page.getByRole("button", { name: "下载更新", exact: true });
23 assert.match(await button.getAttribute("title"), /点击后将自动停止环境、安装并重启/);
24 const bounds = await button.boundingBox();
25 assert.ok(bounds.x < 248 && bounds.y > 700, "update action is not in the bottom-left sidebar");
26 await page.screenshot({ path: join(output, "update-available.png") });
27 await button.click();
28 assert.equal(calls.filter((call) => call.operation === "install").length, 1);
29 await page.getByRole("progressbar", { name: "更新下载进度" }).waitFor();
30 assert.equal(await page.getByRole("progressbar").getAttribute("aria-valuenow"), "50");
31 assert.equal(await page.getByRole("dialog", { name: "Cage 更新" }).count(), 0);
32 await page.evaluate(() => window.dispatchEvent(new CustomEvent("cage-app-update", { detail: { phase: "failed", latestVersion: "0.2.0-alpha.2", message: "更新源暂不可访问,仓库尚未公开", retryable: true } })));
33 await page.getByRole("button", { name: "重试更新", exact: true }).waitFor();
34 await page.getByRole("alert").filter({ hasText: "更新源暂不可访问,仓库尚未公开" }).waitFor();
35 checks.push("bottom-left update affordance", "single install request without a dialog", "inline ring progress", "private source failure visible");
36
37 const downloads = [{ id: "qa-download", name: "report.txt", state: "failed", error: "目标目录暂时无法写入", retryable: true }];
38 let retries = 0, editorRestarts = 0, componentUpdates = 0;
39 await page.route("**/api/browser/tabs", (route) => route.fulfill({ json: { tabs: state.tabs, active: state.active, downloads } }));
40 await page.route("**/api/browser/download-retry", (route) => {
41 assert.deepEqual(route.request().postDataJSON(), { id: "qa-download" });
42 retries++;
43 Object.assign(downloads[0], { state: "saved", retryable: false, error: "", path: "/Users/you/Cage/Downloads/report.txt" });
44 return route.fulfill({ json: { ok: true } });
45 });
46 await page.route("**/api/browser/editor-restart", (route) => {
47 assert.equal(route.request().postDataJSON().workspace, state.settings.workspace);
48 editorRestarts++;
49 return route.fulfill({ json: { ok: true } });
50 });
51 await page.route("**/api/environment/versions", (route) => route.fulfill({ json: {
52 vm_running: true, controller: { version: "0.2.0-alpha.2" }, components: { status: "update_required", update_required: true },
53 tools: { chromium: { current: "156", required: "系统安全更新" }, code_server: { current: "4.100", required: "4.144.0" } }, tools_update_allowed: false,
54 } }));
55 await page.route("**/api/environment/update", (route) => { componentUpdates++; return route.fulfill({ json: { id: "qa-components" } }); });
56 await page.getByRole("button", { name: "启动 Cage 环境", exact: true }).click();
57 await page.getByRole("heading", { name: "Cage 环境已就绪", exact: true }).waitFor();
58 await page.getByRole("button", { name: "打开浏览器", exact: true }).click();
59 await page.getByRole("button", { name: "浏览器下载", exact: true }).click();
60 await page.getByRole("dialog", { name: "下载文件" }).getByText("目标目录暂时无法写入", { exact: true }).waitFor();
61 await page.getByRole("button", { name: "重试保存", exact: true }).click();
62 await page.getByText("已保存到本机", { exact: true }).waitFor();
63 assert.equal(retries, 1);
64 await page.screenshot({ path: join(output, "download-recovery.png") });
65 await page.getByRole("dialog", { name: "下载文件" }).getByRole("button", { name: "关闭面板" }).click();
66 await page.getByRole("button", { name: "打开 默认工作区 的编辑器", exact: true }).click();
67 await page.getByRole("button", { name: "浏览器菜单", exact: true }).click();
68 await page.getByRole("menuitem", { name: "恢复编辑器", exact: true }).click();
69 await page.getByRole("dialog", { name: "重启编辑器?" }).getByRole("button", { name: "重启编辑器", exact: true }).click();
70 await page.getByText("编辑器已恢复", { exact: true }).waitFor();
71 assert.equal(editorRestarts, 1);
72 assert.equal(state.status.vm_running, true);
73 checks.push("download retry reports durable save", "editor recovery leaves VM running");
74 await page.getByRole("button", { name: "设置", exact: false }).first().click();
75 await page.getByRole("button", { name: "环境与恢复", exact: true }).click();
76 await page.getByRole("region", { name: "环境版本" }).getByText("需要更新", { exact: true }).waitFor();
77 assert.equal(await page.getByRole("button", { name: "更新环境工具", exact: true }).isDisabled(), true);
78 await page.getByRole("button", { name: "更新环境工具", exact: true }).scrollIntoViewIfNeeded();
79 await page.screenshot({ path: join(output, "environment-versions.png") });
80 await page.getByRole("button", { name: "更新环境组件", exact: true }).click();
81 await page.getByRole("dialog", { name: "更新环境组件?" }).getByRole("button", { name: "更新组件", exact: true }).click();
82 await page.waitForTimeout(50);
83 assert.equal(componentUpdates, 1);
84 assert.ok(calls.some((call) => call.action === "workbenchReady"), "successful initialized workbench did not acknowledge launch");
85 assert.deepEqual(errors, []);
86 checks.push("environment versions and guarded tool update", "explicit component update", "initialized workbench launch acknowledgement");
87} finally { await browser.close(); }
88
89let prematureReady = false;
90const broken = await createWorkbench({ startupFailure: true, nativeRequest: async (body) => {
91 if (body.action === "workbenchReady") prematureReady = true;
92 return { phase: "current", currentVersion: "0.2.0-alpha.2" };
93} });
94try {
95 await broken.page.waitForResponse((response) => response.url().endsWith("/api/status") && response.status() === 503);
96 await broken.page.waitForTimeout(100);
97 assert.equal(prematureReady, false, "failed API initialization acknowledged update success");
98 checks.push("startup failure never acknowledges upgrade");
99} finally { await broken.browser.close(); }
100await fs.writeFile(join(output, "ui-checks.json"), JSON.stringify({ checks }, null, 2));
101console.log(JSON.stringify({ checks }));