跳到主要内容

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

浏览文件

app-update-retry-smoke.mjs

43 行 · 2.4 KB历史下载
1import assert from "node:assert/strict";
2import { createWorkbench } from "./workbench-fixture.mjs";
3
4const epoch = new Date("2026-11-07T14:00:00Z");
5for (const platform of ["darwin", "windows", "linux"]) {
6 const calls = [];
7 let update = platform === "linux" ? { phase: "manual", message: "使用系统包更新" } : {
8 phase: "failed", message: "更新源请求受限,请稍后重试", currentVersion: "0.1.0", latestVersion: "0.2.0",
9 retryable: true, retryAt: new Date(+epoch + 60*60*1000).toISOString(),
10 };
11 const fixture = await createWorkbench({
12 clientContext: { mode: "local", connection_id: "local", client_platform: platform, server_platform: platform, connection: { state: "disconnected" } },
13 beforeNavigate: page => page.clock.install({ time: epoch }),
14 nativeRequest: async body => {
15 if (body.action !== "appUpdate") return null;
16 calls.push(body.operation);
17 if (body.operation === "check") update = { phase: "current", currentVersion: "0.1.0", retryAt: "" };
18 return update;
19 },
20 });
21 const { page, browser, errors } = fixture;
22 try {
23 await page.waitForFunction(() => document.querySelector(".app-update-button") || !document.querySelector(".loading-screen"));
24 if (platform === "linux") {
25 await page.clock.fastForward(7*60*60*1000);
26 assert.deepEqual(calls, ["status"], "Linux must keep system package updates");
27 } else {
28 await page.getByRole("button", { name: "等待重试更新", exact: true }).waitFor();
29 assert.ok(await page.getByRole("button", { name: "等待重试更新", exact: true }).isDisabled());
30 assert.deepEqual(calls, ["status"], "startup must respect the native retry deadline");
31 await page.clock.fastForward(6*60*1000);
32 await page.evaluate(() => window.dispatchEvent(new Event("focus")));
33 assert.deepEqual(calls, ["status"], "the five-minute timer and focus must not bypass cooldown");
34 await page.clock.fastForward(53*60*1000);
35 assert.deepEqual(calls, ["status"], "must not retry before the server deadline");
36 await page.clock.fastForward(2*60*1000);
37 await page.waitForFunction(() => !document.querySelector(".app-update-button"));
38 assert.deepEqual(calls, ["status", "check"], "retry once when the server deadline passes");
39 }
40 assert.deepEqual(errors, []);
41 console.log(`PASS: ${platform} update cooldown`);
42 } finally { await browser.close(); }
43}