@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,265 @@
1
+ import {
2
+ ReactorBuilder,
3
+ ReactorClientBuilder,
4
+ type InProcessReactorClientModule,
5
+ } from "@powerhousedao/reactor";
6
+ import {
7
+ driveDocumentModelModule,
8
+ setDriveName,
9
+ } from "@powerhousedao/shared/document-drive";
10
+ import type { DriveInput } from "@powerhousedao/shared/document-drive";
11
+ import {
12
+ withSignaturePolicy,
13
+ type DocumentModelModule,
14
+ } from "@powerhousedao/shared/document-model";
15
+ import { deleteDocumentAction } from "@powerhousedao/reactor";
16
+ import { documentModelDocumentModelModule } from "document-model";
17
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
18
+ import { addDefaultDrive, ensureDrive } from "../src/utils.mjs";
19
+
20
+ const PORT = 4001;
21
+
22
+ const workflows = (id: string): DriveInput =>
23
+ ({
24
+ id,
25
+ slug: "workflows",
26
+ global: { name: "Workflows" },
27
+ local: {
28
+ availableOffline: true,
29
+ listeners: [],
30
+ sharingType: "public",
31
+ triggers: [],
32
+ },
33
+ }) as DriveInput;
34
+
35
+ describe("addDefaultDrive with a slug another document holds", () => {
36
+ let module: InProcessReactorClientModule;
37
+ const logger = { error: vi.fn() };
38
+
39
+ beforeEach(async () => {
40
+ logger.error.mockClear();
41
+ module = await new ReactorClientBuilder()
42
+ .withReactorBuilder(
43
+ new ReactorBuilder().withDocumentModelSources([
44
+ driveDocumentModelModule as unknown as DocumentModelModule,
45
+ documentModelDocumentModelModule as unknown as DocumentModelModule,
46
+ ]),
47
+ )
48
+ .buildModule();
49
+ });
50
+
51
+ afterEach(() => {
52
+ module.reactor.kill();
53
+ });
54
+
55
+ const isCreated = (id: string) =>
56
+ module.client.get(id).then(
57
+ () => true,
58
+ () => false,
59
+ );
60
+
61
+ it("creates the drive when the slug is free", async () => {
62
+ await expect(
63
+ addDefaultDrive(module.client, workflows("workflows-a"), PORT, logger),
64
+ ).resolves.toBe(`http://localhost:${PORT}/d/workflows-a`);
65
+ await expect(module.client.resolveIdOrSlug("workflows")).resolves.toBe(
66
+ "workflows-a",
67
+ );
68
+ });
69
+
70
+ // A project moved to another folder hashes its drive ids anew.
71
+ it("serves the drive that holds the slug instead of creating a twin", async () => {
72
+ await addDefaultDrive(
73
+ module.client,
74
+ workflows("workflows-a"),
75
+ PORT,
76
+ logger,
77
+ );
78
+ await expect(
79
+ addDefaultDrive(module.client, workflows("workflows-b"), PORT, logger),
80
+ ).resolves.toBe(`http://localhost:${PORT}/d/workflows-a`);
81
+ expect(await isCreated("workflows-b")).toBe(false);
82
+ expect(logger.error).not.toHaveBeenCalled();
83
+ });
84
+
85
+ it("logs an error and creates nothing when another kind of document holds it", async () => {
86
+ const other = withSignaturePolicy(
87
+ documentModelDocumentModelModule.utils.createDocument(),
88
+ "legacy",
89
+ );
90
+ other.header.slug = "workflows";
91
+ await module.client.create(other);
92
+
93
+ await expect(
94
+ addDefaultDrive(module.client, workflows("workflows-c"), PORT, logger),
95
+ ).resolves.toBeUndefined();
96
+ expect(await isCreated("workflows-c")).toBe(false);
97
+ expect(logger.error).toHaveBeenCalledWith(
98
+ `The default drive "workflows" was not created: the slug belongs to powerhouse/document-model document ${other.header.id}.`,
99
+ );
100
+ });
101
+ });
102
+
103
+ describe.each([
104
+ ["without document decisions", false],
105
+ ["with document decisions", true],
106
+ ])("ensureDrive %s", (_name, documentDecisions) => {
107
+ let module: InProcessReactorClientModule;
108
+ const logger = { error: vi.fn() };
109
+ const mail = { slug: "mail", global: { name: "Mail" } };
110
+
111
+ const deleteDrive = async (id: string) => {
112
+ await (
113
+ await module.client.write.deleteDocument(id)
114
+ ).readable;
115
+ };
116
+
117
+ beforeEach(async () => {
118
+ logger.error.mockClear();
119
+ module = await new ReactorClientBuilder()
120
+ .withCreateSignaturePolicy("legacy")
121
+ .withReactorBuilder(
122
+ new ReactorBuilder()
123
+ .withDocumentModelSources([
124
+ driveDocumentModelModule as unknown as DocumentModelModule,
125
+ documentModelDocumentModelModule as unknown as DocumentModelModule,
126
+ ])
127
+ .withExecutorConfig({ featureFlags: { documentDecisions } }),
128
+ )
129
+ .buildModule();
130
+ });
131
+
132
+ afterEach(() => {
133
+ module.reactor.kill();
134
+ });
135
+
136
+ it("generates the id of a drive declared by its slug alone", async () => {
137
+ await ensureDrive(module.client, mail, PORT, logger);
138
+
139
+ const id = await module.client.resolveIdOrSlug("mail");
140
+ expect(id).not.toBe("mail");
141
+ const drive = await module.client.get(id);
142
+ expect(drive.header.slug).toBe("mail");
143
+ expect(drive.header.documentType).toBe("powerhouse/document-drive");
144
+ });
145
+
146
+ // A random id can't clash, so a second boot must find the drive by its slug.
147
+ it("finds that drive again on the next boot instead of making a twin", async () => {
148
+ await ensureDrive(module.client, mail, PORT, logger);
149
+ const first = await module.client.resolveIdOrSlug("mail");
150
+
151
+ await ensureDrive(module.client, mail, PORT, logger);
152
+
153
+ const { results } = await module.client.find({
154
+ type: "powerhouse/document-drive",
155
+ });
156
+ expect(results.map((drive) => drive.header.id)).toEqual([first]);
157
+ });
158
+
159
+ it("leaves a drive of another type under the slug as it is", async () => {
160
+ await ensureDrive(module.client, mail, PORT, logger);
161
+ const id = await module.client.resolveIdOrSlug("mail");
162
+
163
+ await expect(
164
+ ensureDrive(
165
+ module.client,
166
+ { ...mail, documentType: "powerhouse/reactor-drive" },
167
+ PORT,
168
+ logger,
169
+ ),
170
+ ).resolves.toBe(`http://localhost:${PORT}/d/${id}`);
171
+ expect(logger.error).not.toHaveBeenCalled();
172
+ });
173
+
174
+ it("finds a drive whose id equals its slug, as older stores hold them", async () => {
175
+ await ensureDrive(module.client, { ...mail, id: "mail" }, PORT, logger);
176
+
177
+ await expect(ensureDrive(module.client, mail, PORT, logger)).resolves.toBe(
178
+ `http://localhost:${PORT}/d/mail`,
179
+ );
180
+ await expect(module.client.resolveIdOrSlug("mail")).resolves.toBe("mail");
181
+ });
182
+
183
+ it("makes a new empty drive after the drive under the slug was deleted", async () => {
184
+ await ensureDrive(module.client, mail, PORT, logger);
185
+ const first = await module.client.resolveIdOrSlug("mail");
186
+ await deleteDrive(first);
187
+
188
+ await ensureDrive(module.client, mail, PORT, logger);
189
+
190
+ const second = await module.client.resolveIdOrSlug("mail");
191
+ expect(second).not.toBe(first);
192
+ expect(logger.error).not.toHaveBeenCalled();
193
+ });
194
+
195
+ // Stores from before generated ids: the deleted drive's id is the slug.
196
+ it("points the slug at the new drive when the deleted drive's id was that slug", async () => {
197
+ await ensureDrive(module.client, { ...mail, id: "mail" }, PORT, logger);
198
+ await deleteDrive("mail");
199
+
200
+ await ensureDrive(module.client, mail, PORT, logger);
201
+
202
+ const id = await module.client.resolveIdOrSlug("mail");
203
+ expect(id).not.toBe("mail");
204
+ await expect(module.client.get("mail")).resolves.toMatchObject({
205
+ header: { id },
206
+ });
207
+ // Writes resolve through the identity table, reads through the view
208
+ const renamed = await module.client.execute("mail", "main", [
209
+ setDriveName({ name: "Renamed" }),
210
+ ]);
211
+ expect(renamed.header.id).toBe(id);
212
+ });
213
+
214
+ // A project-hashed drive declares an id, and that id outlives the drive.
215
+ it.each([
216
+ ["a different slug", "mail", "mail-1234abcd"],
217
+ ["the same slug", "mail-1234abcd", "mail-1234abcd"],
218
+ ])(
219
+ "makes a new drive when a deleted drive holds the declared id, under %s",
220
+ async (_case, slug, id) => {
221
+ const declared = { ...mail, slug, id };
222
+ await ensureDrive(module.client, declared, PORT, logger);
223
+ await deleteDrive(id);
224
+
225
+ await expect(
226
+ ensureDrive(module.client, declared, PORT, logger),
227
+ ).resolves.toBe(`http://localhost:${PORT}/d/${slug}`);
228
+
229
+ const created = await module.client.resolveIdOrSlug(slug);
230
+ expect(created).not.toBe(id);
231
+
232
+ await ensureDrive(module.client, declared, PORT, logger);
233
+ await expect(module.client.resolveIdOrSlug(slug)).resolves.toBe(created);
234
+ expect(logger.error).not.toHaveBeenCalled();
235
+ },
236
+ );
237
+
238
+ it("leaves a drive deleted when the delete kept its slug", async () => {
239
+ await ensureDrive(module.client, mail, PORT, logger);
240
+ const id = await module.client.resolveIdOrSlug("mail");
241
+ await (
242
+ await module.client.write.execute(id, "main", [
243
+ deleteDocumentAction(id, { keepSlug: true }),
244
+ ])
245
+ ).readable;
246
+
247
+ await expect(
248
+ ensureDrive(module.client, mail, PORT, logger),
249
+ ).resolves.toBeUndefined();
250
+
251
+ const { results } = await module.client.find({
252
+ type: "powerhouse/document-drive",
253
+ });
254
+ expect(results).toEqual([]);
255
+ expect(logger.error).toHaveBeenCalledWith(
256
+ `The default drive "mail" was not created: it was deleted, and its slug kept.`,
257
+ );
258
+ });
259
+
260
+ it("refuses a drive with neither a slug nor an id", async () => {
261
+ await expect(
262
+ ensureDrive(module.client, { global: { name: "x" } }, PORT, logger),
263
+ ).rejects.toThrow("A drive needs a slug");
264
+ });
265
+ });
@@ -0,0 +1,435 @@
1
+ // A delegate signing publishes as a person, over a real reactor with real
2
+ // keys and credentials, and everything around it (ADR 0008). The host has no
3
+ // address, as a container with no `ph login` has none.
4
+ import {
5
+ ReactorBuilder,
6
+ ReactorClientBuilder,
7
+ type IReactorClient,
8
+ type InProcessReactorClientModule,
9
+ type SignatureTrustPolicy,
10
+ type SignerConfig,
11
+ } from "@powerhousedao/reactor";
12
+ import { publishRunUser } from "@powerhousedao/reactor-workflow";
13
+ import {
14
+ deserializeSignature,
15
+ serializeSignature,
16
+ type Action,
17
+ type DocumentModelModule,
18
+ type Operation,
19
+ } from "@powerhousedao/shared/document-model";
20
+ import {
21
+ Workflow,
22
+ actions as workflowActions,
23
+ } from "@powerhousedao/workflow/document-models/workflow";
24
+ import {
25
+ buildAndSignCredential,
26
+ createDelegation,
27
+ MemoryKeyStorage,
28
+ RenownCryptoBuilder,
29
+ RenownCryptoSigner,
30
+ signDelegatedAction,
31
+ type IRenown,
32
+ type IRenownCrypto,
33
+ type PowerhouseVerifiableCredential,
34
+ type SignCredentialTypedData,
35
+ } from "@renown/sdk/node";
36
+ import { createRequire } from "node:module";
37
+ import { afterAll, beforeAll, describe, expect, it } from "vitest";
38
+ import {
39
+ getDelegationTrustPolicyConfig,
40
+ getRenownTrustPolicyConfig,
41
+ } from "../src/renown.js";
42
+
43
+ // viem is the SDK's own dependency; the switchboard does not declare it.
44
+ type Account = {
45
+ address: `0x${string}`;
46
+ signTypedData(args: unknown): Promise<`0x${string}`>;
47
+ };
48
+ const { privateKeyToAccount } = createRequire(
49
+ import.meta.resolve("@renown/sdk/node"),
50
+ )("viem/accounts") as {
51
+ privateKeyToAccount: (key: `0x${string}`) => Account;
52
+ };
53
+
54
+ // Well-known Anvil dev keys; never used for anything real.
55
+ const PERSON = privateKeyToAccount(
56
+ "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
57
+ );
58
+ const USER = { address: PERSON.address, networkId: "eip155", chainId: 1 };
59
+ const SCOPE = { ops: ["PUBLISH_WORKFLOW"], res: "sektar/integration:i-1" };
60
+
61
+ const newCrypto = (): Promise<IRenownCrypto> =>
62
+ new RenownCryptoBuilder().withKeyPairStorage(new MemoryKeyStorage()).build();
63
+
64
+ const publish = () =>
65
+ workflowActions.publishWorkflow({ publishedAt: new Date().toISOString() });
66
+
67
+ type Trust = Pick<SignerConfig, "trustPolicy" | "workerTrustPolicy">;
68
+
69
+ async function reactorOf(
70
+ hostSigner: RenownCryptoSigner,
71
+ trust: Trust,
72
+ featureFlags = {},
73
+ ): Promise<InProcessReactorClientModule> {
74
+ return new ReactorClientBuilder()
75
+ .withSigner(hostSigner)
76
+ .withCreateSignaturePolicy("v2-required")
77
+ .withReactorBuilder(
78
+ new ReactorBuilder()
79
+ .withDocumentModelSources([Workflow as unknown as DocumentModelModule])
80
+ .withExecutorConfig({ featureFlags })
81
+ .withTrustPolicy(trust.trustPolicy as SignatureTrustPolicy),
82
+ )
83
+ .buildModule();
84
+ }
85
+
86
+ async function clientOver(
87
+ over: InProcessReactorClientModule,
88
+ signer?: RenownCryptoSigner,
89
+ ): Promise<IReactorClient> {
90
+ const builder = new ReactorClientBuilder().withReactor(
91
+ over.reactor,
92
+ over.eventBus,
93
+ over.documentIndexer,
94
+ over.documentView,
95
+ );
96
+ return (signer ? builder.withSigner(signer) : builder).build();
97
+ }
98
+
99
+ describe("delegated publishes", () => {
100
+ let session: IRenownCrypto;
101
+ let delegate: IRenownCrypto;
102
+ let hostCrypto: IRenownCrypto;
103
+ let hostSigner: RenownCryptoSigner;
104
+ let credential: PowerhouseVerifiableCredential;
105
+ let statement: string;
106
+ let module: InProcessReactorClientModule;
107
+
108
+ const statementFor = (
109
+ overrides: Partial<Parameters<typeof createDelegation>[0]> = {},
110
+ ) =>
111
+ createDelegation({
112
+ issuer: session.issuer,
113
+ credential,
114
+ delegate: delegate.did,
115
+ environment: hostCrypto.did,
116
+ scope: SCOPE,
117
+ ...overrides,
118
+ });
119
+
120
+ const signed = (
121
+ action: Action,
122
+ documentId: string,
123
+ by: { crypto?: IRenownCrypto; statement?: string } = {},
124
+ ) =>
125
+ signDelegatedAction({
126
+ action,
127
+ target: { documentId, branch: "main" },
128
+ crypto: by.crypto ?? delegate,
129
+ appName: "sektar-runner",
130
+ user: USER,
131
+ statement: by.statement ?? statement,
132
+ });
133
+
134
+ const newWorkflow = async (
135
+ over: InProcessReactorClientModule = module,
136
+ ): Promise<string> => {
137
+ const created = await over.client.create(Workflow.utils.createDocument());
138
+ return created.header.id;
139
+ };
140
+
141
+ const submit = async (id: string, actions: Action[]) => {
142
+ const job = await module.reactor.execute(id, "main", actions);
143
+ return module.client.waitForJob(job);
144
+ };
145
+
146
+ const hostIdentity = () => ({ key: hostCrypto.did });
147
+
148
+ const publishes = async (id: string): Promise<Operation[]> => {
149
+ const page = await module.client.getOperations(
150
+ id,
151
+ { scopes: ["global"] },
152
+ { actionTypes: ["PUBLISH_WORKFLOW"] },
153
+ );
154
+ return page.results;
155
+ };
156
+
157
+ beforeAll(async () => {
158
+ session = await newCrypto();
159
+ delegate = await newCrypto();
160
+ hostCrypto = await newCrypto();
161
+ hostSigner = new RenownCryptoSigner(hostCrypto, "switchboard");
162
+ credential = await buildAndSignCredential({
163
+ signTypedData: ((args) =>
164
+ PERSON.signTypedData(args)) as SignCredentialTypedData,
165
+ address: PERSON.address,
166
+ chainId: 1,
167
+ app: "connect",
168
+ appId: session.did,
169
+ });
170
+ statement = await statementFor();
171
+ module = await reactorOf(
172
+ hostSigner,
173
+ getDelegationTrustPolicyConfig({
174
+ signer: hostSigner,
175
+ } as unknown as IRenown),
176
+ );
177
+ }, 60_000);
178
+
179
+ afterAll(() => {
180
+ module.reactor.kill();
181
+ });
182
+
183
+ describe("with authEnforcement off", () => {
184
+ it("makes the person the run user of a publish the delegate signed", async () => {
185
+ const id = await newWorkflow();
186
+ const job = await submit(id, [await signed(publish(), id)]);
187
+ expect(job.status).not.toBe("FAILED");
188
+
189
+ const runUser = await publishRunUser(module.client, id, hostIdentity());
190
+ expect(runUser?.address).toBe(PERSON.address);
191
+ expect(runUser?.subject.key).toBe(delegate.did);
192
+ });
193
+
194
+ it("keeps the statement on the stored operation", async () => {
195
+ const id = await newWorkflow();
196
+ await submit(id, [await signed(publish(), id)]);
197
+ const [operation] = await publishes(id);
198
+ const signatures = operation.action.context!.signer!.signatures;
199
+ expect(signatures).toHaveLength(2);
200
+ expect(signatures[0][3]).toBe(statement);
201
+ });
202
+
203
+ it("takes a batch mixing the host's actions and a delegate's", async () => {
204
+ const id = await newWorkflow();
205
+ const client = await clientOver(module, hostSigner);
206
+ await client.execute(id, "main", [
207
+ workflowActions.setWorkflowName({ name: "Mixed" }),
208
+ await signed(publish(), id),
209
+ workflowActions.setWorkflowStatus({ status: "DISABLED" }),
210
+ ]);
211
+
212
+ const page = await module.client.getOperations(id, {
213
+ scopes: ["global"],
214
+ });
215
+ const keys = page.results.map(
216
+ (operation) => operation.action.context?.signer?.app.key,
217
+ );
218
+ expect(keys).toEqual([hostCrypto.did, delegate.did, hostCrypto.did]);
219
+ const runUser = await publishRunUser(module.client, id, hostIdentity());
220
+ expect(runUser?.address).toBe(PERSON.address);
221
+ });
222
+
223
+ it("refuses a stolen statement used by another key", async () => {
224
+ const id = await newWorkflow();
225
+ const thief = await newCrypto();
226
+ const job = await submit(id, [
227
+ await signed(publish(), id, { crypto: thief }),
228
+ ]);
229
+ expect(job.status).toBe("FAILED");
230
+ expect(JSON.stringify(job.error)).toMatch(/SIGNER_UNAUTHORIZED/);
231
+ expect(await publishes(id)).toEqual([]);
232
+ });
233
+
234
+ it("refuses a statement for another environment at first write", async () => {
235
+ const id = await newWorkflow();
236
+ const elsewhere = await newCrypto();
237
+ const job = await submit(id, [
238
+ await signed(publish(), id, {
239
+ statement: await statementFor({ environment: elsewhere.did }),
240
+ }),
241
+ ]);
242
+ expect(job.status).toBe("FAILED");
243
+ expect(JSON.stringify(job.error)).toMatch(/SIGNER_UNAUTHORIZED/);
244
+ });
245
+
246
+ it("refuses a delegate signing outside its scope", async () => {
247
+ const id = await newWorkflow();
248
+ const job = await submit(id, [
249
+ await signed(
250
+ workflowActions.setWorkflowStatus({ status: "ENABLED" }),
251
+ id,
252
+ ),
253
+ ]);
254
+ expect(job.status).toBe("FAILED");
255
+ expect(JSON.stringify(job.error)).toMatch(/SIGNER_UNAUTHORIZED/);
256
+ });
257
+
258
+ it("refuses an unsigned caller claiming a delegate", async () => {
259
+ const id = await newWorkflow();
260
+ const action = await signed(publish(), id);
261
+ const claimed: Action = {
262
+ ...action,
263
+ context: {
264
+ signer: {
265
+ user: USER,
266
+ app: { name: "sektar-runner", key: "" },
267
+ signatures: [],
268
+ },
269
+ },
270
+ };
271
+ const job = await submit(id, [claimed]);
272
+ expect(job.status).toBe("FAILED");
273
+ // A v2-required document refuses it before the claim is even read.
274
+ expect(JSON.stringify(job.error)).toMatch(/UNSIGNED_REQUIRED/);
275
+ });
276
+
277
+ it("refuses a claim of the delegate's key with no valid signature", async () => {
278
+ const id = await newWorkflow();
279
+ const action = await signed(publish(), id);
280
+ const signer = action.context!.signer!;
281
+ const tuple = signer.signatures.at(-1)!;
282
+ const forged: Action = {
283
+ ...action,
284
+ context: {
285
+ signer: {
286
+ ...signer,
287
+ signatures: [
288
+ signer.signatures[0],
289
+ [tuple[0], tuple[1], tuple[2], tuple[3], `0x${"ab".repeat(64)}`],
290
+ ],
291
+ },
292
+ },
293
+ };
294
+ const job = await submit(id, [forged]);
295
+ expect(job.status).toBe("FAILED");
296
+ expect(JSON.stringify(job.error)).toMatch(/BAD_SIGNATURE/);
297
+ });
298
+
299
+ it("stores a replayed operation once", async () => {
300
+ const id = await newWorkflow();
301
+ const action = await signed(publish(), id);
302
+ await submit(id, [action]);
303
+ await submit(id, [action]);
304
+ expect(await publishes(id)).toHaveLength(1);
305
+ });
306
+ });
307
+
308
+ describe("a host with no delegations", () => {
309
+ it("signs a publish itself, which has no run user", async () => {
310
+ const id = await newWorkflow();
311
+ const client = await clientOver(module, hostSigner);
312
+ await client.execute(id, "main", [publish()]);
313
+ expect(
314
+ await publishRunUser(module.client, id, hostIdentity()),
315
+ ).toBeNull();
316
+ });
317
+
318
+ it("still accepts a signed write with no statement, as the default did", async () => {
319
+ const id = await newWorkflow();
320
+ const someone = new RenownCryptoSigner(await newCrypto(), "app", USER);
321
+ const client = await clientOver(module, someone);
322
+ await client.execute(id, "main", [publish()]);
323
+ const runUser = await publishRunUser(module.client, id, hostIdentity());
324
+ expect(runUser?.address).toBe(PERSON.address);
325
+ });
326
+
327
+ it("asks nothing of Renown", () => {
328
+ const trust = getDelegationTrustPolicyConfig({
329
+ signer: hostSigner,
330
+ } as unknown as IRenown);
331
+ expect(trust.workerTrustPolicy?.initArgs).toMatchObject({
332
+ delegationOnly: true,
333
+ });
334
+ });
335
+ });
336
+
337
+ describe("on load", () => {
338
+ it("takes a delegated operation from a peer, across the wire format", async () => {
339
+ const id = await newWorkflow();
340
+ await submit(id, [await signed(publish(), id)]);
341
+
342
+ // Another host: its environment is not the statement's.
343
+ const peerCrypto = await newCrypto();
344
+ const peerSigner = new RenownCryptoSigner(peerCrypto, "switchboard");
345
+ const peer = await reactorOf(
346
+ peerSigner,
347
+ getDelegationTrustPolicyConfig({
348
+ signer: peerSigner,
349
+ } as unknown as IRenown),
350
+ );
351
+ try {
352
+ for (const scope of ["document", "global"]) {
353
+ const page = await module.client.getOperations(id, {
354
+ scopes: [scope],
355
+ });
356
+ const overTheWire = page.results.map((operation) => {
357
+ const signer = operation.action.context?.signer;
358
+ if (!signer) return operation;
359
+ return {
360
+ ...operation,
361
+ action: {
362
+ ...operation.action,
363
+ context: {
364
+ ...operation.action.context,
365
+ signer: {
366
+ ...signer,
367
+ signatures: signer.signatures
368
+ .map((tuple) => serializeSignature(tuple))
369
+ .map((wire) => deserializeSignature(wire)),
370
+ },
371
+ },
372
+ },
373
+ };
374
+ });
375
+ const job = await peer.reactor.load(id, "main", overTheWire);
376
+ const done = await peer.client.waitForJob(job);
377
+ expect(done.status).not.toBe("FAILED");
378
+ }
379
+ const runUser = await publishRunUser(peer.client, id, {
380
+ key: peerCrypto.did,
381
+ });
382
+ expect(runUser?.address).toBe(PERSON.address);
383
+ expect(runUser?.subject.key).toBe(delegate.did);
384
+ } finally {
385
+ peer.reactor.kill();
386
+ }
387
+ });
388
+ });
389
+
390
+ describe("with authEnforcement on", () => {
391
+ let enforcing: InProcessReactorClientModule;
392
+
393
+ const submitted = async (id: string, action: Action) => {
394
+ const job = await enforcing.reactor.execute(id, "main", [action]);
395
+ return enforcing.client.waitForJob(job);
396
+ };
397
+
398
+ beforeAll(async () => {
399
+ const trust = await getRenownTrustPolicyConfig(
400
+ {
401
+ source: "self",
402
+ // Renown knows of no credential for the delegate, and is not asked.
403
+ request: () => Promise.resolve({ renownCredentials: [] }),
404
+ },
405
+ { signer: hostSigner } as unknown as IRenown,
406
+ );
407
+ enforcing = await reactorOf(hostSigner, trust, {
408
+ documentDecisions: true,
409
+ authEnforcement: true,
410
+ });
411
+ }, 60_000);
412
+
413
+ afterAll(() => {
414
+ enforcing.reactor.kill();
415
+ });
416
+
417
+ it("accepts a valid chain, and refuses it with the statement stripped", async () => {
418
+ const id = await newWorkflow(enforcing);
419
+ const action = await signed(publish(), id);
420
+ expect((await submitted(id, action)).status).not.toBe("FAILED");
421
+
422
+ const again = await signed(publish(), id);
423
+ const signer = again.context!.signer!;
424
+ const stripped: Action = {
425
+ ...again,
426
+ context: {
427
+ signer: { ...signer, signatures: signer.signatures.slice(-1) },
428
+ },
429
+ };
430
+ const job = await submitted(id, stripped);
431
+ expect(job.status).toBe("FAILED");
432
+ expect(JSON.stringify(job.error)).toMatch(/SIGNER_UNAUTHORIZED/);
433
+ });
434
+ });
435
+ });