@powerhousedao/switchboard 6.2.3-dev.1 → 6.2.3-dev.100

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 (312) 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/redact-webhook-path.test.d.ts +2 -0
  92. package/.tsbuild/test/redact-webhook-path.test.d.ts.map +1 -0
  93. package/.tsbuild/test/renown-storage-path.test.d.ts +2 -0
  94. package/.tsbuild/test/renown-storage-path.test.d.ts.map +1 -0
  95. package/.tsbuild/test/renown-trust-policy.test.d.ts +2 -0
  96. package/.tsbuild/test/renown-trust-policy.test.d.ts.map +1 -0
  97. package/.tsbuild/test/served-schemas.test.d.ts +2 -0
  98. package/.tsbuild/test/served-schemas.test.d.ts.map +1 -0
  99. package/.tsbuild/test/shutdown.test.d.ts +2 -0
  100. package/.tsbuild/test/shutdown.test.d.ts.map +1 -0
  101. package/.tsbuild/test/snapshot-writer.d.ts +18 -0
  102. package/.tsbuild/test/snapshot-writer.d.ts.map +1 -0
  103. package/.tsbuild/test/store-lock.test.d.ts +2 -0
  104. package/.tsbuild/test/store-lock.test.d.ts.map +1 -0
  105. package/.tsbuild/test/two-switchboards.test.d.ts +2 -0
  106. package/.tsbuild/test/two-switchboards.test.d.ts.map +1 -0
  107. package/.tsbuild/test/unsupported-stored-documents.test.d.ts +2 -0
  108. package/.tsbuild/test/unsupported-stored-documents.test.d.ts.map +1 -0
  109. package/.tsbuild/test/workflow/harness.d.ts +56 -0
  110. package/.tsbuild/test/workflow/harness.d.ts.map +1 -0
  111. package/.tsbuild/test/workflow/oauth-apps-config.test.d.ts +2 -0
  112. package/.tsbuild/test/workflow/oauth-apps-config.test.d.ts.map +1 -0
  113. package/.tsbuild/test/workflow/oauth.test.d.ts +2 -0
  114. package/.tsbuild/test/workflow/oauth.test.d.ts.map +1 -0
  115. package/.tsbuild/test/workflow/resolvers.test.d.ts +2 -0
  116. package/.tsbuild/test/workflow/resolvers.test.d.ts.map +1 -0
  117. package/.tsbuild/test/workflow/runtime-host.test.d.ts +2 -0
  118. package/.tsbuild/test/workflow/runtime-host.test.d.ts.map +1 -0
  119. package/.tsbuild/test/workflow/waitpoint-routes.test.d.ts +2 -0
  120. package/.tsbuild/test/workflow/waitpoint-routes.test.d.ts.map +1 -0
  121. package/.tsbuild/test/workflow/waitpoint-runtime.test.d.ts +2 -0
  122. package/.tsbuild/test/workflow/waitpoint-runtime.test.d.ts.map +1 -0
  123. package/.tsbuild/test/workflow/webhook-dedupe.test.d.ts +2 -0
  124. package/.tsbuild/test/workflow/webhook-dedupe.test.d.ts.map +1 -0
  125. package/.tsbuild/test/workflow/webhook-signed.test.d.ts +2 -0
  126. package/.tsbuild/test/workflow/webhook-signed.test.d.ts.map +1 -0
  127. package/.tsbuild/test/workflow/webhook-trigger-test.test.d.ts +2 -0
  128. package/.tsbuild/test/workflow/webhook-trigger-test.test.d.ts.map +1 -0
  129. package/.tsbuild/test/workflow/webhook-unsigned.test.d.ts +2 -0
  130. package/.tsbuild/test/workflow/webhook-unsigned.test.d.ts.map +1 -0
  131. package/.tsbuild/test/workflow-reactor-access.test.d.ts +2 -0
  132. package/.tsbuild/test/workflow-reactor-access.test.d.ts.map +1 -0
  133. package/.tsbuild/test/workflow-reactor-enforcement.test.d.ts +2 -0
  134. package/.tsbuild/test/workflow-reactor-enforcement.test.d.ts.map +1 -0
  135. package/.tsbuild/test/workflow-read-gate.test.d.ts +2 -0
  136. package/.tsbuild/test/workflow-read-gate.test.d.ts.map +1 -0
  137. package/.tsbuild/test/workflow-runtime.test.d.ts +2 -0
  138. package/.tsbuild/test/workflow-runtime.test.d.ts.map +1 -0
  139. package/.tsbuild/test/workflows-plugin-config.test.d.ts +2 -0
  140. package/.tsbuild/test/workflows-plugin-config.test.d.ts.map +1 -0
  141. package/.tsbuild/tsconfig.tsbuildinfo +1 -1
  142. package/.tsbuild/tsdown.config.d.ts.map +1 -1
  143. package/.tsbuild/vitest.config.d.ts.map +1 -1
  144. package/Auth.md +144 -2
  145. package/CHANGELOG.md +1356 -0
  146. package/README.md +102 -22
  147. package/dist/boot.d.mts +46 -0
  148. package/dist/boot.d.mts.map +1 -0
  149. package/dist/boot.mjs +67 -0
  150. package/dist/boot.mjs.map +1 -0
  151. package/dist/config/from-env.d.mts +15 -0
  152. package/dist/config/from-env.d.mts.map +1 -0
  153. package/dist/config/from-env.mjs +4 -0
  154. package/dist/config/schema.d.mts +3 -0
  155. package/dist/config/schema.mjs +4 -0
  156. package/dist/from-env-FH4fPeIE.mjs +481 -0
  157. package/dist/from-env-FH4fPeIE.mjs.map +1 -0
  158. package/dist/index.d.mts +2 -1
  159. package/dist/index.mjs +98 -80
  160. package/dist/index.mjs.map +1 -1
  161. package/dist/install-packages.d.mts +2 -1
  162. package/dist/install-packages.mjs +2 -2
  163. package/dist/install-packages.mjs.map +1 -1
  164. package/dist/mcp-SsBK14Jm.mjs +32 -0
  165. package/dist/mcp-SsBK14Jm.mjs.map +1 -0
  166. package/dist/migrate.d.mts +2 -1
  167. package/dist/migrate.mjs +7 -5
  168. package/dist/migrate.mjs.map +1 -1
  169. package/dist/plugin-host-CK9_tVak.d.mts +46 -0
  170. package/dist/plugin-host-CK9_tVak.d.mts.map +1 -0
  171. package/dist/plugins/ai.d.mts +37 -0
  172. package/dist/plugins/ai.d.mts.map +1 -0
  173. package/dist/plugins/ai.mjs +400 -0
  174. package/dist/plugins/ai.mjs.map +1 -0
  175. package/dist/plugins/attachments.d.mts +33 -0
  176. package/dist/plugins/attachments.d.mts.map +1 -0
  177. package/dist/plugins/attachments.mjs +4 -0
  178. package/dist/plugins/mcp.d.mts +31 -0
  179. package/dist/plugins/mcp.d.mts.map +1 -0
  180. package/dist/plugins/mcp.mjs +4 -0
  181. package/dist/plugins/privacy.d.mts +22 -0
  182. package/dist/plugins/privacy.d.mts.map +1 -0
  183. package/dist/plugins/privacy.mjs +4 -0
  184. package/dist/plugins/workflows.d.mts +79 -0
  185. package/dist/plugins/workflows.d.mts.map +1 -0
  186. package/dist/plugins/workflows.mjs +4 -0
  187. package/dist/postgres-url-DTDhBjXX.mjs +11 -0
  188. package/dist/postgres-url-DTDhBjXX.mjs.map +1 -0
  189. package/dist/privacy-BO8Q25xI.mjs +44 -0
  190. package/dist/privacy-BO8Q25xI.mjs.map +1 -0
  191. package/dist/privacy-DxIJGH4P.mjs +91 -0
  192. package/dist/privacy-DxIJGH4P.mjs.map +1 -0
  193. package/dist/renown-layers-DmbWLt46.mjs +42 -0
  194. package/dist/renown-layers-DmbWLt46.mjs.map +1 -0
  195. package/dist/schema-CsY8bjsu.mjs +329 -0
  196. package/dist/schema-CsY8bjsu.mjs.map +1 -0
  197. package/dist/schema-MAUTnmj1.d.mts +251 -0
  198. package/dist/schema-MAUTnmj1.d.mts.map +1 -0
  199. package/dist/server-CirQ9hyu.mjs +2732 -0
  200. package/dist/server-CirQ9hyu.mjs.map +1 -0
  201. package/dist/server.d.mts +129 -189
  202. package/dist/server.d.mts.map +1 -1
  203. package/dist/server.mjs +5 -5
  204. package/dist/types-CidZdkhU.d.mts +314 -0
  205. package/dist/types-CidZdkhU.d.mts.map +1 -0
  206. package/dist/utils-Cm0TE6dP.mjs +148 -0
  207. package/dist/utils-Cm0TE6dP.mjs.map +1 -0
  208. package/dist/utils.d.mts +30 -5
  209. package/dist/utils.d.mts.map +1 -1
  210. package/dist/utils.mjs +5 -4
  211. package/dist/worker-pool-gyxJnCxA.mjs +304 -0
  212. package/dist/worker-pool-gyxJnCxA.mjs.map +1 -0
  213. package/dist/workflow-runtime-CF5pc8mt.d.mts +33 -0
  214. package/dist/workflow-runtime-CF5pc8mt.d.mts.map +1 -0
  215. package/dist/workflows-C9BQlyT0.mjs +1943 -0
  216. package/dist/workflows-C9BQlyT0.mjs.map +1 -0
  217. package/package.json +85 -24
  218. package/scripts/install-packages.sh +0 -0
  219. package/test/ai-gateway.test.ts +612 -0
  220. package/test/attachment-reference-read-model.test.ts +28 -20
  221. package/test/attachments/auth.test.ts +85 -0
  222. package/test/attachments/byte-grants.test.ts +290 -0
  223. package/test/attachments/byte-routes-read-gate.integration.test.ts +314 -0
  224. package/test/attachments/download-target.test.ts +211 -32
  225. package/test/attachments/index.test.ts +47 -4
  226. package/test/attachments/reserve-metadata-parity.test.ts +96 -0
  227. package/test/attachments/routes-integration.test.ts +60 -4
  228. package/test/attachments/routes.test.ts +297 -35
  229. package/test/attachments/service-config.test.ts +41 -19
  230. package/test/attachments/url-signer.test.ts +105 -0
  231. package/test/boot-auth-config.test.ts +109 -0
  232. package/test/boot-create-signature-policy.test.ts +110 -0
  233. package/test/boot-desktop-auth.test.ts +278 -0
  234. package/test/boot-env-isolation.test.ts +26 -0
  235. package/test/boot-helpers.ts +19 -0
  236. package/test/boot-inspection-enabled.test.ts +140 -0
  237. package/test/boot-mcp-auth.test.ts +449 -0
  238. package/test/boot-mcp-enabled.test.ts +119 -0
  239. package/test/boot-port-zero.test.ts +101 -0
  240. package/test/boot-preconditions.test.ts +213 -0
  241. package/test/boot-privacy.test.ts +232 -0
  242. package/test/boot-ready-drives.test.ts +141 -0
  243. package/test/boot-undo-v3-flag.test.ts +120 -0
  244. package/test/boot-unsupported-stored-documents.test.ts +214 -0
  245. package/test/boot-without-renown.test.ts +83 -0
  246. package/test/boot-without-require-signatures.test.ts +76 -0
  247. package/test/boot-worker-trust-policy.test.ts +91 -0
  248. package/test/boot-workflow-singleton-conflict.test.ts +109 -0
  249. package/test/boot-workflow-singleton-retry.test.ts +122 -0
  250. package/test/builder-defaults.test.ts +80 -0
  251. package/test/config-from-env.test.ts +963 -0
  252. package/test/config-merge.test.ts +248 -0
  253. package/test/config-schema.test.ts +167 -0
  254. package/test/create-signature-policy.test.ts +69 -0
  255. package/test/default-drive-protocol-versions.test.ts +79 -0
  256. package/test/default-drive-slug.test.ts +265 -0
  257. package/test/delegated-publish.test.ts +435 -0
  258. package/test/durable-node-fs-pg16.test.ts +80 -0
  259. package/test/fatal-shutdown.test.ts +205 -0
  260. package/test/goldens/packages.graphql +797 -0
  261. package/test/goldens/privacy.graphql +853 -0
  262. package/test/goldens/reactor-drive-nodes.graphql +827 -0
  263. package/test/goldens/resolvers.json +327 -0
  264. package/test/goldens/supergraph.graphql +5918 -0
  265. package/test/goldens/workflow-runtime.graphql +1548 -0
  266. package/test/inspection-throttle.test.ts +23 -0
  267. package/test/keyframe-reclaim-store.test.ts +156 -0
  268. package/test/observability-signals.test.ts +131 -0
  269. package/test/permissions-backfill.test.ts +486 -0
  270. package/test/pglite-dialect.test.ts +237 -2
  271. package/test/pglite-preflight.test.ts +313 -0
  272. package/test/pglite-storage-dirs.test.ts +113 -0
  273. package/test/pglite-store.test.ts +441 -0
  274. package/test/pglite-version.test.ts +9 -1
  275. package/test/plugin-config-schemas.test.ts +83 -0
  276. package/test/plugin-presence.test.ts +262 -0
  277. package/test/port-probe.test.ts +45 -0
  278. package/test/processor-timing-log.test.ts +109 -0
  279. package/test/reactor-feature-flags.test.ts +20 -0
  280. package/test/redact-webhook-path.test.ts +62 -0
  281. package/test/renown-storage-path.test.ts +40 -0
  282. package/test/renown-trust-policy.test.ts +313 -0
  283. package/test/served-schemas.test.ts +134 -0
  284. package/test/shutdown.test.ts +278 -0
  285. package/test/snapshot-writer.ts +94 -0
  286. package/test/store-lock.test.ts +65 -0
  287. package/test/two-switchboards.test.ts +146 -0
  288. package/test/unsupported-stored-documents.test.ts +72 -0
  289. package/test/worker-pool.test.ts +27 -1
  290. package/test/workflow/harness.ts +289 -0
  291. package/test/workflow/oauth-apps-config.test.ts +66 -0
  292. package/test/workflow/oauth.test.ts +286 -0
  293. package/test/workflow/resolvers.test.ts +488 -0
  294. package/test/workflow/runtime-host.test.ts +19 -0
  295. package/test/workflow/waitpoint-routes.test.ts +306 -0
  296. package/test/workflow/waitpoint-runtime.test.ts +204 -0
  297. package/test/workflow/webhook-dedupe.test.ts +295 -0
  298. package/test/workflow/webhook-signed.test.ts +509 -0
  299. package/test/workflow/webhook-trigger-test.test.ts +82 -0
  300. package/test/workflow/webhook-unsigned.test.ts +345 -0
  301. package/test/workflow-reactor-access.test.ts +384 -0
  302. package/test/workflow-reactor-enforcement.test.ts +808 -0
  303. package/test/workflow-read-gate.test.ts +213 -0
  304. package/test/workflow-runtime.test.ts +1254 -0
  305. package/test/workflows-plugin-config.test.ts +77 -0
  306. package/tsconfig.json +11 -2
  307. package/tsdown.config.ts +13 -1
  308. package/vitest.config.ts +65 -0
  309. package/dist/server-B2r6AQ4Q.mjs +0 -1553
  310. package/dist/server-B2r6AQ4Q.mjs.map +0 -1
  311. package/dist/utils-Baw7rThP.mjs +0 -80
  312. package/dist/utils-Baw7rThP.mjs.map +0 -1
