| 1 | import assert from "node:assert/strict"; |
| 2 | import { createWorkbench } from "./workbench-fixture.mjs"; |
| 3 | |
| 4 | const parts = []; |
| 5 | for await (const chunk of process.stdin) parts.push(chunk); |
| 6 | const input = JSON.parse(Buffer.concat(parts).toString()); |
| 7 | const fixture = await createWorkbench({ |
| 8 | url: input.origin, |
| 9 | mockWebSockets: false, |
| 10 | cliRequest: route => route.continue(), |
| 11 | beforeNavigate: page => page.context().addCookies([{ name: input.cookie, value: input.session, url: input.origin }]), |
| 12 | }); |
| 13 | try { |
| 14 | const { page, state } = fixture; |
| 15 | await page.route("**/api/terminals**", route => route.continue()); |
| 16 | state.status.ready = state.status.vm_running = true; |
| 17 | state.status.projects = [input.project]; |
| 18 | state.status.environment_directory = state.settings.workspace = input.project; |
| 19 | let output = ""; |
| 20 | page.on("websocket", socket => { |
| 21 | if (!socket.url().includes("/terminals/")) return; |
| 22 | socket.on("framereceived", ({ payload }) => { output = (output + payload.toString()).slice(-65536); }); |
| 23 | }); |
| 24 | await page.reload(); |
| 25 | await page.evaluate(() => { |
| 26 | window.visibleStartupWarnings = 0; |
| 27 | const check = () => { |
| 28 | for (const host of document.querySelectorAll(".terminal-host")) { |
| 29 | const text = host.querySelector(".xterm-rows")?.textContent.replace(/\s/g, "") || ""; |
| 30 | if (getComputedStyle(host).visibility === "visible" && text.includes("Loadingdevelopmentchannels")) window.visibleStartupWarnings++; |
| 31 | } |
| 32 | }; |
| 33 | new MutationObserver(check).observe(document.body, { attributes: true, childList: true, subtree: true }); |
| 34 | }); |
| 35 | await page.getByRole("button", { name: "新建终端", exact: true }).first().click(); |
| 36 | await page.getByRole("menuitem", { name: "Claude 终端", exact: true }).click(); |
| 37 | await page.getByText("正在准备 Claude 会话…", { exact: true }).waitFor(); |
| 38 | await page.locator(".terminal-host").waitFor({ state: "visible" }); |
| 39 | await page.waitForFunction(() => document.querySelector(".xterm-rows")?.textContent.includes("Claude Code")); |
| 40 | const text = output.replace(/\x1b\[[0-?]*[ -/]*[@-~]|\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/g, "").replace(/\s/g, ""); |
| 41 | assert.ok(text.includes("Loadingdevelopmentchannels"), "the genuine CLI confirmation must still exist in the raw output"); |
| 42 | assert.equal(await page.evaluate(() => window.visibleStartupWarnings), 0, "the genuine startup confirmation flashed on screen"); |
| 43 | assert.deepEqual(fixture.errors, []); |
| 44 | console.log("PASS: genuine Claude Code, isolated SSH/PTY and product WebSocket reach the desktop session without displaying the channel confirmation"); |
| 45 | } finally { await fixture.browser.close(); } |