跳到主要内容

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

浏览文件

safety-state.test.mjs

82 行 · 3.0 KB历史下载
1import test from "node:test";
2import assert from "node:assert/strict";
3import {
4 networkState,
5 reportForSharing,
6 isGuestLocalURL,
7 canonicalExitPolicy,
8 isSafetyCheckMessage,
9} from "./safety-state.mjs";
10
11test("check failures and incomplete evidence link to the checklist without tagging unrelated errors", () => {
12 for (const message of [
13 "关键检查尚未通过,外网保持关闭",
14 "关键检测证据不完整,外网保持关闭",
15 "Cage 外网未放行,请在工作台完成关键检查",
16 "代理节点尚未应用或配置不一致,请重新应用节点;外网保持关闭",
17 "浏览器配置检查未通过:语言不一致",
18 ]) assert.equal(isSafetyCheckMessage(message), true, message);
19 for (const message of [undefined, "", "关键检查已通过", "关键检查进行中", "项目文件夹连接失败", "Git 设置已写入,但检查尚未通过。", "资源限制未通过核验"])
20 assert.equal(isSafetyCheckMessage(message), false, message);
21});
22
23test("an unchanged exit policy does not restart the VM because of empty optional fields", () => {
24 assert.deepEqual(
25 canonicalExitPolicy({
26 mode: "dynamic",
27 scope: "country",
28 country_code: "US",
29 }),
30 canonicalExitPolicy({
31 mode: "dynamic",
32 scope: "country",
33 country_code: "US",
34 ip: "",
35 region: "",
36 city: "",
37 }),
38 );
39});
40
41test("only a live gate lease displays networking as allowed", () => {
42 const now = Date.now();
43 const status = {
44 vm_running: true,
45 safety: {
46 gate: { mode: "open", until: new Date(now + 1000).toISOString() },
47 report: { checks: [{ state: "passed" }] },
48 },
49 };
50 assert.equal(networkState(status, now).mode, "open");
51 assert.equal(networkState(status, now + 2000).mode, "closed");
52 status.safety.gate.mode = "closed";
53 assert.equal(networkState(status, now).mode, "closed");
54 status.safety.gate = null;
55 assert.equal(networkState(status, now).mode, "unknown");
56 status.vm_running = false;
57 assert.equal(networkState(status, now).mode, "stopped");
58});
59
60test("shared reports omit identifiers and secret-derived configuration hashes", () => {
61 const report = {
62 policy: "v1",
63 created_at: "today",
64 checks: [],
65 run_id: "private-run",
66 check_id: "private-check",
67 configuration: "secret-derived-hash",
68 ip: "private-ip",
69 };
70 const text = JSON.stringify(reportForSharing(report));
71 assert.ok(!text.includes("private") && !text.includes("secret-derived"));
72});
73
74test("offline browser previews allow guest loopback only", () => {
75 assert.equal(isGuestLocalURL("http://localhost:3000"), true);
76 assert.equal(isGuestLocalURL("http://127.0.0.1:18080"), true);
77 assert.equal(isGuestLocalURL("http://[::1]:3000"), true);
78 assert.equal(isGuestLocalURL("about:blank"), true);
79 assert.equal(isGuestLocalURL("https://localhost.attacker.example"), false);
80 assert.equal(isGuestLocalURL("http://192.168.5.2:17777"), false);
81 assert.equal(isGuestLocalURL("https://example.com"), false);
82});