MCPcopy Create free account
hub / github.com/cloudflare/computer / TestBackend

Class TestBackend

packages/computer/src/backends/test.ts:26–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24}
25
26export 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
54function toWebSocketUrl(input: string): string {
55 if (input.startsWith("ws://") || input.startsWith("wss://")) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected