The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { expect } from "e2e"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | |
| 4 | import { runPromise, test, WEB } from "./t3.ts"; |
| 5 | |
| 6 | interface Fault { |
| 7 | readonly failConfigStreamWhileInterrupted: () => boolean; |
| 8 | } |
| 9 | |
| 10 | test( |
| 11 | "The app reconnects after its config stream fails while interrupted", |
| 12 | WEB, |
| 13 | async ({ t3, app, screen, browser }) => { |
| 14 | const project = await t3.project("demo"); |
| 15 | const thread = await t3.thread({ |
| 16 | project, |
| 17 | title: "Earlier work", |
| 18 | messages: ["Print the JSON"], |
| 19 | model: "command-output", |
| 20 | }); |
| 21 | // Injected fault: the page hands the app one server frame that ends the config |
| 22 | // subscription with a typed failure and an interruption in the same cause. |
| 23 | await browser.addInitScript(() => { |
| 24 | let deliver: (() => void) | null = null; |
| 25 | const NativeWebSocket = window.WebSocket; |
| 26 | window.WebSocket = class extends NativeWebSocket { |
| 27 | override send(data: Parameters<WebSocket["send"]>[0]) { |
| 28 | if (typeof data === "string" && data.includes('"tag":"subscribeServerConfig"')) { |
| 29 | const requestId = (JSON.parse(data) as { id: number | string }).id; |
| 30 | deliver = () => |
| 31 | this.dispatchEvent( |
| 32 | new MessageEvent("message", { |
| 33 | data: JSON.stringify({ |
| 34 | _tag: "Exit", |
| 35 | requestId, |
| 36 | exit: { |
| 37 | _tag: "Failure", |
| 38 | cause: [ |
| 39 | { |
| 40 | _tag: "Fail", |
| 41 | error: { |
| 42 | _tag: "KeybindingsConfigParseError", |
| 43 | configPath: "/demo/keybindings.json", |
| 44 | detail: "Injected failure.", |
| 45 | }, |
| 46 | }, |
| 47 | { _tag: "Interrupt", fiberId: 1 }, |
| 48 | ], |
| 49 | }, |
| 50 | }), |
| 51 | }), |
| 52 | ); |
| 53 | } |
| 54 | super.send(data); |
| 55 | } |
| 56 | }; |
| 57 | (window as unknown as { __fault: Fault }).__fault = { |
| 58 | failConfigStreamWhileInterrupted: () => { |
| 59 | deliver?.(); |
| 60 | return deliver !== null; |
| 61 | }, |
| 62 | }; |
| 63 | }); |
| 64 | await browser.emulateMedia({ colorScheme: "dark", reducedMotion: "reduce" }); |
| 65 | await t3.open(thread); |
| 66 | |
| 67 | const reply = screen.getByText("The command printed one JSON line."); |
| 68 | await expect(reply.first()).toBeVisible(); |
| 69 | await app.screenshot("1-connected"); |
| 70 | |
| 71 | const delivered = await browser.evaluate(() => |
| 72 | (window as unknown as { __fault: Fault }).__fault.failConfigStreamWhileInterrupted(), |
| 73 | ); |
| 74 | expect(delivered).toBe(true); |
| 75 | // A live loop reconnects well within each wait; a dead one never does. |
| 76 | await runPromise(Effect.sleep("5 seconds")); |
| 77 | await app.screenshot("2-five-seconds-after-the-failure"); |
| 78 | |
| 79 | await screen.getByRole("textbox").fill("Are you still there?"); |
| 80 | await screen.getByRole("textbox").press("Enter"); |
| 81 | await runPromise(Effect.sleep("3 seconds")); |
| 82 | await app.screenshot("3-after-pressing-enter"); |
| 83 | await expect(reply.nth(1)).toBeVisible(); |
| 84 | }, |
| 85 | ); |