| 24 | } |
| 25 | |
| 26 | export class TestBackend implements WorkspaceBackend { |
| 27 | readonly type = "test"; |
| 28 | readonly id: string; |
| 29 | readonly #url: string; |
| 30 | |
| 31 | constructor(options: TestBackendOptions) { |
| 32 | this.id = options.id ?? "test"; |
| 33 | this.#url = options.url; |
| 34 | } |
| 35 | |
| 36 | async connect(): Promise<BackendHandle> { |
| 37 | const wsUrl = toWebSocketUrl(this.#url); |
| 38 | // Probe /health before constructing the RPC stub. capnweb's |
| 39 | // WebSocket session queues calls until the upgrade succeeds, |
| 40 | // so we'd otherwise discover a misconfigured URL only on the |
| 41 | // first RPC. The probe surfaces "harness forgot to start the |
| 42 | // container" up front. |
| 43 | await probeHealth(this.#url); |
| 44 | const client = createWorkspaceClient({ url: `${wsUrl}/ws` }); |
| 45 | return { |
| 46 | rpc: client, |
| 47 | close: async () => { |
| 48 | await client.close(); |
| 49 | }, |
| 50 | }; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | function toWebSocketUrl(input: string): string { |
| 55 | if (input.startsWith("ws://") || input.startsWith("wss://")) { |
nothing calls this directly
no outgoing calls
no test coverage detected