| 1 | import assert from "node:assert/strict"; |
| 2 | import { createWorkbench } from "./workbench-fixture.mjs"; |
| 3 | |
| 4 | const epoch = new Date("2026-11-08T03:00:00Z"); |
| 5 | for (const platform of ["darwin", "windows"]) { |
| 6 | let proxyReady = false; |
| 7 | const calls = []; |
| 8 | const fixture = await createWorkbench({ |
| 9 | clientContext: { mode: "local", connection_id: "local", client_platform: platform, server_platform: platform, connection: { state: "disconnected" } }, |
| 10 | beforeNavigate: page => page.clock.install({ time: epoch }), |
| 11 | nativeRequest: async body => { |
| 12 | if (body.action !== "appUpdate") return null; |
| 13 | calls.push(body.operation); |
| 14 | return { phase: proxyReady ? "current" : "waiting", message: proxyReady ? "已是最新版本" : "所选代理未运行,更新检查将在代理就绪后重试", retryAt: "" }; |
| 15 | }, |
| 16 | }); |
| 17 | try { |
| 18 | await fixture.page.waitForFunction(() => !document.querySelector(".loading-screen")); |
| 19 | await fixture.page.evaluate(() => window.dispatchEvent(new Event("focus"))); |
| 20 | assert.deepEqual(calls, ["status", "check"]); |
| 21 | assert.equal(await fixture.page.locator(".app-update-error").count(), 0, "waiting is not an update-failure alert"); |
| 22 | await fixture.page.clock.fastForward(4 * 60 * 1000); |
| 23 | assert.deepEqual(calls, ["status", "check"], "no tight retry loop while proxy is unavailable"); |
| 24 | proxyReady = true; |
| 25 | await fixture.page.clock.fastForward(2 * 60 * 1000); |
| 26 | await fixture.page.waitForFunction(() => !document.querySelector(".app-update-error")); |
| 27 | assert.deepEqual(calls, ["status", "check", "check"], "waiting checks resume on the existing five-minute retry schedule"); |
| 28 | assert.deepEqual(fixture.errors, []); |
| 29 | console.log(`PASS: ${platform} update waits and recovers without failure alerts`); |
| 30 | } finally { await fixture.browser.close(); } |
| 31 | } |
| 32 | |
| 33 | const fixture = await createWorkbench({ beforeNavigate: page => page.clock.install({ time: epoch }) }); |
| 34 | try { |
| 35 | const { page, state } = fixture; |
| 36 | let broken = true; |
| 37 | let polls = 0; |
| 38 | await page.exposeFunction("filePollCountForTest", () => polls); |
| 39 | const failure = "Claude Desktop 的文件服务已经退出,请重新打开应用"; |
| 40 | await page.route("**/api/input/files/desktop/requests", route => { |
| 41 | polls++; |
| 42 | return broken ? route.fulfill({ status: 503, contentType: "text/plain", body: failure }) |
| 43 | : route.fulfill({ json: { available: true, uploads: [], downloads: [], opens: [] } }); |
| 44 | }); |
| 45 | state.status.ready = state.status.vm_running = true; |
| 46 | await page.reload(); |
| 47 | await page.getByText(failure, { exact: false }).waitFor(); |
| 48 | assert.equal(polls, 1, "real file-service failure is visible to the user"); |
| 49 | await page.clock.fastForward(2500); |
| 50 | assert.equal(polls, 1, "failed poll backs off instead of retrying at 1.5 seconds"); |
| 51 | await page.clock.fastForward(1000); |
| 52 | await page.waitForFunction(async () => await window.filePollCountForTest() >= 2); |
| 53 | assert.equal(polls, 2); |
| 54 | broken = false; |
| 55 | await page.clock.fastForward(6500); |
| 56 | await page.waitForFunction(async () => await window.filePollCountForTest() >= 3); |
| 57 | const recovered = polls; |
| 58 | await page.clock.fastForward(1600); |
| 59 | await page.waitForFunction(async previous => await window.filePollCountForTest() > previous, recovered); |
| 60 | assert.ok(polls > recovered, "normal polling cadence returns after recovery"); |
| 61 | |
| 62 | await page.getByRole("button", { name: "打开浏览器", exact: true }).click(); |
| 63 | const trigger = page.getByRole("button", { name: "浏览器下载", exact: true }); |
| 64 | for (let round = 0; round < 4; round++) { |
| 65 | await trigger.click(); |
| 66 | await page.getByRole("dialog", { name: "下载文件", exact: true }).waitFor(); |
| 67 | await page.getByRole("button", { name: "工作台", exact: true }).click(); |
| 68 | await page.setViewportSize({ width: 950 + round * 25, height: 720 }); |
| 69 | await page.getByRole("button", { name: "打开浏览器", exact: true }).click(); |
| 70 | } |
| 71 | assert.deepEqual(fixture.errors, [], "closing panels and resizing must not leave null-reference callbacks"); |
| 72 | console.log("PASS: file polling reports failures, backs off, recovers, and panel teardown remains safe"); |
| 73 | } finally { await fixture.browser.close(); } |