@powerhousedao/switchboard 6.2.3-dev.10 → 6.2.3-dev.101

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (310) hide show
  1. package/.tsbuild/test/ai-gateway.test.d.ts +2 -0
  2. package/.tsbuild/test/ai-gateway.test.d.ts.map +1 -0
  3. package/.tsbuild/test/attachments/byte-grants.test.d.ts +2 -0
  4. package/.tsbuild/test/attachments/byte-grants.test.d.ts.map +1 -0
  5. package/.tsbuild/test/attachments/byte-routes-read-gate.integration.test.d.ts +2 -0
  6. package/.tsbuild/test/attachments/byte-routes-read-gate.integration.test.d.ts.map +1 -0
  7. package/.tsbuild/test/attachments/reserve-metadata-parity.test.d.ts +2 -0
  8. package/.tsbuild/test/attachments/reserve-metadata-parity.test.d.ts.map +1 -0
  9. package/.tsbuild/test/attachments/url-signer.test.d.ts +2 -0
  10. package/.tsbuild/test/attachments/url-signer.test.d.ts.map +1 -0
  11. package/.tsbuild/test/boot-auth-config.test.d.ts +2 -0
  12. package/.tsbuild/test/boot-auth-config.test.d.ts.map +1 -0
  13. package/.tsbuild/test/boot-create-signature-policy.test.d.ts +2 -0
  14. package/.tsbuild/test/boot-create-signature-policy.test.d.ts.map +1 -0
  15. package/.tsbuild/test/boot-desktop-auth.test.d.ts +2 -0
  16. package/.tsbuild/test/boot-desktop-auth.test.d.ts.map +1 -0
  17. package/.tsbuild/test/boot-env-isolation.test.d.ts +2 -0
  18. package/.tsbuild/test/boot-env-isolation.test.d.ts.map +1 -0
  19. package/.tsbuild/test/boot-helpers.d.ts +5 -0
  20. package/.tsbuild/test/boot-helpers.d.ts.map +1 -0
  21. package/.tsbuild/test/boot-inspection-enabled.test.d.ts +2 -0
  22. package/.tsbuild/test/boot-inspection-enabled.test.d.ts.map +1 -0
  23. package/.tsbuild/test/boot-mcp-auth.test.d.ts +2 -0
  24. package/.tsbuild/test/boot-mcp-auth.test.d.ts.map +1 -0
  25. package/.tsbuild/test/boot-mcp-enabled.test.d.ts +2 -0
  26. package/.tsbuild/test/boot-mcp-enabled.test.d.ts.map +1 -0
  27. package/.tsbuild/test/boot-port-zero.test.d.ts +2 -0
  28. package/.tsbuild/test/boot-port-zero.test.d.ts.map +1 -0
  29. package/.tsbuild/test/boot-preconditions.test.d.ts +2 -0
  30. package/.tsbuild/test/boot-preconditions.test.d.ts.map +1 -0
  31. package/.tsbuild/test/boot-privacy.test.d.ts +2 -0
  32. package/.tsbuild/test/boot-privacy.test.d.ts.map +1 -0
  33. package/.tsbuild/test/boot-ready-drives.test.d.ts +2 -0
  34. package/.tsbuild/test/boot-ready-drives.test.d.ts.map +1 -0
  35. package/.tsbuild/test/boot-undo-v3-flag.test.d.ts +2 -0
  36. package/.tsbuild/test/boot-undo-v3-flag.test.d.ts.map +1 -0
  37. package/.tsbuild/test/boot-unsupported-stored-documents.test.d.ts +2 -0
  38. package/.tsbuild/test/boot-unsupported-stored-documents.test.d.ts.map +1 -0
  39. package/.tsbuild/test/boot-without-renown.test.d.ts +2 -0
  40. package/.tsbuild/test/boot-without-renown.test.d.ts.map +1 -0
  41. package/.tsbuild/test/boot-without-require-signatures.test.d.ts +2 -0
  42. package/.tsbuild/test/boot-without-require-signatures.test.d.ts.map +1 -0
  43. package/.tsbuild/test/boot-worker-trust-policy.test.d.ts +2 -0
  44. package/.tsbuild/test/boot-worker-trust-policy.test.d.ts.map +1 -0
  45. package/.tsbuild/test/boot-workflow-singleton-conflict.test.d.ts +2 -0
  46. package/.tsbuild/test/boot-workflow-singleton-conflict.test.d.ts.map +1 -0
  47. package/.tsbuild/test/boot-workflow-singleton-retry.test.d.ts +2 -0
  48. package/.tsbuild/test/boot-workflow-singleton-retry.test.d.ts.map +1 -0
  49. package/.tsbuild/test/builder-defaults.test.d.ts +2 -0
  50. package/.tsbuild/test/builder-defaults.test.d.ts.map +1 -0
  51. package/.tsbuild/test/config-from-env.test.d.ts +2 -0
  52. package/.tsbuild/test/config-from-env.test.d.ts.map +1 -0
  53. package/.tsbuild/test/config-merge.test.d.ts +2 -0
  54. package/.tsbuild/test/config-merge.test.d.ts.map +1 -0
  55. package/.tsbuild/test/config-schema.test.d.ts +2 -0
  56. package/.tsbuild/test/config-schema.test.d.ts.map +1 -0
  57. package/.tsbuild/test/create-signature-policy.test.d.ts +2 -0
  58. package/.tsbuild/test/create-signature-policy.test.d.ts.map +1 -0
  59. package/.tsbuild/test/default-drive-protocol-versions.test.d.ts +2 -0
  60. package/.tsbuild/test/default-drive-protocol-versions.test.d.ts.map +1 -0
  61. package/.tsbuild/test/default-drive-slug.test.d.ts +2 -0
  62. package/.tsbuild/test/default-drive-slug.test.d.ts.map +1 -0
  63. package/.tsbuild/test/delegated-publish.test.d.ts +2 -0
  64. package/.tsbuild/test/delegated-publish.test.d.ts.map +1 -0
  65. package/.tsbuild/test/durable-node-fs-pg16.test.d.ts +2 -0
  66. package/.tsbuild/test/durable-node-fs-pg16.test.d.ts.map +1 -0
  67. package/.tsbuild/test/fatal-shutdown.test.d.ts +2 -0
  68. package/.tsbuild/test/fatal-shutdown.test.d.ts.map +1 -0
  69. package/.tsbuild/test/inspection-throttle.test.d.ts +2 -0
  70. package/.tsbuild/test/inspection-throttle.test.d.ts.map +1 -0
  71. package/.tsbuild/test/keyframe-reclaim-store.test.d.ts +2 -0
  72. package/.tsbuild/test/keyframe-reclaim-store.test.d.ts.map +1 -0
  73. package/.tsbuild/test/observability-signals.test.d.ts +2 -0
  74. package/.tsbuild/test/observability-signals.test.d.ts.map +1 -0
  75. package/.tsbuild/test/permissions-backfill.test.d.ts +2 -0
  76. package/.tsbuild/test/permissions-backfill.test.d.ts.map +1 -0
  77. package/.tsbuild/test/pglite-preflight.test.d.ts +2 -0
  78. package/.tsbuild/test/pglite-preflight.test.d.ts.map +1 -0
  79. package/.tsbuild/test/pglite-storage-dirs.test.d.ts +2 -0
  80. package/.tsbuild/test/pglite-storage-dirs.test.d.ts.map +1 -0
  81. package/.tsbuild/test/pglite-store.test.d.ts +2 -0
  82. package/.tsbuild/test/pglite-store.test.d.ts.map +1 -0
  83. package/.tsbuild/test/plugin-config-schemas.test.d.ts +2 -0
  84. package/.tsbuild/test/plugin-config-schemas.test.d.ts.map +1 -0
  85. package/.tsbuild/test/plugin-presence.test.d.ts +2 -0
  86. package/.tsbuild/test/plugin-presence.test.d.ts.map +1 -0
  87. package/.tsbuild/test/port-probe.test.d.ts +2 -0
  88. package/.tsbuild/test/port-probe.test.d.ts.map +1 -0
  89. package/.tsbuild/test/processor-timing-log.test.d.ts +2 -0
  90. package/.tsbuild/test/processor-timing-log.test.d.ts.map +1 -0
  91. package/.tsbuild/test/renown-storage-path.test.d.ts +2 -0
  92. package/.tsbuild/test/renown-storage-path.test.d.ts.map +1 -0
  93. package/.tsbuild/test/renown-trust-policy.test.d.ts +2 -0
  94. package/.tsbuild/test/renown-trust-policy.test.d.ts.map +1 -0
  95. package/.tsbuild/test/served-schemas.test.d.ts +2 -0
  96. package/.tsbuild/test/served-schemas.test.d.ts.map +1 -0
  97. package/.tsbuild/test/shutdown.test.d.ts +2 -0
  98. package/.tsbuild/test/shutdown.test.d.ts.map +1 -0
  99. package/.tsbuild/test/snapshot-writer.d.ts +18 -0
  100. package/.tsbuild/test/snapshot-writer.d.ts.map +1 -0
  101. package/.tsbuild/test/store-lock.test.d.ts +2 -0
  102. package/.tsbuild/test/store-lock.test.d.ts.map +1 -0
  103. package/.tsbuild/test/two-switchboards.test.d.ts +2 -0
  104. package/.tsbuild/test/two-switchboards.test.d.ts.map +1 -0
  105. package/.tsbuild/test/unsupported-stored-documents.test.d.ts +2 -0
  106. package/.tsbuild/test/unsupported-stored-documents.test.d.ts.map +1 -0
  107. package/.tsbuild/test/workflow/harness.d.ts +56 -0
  108. package/.tsbuild/test/workflow/harness.d.ts.map +1 -0
  109. package/.tsbuild/test/workflow/oauth-apps-config.test.d.ts +2 -0
  110. package/.tsbuild/test/workflow/oauth-apps-config.test.d.ts.map +1 -0
  111. package/.tsbuild/test/workflow/oauth.test.d.ts +2 -0
  112. package/.tsbuild/test/workflow/oauth.test.d.ts.map +1 -0
  113. package/.tsbuild/test/workflow/resolvers.test.d.ts +2 -0
  114. package/.tsbuild/test/workflow/resolvers.test.d.ts.map +1 -0
  115. package/.tsbuild/test/workflow/runtime-host.test.d.ts +2 -0
  116. package/.tsbuild/test/workflow/runtime-host.test.d.ts.map +1 -0
  117. package/.tsbuild/test/workflow/waitpoint-routes.test.d.ts +2 -0
  118. package/.tsbuild/test/workflow/waitpoint-routes.test.d.ts.map +1 -0
  119. package/.tsbuild/test/workflow/waitpoint-runtime.test.d.ts +2 -0
  120. package/.tsbuild/test/workflow/waitpoint-runtime.test.d.ts.map +1 -0
  121. package/.tsbuild/test/workflow/webhook-dedupe.test.d.ts +2 -0
  122. package/.tsbuild/test/workflow/webhook-dedupe.test.d.ts.map +1 -0
  123. package/.tsbuild/test/workflow/webhook-signed.test.d.ts +2 -0
  124. package/.tsbuild/test/workflow/webhook-signed.test.d.ts.map +1 -0
  125. package/.tsbuild/test/workflow/webhook-trigger-test.test.d.ts +2 -0
  126. package/.tsbuild/test/workflow/webhook-trigger-test.test.d.ts.map +1 -0
  127. package/.tsbuild/test/workflow/webhook-unsigned.test.d.ts +2 -0
  128. package/.tsbuild/test/workflow/webhook-unsigned.test.d.ts.map +1 -0
  129. package/.tsbuild/test/workflow-reactor-access.test.d.ts +2 -0
  130. package/.tsbuild/test/workflow-reactor-access.test.d.ts.map +1 -0
  131. package/.tsbuild/test/workflow-reactor-enforcement.test.d.ts +2 -0
  132. package/.tsbuild/test/workflow-reactor-enforcement.test.d.ts.map +1 -0
  133. package/.tsbuild/test/workflow-read-gate.test.d.ts +2 -0
  134. package/.tsbuild/test/workflow-read-gate.test.d.ts.map +1 -0
  135. package/.tsbuild/test/workflow-runtime.test.d.ts +2 -0
  136. package/.tsbuild/test/workflow-runtime.test.d.ts.map +1 -0
  137. package/.tsbuild/test/workflows-plugin-config.test.d.ts +2 -0
  138. package/.tsbuild/test/workflows-plugin-config.test.d.ts.map +1 -0
  139. package/.tsbuild/tsconfig.tsbuildinfo +1 -1
  140. package/.tsbuild/tsdown.config.d.ts.map +1 -1
  141. package/.tsbuild/vitest.config.d.ts.map +1 -1
  142. package/Auth.md +144 -2
  143. package/CHANGELOG.md +1299 -0
  144. package/README.md +102 -22
  145. package/dist/boot.d.mts +46 -0
  146. package/dist/boot.d.mts.map +1 -0
  147. package/dist/boot.mjs +67 -0
  148. package/dist/boot.mjs.map +1 -0
  149. package/dist/config/from-env.d.mts +15 -0
  150. package/dist/config/from-env.d.mts.map +1 -0
  151. package/dist/config/from-env.mjs +4 -0
  152. package/dist/config/schema.d.mts +3 -0
  153. package/dist/config/schema.mjs +4 -0
  154. package/dist/from-env-FH4fPeIE.mjs +481 -0
  155. package/dist/from-env-FH4fPeIE.mjs.map +1 -0
  156. package/dist/index.d.mts +2 -1
  157. package/dist/index.mjs +84 -84
  158. package/dist/index.mjs.map +1 -1
  159. package/dist/install-packages.d.mts +2 -1
  160. package/dist/install-packages.mjs +2 -2
  161. package/dist/install-packages.mjs.map +1 -1
  162. package/dist/mcp-SsBK14Jm.mjs +32 -0
  163. package/dist/mcp-SsBK14Jm.mjs.map +1 -0
  164. package/dist/migrate.d.mts +2 -1
  165. package/dist/migrate.mjs +7 -5
  166. package/dist/migrate.mjs.map +1 -1
  167. package/dist/plugin-host-CK9_tVak.d.mts +46 -0
  168. package/dist/plugin-host-CK9_tVak.d.mts.map +1 -0
  169. package/dist/plugins/ai.d.mts +37 -0
  170. package/dist/plugins/ai.d.mts.map +1 -0
  171. package/dist/plugins/ai.mjs +400 -0
  172. package/dist/plugins/ai.mjs.map +1 -0
  173. package/dist/plugins/attachments.d.mts +33 -0
  174. package/dist/plugins/attachments.d.mts.map +1 -0
  175. package/dist/plugins/attachments.mjs +4 -0
  176. package/dist/plugins/mcp.d.mts +31 -0
  177. package/dist/plugins/mcp.d.mts.map +1 -0
  178. package/dist/plugins/mcp.mjs +4 -0
  179. package/dist/plugins/privacy.d.mts +22 -0
  180. package/dist/plugins/privacy.d.mts.map +1 -0
  181. package/dist/plugins/privacy.mjs +4 -0
  182. package/dist/plugins/workflows.d.mts +79 -0
  183. package/dist/plugins/workflows.d.mts.map +1 -0
  184. package/dist/plugins/workflows.mjs +4 -0
  185. package/dist/postgres-url-DTDhBjXX.mjs +11 -0
  186. package/dist/postgres-url-DTDhBjXX.mjs.map +1 -0
  187. package/dist/privacy-BO8Q25xI.mjs +44 -0
  188. package/dist/privacy-BO8Q25xI.mjs.map +1 -0
  189. package/dist/privacy-DxIJGH4P.mjs +91 -0
  190. package/dist/privacy-DxIJGH4P.mjs.map +1 -0
  191. package/dist/renown-layers-DmbWLt46.mjs +42 -0
  192. package/dist/renown-layers-DmbWLt46.mjs.map +1 -0
  193. package/dist/schema-CsY8bjsu.mjs +329 -0
  194. package/dist/schema-CsY8bjsu.mjs.map +1 -0
  195. package/dist/schema-MAUTnmj1.d.mts +251 -0
  196. package/dist/schema-MAUTnmj1.d.mts.map +1 -0
  197. package/dist/server-CirQ9hyu.mjs +2732 -0
  198. package/dist/server-CirQ9hyu.mjs.map +1 -0
  199. package/dist/server.d.mts +129 -189
  200. package/dist/server.d.mts.map +1 -1
  201. package/dist/server.mjs +5 -5
  202. package/dist/types-CidZdkhU.d.mts +314 -0
  203. package/dist/types-CidZdkhU.d.mts.map +1 -0
  204. package/dist/utils-Cm0TE6dP.mjs +148 -0
  205. package/dist/utils-Cm0TE6dP.mjs.map +1 -0
  206. package/dist/utils.d.mts +30 -5
  207. package/dist/utils.d.mts.map +1 -1
  208. package/dist/utils.mjs +5 -4
  209. package/dist/worker-pool-gyxJnCxA.mjs +304 -0
  210. package/dist/worker-pool-gyxJnCxA.mjs.map +1 -0
  211. package/dist/workflow-runtime-CF5pc8mt.d.mts +33 -0
  212. package/dist/workflow-runtime-CF5pc8mt.d.mts.map +1 -0
  213. package/dist/workflows-C9BQlyT0.mjs +1943 -0
  214. package/dist/workflows-C9BQlyT0.mjs.map +1 -0
  215. package/package.json +85 -24
  216. package/scripts/install-packages.sh +0 -0
  217. package/test/ai-gateway.test.ts +612 -0
  218. package/test/attachment-reference-read-model.test.ts +28 -20
  219. package/test/attachments/auth.test.ts +85 -0
  220. package/test/attachments/byte-grants.test.ts +290 -0
  221. package/test/attachments/byte-routes-read-gate.integration.test.ts +314 -0
  222. package/test/attachments/download-target.test.ts +211 -32
  223. package/test/attachments/index.test.ts +47 -4
  224. package/test/attachments/reserve-metadata-parity.test.ts +96 -0
  225. package/test/attachments/routes-integration.test.ts +60 -4
  226. package/test/attachments/routes.test.ts +297 -35
  227. package/test/attachments/service-config.test.ts +41 -19
  228. package/test/attachments/url-signer.test.ts +105 -0
  229. package/test/boot-auth-config.test.ts +109 -0
  230. package/test/boot-create-signature-policy.test.ts +110 -0
  231. package/test/boot-desktop-auth.test.ts +278 -0
  232. package/test/boot-env-isolation.test.ts +26 -0
  233. package/test/boot-helpers.ts +19 -0
  234. package/test/boot-inspection-enabled.test.ts +140 -0
  235. package/test/boot-mcp-auth.test.ts +449 -0
  236. package/test/boot-mcp-enabled.test.ts +119 -0
  237. package/test/boot-port-zero.test.ts +101 -0
  238. package/test/boot-preconditions.test.ts +213 -0
  239. package/test/boot-privacy.test.ts +232 -0
  240. package/test/boot-ready-drives.test.ts +141 -0
  241. package/test/boot-undo-v3-flag.test.ts +120 -0
  242. package/test/boot-unsupported-stored-documents.test.ts +214 -0
  243. package/test/boot-without-renown.test.ts +83 -0
  244. package/test/boot-without-require-signatures.test.ts +76 -0
  245. package/test/boot-worker-trust-policy.test.ts +91 -0
  246. package/test/boot-workflow-singleton-conflict.test.ts +109 -0
  247. package/test/boot-workflow-singleton-retry.test.ts +122 -0
  248. package/test/builder-defaults.test.ts +80 -0
  249. package/test/config-from-env.test.ts +963 -0
  250. package/test/config-merge.test.ts +248 -0
  251. package/test/config-schema.test.ts +167 -0
  252. package/test/create-signature-policy.test.ts +69 -0
  253. package/test/default-drive-protocol-versions.test.ts +79 -0
  254. package/test/default-drive-slug.test.ts +265 -0
  255. package/test/delegated-publish.test.ts +435 -0
  256. package/test/durable-node-fs-pg16.test.ts +80 -0
  257. package/test/fatal-shutdown.test.ts +205 -0
  258. package/test/goldens/packages.graphql +797 -0
  259. package/test/goldens/privacy.graphql +853 -0
  260. package/test/goldens/reactor-drive-nodes.graphql +827 -0
  261. package/test/goldens/resolvers.json +327 -0
  262. package/test/goldens/supergraph.graphql +5918 -0
  263. package/test/goldens/workflow-runtime.graphql +1548 -0
  264. package/test/inspection-throttle.test.ts +23 -0
  265. package/test/keyframe-reclaim-store.test.ts +156 -0
  266. package/test/observability-signals.test.ts +131 -0
  267. package/test/permissions-backfill.test.ts +486 -0
  268. package/test/pglite-dialect.test.ts +237 -2
  269. package/test/pglite-preflight.test.ts +313 -0
  270. package/test/pglite-storage-dirs.test.ts +113 -0
  271. package/test/pglite-store.test.ts +441 -0
  272. package/test/pglite-version.test.ts +9 -1
  273. package/test/plugin-config-schemas.test.ts +83 -0
  274. package/test/plugin-presence.test.ts +262 -0
  275. package/test/port-probe.test.ts +45 -0
  276. package/test/processor-timing-log.test.ts +109 -0
  277. package/test/reactor-feature-flags.test.ts +20 -0
  278. package/test/redact-webhook-path.test.ts +9 -0
  279. package/test/renown-storage-path.test.ts +40 -0
  280. package/test/renown-trust-policy.test.ts +313 -0
  281. package/test/served-schemas.test.ts +134 -0
  282. package/test/shutdown.test.ts +278 -0
  283. package/test/snapshot-writer.ts +94 -0
  284. package/test/store-lock.test.ts +65 -0
  285. package/test/two-switchboards.test.ts +146 -0
  286. package/test/unsupported-stored-documents.test.ts +72 -0
  287. package/test/worker-pool.test.ts +27 -1
  288. package/test/workflow/harness.ts +289 -0
  289. package/test/workflow/oauth-apps-config.test.ts +66 -0
  290. package/test/workflow/oauth.test.ts +286 -0
  291. package/test/workflow/resolvers.test.ts +488 -0
  292. package/test/workflow/runtime-host.test.ts +19 -0
  293. package/test/workflow/waitpoint-routes.test.ts +306 -0
  294. package/test/workflow/waitpoint-runtime.test.ts +204 -0
  295. package/test/workflow/webhook-dedupe.test.ts +295 -0
  296. package/test/workflow/webhook-signed.test.ts +509 -0
  297. package/test/workflow/webhook-trigger-test.test.ts +82 -0
  298. package/test/workflow/webhook-unsigned.test.ts +345 -0
  299. package/test/workflow-reactor-access.test.ts +384 -0
  300. package/test/workflow-reactor-enforcement.test.ts +808 -0
  301. package/test/workflow-read-gate.test.ts +213 -0
  302. package/test/workflow-runtime.test.ts +1254 -0
  303. package/test/workflows-plugin-config.test.ts +77 -0
  304. package/tsconfig.json +11 -2
  305. package/tsdown.config.ts +13 -1
  306. package/vitest.config.ts +66 -1
  307. package/dist/server-CiKkVE6g.mjs +0 -1555
  308. package/dist/server-CiKkVE6g.mjs.map +0 -1
  309. package/dist/utils-Baw7rThP.mjs +0 -80
  310. package/dist/utils-Baw7rThP.mjs.map +0 -1
