The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | /// <reference lib="dom" /> |
| 2 | import { expect } from "e2e"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | |
| 5 | import { T3_HOME } from "../e2e.config.ts"; |
| 6 | import { environmentId, rpcClient, runPromise, test, WEB } from "./t3.ts"; |
| 7 | |
| 8 | declare global { |
| 9 | interface Window { |
| 10 | deviceHostProbeGate?: { readonly started: Promise<void>; readonly release: () => void }; |
| 11 | } |
| 12 | } |
| 13 | |
| 14 | test( |
| 15 | "A second SSH connection check keeps the pending status visible", |
| 16 | WEB, |
| 17 | async ({ t3, app, browser, screen }) => { |
| 18 | const origin = app.baseUrl ?? ""; |
| 19 | const environment = await runPromise(environmentId(origin)); |
| 20 | await t3.project("demo"); |
| 21 | await runPromise( |
| 22 | Effect.gen(function* () { |
| 23 | const client = yield* rpcClient(T3_HOME, origin); |
| 24 | yield* client["server.updateSettings"]({ |
| 25 | patch: { |
| 26 | enableDeviceSupport: true, |
| 27 | deviceHosts: [ |
| 28 | { kind: "ssh", id: "slow-host", label: "Slow host", target: "127.0.0.1", port: 1 }, |
| 29 | ], |
| 30 | }, |
| 31 | }); |
| 32 | }).pipe(Effect.scoped), |
| 33 | ); |
| 34 | |
| 35 | // Delay just the explicit probe at the transport boundary until after the UI sample. |
| 36 | await browser.addInitScript(() => { |
| 37 | const held: Array<() => void> = []; |
| 38 | const started = Promise.withResolvers<void>(); |
| 39 | let delaying = true; |
| 40 | const send = WebSocket.prototype.send; |
| 41 | WebSocket.prototype.send = function (this: WebSocket, data) { |
| 42 | if (!delaying || typeof data !== "string") return send.call(this, data); |
| 43 | const parsed = JSON.parse(data); |
| 44 | const messages = [parsed].flat(); |
| 45 | const isProbe = (message: { _tag?: string; tag?: string }) => |
| 46 | message?._tag === "Request" && message.tag === "device.testHost"; |
| 47 | if (!messages.some(isProbe)) return send.call(this, data); |
| 48 | const probes = messages.filter(isProbe); |
| 49 | const other = messages.filter((message) => !isProbe(message)); |
| 50 | if (other.length) send.call(this, JSON.stringify(other)); |
| 51 | held.push(() => send.call(this, Array.isArray(parsed) ? JSON.stringify(probes) : data)); |
| 52 | started.resolve(); |
| 53 | }; |
| 54 | window.deviceHostProbeGate = { |
| 55 | started: started.promise, |
| 56 | release: () => { |
| 57 | delaying = false; |
| 58 | for (const release of held.splice(0)) release(); |
| 59 | }, |
| 60 | }; |
| 61 | }); |
| 62 | |
| 63 | await t3.open(`/settings/devices?machine=${encodeURIComponent(environment)}#device-sources`); |
| 64 | const more = browser.locator("#device-sources").getByRole("button", "More", { exact: true }); |
| 65 | const testConnection = screen.getByRole("menuitem", "Test connection", { exact: true }); |
| 66 | const pending = screen.getByText("Testing connection", { exact: true }); |
| 67 | try { |
| 68 | await more.tap(); |
| 69 | await testConnection.tap(); |
| 70 | await pending.waitFor(); |
| 71 | await browser.evaluate(async () => { |
| 72 | await window.deviceHostProbeGate!.started; |
| 73 | return null; |
| 74 | }); |
| 75 | if (await more.isEnabled()) { |
| 76 | await more.tap(); |
| 77 | await screen.getByRole("menu").waitFor(); |
| 78 | if ((await testConnection.isVisible()) && (await testConnection.isEnabled())) { |
| 79 | await testConnection.tap(); |
| 80 | await testConnection.waitFor({ state: "hidden" }); |
| 81 | } else { |
| 82 | await browser.keyboard.press("Escape"); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | await app.screenshot("second-connection-check"); |
| 87 | expect(await pending.isVisible(), "The SSH connection check still shows as pending").toBe( |
| 88 | true, |
| 89 | ); |
| 90 | } finally { |
| 91 | await browser.evaluate(() => { |
| 92 | window.deviceHostProbeGate?.release(); |
| 93 | return null; |
| 94 | }); |
| 95 | } |
| 96 | }, |
| 97 | ); |