( options: MakeSelfHostTestAppOptions, )
| 178 | } |
| 179 | |
| 180 | export const makeSelfHostTestApp = async ( |
| 181 | options: MakeSelfHostTestAppOptions, |
| 182 | ): Promise<SelfHostTestHandler> => { |
| 183 | const config = loadConfig(); |
| 184 | |
| 185 | const dbHandle = await createSelfHostDb({ |
| 186 | path: options.dbPath ?? config.dbPath, |
| 187 | namespace: SELF_HOST_NAMESPACE, |
| 188 | version: SELF_HOST_SCHEMA_VERSION, |
| 189 | }); |
| 190 | |
| 191 | const sessionStore = makeSelfHostMcpSessionStore(dbHandle); |
| 192 | const pluginsProvider = options.pluginDeps |
| 193 | ? Layer.succeed(PluginsProvider)({ |
| 194 | plugins: (context) => |
| 195 | executorConfig.plugins({ |
| 196 | ...options.pluginDeps, |
| 197 | activeToolkitSlug: |
| 198 | context?.mcpResource?.kind === "toolkit" |
| 199 | ? context.mcpResource.slug |
| 200 | : options.pluginDeps?.activeToolkitSlug, |
| 201 | allowLocalNetwork: |
| 202 | options.pluginDeps?.allowLocalNetwork ?? |
| 203 | process.env.EXECUTOR_ALLOW_LOCAL_NETWORK === "true", |
| 204 | }), |
| 205 | }) |
| 206 | : SelfHostPluginsProvider; |
| 207 | |
| 208 | const { toWebHandler } = ExecutorApp.make({ |
| 209 | plugins: selfHostPlugins, |
| 210 | providers: { |
| 211 | identity: options.identity, |
| 212 | db: SelfHostDbProvider, |
| 213 | engine: { codeExecutor: SelfHostCodeExecutorProvider }, |
| 214 | mcp: { |
| 215 | auth: stubMcpAuth, |
| 216 | sessions: selfHostMcpSessions(sessionStore), |
| 217 | reporter: selfHostMcpReporter, |
| 218 | }, |
| 219 | plugins: { provider: pluginsProvider, config: SelfHostHostConfig }, |
| 220 | errorCapture: ErrorCaptureLive, |
| 221 | }, |
| 222 | extensions: { |
| 223 | routes: [ |
| 224 | HttpApiSwagger.layer(composePluginApi(selfHostPlugins).prefix("/api"), { path: "/docs" }), |
| 225 | ], |
| 226 | }, |
| 227 | config: { mountPrefix: "/api", failure: textFailureStrategy }, |
| 228 | // The test identity is boot-scoped exactly as production's is: no |
| 229 | // requestScoped layer, so the execution middleware leaves IdentityProvider |
| 230 | // residual and `provideMerge(boot)` supplies it. |
| 231 | boot: Layer.merge(Layer.succeed(SelfHostDb)(dbHandle), options.identity), |
| 232 | }); |
| 233 | |
| 234 | const web = toWebHandler(); |
| 235 | return { |
| 236 | handler: web.handler, |
| 237 | dispose: async () => { |
no test coverage detected