@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,262 @@
1
+ import { mkdtemp, rm } from "node:fs/promises";
2
+ import { tmpdir } from "node:os";
3
+ import { join } from "node:path";
4
+ import type { HostPlugin, ResolvedPlugin } from "@powerhousedao/host-core";
5
+ import type { ILogger } from "document-model";
6
+ import { describe, expect, it, vi } from "vitest";
7
+ import {
8
+ builtinSwitchboardPlugins,
9
+ createSwitchboardPluginHost,
10
+ } from "../src/plugin-host.mjs";
11
+ import type { SwitchboardConfigInput } from "../src/config/schema.js";
12
+ import type { startSwitchboard, SwitchboardDeps } from "../src/server.mjs";
13
+ import { bootSwitchboard } from "./boot-helpers.js";
14
+
15
+ function stubLogger(): ILogger {
16
+ const logger = {
17
+ verbose: vi.fn(),
18
+ debug: vi.fn(),
19
+ info: vi.fn(),
20
+ warn: vi.fn(),
21
+ error: vi.fn(),
22
+ child: vi.fn(),
23
+ };
24
+ logger.child.mockReturnValue(logger);
25
+ return logger as unknown as ILogger;
26
+ }
27
+
28
+ /**
29
+ * Boots with FEATURE_PLUGIN_HOST_ENABLED=1, sandboxing the env exactly like
30
+ * boot-mcp-enabled.test.ts: temp PH_REACTOR_DATABASE_URL, MCP_ENABLED cleared
31
+ * so it never leaks into the plugin-host composition under test, and every
32
+ * touched env var restored in `finally`. Workflows stay off by default here
33
+ * — case 5 below covers workflow presence on its own, lighter path.
34
+ */
35
+ async function withPluginHostSwitchboard(
36
+ override: { config?: SwitchboardConfigInput; deps?: SwitchboardDeps },
37
+ run: (
38
+ switchboard: Awaited<ReturnType<typeof startSwitchboard>>,
39
+ ) => Promise<void>,
40
+ ): Promise<void> {
41
+ const tempRoot = await mkdtemp(
42
+ join(tmpdir(), "switchboard-plugin-presence-"),
43
+ );
44
+ const names = [
45
+ "PH_REACTOR_DATABASE_URL",
46
+ "MCP_ENABLED",
47
+ "FEATURE_PLUGIN_HOST_ENABLED",
48
+ ];
49
+ const previous = names.map((name) => [name, process.env[name]] as const);
50
+ process.env.PH_REACTOR_DATABASE_URL = join(tempRoot, "reactor-storage");
51
+ delete process.env.MCP_ENABLED;
52
+ process.env.FEATURE_PLUGIN_HOST_ENABLED = "1";
53
+ let switchboard: Awaited<ReturnType<typeof startSwitchboard>> | undefined;
54
+
55
+ try {
56
+ switchboard = await bootSwitchboard(
57
+ {
58
+ server: { port: 0 },
59
+ storage: { readModel: { url: join(tempRoot, "read-model") } },
60
+ features: { workflows: false, ...override.config?.features },
61
+ packages: { disableLocal: true },
62
+ identity: { keypairPath: join(tempRoot, "identity.json") },
63
+ drive: {
64
+ slug: "default-drive",
65
+ global: { name: "Default Drive" },
66
+ },
67
+ },
68
+ { logger: stubLogger(), ...override.deps },
69
+ );
70
+ await run(switchboard);
71
+ await switchboard.shutdown();
72
+ switchboard = undefined;
73
+ } finally {
74
+ await switchboard?.shutdown();
75
+ for (const [name, value] of previous) {
76
+ if (value === undefined) {
77
+ delete process.env[name];
78
+ } else {
79
+ process.env[name] = value;
80
+ }
81
+ }
82
+ await rm(tempRoot, { recursive: true, force: true });
83
+ }
84
+ }
85
+
86
+ async function postMcp(port: number): Promise<number> {
87
+ const response = await fetch(`http://127.0.0.1:${port}/mcp`, {
88
+ method: "POST",
89
+ headers: {
90
+ "content-type": "application/json",
91
+ accept: "application/json, text/event-stream",
92
+ },
93
+ body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "ping" }),
94
+ });
95
+ await response.body?.cancel();
96
+ return response.status;
97
+ }
98
+
99
+ async function getReservation(port: number): Promise<number> {
100
+ const response = await fetch(
101
+ `http://127.0.0.1:${port}/attachments/reservations/does-not-matter`,
102
+ );
103
+ await response.body?.cancel();
104
+ return response.status;
105
+ }
106
+
107
+ describe("plugin-host composition presence (FEATURE_PLUGIN_HOST_ENABLED)", () => {
108
+ it("DEFAULT composition: mcp mounted, attachments present", async () => {
109
+ await withPluginHostSwitchboard({}, async (switchboard) => {
110
+ expect(switchboard.mcpEnabled).toBe(true);
111
+ expect(await postMcp(switchboard.port)).not.toBe(404);
112
+ expect(switchboard.attachmentService).toBeDefined();
113
+ });
114
+ }, 60_000);
115
+
116
+ it("EMPTY composition ([]): attachments absent", async () => {
117
+ await withPluginHostSwitchboard(
118
+ { deps: { pluginComposition: [] } },
119
+ async (switchboard) => {
120
+ expect(switchboard.attachmentService).toBeUndefined();
121
+ expect(await getReservation(switchboard.port)).toBe(404);
122
+ },
123
+ );
124
+ }, 60_000);
125
+
126
+ // Presence is activation (R2.6c fix): flag-on, startSwitchboard skips the
127
+ // classic mcp/workflows resolvers and initServer normalizes unset values to
128
+ // OFF after transformServerOptions — an absent plugin actually deactivates
129
+ // its subsystem.
130
+ it("EMPTY composition ([]): /mcp does not mount — presence is activation", async () => {
131
+ await withPluginHostSwitchboard(
132
+ { deps: { pluginComposition: [] } },
133
+ async (switchboard) => {
134
+ expect(switchboard.mcpEnabled).toBe(false);
135
+ expect(await postMcp(switchboard.port)).toBe(404);
136
+ },
137
+ );
138
+ }, 60_000);
139
+
140
+ it("SUBSET composition (mcp only): mcp mounted, attachments absent", async () => {
141
+ const mcpOnly = builtinSwitchboardPlugins().filter((resolved) =>
142
+ resolved.entry.module.includes("/plugins/mcp"),
143
+ );
144
+ expect(mcpOnly).toHaveLength(1);
145
+ await withPluginHostSwitchboard(
146
+ { deps: { pluginComposition: mcpOnly } },
147
+ async (switchboard) => {
148
+ expect(switchboard.mcpEnabled).toBe(true);
149
+ expect(await postMcp(switchboard.port)).not.toBe(404);
150
+ expect(switchboard.attachmentService).toBeUndefined();
151
+ expect(await getReservation(switchboard.port)).toBe(404);
152
+ },
153
+ );
154
+ }, 60_000);
155
+
156
+ it("an explicit mcp: false option still wins over the default composition", async () => {
157
+ await withPluginHostSwitchboard(
158
+ { config: { features: { mcp: false } } },
159
+ async (switchboard) => {
160
+ expect(switchboard.mcpEnabled).toBe(false);
161
+ expect(await postMcp(switchboard.port)).toBe(404);
162
+ },
163
+ );
164
+ }, 60_000);
165
+ });
166
+
167
+ describe("plugin-host workflows presence (transformServerOptions)", () => {
168
+ // A real boot's workflows.enabled is resolved classically (env/config,
169
+ // default OFF) in startSwitchboard BEFORE the plugin host is even
170
+ // constructed (server.mts resolveWorkflowsEnabled ~line 1545, pluginHost
171
+ // gate at ~line 407) — by the time the workflows plugin's
172
+ // transformServerOptions hook runs, options.workflows.enabled is already a
173
+ // definite boolean, so its "unless explicit false" short-circuit can never
174
+ // observe an "unset" value through that path. Exercising the hook directly
175
+ // against createSwitchboardPluginHost, as suggested as a fallback, is the
176
+ // only way to observe the plugin's own force-true behavior in isolation —
177
+ // see the suspected-bug note in the final report.
178
+ it("forces workflows.enabled true when the plugin is present, leaves it alone when absent", async () => {
179
+ const withWorkflowsPlugin = createSwitchboardPluginHost(
180
+ { logger: stubLogger(), options: {}, renown: null },
181
+ builtinSwitchboardPlugins(),
182
+ );
183
+ const resolvedWith = await withWorkflowsPlugin.transformOptions<
184
+ Record<string, unknown>
185
+ >({});
186
+ expect(
187
+ (resolvedWith.workflows as { enabled?: boolean } | undefined)?.enabled,
188
+ ).toBe(true);
189
+
190
+ const withoutAnyPlugin = createSwitchboardPluginHost(
191
+ { logger: stubLogger(), options: {}, renown: null },
192
+ [],
193
+ );
194
+ const resolvedWithout = await withoutAnyPlugin.transformOptions<
195
+ Record<string, unknown>
196
+ >({});
197
+ expect(resolvedWithout.workflows).toBeUndefined();
198
+ });
199
+
200
+ it("still honors an explicit workflows.enabled: false even with the plugin present", async () => {
201
+ const host = createSwitchboardPluginHost(
202
+ { logger: stubLogger(), options: {}, renown: null },
203
+ builtinSwitchboardPlugins(),
204
+ );
205
+ const resolved = await host.transformOptions<Record<string, unknown>>({
206
+ workflows: { enabled: false },
207
+ });
208
+ expect(
209
+ (resolved.workflows as { enabled?: boolean } | undefined)?.enabled,
210
+ ).toBe(false);
211
+ });
212
+ });
213
+
214
+ describe("plugin-host onShutdown ordering (runObserveHookSequential)", () => {
215
+ it("runs onShutdown sequentially, in registration order — not by whichever finishes first", async () => {
216
+ const order: string[] = [];
217
+
218
+ function fakePlugin(name: string, delayMs: number): HostPlugin {
219
+ return {
220
+ name,
221
+ appliesTo: "switchboard",
222
+ hooks: {
223
+ onShutdown: async () => {
224
+ if (delayMs > 0) {
225
+ await new Promise((resolve) => setTimeout(resolve, delayMs));
226
+ }
227
+ order.push(name);
228
+ },
229
+ },
230
+ };
231
+ }
232
+
233
+ function resolvedFake(plugin: HostPlugin): ResolvedPlugin {
234
+ return {
235
+ plugin,
236
+ provenance: "local",
237
+ entry: {
238
+ module: `fake:${plugin.name}`,
239
+ enabled: true,
240
+ verbs: "*",
241
+ config: {},
242
+ },
243
+ };
244
+ }
245
+
246
+ // Registered first but slower: if onShutdown ran in parallel (the way
247
+ // the other hook moments do, via Promise.all in runObserveHook), "b"
248
+ // would resolve first and the recorded order would be ["b", "a"].
249
+ // Sequential execution must still record registration order, ["a", "b"].
250
+ const first = fakePlugin("a", 50);
251
+ const second = fakePlugin("b", 0);
252
+
253
+ const host = createSwitchboardPluginHost(
254
+ { logger: stubLogger(), options: {}, renown: null },
255
+ [resolvedFake(first), resolvedFake(second)],
256
+ );
257
+
258
+ await host.observe("onShutdown");
259
+
260
+ expect(order).toEqual(["a", "b"]);
261
+ });
262
+ });
@@ -0,0 +1,45 @@
1
+ import net from "node:net";
2
+ import { afterEach, describe, expect, it, vi } from "vitest";
3
+ import { isPortAvailable } from "../src/server.mjs";
4
+
5
+ // A host without IPv6, e.g. a container: binding `::` fails before the port is tried.
6
+ function withoutIpv6() {
7
+ const { listen } = net.Server.prototype as unknown as {
8
+ listen: (this: net.Server, ...args: unknown[]) => net.Server;
9
+ };
10
+ return vi.spyOn(net.Server.prototype, "listen").mockImplementation(function (
11
+ this: net.Server,
12
+ ...args: unknown[]
13
+ ) {
14
+ const [options] = args as [{ host?: string } | undefined];
15
+ if (options?.host === "::") {
16
+ const error = Object.assign(new Error("address family not supported"), {
17
+ code: "EAFNOSUPPORT",
18
+ });
19
+ queueMicrotask(() => this.emit("error", error));
20
+ return this;
21
+ }
22
+ return listen.apply(this, args);
23
+ });
24
+ }
25
+
26
+ afterEach(() => {
27
+ vi.restoreAllMocks();
28
+ });
29
+
30
+ describe("isPortAvailable", () => {
31
+ it("probes IPv4 on a host without IPv6", async () => {
32
+ withoutIpv6();
33
+ const busy = net.createServer();
34
+ await new Promise<void>((resolve) =>
35
+ busy.listen({ port: 0, host: "0.0.0.0" }, resolve),
36
+ );
37
+ const { port } = busy.address() as net.AddressInfo;
38
+ try {
39
+ await expect(isPortAvailable(port)).resolves.toBe(false);
40
+ } finally {
41
+ await new Promise((resolve) => busy.close(resolve));
42
+ }
43
+ await expect(isPortAvailable(port)).resolves.toBe(true);
44
+ });
45
+ });
@@ -0,0 +1,109 @@
1
+ import type { InspectorProcessorTimingReport } from "@powerhousedao/reactor";
2
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3
+ import { startProcessorTimingLog } from "../src/processor-timing-log.mjs";
4
+
5
+ function report(
6
+ level: InspectorProcessorTimingReport["level"],
7
+ phase: "catching-up" | "live",
8
+ ): InspectorProcessorTimingReport {
9
+ const counters = {
10
+ batches: 1,
11
+ opsDelivered: 1,
12
+ opsScanned: 1,
13
+ opsMatched: 1,
14
+ pages: 1,
15
+ handlerMs: 2_000,
16
+ maxBatchMs: 0,
17
+ readMs: 0,
18
+ lookupMs: 0,
19
+ fillMs: 0,
20
+ slotWaitMs: 0,
21
+ pauseMs: 0,
22
+ errors: 0,
23
+ };
24
+ const horizon = {
25
+ live: { ...counters, handlerMs: 0 },
26
+ replay: counters,
27
+ ordinalsAdvanced: 1,
28
+ busyMs: 2_000,
29
+ };
30
+ return {
31
+ level,
32
+ windowMs: 60_000,
33
+ head: 10,
34
+ headKnown: true,
35
+ processors: [
36
+ {
37
+ processorId: "p",
38
+ name: "Index",
39
+ driveLabel: "files",
40
+ factoryId: "f",
41
+ driveId: "d",
42
+ phase,
43
+ lastOrdinal: 5,
44
+ queueDepth: { tasks: 0, ops: 0 },
45
+ ordinalsBehind: 5,
46
+ opsPerSecond: 1,
47
+ ordinalsPerSecond: 1,
48
+ etaMs: null,
49
+ sinceUtcMs: 0,
50
+ total: horizon,
51
+ window: horizon,
52
+ windowMs: 60_000,
53
+ currentRun: null,
54
+ lastRun: null,
55
+ lastBatch: null,
56
+ byDocumentType: [],
57
+ },
58
+ ],
59
+ };
60
+ }
61
+
62
+ describe("startProcessorTimingLog", () => {
63
+ beforeEach(() => {
64
+ vi.useFakeTimers();
65
+ });
66
+
67
+ afterEach(() => {
68
+ vi.useRealTimers();
69
+ });
70
+
71
+ it("logs while catching up and one summary when it ends", () => {
72
+ let current = report("basic", "catching-up");
73
+ const lines: string[] = [];
74
+ const stop = startProcessorTimingLog({
75
+ intervalMs: 1_000,
76
+ read: () => current,
77
+ log: (line) => lines.push(line),
78
+ });
79
+
80
+ vi.advanceTimersByTime(2_000);
81
+ expect(lines).toHaveLength(2);
82
+ expect(lines[0]).toContain("catch-up slowest (60 s): Index·files 2.0s");
83
+
84
+ current = report("basic", "live");
85
+ vi.advanceTimersByTime(3_000);
86
+ expect(lines).toHaveLength(3);
87
+ expect(lines[2]).toMatch(/^catch-up done in .*Index·files 2\.0s$/);
88
+ stop();
89
+ });
90
+
91
+ it("stays quiet when live, when off, and after the stop", () => {
92
+ let current = report("basic", "live");
93
+ const log = vi.fn();
94
+ const stop = startProcessorTimingLog({
95
+ intervalMs: 1_000,
96
+ read: () => current,
97
+ log,
98
+ });
99
+ vi.advanceTimersByTime(2_000);
100
+
101
+ current = report("off", "catching-up");
102
+ vi.advanceTimersByTime(2_000);
103
+ stop();
104
+
105
+ current = report("basic", "catching-up");
106
+ vi.advanceTimersByTime(2_000);
107
+ expect(log).not.toHaveBeenCalled();
108
+ });
109
+ });
@@ -47,6 +47,26 @@ describe("resolveReactorFeatureFlags", () => {
47
47
  ]);
