| 1 | import assert from "node:assert/strict"; |
| 2 | import { createWorkbench } from "./workbench-fixture.mjs"; |
| 3 | |
| 4 | for (const [platform, id] of [["darwin","macos"], ["windows","windows-11"], ["linux",null]]) { |
| 5 | for (const fresh of [true, false]) { |
| 6 | const fixture = await createWorkbench({ |
| 7 | clientContext: {mode:"local", connection_id:"local", client_platform:platform, server_platform:platform}, |
| 8 | async beforeNavigate(page, state) { |
| 9 | state.status.local_vm_storage = true; |
| 10 | await page.route("**/api/environment/guest-systems", route => route.fulfill({ |
| 11 | json:{fresh, available:false, system:fresh ? id : null, reason:"此构建缺少原生客户机安装组件"}, |
| 12 | })); |
| 13 | }, |
| 14 | }); |
| 15 | const { browser, page, errors } = fixture; |
| 16 | try { |
| 17 | const region = page.locator(".guest-system-picker"); |
| 18 | if (fresh) { |
| 19 | await region.waitFor(); |
| 20 | if (id) { |
| 21 | const picker = region.getByRole("combobox"); |
| 22 | const storage = page.getByRole("button",{name:"选择环境存储位置"}); |
| 23 | const initialY = (await storage.boundingBox()).y; |
| 24 | await picker.click(); |
| 25 | const option = page.getByRole("option").last(); |
| 26 | assert.equal(await option.getAttribute("aria-disabled"),"true"); |
| 27 | const position = await option.boundingBox(); |
| 28 | assert.ok(Math.abs((await storage.boundingBox()).y - initialY) < 1 && position.height > 0); |
| 29 | await picker.press("Escape"); |
| 30 | assert.ok(Math.abs((await storage.boundingBox()).y - initialY) <= 1, "collapsed picker restores the following control"); |
| 31 | } |
| 32 | } else await region.waitFor({state:"hidden"}); |
| 33 | const submitted = page.waitForRequest(req => req.url().endsWith("/api/start") && req.method()==="POST"); |
| 34 | await page.getByRole("button",{name:"启动 Cage 环境",exact:true}).click(); |
| 35 | assert.deepEqual((await submitted).postDataJSON(), fresh ? {guest_system:"debian-13"} : {}); |
| 36 | assert.deepEqual(errors,[]); |
| 37 | } finally { await browser.close(); } |
| 38 | } |
| 39 | } |
| 40 | console.log("Debian fallback and existing environments verified on all three host types."); |