@@ -0,0 +1,612 @@
1
+ // The AI gateway on a booted Switchboard: real did:key bearers, the real
2
+ // encrypted secret store, and a stub provider that records what it was sent
3
+ // and echoes the credentials back wherever a careless proxy would repeat them.
4
+ import { randomBytes } from "node:crypto";
5
+ import { mkdtemp, rm, writeFile } from "node:fs/promises";
6
+ import {
7
+ createServer,
8
+ type IncomingMessage,
9
+ type Server,
10
+ type ServerResponse,
11
+ } from "node:http";
12
+ import type { AddressInfo } from "node:net";
13
+ import { tmpdir } from "node:os";
14
+ import { join } from "node:path";
15
+ import type { HostPlugin, ResolvedPlugin } from "@powerhousedao/host-core";
16
+ import { MemoryKeyStorage, RenownCryptoBuilder } from "@renown/sdk/node";
17
+ import type { ILogger } from "document-model";
18
+ import {
19
+ afterAll,
20
+ afterEach,
21
+ beforeAll,
22
+ describe,
23
+ expect,
24
+ it,
25
+ vi,
26
+ } from "vitest";
27
+ import { maskKey } from "../src/ai/key-store.mjs";
28
+ import { redactSecrets } from "../src/ai/routes.mjs";
29
+ import { createAiPlugin } from "../src/plugins/ai.mjs";
30
+ import { workflowsPlugin } from "../src/plugins/workflows.mjs";
31
+ import type { SwitchboardReactor } from "../src/types.js";
32
+ import { bootSwitchboard } from "./boot-helpers.js";
33
+
34
+ const ADMIN = "0x1111111111111111111111111111111111111111";
35
+ const USER = "0x2222222222222222222222222222222222222222";
36
+ const KEY = `sk-or-v1-${randomBytes(24).toString("hex")}`;
37
+ const OTHER_KEY = `sk-or-v1-${randomBytes(24).toString("hex")}`;
38
+ const BAD_KEY = `sk-or-v1-${randomBytes(24).toString("hex")}`;
39
+ const DEMO_KEY = `sk-or-v1-${randomBytes(24).toString("hex")}`;
40
+ const DEFAULT_MODEL = "qwen/test-vision";
41
+ const MODELS = { data: [{ id: DEFAULT_MODEL }, { id: "qwen/other" }] };
42
+ const GATEWAY = "/api/@powerhousedao/switchboard/ai";
43
+
44
+ const ENV_KEYS = [
45
+ "PH_REACTOR_DATABASE_URL",
46
+ "PH_WORKFLOWS_SECRETS_MASTER_KEY",
47
+ "MCP_ENABLED",
48
+ "FEATURE_PLUGIN_HOST_ENABLED",
49
+ "AUTH_ENABLED",
50
+ "ADMINS",
51
+ "RESOLVE_CALLER_IDENTITY",
52
+ "SKIP_CREDENTIAL_VERIFICATION",
53
+ ] as const;
54
+
55
+ const logger = {
56
+ verbose: vi.fn(),
57
+ debug: vi.fn(),
58
+ info: vi.fn(),
59
+ warn: vi.fn(),
60
+ error: vi.fn(),
61
+ child: () => logger,
62
+ };
63
+
64
+ type Seen = { path: string; authorization?: string; body: string };
65
+ type Stub = (req: IncomingMessage, res: ServerResponse, seen: Seen) => void;
66
+
67
+ const seen: Seen[] = [];
68
+ let answerChat: Stub | undefined;
69
+ let chatClosed: Promise<void> | undefined;
70
+
71
+ /** Echoes the credential in the body, as a careless upstream error might. */
72
+ function echoRefusal(
73
+ res: ServerResponse,
74
+ status: number,
75
+ authorization: string | undefined,
76
+ ) {
77
+ res.statusCode = status;
78
+ res.setHeader("content-type", "application/json");
79
+ res.end(
80
+ JSON.stringify({
81
+ error: { message: `Refused ${authorization ?? ""}`, code: "refused" },
82
+ }),
83
+ );
84
+ }
85
+
86
+ function stubProvider(req: IncomingMessage, res: ServerResponse): void {
87
+ const chunks: Buffer[] = [];
88
+ req.on("data", (chunk: Buffer) => chunks.push(chunk));
89
+ req.on("end", () => {
90
+ const entry: Seen = {
91
+ path: req.url ?? "",
92
+ authorization: req.headers.authorization,
93
+ body: Buffer.concat(chunks).toString("utf8"),
94
+ };
95
+ seen.push(entry);
96
+ if (req.url === "/key") {
97
+ if (req.headers.authorization === `Bearer ${BAD_KEY}`) {
98
+ echoRefusal(res, 401, req.headers.authorization);
99
+ return;
100
+ }
101
+ res.setHeader("content-type", "application/json");
102
+ res.end(JSON.stringify({ data: { label: "stub" } }));
103
+ return;
104
+ }
105
+ if (req.url === "/models") {
106
+ res.setHeader("content-type", "application/json");
107
+ res.end(JSON.stringify(MODELS));
108
+ return;
109
+ }
110
+ if (answerChat) {
111
+ answerChat(req, res, entry);
112
+ return;
113
+ }
114
+ res.setHeader("content-type", "text/event-stream");
115
+ res.end('data: {"choices":[]}\n\ndata: [DONE]\n\n');
116
+ });
117
+ }
118
+
119
+ let tempRoot = "";
120
+ let previous: [string, string | undefined][] = [];
121
+ let switchboard: SwitchboardReactor | undefined;
122
+ let provider: Server;
123
+ const tokens: Record<string, string> = {};
124
+ const consoleLines: string[] = [];
125
+
126
+ const resolved = (plugin: HostPlugin, module: string): ResolvedPlugin => ({
127
+ plugin,
128
+ provenance: "built-in",
129
+ entry: { enabled: true, verbs: "*", config: {}, module },
130
+ });
131
+
132
+ async function bearerFor(address: string): Promise<string> {
133
+ const crypto = await new RenownCryptoBuilder()
134
+ .withKeyPairStorage(new MemoryKeyStorage())
135
+ .build();
136
+ return crypto.getBearerToken(address);
137
+ }
138
+
139
+ type Caller = typeof ADMIN | typeof USER | "anonymous";
140
+
141
+ function call(
142
+ caller: Caller,
143
+ path: string,
144
+ init: { method?: string; body?: string; signal?: AbortSignal } = {},
145
+ ): Promise<Response> {
146
+ return fetch(`http://127.0.0.1:${switchboard!.port}${GATEWAY}${path}`, {
147
+ ...init,
148
+ headers: {
149
+ "content-type": "application/json",
150
+ ...(caller === "anonymous"
151
+ ? {}
152
+ : { authorization: `Bearer ${tokens[caller]}` }),
153
+ },
154
+ });
155
+ }
156
+
157
+ const setKey = (value: string) =>
158
+ call(ADMIN, "/key", { method: "PUT", body: JSON.stringify({ value }) });
159
+
160
+ const chat = (body: unknown, signal?: AbortSignal) =>
161
+ call(ADMIN, "/v1/chat/completions", {
162
+ method: "POST",
163
+ body: JSON.stringify(body),
164
+ signal,
165
+ });
166
+
167
+ const lastChat = () => seen.findLast((s) => s.path === "/chat/completions")!;
168
+
169
+ beforeAll(async () => {
170
+ provider = createServer(stubProvider);
171
+ await new Promise<void>((resolve) =>
172
+ provider.listen(0, "127.0.0.1", resolve),
173
+ );
174
+ const upstreamUrl = `http://127.0.0.1:${(provider.address() as AddressInfo).port}`;
175
+
176
+ tempRoot = await mkdtemp(join(tmpdir(), "switchboard-ai-gateway-"));
177
+ previous = ENV_KEYS.map((name) => [name, process.env[name]]);
178
+ for (const name of ENV_KEYS) delete process.env[name];
179
+ process.env.PH_REACTOR_DATABASE_URL = join(tempRoot, "reactor-storage");
180
+ process.env.PH_WORKFLOWS_SECRETS_MASTER_KEY = randomBytes(32).toString("hex");
181
+ process.env.FEATURE_PLUGIN_HOST_ENABLED = "1";
182
+ const configFile = join(tempRoot, "powerhouse.config.json");
183
+ await writeFile(
184
+ configFile,
185
+ JSON.stringify({ ai: { demoKeyFile: "./demo-key.txt" } }),
186
+ );
187
+ await writeFile(join(tempRoot, "demo-key.txt"), `${DEMO_KEY}\n`);
188
+
189
+ for (const method of ["log", "info", "warn", "error"] as const) {
190
+ vi.spyOn(console, method).mockImplementation((...args: unknown[]) => {
191
+ consoleLines.push(args.map(String).join(" "));
192
+ });
193
+ }
194
+
195
+ switchboard = await bootSwitchboard(
196
+ {
197
+ configFile,
198
+ server: { port: 0 },
199
+ storage: { readModel: { url: join(tempRoot, "read-model") } },
200
+ features: { workflows: true, mcp: false },
201
+ packages: { disableLocal: true },
202
+ identity: { keypairPath: join(tempRoot, "identity.json") },
203
+ auth: {
204
+ enabled: true,
205
+ admins: [ADMIN],
206
+ skipCredentialVerification: true,
207
+ renown: { switchboardUrl: "http://127.0.0.1:9/graphql" },
208
+ },
209
+ },
210
+ {
211
+ logger: logger as unknown as ILogger,
212
+ pluginComposition: [
213
+ resolved(
214
+ workflowsPlugin as HostPlugin,
215
+ "@powerhousedao/switchboard/plugins/workflows",
216
+ ),
217
+ resolved(
218
+ createAiPlugin({
219
+ defaultModel: DEFAULT_MODEL,
220
+ maxOutputTokens: 1000,
221
+ upstreamUrl,
222
+ }) as HostPlugin,
223
+ "@powerhousedao/switchboard/plugins/ai",
224
+ ),
225
+ ],
226
+ },
227
+ );
228
+
229
+ tokens[ADMIN] = await bearerFor(ADMIN);
230
+ tokens[USER] = await bearerFor(USER);
231
+ }, 120_000);
232
+
233
+ afterAll(async () => {
234
+ await switchboard?.shutdown();
235
+ await new Promise((resolve) => provider.close(resolve));
236
+ vi.restoreAllMocks();
237
+ for (const [name, value] of previous) {
238
+ if (value === undefined) delete process.env[name];
239
+ else process.env[name] = value;
240
+ }
241
+ await rm(tempRoot, { recursive: true, force: true });
242
+ }, 60_000);
243
+
244
+ afterEach(() => {
245
+ answerChat = undefined;
246
+ chatClosed = undefined;
247
+ });
248
+
249
+ describe("the gateway on a signed-in host", () => {
250
+ it("answers only admins, on every route", async () => {
251
+ const routes: [string, string][] = [
252
+ ["GET", "/status"],
253
+ ["PUT", "/key"],
254
+ ["PUT", "/key/demo"],
255
+ ["DELETE", "/key"],
256
+ ["PUT", "/model"],
257
+ ["GET", "/v1/models"],
258
+ ["POST", "/v1/chat/completions"],
259
+ ];
260
+ for (const [method, path] of routes) {
261
+ const body = method === "GET" ? undefined : "{}";
262
+ const anonymous = await call("anonymous", path, { method, body });
263
+ expect([method, path, anonymous.status]).toEqual([method, path, 401]);
264
+ const user = await call(USER, path, { method, body });
265
+ expect([method, path, user.status]).toEqual([method, path, 403]);
266
+ }
267
+ });
268
+
269
+ it("reports not configured, and the chat refuses until a key is set", async () => {
270
+ const status = await call(ADMIN, "/status");
271
+ expect(status.status).toBe(200);
272
+ expect(await status.json()).toEqual({
273
+ configured: false,
274
+ keyHint: null,
275
+ keySetBy: null,
276
+ keySetAt: null,
277
+ model: DEFAULT_MODEL,
278
+ demoKeyAvailable: true,
279
+ });
280
+ const refused = await chat({ messages: [] });
281
+ expect(refused.status).toBe(503);
282
+ expect(await refused.text()).toContain("not_configured");
283
+ });
284
+
285
+ it("does not store a key the provider refuses, nor repeat it", async () => {
286
+ const answer = await setKey(BAD_KEY);
287
+ expect(answer.status).toBe(400);
288
+ expect(await answer.text()).not.toContain(BAD_KEY);
289
+ const status = (await (await call(ADMIN, "/status")).json()) as {
290
+ configured: boolean;
291
+ };
292
+ expect(status.configured).toBe(false);
293
+ });
294
+
295
+ it("does not repeat a malformed body that holds a key", async () => {
296
+ const answer = await call(ADMIN, "/key", {
297
+ method: "PUT",
298
+ body: `${BAD_KEY} is not JSON`,
299
+ });
300
+ expect(answer.status).toBe(400);
301
+ expect(await answer.text()).not.toContain(BAD_KEY);
302
+ });
303
+
304
+ it("stores a key the provider accepts and shows only a hint", async () => {
305
+ const answer = await setKey(KEY);
306
+ expect(answer.status).toBe(200);
307
+ const text = await answer.text();
308
+ expect(text).not.toContain(KEY);
309
+ const status = JSON.parse(text) as Record<string, unknown>;
310
+ expect(status).toMatchObject({
311
+ configured: true,
312
+ keyHint: `sk-or-v1-…${KEY.slice(-4)}`,
313
+ keySetBy: ADMIN,
314
+ model: DEFAULT_MODEL,
315
+ });
316
+ expect(seen.at(-1)).toMatchObject({
317
+ path: "/key",
318
+ authorization: `Bearer ${KEY}`,
319
+ });
320
+ });
321
+
322
+ it("keeps the working key when a replacement is refused", async () => {
323
+ expect((await setKey(BAD_KEY)).status).toBe(400);
324
+ const status = (await (await call(ADMIN, "/status")).json()) as {
325
+ keyHint: string;
326
+ };
327
+ expect(status.keyHint).toContain(KEY.slice(-4));
328
+ });
329
+
330
+ it("forwards a chat with the stored key, the host's model and capped tokens", async () => {
331
+ const answer = await chat({
332
+ model: "someone/expensive",
333
+ provider: { order: ["x"] },
334
+ max_tokens: 999_999,
335
+ stream: true,
336
+ messages: [
337
+ {
338
+ role: "user",
339
+ content: [
340
+ { type: "text", text: "What is this?" },
341
+ {
342
+ type: "image_url",
343
+ image_url: { url: "data:image/png;base64,AAAA" },
344
+ },
345
+ ],
346
+ },
347
+ ],
348
+ });
349
+ expect(answer.status).toBe(200);
350
+ expect(answer.headers.get("content-type")).toContain("text/event-stream");
351
+ await answer.text();
352
+
353
+ const forwarded = lastChat();
354
+ expect(forwarded.authorization).toBe(`Bearer ${KEY}`);
355
+ const body = JSON.parse(forwarded.body) as Record<string, unknown>;
356
+ expect(body.model).toBe(DEFAULT_MODEL);
357
+ expect(body.max_tokens).toBe(1000);
358
+ expect(body.provider).toBeUndefined();
359
+ expect(JSON.stringify(body.messages)).toContain(
360
+ "data:image/png;base64,AAAA",
361
+ );
362
+ });
363
+
364
+ it("streams the answer through as it is produced", async () => {
365
+ let finish = () => {};
366
+ const finishing = new Promise<void>((resolve) => {
367
+ finish = resolve;
368
+ });
369
+ answerChat = (_req, res) => {
370
+ res.setHeader("content-type", "text/event-stream");
371
+ res.write("data: first\n\n");
372
+ void finishing.then(() => res.end("data: second\n\n"));
373
+ };
374
+ const answer = await chat({ messages: [], stream: true });
375
+ const reader = (answer.body as ReadableStream<Uint8Array>).getReader();
376
+ const first = await reader.read();
377
+ // The first event arrived while the provider is still holding the rest.
378
+ expect(new TextDecoder().decode(first.value)).toContain("first");
379
+ finish();
380
+ let rest = "";
381
+ for (;;) {
382
+ const next = await reader.read();
383
+ if (next.done) break;
384
+ rest += new TextDecoder().decode(next.value);
385
+ }
386
+ expect(rest).toContain("second");
387
+ });
388
+
389
+ it("stops the provider's call when the client goes away", async () => {
390
+ chatClosed = new Promise<void>((resolve) => {
391
+ answerChat = (_req, res) => {
392
+ res.setHeader("content-type", "text/event-stream");
393
+ res.write("data: first\n\n");
394
+ res.on("close", resolve);
395
+ };
396
+ });
397
+ const controller = new AbortController();
398
+ const answer = await chat(
399
+ { messages: [], stream: true },
400
+ controller.signal,
401
+ );
402
+ await answer.body!.getReader().read();
403
+ controller.abort();
404
+ await chatClosed;
405
+ });
406
+
407
+ it("keeps the provider's status but never echoes the key from an error", async () => {
408
+ answerChat = (req, res) => echoRefusal(res, 429, req.headers.authorization);
409
+ const answer = await chat({ messages: [] });
410
+ expect(answer.status).toBe(429);
411
+ const text = await answer.text();
412
+ expect(text).toContain("Refused");
413
+ expect(text).not.toContain(KEY);
414
+ });
415
+
416
+ it("does not pass on an error body that is not JSON", async () => {
417
+ answerChat = (req, res) => {
418
+ res.statusCode = 500;
419
+ res.end(`upstream trace, headers: ${req.headers.authorization}`);
420
+ };
421
+ const answer = await chat({ messages: [] });
422
+ expect(answer.status).toBe(500);
423
+ expect(await answer.text()).not.toContain(KEY);
424
+ });
425
+
426
+ it("lists the provider's models", async () => {
427
+ const answer = await call(ADMIN, "/v1/models");
428
+ expect(answer.status).toBe(200);
429
+ expect(await answer.json()).toEqual(MODELS);
430
+ });
431
+
432
+ it("takes only a model the provider has, and chats with it", async () => {
433
+ const unknown = await call(ADMIN, "/model", {
434
+ method: "PUT",
435
+ body: JSON.stringify({ model: "nobody/nothing" }),
436
+ });
437
+ expect(unknown.status).toBe(400);
438
+
439
+ const known = await call(ADMIN, "/model", {
440
+ method: "PUT",
441
+ body: JSON.stringify({ model: "qwen/other" }),
442
+ });
443
+ expect(known.status).toBe(200);
444
+ expect(await known.json()).toMatchObject({ model: "qwen/other" });
445
+
446
+ await (await chat({ messages: [] })).text();
447
+ expect(JSON.parse(lastChat().body)).toMatchObject({ model: "qwen/other" });
448
+ });
449
+
450
+ it("rotates on a second set, so the old key stops being used", async () => {
451
+ expect((await setKey(OTHER_KEY)).status).toBe(200);
452
+ await (await chat({ messages: [] })).text();
453
+ expect(lastChat().authorization).toBe(`Bearer ${OTHER_KEY}`);
454
+ });
455
+
456
+ it("forgets the key on reset", async () => {
457
+ const answer = await call(ADMIN, "/key", { method: "DELETE" });
458
+ expect(answer.status).toBe(200);
459
+ expect(await answer.json()).toMatchObject({
460
+ configured: false,
461
+ keyHint: null,
462
+ });
463
+ expect((await chat({ messages: [] })).status).toBe(503);
464
+ });
465
+
466
+ it("logged no key at any point", () => {
467
+ const logged = [
468
+ ...consoleLines,
469
+ ...[logger.debug, logger.info, logger.warn, logger.error].flatMap((fn) =>
470
+ fn.mock.calls.map((args) => JSON.stringify(args)),
471
+ ),
472
+ ].join("\n");
473
+ expect(logged.length).toBeGreaterThan(0);
474
+ for (const key of [KEY, OTHER_KEY, BAD_KEY]) {
475
+ expect(logged).not.toContain(key);
476
+ }
477
+ });
478
+ });
479
+
480
+ describe("the demo key", () => {
481
+ const demoFile = () => join(tempRoot, "demo-key.txt");
482
+ const useDemoKey = () => call(ADMIN, "/key/demo", { method: "PUT" });
483
+ const status = async () =>
484
+ (await (await call(ADMIN, "/status")).json()) as {
485
+ demoKeyAvailable: boolean;
486
+ keyHint: string;
487
+ };
488
+
489
+ afterEach(async () => {
490
+ await writeFile(demoFile(), DEMO_KEY);
491
+ await setKey(KEY);
492
+ });
493
+
494
+ it("is tested and stored like any key, and never reaches the browser", async () => {
495
+ const answer = await useDemoKey();
496
+ const text = await answer.text();
497
+
498
+ expect(answer.status).toBe(200);
499
+ expect(text).not.toContain(DEMO_KEY);
500
+ expect(seen.at(-1)).toMatchObject({
501
+ path: "/key",
502
+ authorization: `Bearer ${DEMO_KEY}`,
503
+ });
504
+ expect((await status()).keyHint).toContain(DEMO_KEY.slice(-4));
505
+ await chat({ messages: [] });
506
+ expect(lastChat().authorization).toBe(`Bearer ${DEMO_KEY}`);
507
+ });
508
+
509
+ it("keeps the working key when the provider refuses it", async () => {
510
+ await writeFile(demoFile(), BAD_KEY);
511
+
512
+ const answer = await useDemoKey();
513
+
514
+ expect(answer.status).toBe(400);
515
+ expect(await answer.text()).not.toContain(BAD_KEY);
516
+ expect((await status()).keyHint).toContain(KEY.slice(-4));
517
+ });
518
+
519
+ it("isn't offered when the file has gone", async () => {
520
+ await rm(demoFile());
521
+
522
+ expect((await status()).demoKeyAvailable).toBe(false);
523
+ expect((await useDemoKey()).status).toBe(404);
524
+ });
525
+ });
526
+
527
+ describe("the plugin's mount", () => {
528
+ const fakeContext = (policy: string) => {
529
+ const route = vi.fn();
530
+ const warn = vi.fn();
531
+ return {
532
+ route,
533
+ warn,
534
+ ctx: {
535
+ logger: { warn },
536
+ options: {},
537
+ renown: null,
538
+ contributions: {},
539
+ api: {
540
+ authorizationService: {
541
+ config: { policy },
542
+ isSupremeAdmin: () => true,
543
+ },
544
+ httpRoutes: { scopeFor: () => ({ route }) },
545
+ },
546
+ } as never,
547
+ };
548
+ };
549
+
550
+ it("stays off without sign-in, where everyone would be an admin", () => {
551
+ const { ctx, route, warn } = fakeContext("OPEN");
552
+ createAiPlugin({ defaultModel: "m" }).hooks?.onHttpMounting?.(ctx);
553
+ expect(route).not.toHaveBeenCalled();
554
+ expect(warn).toHaveBeenCalledOnce();
555
+ });
556
+
557
+ it("mounts without sign-in only when told to", () => {
558
+ const { ctx, route } = fakeContext("OPEN");
559
+ createAiPlugin({
560
+ defaultModel: "m",
561
+ allowWithoutAuth: true,
562
+ }).hooks?.onHttpMounting?.(ctx);
563
+ expect(route).toHaveBeenCalled();
564
+ });
565
+
566
+ it("answers 503 while the workflow runtime is absent", async () => {
567
+ const { ctx, route } = fakeContext("ADMIN_ONLY");
568
+ createAiPlugin({ defaultModel: "m" }).hooks?.onHttpMounting?.(ctx);
569
+ const status = route.mock.calls
570
+ .map(
571
+ ([spec]) =>
572
+ spec as {
573
+ method: string;
574
+ path: string;
575
+ handler: (r: Request, c: unknown) => Promise<Response>;
576
+ },
577
+ )
578
+ .find((spec) => spec.path === "ai/status")!;
579
+ const answer = await status.handler(
580
+ new Request("http://localhost/status"),
581
+ {},
582
+ );
583
+ expect(answer.status).toBe(503);
584
+ });
585
+
586
+ it("requires a default model and rejects a typo'd key", () => {
587
+ expect(() => createAiPlugin({})).toThrow();
588
+ expect(() => createAiPlugin({ defaultModel: "m", modle: "x" })).toThrow();
589
+ });
590
+ });
591
+
592
+ describe("masking", () => {
593
+ it("keeps the provider prefix and the last four", () => {
594
+ expect(maskKey("sk-or-v1-0123456789abcdef0123456789abcd")).toBe(
595
+ "sk-or-v1-…abcd",
596
+ );
597
+ });
598
+
599
+ it("shows no tail of a short value", () => {
600
+ expect(maskKey("sk-or-v1-abcd")).toBe("sk-or-v1-…");
601
+ expect(maskKey("short")).toBe("…");
602
+ });
603
+
604
+ it("removes the key and anything shaped like one", () => {
605
+ expect(
606
+ redactSecrets(
607
+ "a Bearer xyz b sk-or-v1-aaaabbbbcccc c opaque d",
608
+ "opaque",
609
+ ),
610
+ ).toBe("a Bearer [redacted] b [redacted] c [redacted] d");
611
+ });
612
+ });
@@ -35,7 +35,8 @@ import {
35
35
  registerAttachmentReferenceReadModelOnModule,
36
36
  } from "../src/attachment-reference-read-model.mjs";