@@ -0,0 +1,313 @@
1
+ import type {
2
+ ActionSigner,
3
+ ISigner,
4
+ } from "@powerhousedao/shared/document-model";
5
+ import {
6
+ ReactorBuilder,
7
+ ReactorClientBuilder,
8
+ type SignatureTrustPolicy,
9
+ } from "@powerhousedao/reactor";
10
+ import type { IRenown } from "@renown/sdk/node";
11
+ import { existsSync } from "node:fs";
12
+ import { pathToFileURL } from "node:url";
13
+ import { afterEach, describe, expect, it, vi } from "vitest";
14
+ import { workerTrustPolicyIssue } from "../src/boot-preconditions.mjs";
15
+ import { applySwitchboardReactorDefaults } from "../src/builder-defaults.mjs";
16
+ import { getRenownTrustPolicyConfig } from "../src/renown.js";
17
+
18
+ const WALLET = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266";
19
+ const CONNECT_KEY = "did:key:zDnaeConnectKey";
20
+ const SWITCHBOARD_KEY = "did:key:zDnaeSwitchboardKey";
21
+ const SWITCHBOARD_USER = {
22
+ address: "0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
23
+ networkId: "eip155",
24
+ chainId: 1,
25
+ };
26
+ const GRAPHQL = "http://renown.test/graphql";
27
+
28
+ // Signed by WALLET's Anvil dev key; its expiry is ignored by the policy.
29
+ const CREDENTIAL_ROW = {
30
+ documentId: "doc-cred",
31
+ credentialId: "urn:uuid:c7882913-68ef-48e5-9e89-f2948d2ca22c",
32
+ context: ["https://www.w3.org/2018/credentials/v1"],
33
+ type: ["VerifiableCredential", "RenownCredential"],
34
+ issuerId: "did:pkh:eip155:1:0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
35
+ issuerEthereumAddress: WALLET,
36
+ issuanceDate: "2026-09-24T00:48:25.566Z",
37
+ expirationDate: "2026-10-01T00:48:25.566Z",
38
+ credentialSubjectId: CONNECT_KEY,
39
+ credentialSubjectApp: "connect",
40
+ credentialStatusId: null,
41
+ credentialStatusType: null,
42
+ credentialSchemaId: "https://renown.id/schemas/renown-credential/v1",
43
+ credentialSchemaType: "JsonSchemaValidator2018",
44
+ proofVerificationMethod:
45
+ "did:pkh:eip155:1:0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
46
+ proofEthereumAddress: WALLET,
47
+ proofCreated: "2026-09-24T00:48:25.566Z",
48
+ proofPurpose: "assertionMethod",
49
+ proofType: "EthereumEip712Signature2021",
50
+ proofValue:
51
+ "0xe8d7a2468b9eb21286483fd88601d350ac7a8ed908506e51a34c6b119f93a7d75c6284a3f231698f6fcc8a3ad0ec5096a34811c7b6adef2d1e4146ddb22826a91c",
52
+ proofEip712Domain: JSON.stringify({ version: "1", chainId: 1 }),
53
+ proofEip712PrimaryType: "VerifiableCredential",
54
+ revoked: false,
55
+ };
56
+
57
+ function stubRenown(user: ActionSigner["user"] = SWITCHBOARD_USER): IRenown {
58
+ const signer = {
59
+ user,
60
+ app: { name: "switchboard", key: SWITCHBOARD_KEY },
61
+ } as unknown as ISigner;
62
+ return { signer } as unknown as IRenown;
63
+ }
64
+
65
+ function claim(address: string, key: string): ActionSigner {
66
+ return {
67
+ user: { address, networkId: "eip155", chainId: 1 },
68
+ app: { name: "connect", key },
69
+ signatures: [],
70
+ };
71
+ }
72
+
73
+ /** Answers the renown read model with `rows`; counts the requests. */
74
+ function mockReadModel(rows: unknown[] = [CREDENTIAL_ROW]) {
75
+ return vi.spyOn(globalThis, "fetch").mockImplementation(() =>
76
+ Promise.resolve(
77
+ new Response(JSON.stringify({ data: { renownCredentials: rows } }), {
78
+ status: 200,
79
+ }),
80
+ ),
81
+ );
82
+ }
83
+
84
+ async function remotePolicy(
85
+ renown = stubRenown(),
86
+ ): Promise<SignatureTrustPolicy> {
87
+ const { trustPolicy } = await getRenownTrustPolicyConfig(
88
+ { source: "remote", switchboardUrl: GRAPHQL },
89
+ renown,
90
+ );
91
+ return trustPolicy!;
92
+ }
93
+
94
+ describe("getRenownTrustPolicyConfig", () => {
95
+ afterEach(() => vi.restoreAllMocks());
96
+
97
+ it("accepts a key a credential binds to the claimed wallet", async () => {
98
+ const fetchMock = mockReadModel();
99
+ const policy = await remotePolicy();
100
+
101
+ await expect(
102
+ policy.authorizeSigner(claim(WALLET, CONNECT_KEY), CONNECT_KEY, "doc"),
103
+ ).resolves.toBe(true);
104
+ expect(fetchMock.mock.calls[0][0]).toBe(GRAPHQL);
105
+ });
106
+
107
+ it("refuses a mismatched address or key", async () => {
108
+ mockReadModel();
109
+ const policy = await remotePolicy();
110
+
111
+ await expect(
112
+ policy.authorizeSigner(
113
+ claim(SWITCHBOARD_USER.address, CONNECT_KEY),
114
+ CONNECT_KEY,
115
+ "doc",
116
+ ),
117
+ ).resolves.toBe(false);
118
+ await expect(
119
+ policy.authorizeSigner(
120
+ claim(WALLET, "did:key:zDnaeOther"),
121
+ "did:key:zDnaeOther",
122
+ "doc",
123
+ ),
124
+ ).resolves.toBe(false);
125
+ });
126
+
127
+ it("refuses a key no credential binds yet", async () => {
128
+ const fetchMock = mockReadModel([]);
129
+ const policy = await remotePolicy();
130
+
131
+ await expect(
132
+ policy.authorizeSigner(claim(WALLET, CONNECT_KEY), CONNECT_KEY, "doc"),
133
+ ).resolves.toBe(false);
134
+ await expect(
135
+ policy.authorizeSigner(claim(WALLET, CONNECT_KEY), CONNECT_KEY, "doc"),
136
+ ).resolves.toBe(false);
137
+ expect(fetchMock).toHaveBeenCalledTimes(1);
138
+ });
139
+
140
+ it("caches an acceptance per (address, key)", async () => {
141
+ const fetchMock = mockReadModel();
142
+ const policy = await remotePolicy();
143
+ const signer = claim(WALLET, CONNECT_KEY);
144
+
145
+ await policy.authorizeSigner(signer, CONNECT_KEY, "doc-1");
146
+ fetchMock.mockRejectedValue(new TypeError("offline"));
147
+
148
+ await expect(
149
+ policy.authorizeSigner(signer, CONNECT_KEY, "doc-2"),
150
+ ).resolves.toBe(true);
151
+ expect(fetchMock).toHaveBeenCalledTimes(1);
152
+ });
153
+
154
+ it("throws on a network failure rather than refusing", async () => {
155
+ vi.spyOn(globalThis, "fetch").mockRejectedValue(new TypeError("offline"));
156
+ const policy = await remotePolicy();
157
+
158
+ await expect(
159
+ policy.authorizeSigner(claim(WALLET, CONNECT_KEY), CONNECT_KEY, "doc"),
160
+ ).rejects.toThrow("offline");
161
+ });
162
+
163
+ it("accepts the switchboard's own key for its own user without a lookup", async () => {
164
+ const fetchMock = mockReadModel([]);
165
+ const policy = await remotePolicy();
166
+
167
+ await expect(
168
+ policy.authorizeSigner(
169
+ claim(SWITCHBOARD_USER.address, SWITCHBOARD_KEY),
170
+ SWITCHBOARD_KEY,
171
+ "doc",
172
+ ),
173
+ ).resolves.toBe(true);
174
+ expect(fetchMock).not.toHaveBeenCalled();
175
+ });
176
+
177
+ it("matches the switchboard's own key against its current user", async () => {
178
+ const fetchMock = mockReadModel([]);
179
+ const renown = stubRenown();
180
+ const policy = await remotePolicy(renown);
181
+
182
+ renown.signer.user = { address: WALLET, networkId: "eip155", chainId: 1 };
183
+
184
+ await expect(
185
+ policy.authorizeSigner(
186
+ claim(WALLET, SWITCHBOARD_KEY),
187
+ SWITCHBOARD_KEY,
188
+ "doc",
189
+ ),
190
+ ).resolves.toBe(true);
191
+ expect(fetchMock).not.toHaveBeenCalled();
192
+ await expect(
193
+ policy.authorizeSigner(
194
+ claim(SWITCHBOARD_USER.address, SWITCHBOARD_KEY),
195
+ SWITCHBOARD_KEY,
196
+ "doc",
197
+ ),
198
+ ).resolves.toBe(false);
199
+ });
200
+
201
+ it("gives pooled workers a spec that builds the same policy", async () => {
202
+ const fetchMock = mockReadModel();
203
+ const { workerTrustPolicy } = await getRenownTrustPolicyConfig(
204
+ { source: "remote", switchboardUrl: GRAPHQL },
205
+ stubRenown(),
206
+ );
207
+
208
+ const module = workerTrustPolicy!.module;
209
+ expect(module.exportName).toBe("createRenownTrustPolicy");
210
+ const filePath = "filePath" in module ? module.filePath : "";
211
+ expect(existsSync(filePath)).toBe(true);
212
+ expect(workerTrustPolicy!.initArgs).toEqual({
213
+ switchboard: GRAPHQL,
214
+ self: { key: SWITCHBOARD_KEY, user: SWITCHBOARD_USER },
215
+ });
216
+
217
+ const imported = (await import(pathToFileURL(filePath).href)) as Record<
218
+ string,
219
+ (args: unknown) => SignatureTrustPolicy
220
+ >;
221
+ const policy = imported[module.exportName](workerTrustPolicy!.initArgs);
222
+ await expect(
223
+ policy.authorizeSigner(claim(WALLET, CONNECT_KEY), CONNECT_KEY, "doc"),
224
+ ).resolves.toBe(true);
225
+ expect(fetchMock).toHaveBeenCalledTimes(1);
226
+ });
227
+
228
+ it("reads a self source in process and gives workers no spec", async () => {
229
+ const request = vi.fn(() =>
230
+ Promise.resolve({ renownCredentials: [CREDENTIAL_ROW] }),
231
+ );
232
+ const config = await getRenownTrustPolicyConfig(
233
+ { source: "self", request },
234
+ null,
235
+ );
236
+
237
+ expect(config.workerTrustPolicy).toBeUndefined();
238
+ await expect(
239
+ config.trustPolicy!.authorizeSigner(
240
+ claim(WALLET, CONNECT_KEY),
241
+ CONNECT_KEY,
242
+ "doc",
243
+ ),
244
+ ).resolves.toBe(true);
245
+ expect(request).toHaveBeenCalledTimes(1);
246
+ });
247
+ });
248
+
249
+ describe("workerTrustPolicyIssue", () => {
250
+ it("fails with workers, authEnforcement and a self source", () => {
251
+ expect(
252
+ workerTrustPolicyIssue({
253
+ workers: 2,
254
+ authEnforcement: true,
255
+ renownSource: "self",
256
+ }),
257
+ ).toMatch(
258
+ /REACTOR_WORKERS[\s\S]*REACTOR_AUTH_ENFORCEMENT[\s\S]*RENOWN_SOURCE/,
259
+ );
260
+ });
261
+
262
+ it.each([
263
+ { workers: 0, authEnforcement: true, renownSource: "self" as const },
264
+ { workers: 2, authEnforcement: false, renownSource: "self" as const },
265
+ { workers: 2, authEnforcement: true, renownSource: "remote" as const },
266
+ ])("passes %o", (config) => {
267
+ expect(workerTrustPolicyIssue(config)).toBeUndefined();
268
+ });
269
+ });
270
+
271
+ describe("applySwitchboardReactorDefaults with a trust policy", () => {
272
+ it("gives the reactor the policy and its worker spec", () => {
273
+ const reactorBuilder = new ReactorBuilder();
274
+ const withTrustPolicy = vi.spyOn(reactorBuilder, "withTrustPolicy");
275
+ const trustPolicy: SignatureTrustPolicy = {
276
+ authorizeSigner: () => Promise.resolve(true),
277
+ };
278
+ const workerTrustPolicy = {
279
+ module: { filePath: "/trust.js", exportName: "createTrustPolicy" },
280
+ };
281
+
282
+ applySwitchboardReactorDefaults(
283
+ reactorBuilder,
284
+ new ReactorClientBuilder(),
285
+ {
286
+ includeBaseModels: false,
287
+ signalHandlers: false,
288
+ trustPolicy: { trustPolicy, workerTrustPolicy },
289
+ },
290
+ );
291
+
292
+ expect(withTrustPolicy).toHaveBeenCalledWith(
293
+ trustPolicy,
294
+ workerTrustPolicy,
295
+ );
296
+ expect(reactorBuilder.hasTrustPolicy()).toBe(true);
297
+ });
298
+
299
+ it("leaves the reactor on the default without one", () => {
300
+ const reactorBuilder = new ReactorBuilder();
301
+
302
+ applySwitchboardReactorDefaults(
303
+ reactorBuilder,
304
+ new ReactorClientBuilder(),
305
+ {
306
+ includeBaseModels: false,
307
+ signalHandlers: false,
308
+ },
309
+ );
310
+
311
+ expect(reactorBuilder.hasTrustPolicy()).toBe(false);
312
+ });
313
+ });
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Regenerate after an intended change, from the repository root. Removing the
3
+ * goldens first drops those of endpoints no longer served:
4
+ *
5
+ * rm -rf packages/reactor-api/test/graphql/goldens apps/switchboard/test/goldens && \
6
+ * UPDATE_GOLDENS=1 pnpm --workspace-concurrency=1 \
7
+ * --filter @powerhousedao/reactor-api --filter @powerhousedao/switchboard \
8
+ * exec vitest run served-schemas && pnpm exec oxfmt \
9
+ * packages/reactor-api/test/graphql/goldens apps/switchboard/test/goldens
10
+ */
11
+ import {
12
+ expectSchemaGolden,
13
+ jsonGolden,
14
+ recordServedSchemas,
15
+ type ServedEndpoints,
16
+ } from "@powerhousedao/reactor-api/test";
17
+ import type { ILogger } from "document-model";
18
+ import { mkdtemp, rm, writeFile } from "node:fs/promises";
19
+ import { tmpdir } from "node:os";
20
+ import { join } from "node:path";
21
+ import { fileURLToPath } from "node:url";
22
+ import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
23
+ import type { startSwitchboard } from "../src/server.mjs";
24
+ import { bootSwitchboard } from "./boot-helpers.js";
25
+
26
+ const goldens = (file: string) =>
27
+ fileURLToPath(new URL(`./goldens/${file}`, import.meta.url));
28
+
29
+ const SUBGRAPHS = [
30
+ "packages",
31
+ "privacy",
32
+ "reactor-drive-nodes",
33
+ "workflow-runtime",
34
+ ];
35
+
36
+ const ADMIN = "0xadad00000000000000000000000000000000adad";
37
+ const SECRET = "switchboard-served-schemas-deployment-secret";
38
+
39
+ function stubLogger(): ILogger {
40
+ const logger = {
41
+ verbose: vi.fn(),
42
+ debug: vi.fn(),
43
+ info: vi.fn(),
44
+ warn: vi.fn(),
45
+ error: vi.fn(),
46
+ child: vi.fn(),
47
+ };
48
+ logger.child.mockReturnValue(logger);
49
+ return logger as unknown as ILogger;
50
+ }
51
+
52
+ const realFetch = globalThis.fetch;
53
+ let tempRoot: string;
54
+ let recorder: ReturnType<typeof recordServedSchemas> | undefined;
55
+ let switchboard: Awaited<ReturnType<typeof startSwitchboard>> | undefined;
56
+ let served: ServedEndpoints;
57
+
58
+ beforeAll(async () => {
59
+ tempRoot = await mkdtemp(join(tmpdir(), "switchboard-served-schemas-"));
60
+ const configFile = join(tempRoot, "powerhouse.config.json");
61
+ await writeFile(configFile, "{}");
62
+ // The workflow runtime reads a hard-coded cloud piece catalog at boot.
63
+ vi.stubGlobal(
64
+ "fetch",
65
+ (input: string | URL | Request, init?: RequestInit) => {
66
+ const url = new URL(input instanceof Request ? input.url : String(input));
67
+ return url.hostname === "127.0.0.1"
68
+ ? realFetch(input, init)
69
+ : Promise.reject(new Error(`${url.host} is off limits to this test`));
70
+ },
71
+ );
72
+ recorder = recordServedSchemas();
73
+ // Every switchboard subgraph on, from this config alone: no inherited env,
74
+ // config file or user data. The registry URL only turns the packages
75
+ // subgraph on, and the Renown URL keeps discovery off the network.
76
+ switchboard = await bootSwitchboard(
77
+ {
78
+ server: { port: 0 },
79
+ storage: {
80
+ reactor: { url: join(tempRoot, "reactor") },
81
+ readModel: { url: join(tempRoot, "read-model") },
82
+ userDataDir: tempRoot,
83
+ },
84
+ auth: {
85
+ enabled: true,
86
+ admins: [ADMIN],
87
+ renown: { url: "http://127.0.0.1:9" },
88
+ },
89
+ features: {
90
+ workflows: true,
91
+ mcp: false,
92
+ privacy: { enabled: true, deploymentSecret: SECRET },
93
+ },
94
+ packages: { disableLocal: true, registryUrl: "http://127.0.0.1:9" },
95
+ identity: { keypairPath: join(tempRoot, "identity.json") },
96
+ configFile,
97
+ },
98
+ { logger: stubLogger() },
99
+ {},
100
+ );
101
+ served = await recorder.read(
102
+ (request) => realFetch(request),
103
+ `http://127.0.0.1:${switchboard.port}`,
104
+ SUBGRAPHS,
105
+ );
106
+ }, 120_000);
107
+
108
+ afterAll(async () => {
109
+ try {
110
+ await switchboard?.shutdown();
111
+ } finally {
112
+ recorder?.restore();
113
+ vi.unstubAllGlobals();
114
+ await rm(tempRoot, { recursive: true, force: true });
115
+ }
116
+ });
117
+
118
+ describe("switchboard served schemas", () => {
119
+ it.each(SUBGRAPHS)("serves /graphql/%s as its golden", async (name) => {
120
+ const schema = served.subgraphs.get(name);
121
+ expect(schema, `/graphql/${name} is not served`).toBeDefined();
122
+ await expectSchemaGolden(schema!, goldens(`${name}.graphql`));
123
+ });
124
+
125
+ it("serves /graphql as supergraph.graphql", async () => {
126
+ await expectSchemaGolden(served.supergraph, goldens("supergraph.graphql"));
127
+ });
128
+
129
+ it("binds the resolvers in resolvers.json", async () => {
130
+ expect(served.resolvers).toEqual(
131
+ await jsonGolden(goldens("resolvers.json"), served.resolvers),
132
+ );
133
+ });
134
+ });