| 1 | import assert from "node:assert/strict"; |
| 2 | import fs from "node:fs/promises"; |
| 3 | import { createWorkbench } from "./workbench-fixture.mjs"; |
| 4 | |
| 5 | const output = new URL("../../docs/test-reports/2026-11-04-desktop-memory/", import.meta.url); |
| 6 | await fs.mkdir(output, { recursive: true }); |
| 7 | const { browser, page, state, errors } = await createWorkbench(); |
| 8 | let unavailable = true; |
| 9 | const desktop = { installed: true, running: false, failed: true, failure_reason: "oom-kill", version: "4.4212.0" }; |
| 10 | await page.route("**/api/claude-desktop**", async route => { |
| 11 | if (route.request().method() === "POST") { |
| 12 | return route.fulfill({ status: 502, body: "测试:打开操作失败,请重试" }); |
| 13 | } |
| 14 | if (unavailable) return route.fulfill({ status: 502, body: "无法读取 Claude Desktop 状态,请重试" }); |
| 15 | return route.fulfill({ json: desktop }); |
| 16 | }); |
| 17 | try { |
| 18 | state.status.vm_running = true; |
| 19 | state.status.ready = true; |
| 20 | await page.reload(); |
| 21 | await page.getByRole("button", { name: "Claude Desktop", exact: true }).click(); |
| 22 | await page.getByRole("alert").filter({ hasText: "无法读取 Claude Desktop 状态" }).waitFor(); |
| 23 | unavailable = false; |
| 24 | await page.getByRole("button", { name: "刷新 Claude Desktop 状态", exact: true }).click(); |
| 25 | await page.getByRole("alert").filter({ hasText: "环境内存不足" }).waitFor(); |
| 26 | assert.equal(await page.getByText("无法读取 Claude Desktop 状态,请重试", { exact: true }).count(), 0); |
| 27 | await page.screenshot({ path: new URL("oom-message.png", output).pathname }); |
| 28 | desktop.failed = false; |
| 29 | desktop.failure_reason = ""; |
| 30 | await page.getByRole("button", { name: "刷新 Claude Desktop 状态", exact: true }).click(); |
| 31 | await page.getByRole("alert").waitFor({ state: "hidden" }); |
| 32 | await page.getByRole("button", { name: "打开 Claude Desktop", exact: true }).click(); |
| 33 | await page.getByRole("alert").filter({ hasText: "打开操作失败" }).waitFor(); |
| 34 | await page.getByRole("button", { name: "刷新 Claude Desktop 状态", exact: true }).click(); |
| 35 | await page.getByRole("alert").filter({ hasText: "打开操作失败" }).waitFor(); |
| 36 | assert.deepEqual(errors, []); |
| 37 | const checks = ["status recovery clears stale read error", "OOM reason displayed", "healthy status clears OOM message", "status polling preserves failed user operation"]; |
| 38 | await fs.writeFile(new URL("ui-checks.json", output), JSON.stringify({ complete: true, checks }, null, 2)); |
| 39 | console.log(JSON.stringify({ complete: true, checks })); |
| 40 | } finally { await browser.close(); } |