(token: string)
| 80 | * test seam where a test wants to bypass the boot graph. |
| 81 | */ |
| 82 | export const makeLocalApiHandler = async (token: string): Promise<LocalApiHandler> => { |
| 83 | const { executor, plugins } = await getExecutorBundle(); |
| 84 | |
| 85 | // Build the fixed-execution seam ONCE (one executor + one engine). The same |
| 86 | // Layer is the `fixedExecution` seam declaration AND lives in `boot` so the |
| 87 | // fixed middleware's residual `FixedExecutionProvider` resolves there — exactly |
| 88 | // as self-host declares `db: SelfHostDbProvider` and puts the handle in `boot`. |
| 89 | const fixedExecution = localFixedExecutionLayer(executor); |
| 90 | |
| 91 | // The authoritative identity gate for the typed `/api`: validates the boot |
| 92 | // bearer token and resolves the one local Principal. The Bun shell |
| 93 | // (`serve.ts`) fast-path-rejects unauthenticated requests with the same token. |
| 94 | const identity = makeLocalIdentityLayer(token); |
| 95 | |
| 96 | const { toWebHandler } = ExecutorApp.make({ |
| 97 | plugins, |
| 98 | providers: { |
| 99 | // Single-user: validates the boot bearer token and resolves the one local |
| 100 | // Principal. Boot-scoped (`RIdentity = never`), captured once. |
| 101 | identity, |
| 102 | // The ONE boot executor + engine, served directly — local's fixed |
| 103 | // execution model (no per-request scoped-executor rebuild). |
| 104 | fixedExecution, |
| 105 | // account omitted (local has no account API). |
| 106 | // mcp omitted (local's /mcp is its own in-process surface in serve.ts). |
| 107 | errorCapture: ErrorCaptureLive, |
| 108 | }, |
| 109 | extensions: { |
| 110 | // Swagger UI at /docs, over the root-mounted spec (matches the served |
| 111 | // paths — local serves the API at root; the Bun shell strips `/api`). |
| 112 | routes: [HttpApiSwagger.layer(composePluginApi(plugins), { path: "/docs" })], |
| 113 | }, |
| 114 | // No mountPrefix: local serves the typed API at root and the Bun shell |
| 115 | // strips the `/api` prefix before dispatching here. Local renders identity |
| 116 | // failures as text (matching self-host); the single-user provider never |
| 117 | // produces one in practice. |
| 118 | config: { failure: textFailureStrategy }, |
| 119 | // The boot-scoped context provideMerge'd under everything: the identity |
| 120 | // provider (captured once by the fixed-execution middleware) + the fixed |
| 121 | // execution seam (the one executor + engine + extension map). |
| 122 | boot: Layer.merge(identity, fixedExecution), |
| 123 | }); |
| 124 | |
| 125 | const web = toWebHandler(); |
| 126 | return { handler: web.handler, dispose: web.dispose }; |
| 127 | }; |
no test coverage detected