跳到主要内容

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

浏览文件

exit-policy-region-smoke.mjs

69 行 · 4.1 KB历史下载
1import assert from "node:assert/strict";
2import fs from "node:fs/promises";
3import { fileURLToPath } from "node:url";
4import { chooseInline, createWorkbench } from "./workbench-fixture.mjs";
5
6const output = new URL("../../docs/test-reports/2026-11-07-user-feedback/", import.meta.url);
7await fs.mkdir(output, { recursive: true });
8const { browser, page, state, errors } = await createWorkbench();
9try {
10 state.settings.exit_policy = { mode: "dynamic", scope: "city", country_code: "JP", region: "Kanagawa", city: "Yokohama" };
11 await page.reload();
12 await page.route("**/api/settings/probe", route => route.fulfill({ json: {
13 ip: "192.0.2.10", country: "Japan", country_code: "JP", region: "Kanagawa", city: "Kawasaki",
14 timezone: "Asia/Tokyo", checked_at: new Date().toISOString(),
15 } }));
16 const openSettings = async () => {
17 await page.getByRole("button", { name: /^设置/ }).click();
18 await page.getByRole("button", { name: "网络与代理", exact: true }).click();
19 };
20 await openSettings();
21 await page.getByText("中国大陆出口禁止放行;静态 IP 和不限地区也必须确认出口国家。", { exact: true }).waitFor();
22 const picker = page.getByRole("combobox", { name: "动态 IP 的允许范围", exact: true });
23 const layoutTop = locator => locator.evaluate(element => {
24 let top = element.getBoundingClientRect().top;
25 for (let parent = element.parentElement; parent; parent = parent.parentElement) top += parent.scrollTop;
26 return top;
27 });
28 const country = page.getByLabel("允许的国家/地区代码", { exact: true });
29 await country.click();
30 assert.equal(await page.getByRole("option", { name: "中国", exact: true }).count(), 0, "mainland must not be offered as an allowed exit country");
31 await country.press("Escape");
32 const before = await layoutTop(country);
33 await picker.click();
34 const options = page.getByRole("listbox");
35 await options.waitFor();
36 const expanded = await layoutTop(country);
37 const list = await options.boundingBox();
38 assert.ok(Math.abs(expanded - before) < 1, "floating options must not move the following fields");
39 assert.ok(list.height > 0, "options must remain visible");
40 await picker.press("ArrowDown");
41 await picker.press("Enter");
42 await page.getByLabel("允许的城市", { exact: true }).waitFor({ state: "hidden" });
43 assert.equal(await picker.getAttribute("value"), "region");
44 assert.equal(await page.getByLabel("所属州/省", { exact: true }).inputValue(), "Kanagawa");
45 await page.getByRole("button", { name: "检测当前出口", exact: true }).click();
46 await page.getByText("Japan · Kanagawa · Kawasaki", { exact: true }).waitFor();
47 await page.getByRole("button", { name: "用检测结果填写", exact: true }).click();
48 await page.screenshot({ path: fileURLToPath(new URL("region-settings.png", output)), fullPage: true });
49 await page.getByRole("button", { name: "保存设置", exact: true }).click();
50 await page.getByRole("heading", { name: "网络与代理", exact: true }).waitFor({ state: "hidden" });
51 assert.equal(state.settings.exit_policy.scope, "region");
52 assert.equal(state.settings.exit_policy.region, "Kanagawa");
53 assert.equal(state.settings.exit_policy.country_code, "JP");
54 assert.equal(state.settings.exit_policy.city, "Yokohama", "relaxing the scope must preserve the previously saved city");
55 await page.reload();
56 await openSettings();
57 assert.equal(await picker.getAttribute("value"), "region");
58 assert.equal(await page.getByLabel("所属州/省", { exact: true }).inputValue(), "Kanagawa");
59 await chooseInline(picker, "city");
60 assert.equal(await page.getByLabel("允许的城市", { exact: true }).inputValue(), "Yokohama");
61 await picker.click();
62 await picker.press("Escape");
63 assert.equal(await picker.getAttribute("aria-expanded"), "false");
64 await chooseInline(picker, "any");
65 assert.match(await picker.textContent(), /中国大陆除外/);
66 await page.getByText(/命中大陆网段、定位为中国大陆、无法确认出口地区/).waitFor();
67 assert.deepEqual(errors, []);
68 console.log("PASS: inline mouse/keyboard expansion, region binding, city preservation, save and reload");
69} finally { await browser.close(); }