( options: MakeSelfHostTestAppOptions, )
| 200 | } |
| 201 | |
| 202 | export const makeSelfHostTestApp = async ( |
| 203 | options: MakeSelfHostTestAppOptions, |
| 204 | ): Promise<SelfHostTestHandler> => { |
| 205 | const config = loadConfig(); |
| 206 | |
| 207 | const dbHandle = await createSelfHostDb({ |
| 208 | path: options.dbPath ?? config.dbPath, |
| 209 | namespace: SELF_HOST_NAMESPACE, |
| 210 | version: SELF_HOST_SCHEMA_VERSION, |
| 211 | }); |
| 212 | |
| 213 | const sessionStore = makeSelfHostMcpSessionStore(dbHandle); |
| 214 | const pluginsProvider = options.pluginDeps |
| 215 | ? Layer.succeed(PluginsProvider)({ |
| 216 | plugins: (context) => |
| 217 | executorConfig.plugins({ |
| 218 | ...options.pluginDeps, |
| 219 | activeToolkitSlug: |
| 220 | context?.mcpResource?.kind === "toolkit" |
| 221 | ? context.mcpResource.slug |
| 222 | : options.pluginDeps?.activeToolkitSlug, |
| 223 | allowLocalNetwork: |
| 224 | options.pluginDeps?.allowLocalNetwork ?? |
| 225 | process.env.EXECUTOR_ALLOW_LOCAL_NETWORK === "true", |
| 226 | }), |
| 227 | }) |
| 228 | : SelfHostPluginsProvider; |
| 229 | |
| 230 | const { toWebHandler } = ExecutorApp.make({ |
| 231 | plugins: selfHostPlugins, |
| 232 | providers: { |
| 233 | identity: options.identity, |
| 234 | db: SelfHostDbProvider, |
| 235 | engine: { codeExecutor: SelfHostCodeExecutorProvider }, |
| 236 | mcp: { |
| 237 | auth: stubMcpAuth, |
| 238 | sessions: selfHostMcpSessions(sessionStore), |
| 239 | reporter: selfHostMcpReporter, |
| 240 | }, |
| 241 | plugins: { provider: pluginsProvider, config: SelfHostHostConfig }, |
| 242 | errorCapture: ErrorCaptureLive, |
| 243 | }, |
| 244 | extensions: { |
| 245 | routes: [ |
| 246 | HttpApiSwagger.layer(composePluginApi(selfHostPlugins).prefix("/api"), { path: "/docs" }), |
| 247 | ], |
| 248 | }, |
| 249 | config: { mountPrefix: "/api", failure: textFailureStrategy }, |
| 250 | // The test identity is boot-scoped exactly as production's is: no |
| 251 | // requestScoped layer, so the execution middleware leaves IdentityProvider |
| 252 | // residual and `provideMerge(boot)` supplies it. |
| 253 | boot: Layer.merge(Layer.succeed(SelfHostDb)(dbHandle), options.identity), |
| 254 | }); |
| 255 | |
| 256 | const web = toWebHandler(); |
| 257 | return { |
| 258 | handler: web.handler, |
| 259 | dispose: async () => { |
no test coverage detected