37
37
  import { applySwitchboardReactorDefaults } from "../src/builder-defaults.mjs";
38
- import { startSwitchboard } from "../src/server.mjs";
38
+ import type { startSwitchboard } from "../src/server.mjs";
39
+ import { bootSwitchboard } from "./boot-helpers.js";
39
40
 
40
41
  const REF_A = `attachment://v1:${"a".repeat(64)}` as const;
41
42
  const REF_B = `attachment://v1:${"b".repeat(64)}` as const;
@@ -155,15 +156,16 @@ describe("Switchboard attachment-reference read model registration", () => {
155
156
  let switchboard: Awaited<ReturnType<typeof startSwitchboard>> | undefined;
156
157
 
157
158
  try {
158
- switchboard = await startSwitchboard({
159
- reactor: callerModule,
160
- dbPath: readModelPath,
161
- port: 0,
162
- mcp: false,
163
- disableLocalPackages: true,
164
- identity: { keypairPath: join(tempRoot, "identity.json") },
165
- logger,
166
- });
159
+ switchboard = await bootSwitchboard(
160
+ {
161
+ server: { port: 0 },
162
+ storage: { readModel: { url: readModelPath } },
163
+ features: { mcp: false },
164
+ packages: { disableLocal: true },
165
+ identity: { keypairPath: join(tempRoot, "identity.json") },
166
+ },
167
+ { reactor: callerModule, logger },
168
+ );
167
169
 
168
170
  expect(switchboard.reactor).toBe(callerModule.client);
169
171
  expect(switchboard.attachmentReferenceProjection).toEqual({
@@ -232,6 +234,8 @@ describe("Switchboard attachment-reference read model registration", () => {
232
234
  writtenOrdinals.push(...references.map(({ ordinal }) => ordinal));
233
235
  await attachmentReferenceIndex.store.addReferences(references);
234
236
  },
237
+ removeDocuments: (documentIds) =>
238
+ attachmentReferenceIndex.store.removeDocuments(documentIds),
235
239
  };
236
240
 
237
241
  const coordinator =
@@ -283,7 +287,10 @@ describe("Switchboard attachment-reference read model registration", () => {
283
287
  .withReadModelCoordinator(customCoordinator)
284
288
  .buildModule();
285
289
  const addReferences = vi.fn();
286
- const writer = { addReferences } as IAttachmentReferenceWriter;
290
+ const writer: IAttachmentReferenceWriter = {
291
+ addReferences,
292
+ removeDocuments: vi.fn(),
293
+ };
287
294
 
288
295
  await expect(
289
296
  registerAttachmentReferenceReadModelOnModule(
@@ -327,15 +334,16 @@ describe("Switchboard attachment-reference read model registration", () => {
327
334
  let switchboard: Awaited<ReturnType<typeof startSwitchboard>> | undefined;
328
335
 
329
336
  try {
330
- switchboard = await startSwitchboard({
331
- reactor: callerModule,
332
- dbPath: join(tempRoot, "read-model"),
333
- port: 0,
334
- mcp: false,
335
- disableLocalPackages: true,
336
- identity: { keypairPath: join(tempRoot, "identity.json") },
337
- logger: stubLogger(),
338
- });
337
+ switchboard = await bootSwitchboard(
338
+ {
339
+ server: { port: 0 },
340
+ storage: { readModel: { url: join(tempRoot, "read-model") } },
341
+ features: { mcp: false },
342
+ packages: { disableLocal: true },
343
+ identity: { keypairPath: join(tempRoot, "identity.json") },
344
+ },
345
+ { reactor: callerModule, logger: stubLogger() },
346
+ );
339
347
 
340
348
  expect(switchboard.reactor).toBe(callerModule.client);
341
349
  expect(switchboard.attachmentReferenceProjection).toEqual({