@powerhousedao/switchboard 6.2.3 → 6.3.0-dev.10

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 (271) 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/reserve-metadata-parity.test.d.ts +2 -0
  4. package/.tsbuild/test/attachments/reserve-metadata-parity.test.d.ts.map +1 -0
  5. package/.tsbuild/test/boot-auth-config.test.d.ts +2 -0
  6. package/.tsbuild/test/boot-auth-config.test.d.ts.map +1 -0
  7. package/.tsbuild/test/boot-desktop-auth.test.d.ts +2 -0
  8. package/.tsbuild/test/boot-desktop-auth.test.d.ts.map +1 -0
  9. package/.tsbuild/test/boot-env-isolation.test.d.ts +2 -0
  10. package/.tsbuild/test/boot-env-isolation.test.d.ts.map +1 -0
  11. package/.tsbuild/test/boot-helpers.d.ts +5 -0
  12. package/.tsbuild/test/boot-helpers.d.ts.map +1 -0
  13. package/.tsbuild/test/boot-inspection-enabled.test.d.ts +2 -0
  14. package/.tsbuild/test/boot-inspection-enabled.test.d.ts.map +1 -0
  15. package/.tsbuild/test/boot-mcp-auth.test.d.ts +2 -0
  16. package/.tsbuild/test/boot-mcp-auth.test.d.ts.map +1 -0
  17. package/.tsbuild/test/boot-port-zero.test.d.ts +2 -0
  18. package/.tsbuild/test/boot-port-zero.test.d.ts.map +1 -0
  19. package/.tsbuild/test/boot-preconditions.test.d.ts +2 -0
  20. package/.tsbuild/test/boot-preconditions.test.d.ts.map +1 -0
  21. package/.tsbuild/test/boot-privacy.test.d.ts +2 -0
  22. package/.tsbuild/test/boot-privacy.test.d.ts.map +1 -0
  23. package/.tsbuild/test/boot-ready-drives.test.d.ts +2 -0
  24. package/.tsbuild/test/boot-ready-drives.test.d.ts.map +1 -0
  25. package/.tsbuild/test/boot-undo-v3-flag.test.d.ts +2 -0
  26. package/.tsbuild/test/boot-undo-v3-flag.test.d.ts.map +1 -0
  27. package/.tsbuild/test/boot-workflow-singleton-conflict.test.d.ts +2 -0
  28. package/.tsbuild/test/boot-workflow-singleton-conflict.test.d.ts.map +1 -0
  29. package/.tsbuild/test/boot-workflow-singleton-retry.test.d.ts +2 -0
  30. package/.tsbuild/test/boot-workflow-singleton-retry.test.d.ts.map +1 -0
  31. package/.tsbuild/test/config-from-env.test.d.ts +2 -0
  32. package/.tsbuild/test/config-from-env.test.d.ts.map +1 -0
  33. package/.tsbuild/test/config-merge.test.d.ts +2 -0
  34. package/.tsbuild/test/config-merge.test.d.ts.map +1 -0
  35. package/.tsbuild/test/config-schema.test.d.ts +2 -0
  36. package/.tsbuild/test/config-schema.test.d.ts.map +1 -0
  37. package/.tsbuild/test/default-composition.test.d.ts +2 -0
  38. package/.tsbuild/test/default-composition.test.d.ts.map +1 -0
  39. package/.tsbuild/test/default-drive-protocol-versions.test.d.ts +2 -0
  40. package/.tsbuild/test/default-drive-protocol-versions.test.d.ts.map +1 -0
  41. package/.tsbuild/test/default-drive-slug.test.d.ts +2 -0
  42. package/.tsbuild/test/default-drive-slug.test.d.ts.map +1 -0
  43. package/.tsbuild/test/delegated-publish.test.d.ts +2 -0
  44. package/.tsbuild/test/delegated-publish.test.d.ts.map +1 -0
  45. package/.tsbuild/test/durable-node-fs-pg16.test.d.ts +2 -0
  46. package/.tsbuild/test/durable-node-fs-pg16.test.d.ts.map +1 -0
  47. package/.tsbuild/test/fixtures/mixed-subgraphs/subgraphs/greetings/index.d.ts +13 -0
  48. package/.tsbuild/test/fixtures/mixed-subgraphs/subgraphs/greetings/index.d.ts.map +1 -0
  49. package/.tsbuild/test/fixtures/mixed-subgraphs/subgraphs/index.d.ts +3 -0
  50. package/.tsbuild/test/fixtures/mixed-subgraphs/subgraphs/index.d.ts.map +1 -0
  51. package/.tsbuild/test/fixtures/mixed-subgraphs/subgraphs/tally/index.d.ts +7 -0
  52. package/.tsbuild/test/fixtures/mixed-subgraphs/subgraphs/tally/index.d.ts.map +1 -0
  53. package/.tsbuild/test/inspection-throttle.test.d.ts +2 -0
  54. package/.tsbuild/test/inspection-throttle.test.d.ts.map +1 -0
  55. package/.tsbuild/test/keyframe-reclaim-store.test.d.ts +2 -0
  56. package/.tsbuild/test/keyframe-reclaim-store.test.d.ts.map +1 -0
  57. package/.tsbuild/test/observability-signals.test.d.ts +2 -0
  58. package/.tsbuild/test/observability-signals.test.d.ts.map +1 -0
  59. package/.tsbuild/test/permissions-backfill.test.d.ts +2 -0
  60. package/.tsbuild/test/permissions-backfill.test.d.ts.map +1 -0
  61. package/.tsbuild/test/pglite-preflight.test.d.ts +2 -0
  62. package/.tsbuild/test/pglite-preflight.test.d.ts.map +1 -0
  63. package/.tsbuild/test/pglite-storage-dirs.test.d.ts +2 -0
  64. package/.tsbuild/test/pglite-storage-dirs.test.d.ts.map +1 -0
  65. package/.tsbuild/test/pglite-store.test.d.ts +2 -0
  66. package/.tsbuild/test/pglite-store.test.d.ts.map +1 -0
  67. package/.tsbuild/test/plugin-config-schemas.test.d.ts +2 -0
  68. package/.tsbuild/test/plugin-config-schemas.test.d.ts.map +1 -0
  69. package/.tsbuild/test/plugin-presence.test.d.ts +2 -0
  70. package/.tsbuild/test/plugin-presence.test.d.ts.map +1 -0
  71. package/.tsbuild/test/port-probe.test.d.ts +2 -0
  72. package/.tsbuild/test/port-probe.test.d.ts.map +1 -0
  73. package/.tsbuild/test/processor-timing-log.test.d.ts +2 -0
  74. package/.tsbuild/test/processor-timing-log.test.d.ts.map +1 -0
  75. package/.tsbuild/test/renown-storage-path.test.d.ts +2 -0
  76. package/.tsbuild/test/renown-storage-path.test.d.ts.map +1 -0
  77. package/.tsbuild/test/served-schemas-mixed-package.test.d.ts +2 -0
  78. package/.tsbuild/test/served-schemas-mixed-package.test.d.ts.map +1 -0
  79. package/.tsbuild/test/served-schemas.test.d.ts +2 -0
  80. package/.tsbuild/test/served-schemas.test.d.ts.map +1 -0
  81. package/.tsbuild/test/shutdown.test.d.ts +2 -0
  82. package/.tsbuild/test/shutdown.test.d.ts.map +1 -0
  83. package/.tsbuild/test/snapshot-writer.d.ts +18 -0
  84. package/.tsbuild/test/snapshot-writer.d.ts.map +1 -0
  85. package/.tsbuild/test/store-lock.test.d.ts +2 -0
  86. package/.tsbuild/test/store-lock.test.d.ts.map +1 -0
  87. package/.tsbuild/test/two-switchboards.test.d.ts +2 -0
  88. package/.tsbuild/test/two-switchboards.test.d.ts.map +1 -0
  89. package/.tsbuild/test/workflow/oauth-apps-config.test.d.ts +2 -0
  90. package/.tsbuild/test/workflow/oauth-apps-config.test.d.ts.map +1 -0
  91. package/.tsbuild/test/workflow/runtime-host.test.d.ts +2 -0
  92. package/.tsbuild/test/workflow/runtime-host.test.d.ts.map +1 -0
  93. package/.tsbuild/test/workflow/waitpoint-routes.test.d.ts +2 -0
  94. package/.tsbuild/test/workflow/waitpoint-routes.test.d.ts.map +1 -0
  95. package/.tsbuild/test/workflow/waitpoint-runtime.test.d.ts +2 -0
  96. package/.tsbuild/test/workflow/waitpoint-runtime.test.d.ts.map +1 -0
  97. package/.tsbuild/test/workflow-reactor-access.test.d.ts +2 -0
  98. package/.tsbuild/test/workflow-reactor-access.test.d.ts.map +1 -0
  99. package/.tsbuild/test/workflow-reactor-enforcement.test.d.ts +2 -0
  100. package/.tsbuild/test/workflow-reactor-enforcement.test.d.ts.map +1 -0
  101. package/.tsbuild/test/workflows-plugin-config.test.d.ts +2 -0
  102. package/.tsbuild/test/workflows-plugin-config.test.d.ts.map +1 -0
  103. package/.tsbuild/tsconfig.tsbuildinfo +1 -1
  104. package/Auth.md +108 -2
  105. package/CHANGELOG.md +1122 -2
  106. package/README.md +69 -24
  107. package/dist/boot.d.mts +46 -0
  108. package/dist/boot.d.mts.map +1 -0
  109. package/dist/boot.mjs +67 -0
  110. package/dist/boot.mjs.map +1 -0
  111. package/dist/config/from-env.d.mts +15 -0
  112. package/dist/config/from-env.d.mts.map +1 -0
  113. package/dist/config/from-env.mjs +4 -0
  114. package/dist/config/schema.d.mts +3 -0
  115. package/dist/config/schema.mjs +4 -0
  116. package/dist/from-env-DKK_wPrO.mjs +497 -0
  117. package/dist/from-env-DKK_wPrO.mjs.map +1 -0
  118. package/dist/index.d.mts +1 -2
  119. package/dist/index.mjs +40 -219
  120. package/dist/index.mjs.map +1 -1
  121. package/dist/mcp-VW52B8KD.mjs +32 -0
  122. package/dist/mcp-VW52B8KD.mjs.map +1 -0
  123. package/dist/migrate.mjs +5 -4
  124. package/dist/migrate.mjs.map +1 -1
  125. package/dist/observability-CldagyT_.mjs +224 -0
  126. package/dist/observability-CldagyT_.mjs.map +1 -0
  127. package/dist/observability.d.mts +30 -0
  128. package/dist/observability.d.mts.map +1 -0
  129. package/dist/observability.mjs +4 -0
  130. package/dist/plugin-host-tTjDTNz0.d.mts +46 -0
  131. package/dist/plugin-host-tTjDTNz0.d.mts.map +1 -0
  132. package/dist/plugins/ai.d.mts +37 -0
  133. package/dist/plugins/ai.d.mts.map +1 -0
  134. package/dist/plugins/ai.mjs +400 -0
  135. package/dist/plugins/ai.mjs.map +1 -0
  136. package/dist/plugins/attachments.d.mts +33 -0
  137. package/dist/plugins/attachments.d.mts.map +1 -0
  138. package/dist/plugins/attachments.mjs +4 -0
  139. package/dist/plugins/mcp.d.mts +31 -0
  140. package/dist/plugins/mcp.d.mts.map +1 -0
  141. package/dist/plugins/mcp.mjs +4 -0
  142. package/dist/plugins/privacy.d.mts +22 -0
  143. package/dist/plugins/privacy.d.mts.map +1 -0
  144. package/dist/plugins/privacy.mjs +4 -0
  145. package/dist/plugins/workflows.d.mts +80 -0
  146. package/dist/plugins/workflows.d.mts.map +1 -0
  147. package/dist/plugins/workflows.mjs +4 -0
  148. package/dist/postgres-url-DTDhBjXX.mjs +11 -0
  149. package/dist/postgres-url-DTDhBjXX.mjs.map +1 -0
  150. package/dist/privacy-HQnhqf2H.mjs +91 -0
  151. package/dist/privacy-HQnhqf2H.mjs.map +1 -0
  152. package/dist/privacy-UodgY0i_.mjs +44 -0
  153. package/dist/privacy-UodgY0i_.mjs.map +1 -0
  154. package/dist/renown-layers-DmbWLt46.mjs +42 -0
  155. package/dist/renown-layers-DmbWLt46.mjs.map +1 -0
  156. package/dist/schema-BJ-OFAox.mjs +359 -0
  157. package/dist/schema-BJ-OFAox.mjs.map +1 -0
  158. package/dist/schema-w1lShimw.d.mts +258 -0
  159. package/dist/schema-w1lShimw.d.mts.map +1 -0
  160. package/dist/server-BS-PFzoK.mjs +2752 -0
  161. package/dist/server-BS-PFzoK.mjs.map +1 -0
  162. package/dist/server.d.mts +94 -228
  163. package/dist/server.d.mts.map +1 -1
  164. package/dist/server.mjs +5 -4
  165. package/dist/types-Bk4T4D9F.d.mts +318 -0
  166. package/dist/types-Bk4T4D9F.d.mts.map +1 -0
  167. package/dist/utils-Cm0TE6dP.mjs +148 -0
  168. package/dist/utils-Cm0TE6dP.mjs.map +1 -0
  169. package/dist/utils.d.mts +29 -3
  170. package/dist/utils.d.mts.map +1 -1
  171. package/dist/utils.mjs +5 -4
  172. package/dist/worker-pool-gyxJnCxA.mjs +304 -0
  173. package/dist/worker-pool-gyxJnCxA.mjs.map +1 -0
  174. package/dist/workflow-runtime-CF5pc8mt.d.mts +33 -0
  175. package/dist/workflow-runtime-CF5pc8mt.d.mts.map +1 -0
  176. package/dist/workflows-mdYUh3Us.mjs +1947 -0
  177. package/dist/workflows-mdYUh3Us.mjs.map +1 -0
  178. package/package.json +86 -24
  179. package/scripts/install-packages.sh +0 -0
  180. package/test/ai-gateway.test.ts +612 -0
  181. package/test/attachment-reference-read-model.test.ts +28 -20
  182. package/test/attachments/byte-grants.test.ts +4 -1
  183. package/test/attachments/download-target.test.ts +36 -20
  184. package/test/attachments/index.test.ts +13 -1
  185. package/test/attachments/reserve-metadata-parity.test.ts +96 -0
  186. package/test/attachments/routes-integration.test.ts +1 -0
  187. package/test/attachments/routes.test.ts +132 -12
  188. package/test/attachments/service-config.test.ts +28 -16
  189. package/test/boot-auth-config.test.ts +146 -0
  190. package/test/boot-create-signature-policy.test.ts +15 -13
  191. package/test/boot-desktop-auth.test.ts +278 -0
  192. package/test/boot-env-isolation.test.ts +26 -0
  193. package/test/boot-helpers.ts +19 -0
  194. package/test/boot-inspection-enabled.test.ts +140 -0
  195. package/test/boot-mcp-auth.test.ts +449 -0
  196. package/test/boot-mcp-enabled.test.ts +27 -27
  197. package/test/boot-port-zero.test.ts +101 -0
  198. package/test/boot-preconditions.test.ts +213 -0
  199. package/test/boot-privacy.test.ts +232 -0
  200. package/test/boot-ready-drives.test.ts +141 -0
  201. package/test/boot-undo-v3-flag.test.ts +120 -0
  202. package/test/boot-unsupported-stored-documents.test.ts +23 -19
  203. package/test/boot-without-renown.test.ts +11 -9
  204. package/test/boot-without-require-signatures.test.ts +12 -10
  205. package/test/boot-worker-trust-policy.test.ts +11 -10
  206. package/test/boot-workflow-singleton-conflict.test.ts +109 -0
  207. package/test/boot-workflow-singleton-retry.test.ts +122 -0
  208. package/test/config-from-env.test.ts +968 -0
  209. package/test/config-merge.test.ts +351 -0
  210. package/test/config-schema.test.ts +183 -0
  211. package/test/default-composition.test.ts +290 -0
  212. package/test/default-drive-protocol-versions.test.ts +79 -0
  213. package/test/default-drive-slug.test.ts +265 -0
  214. package/test/delegated-publish.test.ts +435 -0
  215. package/test/durable-node-fs-pg16.test.ts +80 -0
  216. package/test/fatal-shutdown.test.ts +104 -1
  217. package/test/fixtures/mixed-subgraphs/subgraphs/greetings/index.ts +16 -0
  218. package/test/fixtures/mixed-subgraphs/subgraphs/index.ts +3 -0
  219. package/test/fixtures/mixed-subgraphs/subgraphs/tally/index.ts +73 -0
  220. package/test/goldens/packages.graphql +797 -0
  221. package/test/goldens/privacy.graphql +853 -0
  222. package/test/goldens/reactor-drive-nodes.graphql +827 -0
  223. package/test/goldens/resolvers.json +327 -0
  224. package/test/goldens/supergraph.graphql +5918 -0
  225. package/test/goldens/workflow-runtime.graphql +1548 -0
  226. package/test/inspection-throttle.test.ts +23 -0
  227. package/test/keyframe-reclaim-store.test.ts +156 -0
  228. package/test/observability-signals.test.ts +131 -0
  229. package/test/permissions-backfill.test.ts +486 -0
  230. package/test/pglite-dialect.test.ts +237 -2
  231. package/test/pglite-preflight.test.ts +313 -0
  232. package/test/pglite-storage-dirs.test.ts +113 -0
  233. package/test/pglite-store.test.ts +441 -0
  234. package/test/pglite-version.test.ts +9 -1
  235. package/test/plugin-config-schemas.test.ts +83 -0
  236. package/test/plugin-presence.test.ts +262 -0
  237. package/test/port-probe.test.ts +45 -0
  238. package/test/processor-timing-log.test.ts +109 -0
  239. package/test/reactor-feature-flags.test.ts +20 -0
  240. package/test/redact-webhook-path.test.ts +9 -0
  241. package/test/renown-storage-path.test.ts +40 -0
  242. package/test/renown-trust-policy.test.ts +7 -9
  243. package/test/served-schemas-mixed-package.test.ts +251 -0
  244. package/test/served-schemas.test.ts +134 -0
  245. package/test/shutdown.test.ts +278 -0
  246. package/test/snapshot-writer.ts +94 -0
  247. package/test/store-lock.test.ts +65 -0
  248. package/test/two-switchboards.test.ts +146 -0
  249. package/test/worker-pool.test.ts +27 -1
  250. package/test/workflow/oauth-apps-config.test.ts +66 -0
  251. package/test/workflow/oauth.test.ts +82 -10
  252. package/test/workflow/resolvers.test.ts +230 -38
  253. package/test/workflow/runtime-host.test.ts +19 -0
  254. package/test/workflow/waitpoint-routes.test.ts +306 -0
  255. package/test/workflow/waitpoint-runtime.test.ts +204 -0
  256. package/test/workflow/webhook-trigger-test.test.ts +8 -0
  257. package/test/workflow-reactor-access.test.ts +384 -0
  258. package/test/workflow-reactor-enforcement.test.ts +808 -0
  259. package/test/workflow-read-gate.test.ts +128 -60
  260. package/test/workflow-runtime.test.ts +1005 -237
  261. package/test/workflows-plugin-config.test.ts +77 -0
  262. package/tsconfig.json +5 -2
  263. package/tsdown.config.ts +12 -0
  264. package/vitest.config.ts +66 -1
  265. package/.tsbuild/test/mcp-flag.test.d.ts +0 -2
  266. package/.tsbuild/test/mcp-flag.test.d.ts.map +0 -1
  267. package/dist/server-sQoWp21G.mjs +0 -2939
  268. package/dist/server-sQoWp21G.mjs.map +0 -1
  269. package/dist/utils-uaBlzyjS.mjs +0 -86
  270. package/dist/utils-uaBlzyjS.mjs.map +0 -1
  271. package/test/mcp-flag.test.ts +0 -56