48
48
  });
49
49
 
50
+ it("reads REACTOR_UNDO_V3 only when set, on unless the literal false", () => {
51
+ expect(resolveReactorFeatureFlags({}).flags).not.toHaveProperty("undoV3");
52
+ expect(resolveReactorFeatureFlags({ REACTOR_UNDO_V3: "false" })).toEqual({
53
+ flags: {
54
+ documentDecisions: false,
55
+ authEnforcement: false,
56
+ authGroups: false,
57
+ authConditions: false,
58
+ undoV3: false,
59
+ },
60
+ enabled: [],
61
+ });
62
+ expect(
63
+ resolveReactorFeatureFlags({ REACTOR_UNDO_V3: "FALSE" }).flags.undoV3,
64
+ ).toBe(true);
65
+ expect(
66
+ resolveReactorFeatureFlags({ REACTOR_UNDO_V3: "true" }).enabled,
67
+ ).toEqual(["undoV3"]);
68
+ });
69
+
50
70
  it("passes an inconsistent set through for the reactor to reject", () => {
51
71
  // Correcting it here would enforce something other than what was asked for;
52
72
  // the builder throws on the missing prerequisite at boot instead.
@@ -24,11 +24,20 @@ describe("redactWebhookPath", () => {
24
24
  );
25
25
  });
26
26
 
27
+ it("redacts a waitpoint's resume token and its sub-path", () => {
28
+ expect(
29
+ redactWebhookPath(
30
+ `/api/@powerhousedao/workflow/waitpoints/${TOKEN}/confirm?action=approve`,
31
+ ),
32
+ ).toBe("/api/@powerhousedao/workflow/waitpoints/[redacted]");
33
+ });
34
+
27
35
  it("never returns anything containing the token", () => {
28
36
  for (const url of [
29
37
  `/webhooks/${TOKEN}`,
30
38
  `/reactor/webhooks/${TOKEN}`,
31
39
  `/a/b/c/webhooks/${TOKEN}?x=1`,
40
+ `/a/waitpoints/${TOKEN}/sync`,
32
41
  ]) {
33
42
  expect(redactWebhookPath(url)).not.toContain(TOKEN);
34
43
  }
@@ -0,0 +1,40 @@
1
+ import { existsSync } from "node:fs";
2
+ import { mkdir, mkdtemp, rm } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import { afterEach, describe, expect, it } from "vitest";
6
+ import { initRenown } from "../src/renown.js";
7
+
8
+ describe("initRenown storage", () => {
9
+ let userData: string | undefined;
10
+
11
+ afterEach(async () => {
12
+ if (userData) await rm(userData, { recursive: true, force: true });
13
+ });
14
+
15
+ it("keeps renown's user storage under the user-data dir", async () => {
16
+ userData = await mkdtemp(join(tmpdir(), "switchboard-renown-"));
17
+ await initRenown({
18
+ keypairPath: join(userData, ".ph", ".keypair.json"),
19
+ userDataDir: userData,
20
+ });
21
+ expect(existsSync(join(userData, ".ph", ".renown.json"))).toBe(true);
22
+ });
23
+
24
+ it("creates no .ph in cwd when the keypair path is explicit", async () => {
25
+ userData = await mkdtemp(join(tmpdir(), "switchboard-renown-"));
26
+ const cwd = join(userData, "project");
27
+ await mkdir(cwd);
28
+ const before = process.cwd();
29
+ process.chdir(cwd);
30
+ try {
31
+ await initRenown({
32
+ keypairPath: join(userData, ".ph", ".keypair.json"),
33
+ userDataDir: userData,
34
+ });
35
+ } finally {
36
+ process.chdir(before);
37
+ }
38
+ expect(existsSync(join(cwd, ".ph"))).toBe(false);
39
+ });
40
+ });