跳到主要内容

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

浏览文件

readable-errors-smoke.mjs

42 行 · 2.8 KB历史下载
1import assert from "node:assert/strict";
2import { mkdir, writeFile } from "node:fs/promises";
3import { createWorkbench } from "./workbench-fixture.mjs";
4
5const output = process.env.CAGE_ERROR_QA_OUTPUT || "/tmp/cage-readable-errors";
6await mkdir(output, { recursive: true });
7for (const platform of ["darwin", "windows", "linux"]) {
8 const fixture = await createWorkbench({
9 clientContext: { mode: "local", connection_id: "local", client_platform: platform, server_platform: platform, connection: { state: "disconnected" } },
10 });
11 const { page, browser, state, errors } = fixture;
12 try {
13 state.status.job = { id: "readable-failure", kind: "start", running: false, message: "启动环境失败", error: "下载 Linux 镜像失败:等待下载服务器响应超时。请检查所选节点,再继续安装。", log: "fixture download timeout" };
14 await page.reload();
15 await page.getByText("启动环境失败", { exact: true }).first().waitFor();
16 await page.getByRole("alert").filter({ hasText: "等待下载服务器响应超时" }).first().waitFor();
17 await page.getByRole("button", { name: "查看操作详情", exact: true }).first().click();
18 await page.getByRole("dialog", { name: "操作详情", exact: true }).getByText("fixture download timeout", { exact: true }).waitFor();
19 await page.keyboard.press("Escape");
20 await page.screenshot({ path: `${output}/${platform}-startup.png` });
21
22 await page.route("**/api/environment/resources", route => route.fulfill({ status: 503, contentType: "text/html", body: "<html>upstream failed token=private-test-secret</html>" }));
23 const failure = await page.evaluate(async () => {
24 const { api } = await import("/src/api.js");
25 try { await api("/environment/resources"); return "unexpected success"; }
26 catch (error) { return { message: error.message, status: error.status }; }
27 });
28 assert.match(failure.message, /资源配置.*HTTP 503.*尚未就绪/);
29 assert.equal(failure.status, 503);
30 assert.ok(!failure.message.includes("private-test-secret") && !failure.message.includes("<html>"));
31 await page.route("**/api/environment/resources", route => route.fulfill({ status: 200, contentType: "application/json", body: "not-json token=private-test-secret" }));
32 const malformed = await page.evaluate(async () => {
33 const { api } = await import("/src/api.js");
34 try { await api("/environment/resources"); } catch (error) { return error.message; }
35 });
36 assert.match(malformed, /资源配置.*格式无效/);
37 assert.ok(!malformed.includes("private-test-secret"));
38 assert.deepEqual(errors, []);
39 await writeFile(`${output}/${platform}.json`, JSON.stringify({ platform, failure, malformed }, null, 2));
40 console.log(`PASS: ${platform} readable failures`);
41 } finally { await browser.close(); }
42}