| 1 | import assert from "node:assert/strict"; |
| 2 | import { createWorkbench } from "./workbench-fixture.mjs"; |
| 3 | |
| 4 | for (const system of ["macos", "windows-11", "debian"]) { |
| 5 | const calls = []; |
| 6 | const native = system !== "debian"; |
| 7 | const fixture = await createWorkbench({ beforeNavigate: async (page, state) => { |
| 8 | state.account.guest_system = state.status.guest_system = system; |
| 9 | state.status.vm_running = state.status.ready = true; |
| 10 | await page.route("**/api/environment/versions", route => route.fulfill({ json: { |
| 11 | vm_running: true, tools_update_allowed: true, |
| 12 | components: { status: "update_required", update_required: true }, |
| 13 | controller: { version: "fixture-controller" }, |
| 14 | tools: { claude: { current: "2.1.300", required: "2.1.311" }, node: { current: "v24.22.2", required: "24.22.2" } }, |
| 15 | maintenance: native ? { native: true, guest_system: system, requires_closed_terminals: true } : undefined, |
| 16 | } })); |
| 17 | for (const operation of ["update", "tools"]) { |
| 18 | await page.route(`**/api/environment/${operation}`, route => { |
| 19 | calls.push(operation); |
| 20 | return route.fulfill({ status: 409, contentType: "text/plain; charset=utf-8", body: "请先保存工作,结束正在运行的终端和 Claude Code 轮次,再重试更新。" }); |
| 21 | }); |
| 22 | } |
| 23 | } }); |
| 24 | const { page, browser, errors } = fixture; |
| 25 | try { |
| 26 | await page.getByRole("button", { name: "设置", exact: true }).click(); |
| 27 | await page.getByRole("navigation", { name: "设置分组" }).getByRole("button", { name: "环境与恢复", exact: true }).click(); |
| 28 | const panel = page.getByRole("region", { name: "环境版本", exact: true }); |
| 29 | await panel.getByText("2.1.300", { exact: true }).waitFor(); |
| 30 | await panel.getByText("2.1.311", { exact: true }).waitFor(); |
| 31 | for (const operation of ["组件", "工具"]) { |
| 32 | await panel.getByRole("button", { name: `更新环境${operation}`, exact: true }).click(); |
| 33 | const dialog = page.getByRole("dialog", { name: `更新环境${operation}?`, exact: true }); |
| 34 | const text = await dialog.innerText(); |
| 35 | if (native) { |
| 36 | assert.ok(text.includes("结束正在运行的终端和 Claude Code 轮次")); |
| 37 | assert.ok(text.includes("聊天历史、项目文件与登录资料会保留")); |
| 38 | assert.equal(text.includes("验证已绑定客机的管理员账户"), system === "windows-11"); |
| 39 | } else { |
| 40 | assert.ok(text.includes("工作台终端、项目文件和登录状态会保留")); |
| 41 | } |
| 42 | await dialog.getByRole("button", { name: `更新${operation}`, exact: true }).click(); |
| 43 | await panel.getByRole("alert").filter({ hasText: "结束正在运行的终端" }).waitFor(); |
| 44 | } |
| 45 | assert.deepEqual(calls, ["update", "tools"]); |
| 46 | assert.deepEqual(errors, []); |
| 47 | console.log(JSON.stringify({ system, passed: true, calls })); |
| 48 | } finally { |
| 49 | await browser.close(); |
| 50 | } |
| 51 | } |