@@ -1,9 +1,7 @@
1
1
  // What the workflow subgraph does with the caller behind a request: every
2
- // workflow-scoped field hands it to the runtime, and secret writes are admins'.
3
- import type {
4
- Context,
5
- IAuthorizationService,
6
- } from "@powerhousedao/reactor-api";
2
+ // workflow-scoped field, secrets included, hands it to the runtime, which
3
+ // gates secrets on their owner document and creator rather than on admin.
4
+ import type { Context } from "@powerhousedao/reactor-api";
7
5
  import {
8
6
  WORKFLOW_SYNCING_MESSAGE,
9
7
  WorkflowSyncingError,
@@ -36,6 +34,41 @@ function runsInfo(query: string) {
36
34
  const emptyPage = (): Promise<unknown> =>
37
35
  Promise.resolve({ records: [], hasNextPage: false, cursor: null });
38
36
 
37
+ function waitpointRow(id: string, runId: string) {
38
+ return {
39
+ id,
40
+ run_id: runId,
41
+ workflow_id: "wf-1",
42
+ step_id: "step-1",
43
+ step_key: "step_1",
44
+ step_path: "step-1",
45
+ piece_name: "@powerhousedao/piece-approval",
46
+ block_name: "approval",
47
+ type: "WEBHOOK",
48
+ kind: "approval",
49
+ status: "PENDING",
50
+ created_at: "2026-10-28T00:00:00.000Z",
51
+ resume_at: null,
52
+ expires_at: null,
53
+ resolved_at: null,
54
+ decided_by: null,
55
+ approval: '{"title":"Pay?"}',
56
+ };
57
+ }
58
+
59
+ // The run journal's waitpoint read: one pending approval per run.
60
+ function waitpointStore() {
61
+ return {
62
+ listWaitpointsForRuns: vi.fn((runIds: string[]) =>
63
+ Promise.resolve(
64
+ new Map(
65
+ runIds.map((runId) => [runId, [waitpointRow(`wp-${runId}`, runId)]]),
66
+ ),
67
+ ),
68
+ ),
69
+ };
70
+ }
71
+
39
72
  function fakeRuntime() {
40
73
  return {
41
74
  webhookEndpoint: vi.fn(() => Promise.resolve(null)),
@@ -45,40 +78,51 @@ function fakeRuntime() {
45
78
  run: vi.fn(() => Promise.resolve(null)),
46
79
  fire: vi.fn(() => Promise.resolve({})),
47
80
  rerun: vi.fn(() => Promise.resolve({})),
81
+ waitingRuns: vi.fn((): Promise<unknown[]> => Promise.resolve([])),
82
+ waitpointsForRun: vi.fn(() => Promise.resolve([{ id: "wp-2" }])),
83
+ store: vi.fn(() => Promise.resolve(waitpointStore())),
48
84
  testStep: vi.fn(() => Promise.resolve({})),
49
85
  stepOutputTree: vi.fn(() => Promise.resolve({})),
50
86
  blockResolutions: vi.fn(() => Promise.resolve([])),
87
+ searchPieces: vi.fn(() =>
88
+ Promise.resolve({ status: "ready", pieces: [], indexedPieces: 0 }),
89
+ ),
90
+ reactorAccessDenial: vi.fn((): string | undefined => undefined),
51
91
  testTrigger: vi.fn(() => Promise.resolve(null)),
52
92
  cancelTriggerTestFor: vi.fn(() => Promise.resolve(true)),
53
- secrets: vi.fn(() =>
54
- Promise.resolve({
55
- create: vi.fn(() => Promise.resolve({ ref: "secret://v1:00" })),
56
- rotate: vi.fn(() => Promise.resolve({ ref: "secret://v1:00" })),
57
- delete: vi.fn(() => Promise.resolve()),
58
- }),
59
- ),
93
+ createSecret: vi.fn(() => Promise.resolve({ ref: "secret://v1:00" })),
94
+ rotateSecret: vi.fn(() => Promise.resolve({ ref: "secret://v1:00" })),
95
+ deleteSecret: vi.fn(() => Promise.resolve()),
96
+ secretStat: vi.fn(() => Promise.resolve(null)),
97
+ listSecrets: vi.fn(() => Promise.resolve([])),
98
+ canManageSecret: vi.fn(() => Promise.resolve(false)),
99
+ secrets: vi.fn(),
60
100
  };
61
101
  }
62
102
 
63
- function build(isAdmin: boolean) {
103
+ function build() {
64
104
  const runtime = fakeRuntime();
65
- const authorizationService = {
66
- isSupremeAdmin: vi.fn(() => isAdmin),
67
- } as unknown as IAuthorizationService;
68
105
  const resolvers = getResolvers(
69
106
  runtime as unknown as WorkflowRuntimeService,
70
- authorizationService,
107
+ undefined,
108
+ undefined,
109
+ (documentId) =>
110
+ documentId === "wf-hidden"
111
+ ? Promise.reject(new Error("You may not read this workflow"))
112
+ : Promise.resolve(),
71
113
  ) as Record<string, Record<string, Resolver>>;
72
114
  return {
73
115
  runtime,
74
116
  queries: resolvers.WorkflowRuntimeQueries,
75
117
  mutations: resolvers.WorkflowRuntimeMutations,
118
+ secretRecord: resolvers.SecretRecord,
119
+ runRecord: resolvers.WorkflowRunRecord,
76
120
  };
77
121
  }
78
122
 
79
123
  describe("the workflow resolvers and the caller", () => {
80
124
  it("hands the caller to every workflow-scoped field", async () => {
81
- const { runtime, queries, mutations } = build(true);
125
+ const { runtime, queries, mutations } = build();
82
126
 
83
127
  await queries.webhookEndpoint({}, { workflowId: "wf-1" }, CTX);
84
128
  await queries.triggerStates({}, {}, CTX);
@@ -122,7 +166,7 @@ describe("the workflow resolvers and the caller", () => {
122
166
  });
123
167
 
124
168
  it("passes the caller's drive, and tags a still-syncing workflow", async () => {
125
- const { runtime, queries, mutations } = build(true);
169
+ const { runtime, queries, mutations } = build();
126
170
  const drive = { driveId: "drive-1" };
127
171
 
128
172
  await queries.webhookEndpoint({}, { workflowId: "wf-1", ...drive }, CTX);
@@ -143,32 +187,68 @@ describe("the workflow resolvers and the caller", () => {
143
187
  expect(runtime.testStep).toHaveBeenCalledWith("wf-1", "s1", CTX, drive);
144
188
  });
145
189
 
146
- it("refuses secret writes to a caller who does not administer the reactor", async () => {
147
- const { runtime, mutations } = build(false);
190
+ it("hands every secret field to the runtime with the caller, never the store", async () => {
191
+ const { runtime, queries, mutations, secretRecord } = build();
192
+ const stat = { ref: "secret://v1:00", ownerId: "conn-1" };
148
193
 
194
+ await mutations.createSecret(
195
+ {},
196
+ { value: "s3cret", documentId: "conn-1" },
197
+ CTX,
198
+ );
199
+ await mutations.rotateSecret({}, { ref: stat.ref, value: "s" }, CTX);
149
200
  await expect(
150
- mutations.createSecret({}, { value: "s3cret" }, CTX),
151
- ).rejects.toThrow("Admin access required");
152
- await expect(
153
- mutations.rotateSecret({}, { ref: "secret://v1:00", value: "s" }, CTX),
154
- ).rejects.toThrow("Admin access required");
155
- await expect(
156
- mutations.deleteSecret({}, { ref: "secret://v1:00" }, CTX),
157
- ).rejects.toThrow("Admin access required");
158
- // Refused before the store is ever opened.
201
+ mutations.deleteSecret({}, { ref: stat.ref }, CTX),
202
+ ).resolves.toBe(true);
203
+ await queries.secret({}, { ref: stat.ref }, CTX);
204
+ await queries.secrets({}, {}, CTX);
205
+ await secretRecord.manageable(stat, {}, CTX);
206
+
207
+ expect(runtime.createSecret).toHaveBeenCalledWith(
208
+ { value: "s3cret", label: undefined, ownerId: "conn-1" },
209
+ CTX,
210
+ );
211
+ expect(runtime.rotateSecret).toHaveBeenCalledWith(stat.ref, "s", CTX);
212
+ expect(runtime.deleteSecret).toHaveBeenCalledWith(stat.ref, CTX);
213
+ expect(runtime.secretStat).toHaveBeenCalledWith(stat.ref, CTX);
214
+ expect(runtime.listSecrets).toHaveBeenCalledWith(CTX);
215
+ expect(runtime.canManageSecret).toHaveBeenCalledWith(stat, CTX);
216
+ // Nothing reaches the raw store, whose get returns values.
159
217
  expect(runtime.secrets).not.toHaveBeenCalled();
160
218
  });
161
219
 
162
- it("lets an administrator write secrets", async () => {
163
- const { runtime, mutations } = build(true);
220
+ it("tags a secret minted for a document still syncing", async () => {
221
+ const { runtime, mutations } = build();
222
+ runtime.createSecret.mockRejectedValueOnce(new WorkflowSyncingError());
223
+
224
+ await expect(
225
+ mutations.createSecret({}, { value: "s", documentId: "c1" }, CTX),
226
+ ).rejects.toMatchObject({
227
+ extensions: { code: "WORKFLOW_SYNCING", retryable: true },
228
+ });
229
+ });
164
230
 
165
- await mutations.createSecret({}, { value: "s3cret", label: "slack" }, CTX);
231
+ it("serves why a workflow got no reactor access, naming the publisher", async () => {
232
+ const { runtime, queries } = build();
233
+ runtime.reactorAccessDenial.mockReturnValueOnce(
234
+ 'The publisher 0xabc cannot read reactor connection "conn-1"',
235
+ );
166
236
 
167
- expect(runtime.secrets).toHaveBeenCalledTimes(1);
237
+ await expect(
238
+ queries.reactorAccessDenial({}, { workflowId: "wf-1" }, CTX),
239
+ ).resolves.toBe(
240
+ 'The publisher 0xabc cannot read reactor connection "conn-1"',
241
+ );
242
+ await expect(
243
+ queries.reactorAccessDenial({}, { workflowId: "wf-1" }, CTX),
244
+ ).resolves.toBeNull();
245
+ await expect(
246
+ queries.reactorAccessDenial({}, { workflowId: "wf-hidden" }, CTX),
247
+ ).rejects.toThrow("You may not read this workflow");
168
248
  });
169
249
 
170
250
  it("serves the piece version a run's steps ran", async () => {
171
- const { runtime, queries } = build(true);
251
+ const { runtime, queries } = build();
172
252
  runtime.run.mockResolvedValueOnce({
173
253
  row: { id: "run-1", warnings: 1, trigger_payload: null },
174
254
  steps: [
@@ -198,11 +278,24 @@ describe("the workflow resolvers and the caller", () => {
198
278
  versionNote: "Pinned 3.0.0 is not available; runs 2.1.0 from registry",
199
279
  });
200
280
  });
281
+
282
+ it("serves how many iterations a capped run detail holds back", async () => {
283
+ const { runtime, queries } = build();
284
+ runtime.run.mockResolvedValueOnce({
285
+ row: { id: "run-1", warnings: 0, trigger_payload: null },
286
+ steps: [],
287
+ iterationsTotal: 1200,
288
+ } as never);
289
+ const run = (await queries.run({}, { id: "run-1" }, CTX)) as {
290
+ iterationsTotal: number | null;
291
+ };
292
+ expect(run.iterationsTotal).toBe(1200);
293
+ });
201
294
  });
202
295
 
203
296
  describe("the runs listing and step data", () => {
204
297
  it("reads step blobs only when the query selects them", async () => {
205
- const { runtime, queries } = build(false);
298
+ const { runtime, queries } = build();
206
299
  const withData = (query: string) =>
207
300
  queries.runs({}, {}, CTX, runsInfo(query)).then(
208
301
  () =>
@@ -242,7 +335,7 @@ describe("the runs listing and step data", () => {
242
335
 
243
336
  describe("the runs page", () => {
244
337
  it("passes paging through and serves the page", async () => {
245
- const { runtime, queries } = build(false);
338
+ const { runtime, queries } = build();
246
339
  runtime.runsPage.mockResolvedValueOnce({
247
340
  records: [],
248
341
  hasNextPage: true,
@@ -281,7 +374,7 @@ describe("the runs page", () => {
281
374
  });
282
375
 
283
376
  it("reports a cursor it did not issue as bad input", async () => {
284
- const { runtime, queries } = build(false);
377
+ const { runtime, queries } = build();
285
378
  const invalid = new Error("Invalid runs cursor");
286
379
  invalid.name = "InvalidRunCursorError";
287
380
  runtime.runsPage.mockRejectedValueOnce(invalid);
@@ -294,3 +387,102 @@ describe("the runs page", () => {
294
387
  expect(error.extensions?.code).toBe("BAD_USER_INPUT");
295
388
  });
296
389
  });
390
+
391
+ describe("piece search", () => {
392
+ it("passes a valid filter through", async () => {
393
+ const { runtime, queries } = build();
394
+ await queries.searchPieces(
395
+ {},
396
+ { query: "send", kind: "trigger", sources: ["registry", "local"] },
397
+ CTX,
398
+ );
399
+ expect(runtime.searchPieces).toHaveBeenCalledWith("send", {
400
+ kind: "trigger",
401
+ sources: ["registry", "local"],
402
+ categories: undefined,
403
+ limit: undefined,
404
+ });
405
+ });
406
+
407
+ it("refuses a kind or source it does not know, rather than widen", () => {
408
+ const { runtime, queries } = build();
409
+ expect(() =>
410
+ queries.searchPieces({}, { query: "send", kind: "triggers" }, CTX),
411
+ ).toThrow(/kind is "action" or "trigger"/);
412
+ expect(() =>
413
+ queries.searchPieces(
414
+ {},
415
+ { query: "send", kind: "action", sources: ["Registry"] },
416
+ CTX,
417
+ ),
418
+ ).toThrow(/got Registry/);
419
+ expect(runtime.searchPieces).not.toHaveBeenCalled();
420
+ });
421
+ });
422
+
423
+ describe("waitpoints", () => {
424
+ it("serves waiting runs with the waitpoints the runtime listed", async () => {
425
+ const { runtime, queries, runRecord } = build();
426
+ runtime.waitingRuns.mockResolvedValueOnce([
427
+ {
428
+ run: {
429
+ row: { id: "run-1", status: "WAITING", trigger_payload: null },
430
+ steps: [],
431
+ },
432
+ waitpoints: [{ id: "wp-1" }],
433
+ },
434
+ ]);
435
+
436
+ const runs = (await queries.waitingRuns(
437
+ {},
438
+ { driveId: "drive-1", first: 10 },
439
+ CTX,
440
+ )) as { id: string }[];
441
+
442
+ expect(runtime.waitingRuns).toHaveBeenCalledWith(
443
+ { driveId: "drive-1", workflowId: undefined, first: 10 },
444
+ CTX,
445
+ );
446
+ expect(await runRecord.waitpoints(runs[0], {}, CTX)).toEqual([
447
+ { id: "wp-1" },
448
+ ]);
449
+ expect(runtime.waitpointsForRun).not.toHaveBeenCalled();
450
+ });
451
+
452
+ it("reads the waitpoints of every run in a request with one store call", async () => {
453
+ const { runtime, runRecord } = build();
454
+ const store = waitpointStore();
455
+ runtime.store.mockResolvedValueOnce(store);
456
+ const ctx = { ...CTX } as Context;
457
+ const [first, second, again] = (await Promise.all([
458
+ runRecord.waitpoints({ id: "run-1" }, {}, ctx),
459
+ runRecord.waitpoints({ id: "run-2" }, {}, ctx),
460
+ runRecord.waitpoints({ id: "run-1" }, {}, ctx),
461
+ ])) as Array<Array<{ id: string }>>;
462
+
463
+ expect(first).toEqual([
464
+ expect.objectContaining({
465
+ id: "wp-run-1",
466
+ runId: "run-1",
467
+ kind: "approval",
468
+ approval: { title: "Pay?" },
469
+ }),
470
+ ]);
471
+ expect(second!.map((waitpoint) => waitpoint.id)).toEqual(["wp-run-2"]);
472
+ expect(again).toBe(first);
473
+ expect(runtime.store).toHaveBeenCalledTimes(1);
474
+ expect(store.listWaitpointsForRuns).toHaveBeenCalledWith([
475
+ "run-1",
476
+ "run-2",
477
+ ]);
478
+ // The parent resolver served the run; no second run read.
479
+ expect(runtime.waitpointsForRun).not.toHaveBeenCalled();
480
+ expect(runtime.run).not.toHaveBeenCalled();
481
+ });
482
+
483
+ it("serves no waitpoints when the run journal is unavailable", async () => {
484
+ const { runtime, runRecord } = build();
485
+ runtime.store.mockResolvedValueOnce(undefined as never);
486
+ expect(await runRecord.waitpoints({ id: "run-9" }, {}, CTX)).toEqual([]);
487
+ });
488
+ });
@@ -0,0 +1,19 @@
1
+ import type { WorkflowRuntimeService } from "@powerhousedao/reactor-workflow";
2
+ import { hostname } from "node:os";
3
+ import { describe, expect, it } from "vitest";
4
+ import { getResolvers } from "../../src/workflow/resolvers.js";
5
+
6
+ type Resolver = (...args: unknown[]) => unknown;
7
+
8
+ describe("the runtime's host", () => {
9
+ it("is the switchboard on this machine, the id apps record as runner", () => {
10
+ const resolvers = getResolvers({} as WorkflowRuntimeService) as Record<
11
+ string,
12
+ Record<string, Resolver>
13
+ >;
14
+ expect(resolvers.WorkflowRuntimeQueries.host()).toEqual({
15
+ id: `switchboard@${hostname()}`,
16
+ label: hostname(),
17
+ });
18
+ });
19
+ });
@@ -0,0 +1,306 @@
1
+ // The resume URL over a real socket: GET never resumes, the confirm page
2
+ // escapes what it shows, and POST hands the request to the runtime.
3
+ import {
4
+ createHttpAdapter,
5
+ HttpRouteService,
6
+ } from "@powerhousedao/reactor-api";
7
+ import {
8
+ afterAll,
9
+ beforeAll,
10
+ beforeEach,
11
+ describe,
12
+ expect,
13
+ it,
14
+ vi,
15
+ } from "vitest";
16
+ import {
17
+ MAX_REASON_LENGTH,
18
+ registerWaitpointRoutes,
19
+ waitpointBaseUrlOf,
20
+ type WaitpointRouteRuntime,
21
+ } from "../../src/workflow/waitpoint-routes.js";
22
+
23
+ const TOKEN = "tok_abc";
24
+
25
+ describe("the waitpoint resume routes", () => {
26
+ let base: string;
27
+ let close: () => Promise<void>;
28
+ const runtime = {
29
+ describeWaitpointByToken:
30
+ vi.fn<WaitpointRouteRuntime["describeWaitpointByToken"]>(),
31
+ resumeWaitpointByToken:
32
+ vi.fn<WaitpointRouteRuntime["resumeWaitpointByToken"]>(),
33
+ resumeWaitpointByTokenSync:
34
+ vi.fn<WaitpointRouteRuntime["resumeWaitpointByTokenSync"]>(),
35
+ };
36
+
37
+ beforeAll(async () => {
38
+ const { adapter } = await createHttpAdapter("express");
39
+ adapter.setupMiddleware({});
40
+ const server = await adapter.listen(0, undefined, "127.0.0.1");
41
+ const { port } = server.address() as { port: number };
42
+ const url = `http://127.0.0.1:${port}`;
43
+ const routes = new HttpRouteService({
44
+ httpAdapter: adapter,
45
+ publicUrl: url,
46
+ });
47
+ const scope = routes.scopeFor("@powerhousedao/workflow");
48
+ registerWaitpointRoutes(scope, runtime);
49
+ base = `${waitpointBaseUrlOf(scope)!}/${TOKEN}`;
50
+ close = () => new Promise((done) => server.close(() => done()));
51
+ });
52
+
53
+ afterAll(() => close());
54
+
55
+ beforeEach(() => {
56
+ runtime.describeWaitpointByToken.mockReset().mockResolvedValue({
57
+ workflowName: "Invoice <b>approval</b>",
58
+ stepName: `Ask "finance"`,
59
+ status: "PENDING",
60
+ waitingSince: "2026-10-28T09:30:00.000Z",
61
+ });
62
+ runtime.resumeWaitpointByToken
63
+ .mockReset()
64
+ .mockResolvedValue({ status: "resumed" });
65
+ runtime.resumeWaitpointByTokenSync.mockReset().mockResolvedValue({
66
+ status: "resumed",
67
+ reply: {
68
+ status: 201,
69
+ contentType: "application/json",
70
+ body: '{"ok":true}',
71
+ headers: { "x-next": "later" },
72
+ },
73
+ });
74
+ });
75
+
76
+ const form = (action: string, reason = "", accept = "text/html") =>
77
+ fetch(`${base}/confirm?action=${action}`, {
78
+ method: "POST",
79
+ headers: {
80
+ "content-type": "application/x-www-form-urlencoded",
81
+ accept,
82
+ },
83
+ body: new URLSearchParams({ reason }).toString(),
84
+ });
85
+
86
+ it("lives under the workflow package's namespace", () => {
87
+ expect(base).toMatch(
88
+ /\/api\/@powerhousedao\/workflow\/waitpoints\/tok_abc$/,
89
+ );
90
+ });
91
+
92
+ it("serves no resume URL from a host with no public origin", async () => {
93
+ const { adapter } = await createHttpAdapter("express");
94
+ const routes = new HttpRouteService({ httpAdapter: adapter });
95
+ const scope = routes.scopeFor("@powerhousedao/workflow");
96
+ expect(scope.baseUrl).toMatch(/^\/api\//);
97
+ expect(waitpointBaseUrlOf(scope)).toBeUndefined();
98
+ });
99
+
100
+ // The bare URL's page posts to /confirm, relative to the token.
101
+ it.each([
102
+ [
103
+ "GET",
104
+ "?action=approve",
105
+ 200,
106
+ 'formaction="tok_abc/confirm?action=approve"',
107
+ ],
108
+ ["GET", "/sync", 405, undefined],
109
+ ["GET", "/confirm", 200, "<form"],
110
+ ["HEAD", "", 200, ""],
111
+ ["HEAD", "/sync", 405, ""],
112
+ ["HEAD", "/confirm", 200, ""],
113
+ ] as const)(
114
+ "never resumes on %s %s, answering %i",
115
+ async (method, path, status, body) => {
116
+ const response = await fetch(`${base}${path}`, { method });
117
+ expect(response.status).toBe(status);
118
+ if (status === 405) expect(response.headers.get("allow")).toBe("POST");
119
+ const text = await response.text();
120
+ if (body === "") expect(text).toBe("");
121
+ else if (body) expect(text).toContain(body);
122
+ expect(runtime.resumeWaitpointByToken).not.toHaveBeenCalled();
123
+ expect(runtime.resumeWaitpointByTokenSync).not.toHaveBeenCalled();
124
+ },
125
+ );
126
+
127
+ it("serves an escaped confirm page under a strict CSP", async () => {
128
+ const response = await fetch(`${base}/confirm?x=1`);
129
+ expect(response.status).toBe(200);
130
+ expect(response.headers.get("content-type")).toContain("text/html");
131
+ const csp = response.headers.get("content-security-policy") ?? "";
132
+ expect(csp).toContain("default-src 'none'");
133
+ expect(csp).toContain("form-action 'self'");
134
+ expect(response.headers.get("referrer-policy")).toBe("no-referrer");
135
+ const body = await response.text();
136
+ expect(runtime.describeWaitpointByToken).toHaveBeenCalledWith(TOKEN);
137
+ expect(body).toContain("Invoice &lt;b&gt;approval&lt;/b&gt;");
138
+ expect(body).toContain("Ask &quot;finance&quot;");
139
+ expect(body).not.toContain("<b>");
140
+ expect(body).not.toContain("<script");
141
+ expect(body).toContain('formaction="?x=1&amp;action=approve"');
142
+ expect(body).toContain('formaction="?x=1&amp;action=disapprove"');
143
+ });
144
+
145
+ it("describes the workflow and the wait, times in UTC", async () => {
146
+ runtime.describeWaitpointByToken.mockResolvedValueOnce({
147
+ workflowName: "Vendor sign-off",
148
+ workflowDescription: "Ask <the vendor> to sign off\non the new terms.",
149
+ stepName: "Ask vendor",
150
+ actionName: "Create Approval Links",
151
+ status: "PENDING",
152
+ startedAt: "2026-10-28T09:29:00.000Z",
153
+ triggerName: "Manual Trigger",
154
+ waitingSince: "2026-10-28T09:30:00.000Z",
155
+ expiresAt: "2026-11-04T09:30:00.000Z",
156
+ });
157
+ const body = await (await fetch(`${base}/confirm`)).text();
158
+ expect(body).toContain(
159
+ "Ask &lt;the vendor&gt; to sign off\non the new terms.",
160
+ );
161
+ expect(body).toContain("<dd>Ask vendor · Create Approval Links</dd>");
162
+ expect(body).toContain(
163
+ "<dd>28 Oct 2026, 09:29 UTC, by Manual Trigger</dd>",
164
+ );
165
+ expect(body).toContain(
166
+ "<dt>Waiting since</dt><dd>28 Oct 2026, 09:30 UTC</dd>",
167
+ );
168
+ expect(body).toContain("<dt>Expires</dt><dd>4 Nov 2026, 09:30 UTC</dd>");
169
+ });
170
+
171
+ it("names the action only when the step's own name differs", async () => {
172
+ runtime.describeWaitpointByToken.mockResolvedValueOnce({
173
+ workflowName: "wf",
174
+ stepName: "Create approval links",
175
+ actionName: "Create Approval Links",
176
+ status: "PENDING",
177
+ waitingSince: "2026-10-28T09:30:00.000Z",
178
+ });
179
+ const body = await (await fetch(`${base}/confirm`)).text();
180
+ expect(body).toContain("<dd>Create approval links</dd>");
181
+ });
182
+
183
+ it.each([
184
+ ["COMPLETED", "Already responded"],
185
+ ["CONSUMED", "Already responded"],
186
+ ["EXPIRED", "Request expired"],
187
+ ["CANCELLED", "Run cancelled"],
188
+ ] as const)("shows a %s waitpoint without a form", async (status, title) => {
189
+ runtime.describeWaitpointByToken.mockResolvedValueOnce({
190
+ workflowName: "wf",
191
+ stepName: "step",
192
+ status,
193
+ waitingSince: "2026-10-28T09:30:00.000Z",
194
+ });
195
+ const body = await (await fetch(`${base}/confirm`)).text();
196
+ expect(body).toContain(title);
197
+ expect(body).not.toContain("<form");
198
+ });
199
+
200
+ it("answers 404 for a token the runtime does not know", async () => {
201
+ runtime.describeWaitpointByToken.mockResolvedValueOnce(undefined);
202
+ expect((await fetch(`${base}/confirm`)).status).toBe(404);
203
+ });
204
+
205
+ it("resumes on POST with body, headers and query, answering JSON", async () => {
206
+ const response = await fetch(`${base}?a=1`, {
207
+ method: "POST",
208
+ headers: {
209
+ "content-type": "application/json",
210
+ authorization: "Bearer secret",
211
+ },
212
+ body: JSON.stringify({ ok: true }),
213
+ });
214
+ expect(response.status).toBe(200);
215
+ expect(await response.json()).toMatchObject({ status: "resumed" });
216
+ const [token, payload] = runtime.resumeWaitpointByToken.mock.calls[0]!;
217
+ expect(token).toBe(TOKEN);
218
+ expect(payload.body).toEqual({ ok: true });
219
+ expect(payload.queryParams).toEqual({ a: "1" });
220
+ expect(payload.headers?.["content-type"]).toBe("application/json");
221
+ // Credentials are not journaled with the payload.
222
+ expect(payload.headers?.authorization).toBeUndefined();
223
+ });
224
+
225
+ it("answers the sync sub-path with the resumed run's reply", async () => {
226
+ const response = await fetch(`${base}/sync`, { method: "POST" });
227
+ expect(runtime.resumeWaitpointByTokenSync).toHaveBeenCalledOnce();
228
+ expect(runtime.resumeWaitpointByToken).not.toHaveBeenCalled();
229
+ expect(response.status).toBe(201);
230
+ expect(response.headers.get("x-next")).toBe("later");
231
+ expect(await response.json()).toEqual({ ok: true });
232
+ });
233
+
234
+ it("answers a gone waitpoint on the sync sub-path with 410", async () => {
235
+ runtime.resumeWaitpointByTokenSync.mockResolvedValue({ status: "gone" });
236
+ const response = await fetch(`${base}/sync`, { method: "POST" });
237
+ expect(response.status).toBe(410);
238
+ });
239
+
240
+ it("answers the confirm form with an HTML page", async () => {
241
+ const response = await form("disapprove", "too expensive");
242
+ expect(response.headers.get("content-type")).toContain("text/html");
243
+ expect(await response.text()).toContain("You disapproved this request.");
244
+ const [, payload] = runtime.resumeWaitpointByToken.mock.calls[0]!;
245
+ expect(payload.body).toEqual({ reason: "too expensive" });
246
+ expect(payload.queryParams).toEqual({
247
+ action: "disapprove",
248
+ reason: "too expensive",
249
+ });
250
+ });
251
+
252
+ it("refuses a confirm POST without an action, recording nothing", async () => {
253
+ expect((await form("maybe")).status).toBe(400);
254
+ expect(runtime.resumeWaitpointByToken).not.toHaveBeenCalled();
255
+ });
256
+
257
+ it("refuses an over-long reason, recording nothing", async () => {
258
+ const response = await form("approve", "x".repeat(MAX_REASON_LENGTH + 1));
259
+ expect(response.status).toBe(400);
260
+ expect(runtime.resumeWaitpointByToken).not.toHaveBeenCalled();
261
+ });
262
+
263
+ it("refuses a body past 1 MiB", async () => {
264
+ const response = await fetch(base, {
265
+ method: "POST",
266
+ headers: { "content-type": "text/plain" },
267
+ body: "x".repeat(1_048_577),
268
+ });
269
+ expect(response.status).toBe(413);
270
+ expect(runtime.resumeWaitpointByToken).not.toHaveBeenCalled();
271
+ });
272
+
273
+ it("answers a repeat as already responded and a gone waitpoint as 410", async () => {
274
+ runtime.resumeWaitpointByToken.mockResolvedValueOnce({ status: "already" });
275
+ const already = await form("approve");
276
+ expect(already.status).toBe(200);
277
+ expect(await already.text()).toContain("Already responded");
278
+
279
+ runtime.resumeWaitpointByToken.mockResolvedValueOnce({ status: "gone" });
280
+ const gone = await fetch(base, { method: "POST" });
281
+ expect(gone.status).toBe(410);
282
+ expect(await gone.json()).toMatchObject({
283
+ status: "gone",
284
+ discarded: true,
285
+ });
286
+ });
287
+
288
+ it("tells a sub-flow's response whether it was discarded", async () => {
289
+ const respond = () =>
290
+ fetch(base, {
291
+ method: "POST",
292
+ headers: { "content-type": "application/json" },
293
+ body: JSON.stringify({ status: "success", data: { ok: true } }),
294
+ });
295
+ runtime.resumeWaitpointByToken.mockResolvedValueOnce({ status: "resumed" });
296
+ expect(await (await respond()).json()).toMatchObject({
297
+ status: "resumed",
298
+ discarded: false,
299
+ });
300
+ runtime.resumeWaitpointByToken.mockResolvedValueOnce({ status: "already" });
301
+ expect(await (await respond()).json()).toMatchObject({
302
+ status: "already",
303
+ discarded: false,
304
+ });
305
+ });
306
+ });