(
organizationId: string,
options: BuildOptions & { readonly caps?: ClientCapabilities } = {},
)
| 131 | // them connected to an in-memory MCP client. Shaped as an acquireRelease so |
| 132 | // the transport teardown is guaranteed when the test scope closes. |
| 133 | const openSession = ( |
| 134 | organizationId: string, |
| 135 | options: BuildOptions & { readonly caps?: ClientCapabilities } = {}, |
| 136 | ) => |
| 137 | Effect.acquireRelease( |
| 138 | Effect.gen(function* () { |
| 139 | const executor = yield* buildScopedExecutor(organizationId, `Org ${organizationId}`, options); |
| 140 | const engine = createExecutionEngine({ executor, codeExecutor: makeQuickJsExecutor() }); |
| 141 | const mcpServer = yield* buildMcpServer({ |
| 142 | engine, |
| 143 | appsEnabled: false, |
| 144 | requestStateSigningKey: new Uint8Array(32).fill(23), |
| 145 | requestStatePrincipal: `cloud-mcp-test:${organizationId}`, |
| 146 | sessionful: true, |
| 147 | elicitationMode: options.elicitationMode ? { mode: options.elicitationMode } : undefined, |
| 148 | }); |
| 149 | const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); |
| 150 | const client = new Client( |
| 151 | { name: "cloud-e2e-test", version: "1.0.0" }, |
| 152 | { capabilities: options.caps ?? ELICITATION_CAPS }, |
| 153 | ); |
| 154 | yield* Effect.promise(() => mcpServer.connect(serverTransport)); |
| 155 | yield* Effect.promise(() => client.connect(clientTransport)); |
| 156 | return { client, clientTransport, serverTransport }; |
| 157 | }), |
| 158 | ({ clientTransport, serverTransport }) => |
| 159 | Effect.all( |
| 160 | [ |
| 161 | Effect.tryPromise({ |
| 162 | try: () => clientTransport.close(), |
| 163 | catch: (cause) => cause, |
| 164 | }).pipe(Effect.ignore), |
| 165 | Effect.tryPromise({ |
| 166 | try: () => serverTransport.close(), |
| 167 | catch: (cause) => cause, |
| 168 | }).pipe(Effect.ignore), |
| 169 | ], |
| 170 | { discard: true }, |
| 171 | ), |
| 172 | ).pipe(Effect.map(({ client }) => ({ client }))); |
| 173 | |
| 174 | const nextOrgId = (() => { |
| 175 | let seq = 0; |
no test coverage detected