@pikku/core 0.12.2 → 0.12.4

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 (282) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/crypto-utils.d.ts +10 -0
  3. package/dist/crypto-utils.js +62 -0
  4. package/dist/function/function-runner.js +4 -4
  5. package/dist/function/functions.types.d.ts +26 -1
  6. package/dist/function/functions.types.js +16 -0
  7. package/dist/handle-error.d.ts +1 -1
  8. package/dist/handle-error.js +7 -3
  9. package/dist/index.d.ts +14 -2
  10. package/dist/index.js +1 -1
  11. package/dist/pikku-state.js +3 -1
  12. package/dist/schema.js +1 -1
  13. package/dist/services/in-memory-workflow-service.d.ts +22 -3
  14. package/dist/services/in-memory-workflow-service.js +77 -1
  15. package/dist/services/workflow-service.d.ts +8 -2
  16. package/dist/testing/index.d.ts +2 -0
  17. package/dist/testing/index.js +1 -0
  18. package/dist/testing/service-tests.d.ts +31 -0
  19. package/dist/testing/service-tests.js +598 -0
  20. package/dist/types/core.types.d.ts +9 -1
  21. package/dist/types/state.types.d.ts +4 -2
  22. package/dist/utils/hash.d.ts +2 -0
  23. package/dist/utils/hash.js +23 -0
  24. package/dist/wirings/ai-agent/agent-dynamic-workflow.d.ts +6 -0
  25. package/dist/wirings/ai-agent/agent-dynamic-workflow.js +348 -0
  26. package/dist/wirings/ai-agent/ai-agent-memory.d.ts +1 -1
  27. package/dist/wirings/ai-agent/ai-agent-memory.js +6 -5
  28. package/dist/wirings/ai-agent/ai-agent-prepare.d.ts +10 -7
  29. package/dist/wirings/ai-agent/ai-agent-prepare.js +127 -47
  30. package/dist/wirings/ai-agent/ai-agent-runner.d.ts +4 -0
  31. package/dist/wirings/ai-agent/ai-agent-runner.js +381 -27
  32. package/dist/wirings/ai-agent/ai-agent-stream.d.ts +7 -2
  33. package/dist/wirings/ai-agent/ai-agent-stream.js +109 -46
  34. package/dist/wirings/ai-agent/ai-agent.types.d.ts +22 -1
  35. package/dist/wirings/ai-agent/index.d.ts +1 -2
  36. package/dist/wirings/ai-agent/index.js +1 -2
  37. package/dist/wirings/channel/channel-handler.js +5 -1
  38. package/dist/wirings/channel/channel.types.d.ts +1 -7
  39. package/dist/wirings/channel/local/local-channel-handler.d.ts +1 -1
  40. package/dist/wirings/channel/local/local-channel-handler.js +5 -3
  41. package/dist/wirings/channel/local/local-channel-runner.js +14 -4
  42. package/dist/wirings/channel/serverless/serverless-channel-runner.js +4 -1
  43. package/dist/wirings/cli/cli-runner.js +10 -2
  44. package/dist/wirings/cli/cli.types.d.ts +1 -0
  45. package/dist/wirings/http/http-routes.js +0 -1
  46. package/dist/wirings/http/http-runner.d.ts +1 -1
  47. package/dist/wirings/http/http-runner.js +25 -3
  48. package/dist/wirings/http/http.types.d.ts +3 -11
  49. package/dist/wirings/http/index.d.ts +2 -1
  50. package/dist/wirings/http/index.js +1 -0
  51. package/dist/wirings/http/pikku-fetch-http-request.d.ts +1 -0
  52. package/dist/wirings/http/pikku-fetch-http-request.js +3 -0
  53. package/dist/wirings/http/pikku-fetch-http-response.d.ts +1 -0
  54. package/dist/wirings/http/pikku-fetch-http-response.js +4 -4
  55. package/dist/wirings/http/web-request.d.ts +12 -0
  56. package/dist/wirings/http/web-request.js +85 -0
  57. package/dist/wirings/mcp/mcp-endpoint-registry.js +1 -1
  58. package/dist/wirings/mcp/mcp-runner.js +13 -1
  59. package/dist/wirings/rpc/rpc-runner.d.ts +30 -6
  60. package/dist/wirings/rpc/rpc-runner.js +36 -14
  61. package/dist/wirings/rpc/rpc-types.d.ts +6 -1
  62. package/dist/wirings/rpc/wire-addon.d.ts +1 -0
  63. package/dist/wirings/rpc/wire-addon.js +1 -1
  64. package/dist/wirings/scheduler/scheduler-runner.js +1 -0
  65. package/dist/wirings/workflow/graph/graph-validation.d.ts +3 -0
  66. package/dist/wirings/workflow/graph/graph-validation.js +175 -0
  67. package/dist/wirings/workflow/graph/index.d.ts +1 -0
  68. package/dist/wirings/workflow/graph/index.js +1 -0
  69. package/dist/wirings/workflow/index.d.ts +1 -1
  70. package/dist/wirings/workflow/pikku-workflow-service.d.ts +8 -2
  71. package/dist/wirings/workflow/pikku-workflow-service.js +1 -2
  72. package/dist/wirings/workflow/workflow.types.d.ts +10 -1
  73. package/lcov.info +18891 -0
  74. package/package.json +4 -2
  75. package/dist/wirings/ai-agent/ai-agent-assistant-ui.d.ts +0 -5
  76. package/dist/wirings/ai-agent/ai-agent-assistant-ui.js +0 -168
  77. package/src/crypto-utils.test.ts +0 -116
  78. package/src/crypto-utils.ts +0 -99
  79. package/src/errors/error-handler.ts +0 -62
  80. package/src/errors/error.test.ts +0 -195
  81. package/src/errors/errors.ts +0 -374
  82. package/src/errors/index.ts +0 -2
  83. package/src/factory-functions.test.ts +0 -109
  84. package/src/function/function-runner.test.ts +0 -536
  85. package/src/function/function-runner.ts +0 -365
  86. package/src/function/functions.types.ts +0 -267
  87. package/src/function/index.ts +0 -5
  88. package/src/handle-error.test.ts +0 -361
  89. package/src/handle-error.ts +0 -65
  90. package/src/index.ts +0 -104
  91. package/src/internal.ts +0 -6
  92. package/src/middleware/auth-apikey.test.ts +0 -363
  93. package/src/middleware/auth-apikey.ts +0 -47
  94. package/src/middleware/auth-bearer.test.ts +0 -450
  95. package/src/middleware/auth-bearer.ts +0 -72
  96. package/src/middleware/auth-cookie.test.ts +0 -528
  97. package/src/middleware/auth-cookie.ts +0 -80
  98. package/src/middleware/cors.test.ts +0 -424
  99. package/src/middleware/cors.ts +0 -104
  100. package/src/middleware/index.ts +0 -5
  101. package/src/middleware/remote-auth.test.ts +0 -488
  102. package/src/middleware/remote-auth.ts +0 -68
  103. package/src/middleware/timeout.ts +0 -15
  104. package/src/middleware-runner.test.ts +0 -418
  105. package/src/middleware-runner.ts +0 -234
  106. package/src/permissions.test.ts +0 -434
  107. package/src/permissions.ts +0 -319
  108. package/src/pikku-request.ts +0 -23
  109. package/src/pikku-response.ts +0 -5
  110. package/src/pikku-state.test.ts +0 -224
  111. package/src/pikku-state.ts +0 -214
  112. package/src/run-tests-script.test.ts +0 -49
  113. package/src/schema.test.ts +0 -249
  114. package/src/schema.ts +0 -151
  115. package/src/services/ai-agent-runner-service.ts +0 -41
  116. package/src/services/ai-run-state-service.ts +0 -20
  117. package/src/services/ai-storage-service.ts +0 -39
  118. package/src/services/content-service.ts +0 -76
  119. package/src/services/deployment-service.ts +0 -22
  120. package/src/services/gateway-service.ts +0 -20
  121. package/src/services/gopass-secrets.ts +0 -98
  122. package/src/services/in-memory-ai-run-state-service.ts +0 -73
  123. package/src/services/in-memory-trigger-service.ts +0 -64
  124. package/src/services/in-memory-workflow-service.test.ts +0 -351
  125. package/src/services/in-memory-workflow-service.ts +0 -395
  126. package/src/services/index.ts +0 -56
  127. package/src/services/jwt-service.ts +0 -30
  128. package/src/services/local-content.ts +0 -120
  129. package/src/services/local-gateway-service.ts +0 -62
  130. package/src/services/local-secrets.test.ts +0 -80
  131. package/src/services/local-secrets.ts +0 -94
  132. package/src/services/local-variables.test.ts +0 -61
  133. package/src/services/local-variables.ts +0 -39
  134. package/src/services/logger-console.test.ts +0 -118
  135. package/src/services/logger-console.ts +0 -98
  136. package/src/services/logger.ts +0 -57
  137. package/src/services/scheduler-service.ts +0 -86
  138. package/src/services/schema-service.ts +0 -33
  139. package/src/services/scoped-secret-service.test.ts +0 -74
  140. package/src/services/scoped-secret-service.ts +0 -41
  141. package/src/services/secret-service.ts +0 -38
  142. package/src/services/trigger-service.ts +0 -17
  143. package/src/services/typed-secret-service.test.ts +0 -93
  144. package/src/services/typed-secret-service.ts +0 -70
  145. package/src/services/typed-variables-service.test.ts +0 -73
  146. package/src/services/typed-variables-service.ts +0 -81
  147. package/src/services/user-session-service.test.ts +0 -113
  148. package/src/services/user-session-service.ts +0 -86
  149. package/src/services/variables-service.ts +0 -11
  150. package/src/services/workflow-service.ts +0 -84
  151. package/src/time-utils.test.ts +0 -56
  152. package/src/time-utils.ts +0 -107
  153. package/src/types/core.types.ts +0 -470
  154. package/src/types/state.types.ts +0 -186
  155. package/src/utils.test.ts +0 -350
  156. package/src/utils.ts +0 -129
  157. package/src/version.test.ts +0 -80
  158. package/src/version.ts +0 -25
  159. package/src/wirings/ai-agent/ai-agent-assistant-ui.test.ts +0 -363
  160. package/src/wirings/ai-agent/ai-agent-assistant-ui.ts +0 -238
  161. package/src/wirings/ai-agent/ai-agent-helpers.test.ts +0 -152
  162. package/src/wirings/ai-agent/ai-agent-helpers.ts +0 -76
  163. package/src/wirings/ai-agent/ai-agent-memory.ts +0 -309
  164. package/src/wirings/ai-agent/ai-agent-model-config.test.ts +0 -115
  165. package/src/wirings/ai-agent/ai-agent-model-config.ts +0 -43
  166. package/src/wirings/ai-agent/ai-agent-prepare.ts +0 -522
  167. package/src/wirings/ai-agent/ai-agent-registry.test.ts +0 -37
  168. package/src/wirings/ai-agent/ai-agent-registry.ts +0 -82
  169. package/src/wirings/ai-agent/ai-agent-runner.test.ts +0 -317
  170. package/src/wirings/ai-agent/ai-agent-runner.ts +0 -251
  171. package/src/wirings/ai-agent/ai-agent-stream.test.ts +0 -652
  172. package/src/wirings/ai-agent/ai-agent-stream.ts +0 -1060
  173. package/src/wirings/ai-agent/ai-agent.types.ts +0 -360
  174. package/src/wirings/ai-agent/index.ts +0 -41
  175. package/src/wirings/channel/channel-common.ts +0 -90
  176. package/src/wirings/channel/channel-handler.ts +0 -241
  177. package/src/wirings/channel/channel-middleware-runner.ts +0 -120
  178. package/src/wirings/channel/channel-runner.ts +0 -166
  179. package/src/wirings/channel/channel-store.ts +0 -29
  180. package/src/wirings/channel/channel.types.ts +0 -178
  181. package/src/wirings/channel/define-channel-routes.ts +0 -25
  182. package/src/wirings/channel/eventhub-service.ts +0 -34
  183. package/src/wirings/channel/eventhub-store.ts +0 -13
  184. package/src/wirings/channel/index.ts +0 -24
  185. package/src/wirings/channel/local/index.ts +0 -3
  186. package/src/wirings/channel/local/local-channel-handler.ts +0 -79
  187. package/src/wirings/channel/local/local-channel-runner.test.ts +0 -215
  188. package/src/wirings/channel/local/local-channel-runner.ts +0 -200
  189. package/src/wirings/channel/local/local-eventhub-service.test.ts +0 -95
  190. package/src/wirings/channel/local/local-eventhub-service.ts +0 -101
  191. package/src/wirings/channel/log-channels.ts +0 -20
  192. package/src/wirings/channel/pikku-abstract-channel-handler.test.ts +0 -54
  193. package/src/wirings/channel/pikku-abstract-channel-handler.ts +0 -45
  194. package/src/wirings/channel/serverless/index.ts +0 -5
  195. package/src/wirings/channel/serverless/serverless-channel-runner.ts +0 -286
  196. package/src/wirings/cli/channel/cli-channel-runner.ts +0 -136
  197. package/src/wirings/cli/channel/index.ts +0 -1
  198. package/src/wirings/cli/cli-runner.test.ts +0 -403
  199. package/src/wirings/cli/cli-runner.ts +0 -519
  200. package/src/wirings/cli/cli.types.ts +0 -357
  201. package/src/wirings/cli/command-parser.test.ts +0 -445
  202. package/src/wirings/cli/command-parser.ts +0 -504
  203. package/src/wirings/cli/define-cli-commands.ts +0 -24
  204. package/src/wirings/cli/index.ts +0 -19
  205. package/src/wirings/gateway/gateway-runner.test.ts +0 -474
  206. package/src/wirings/gateway/gateway-runner.ts +0 -411
  207. package/src/wirings/gateway/gateway.types.ts +0 -149
  208. package/src/wirings/gateway/index.ts +0 -13
  209. package/src/wirings/http/http-routes.test.ts +0 -322
  210. package/src/wirings/http/http-routes.ts +0 -198
  211. package/src/wirings/http/http-runner.test.ts +0 -144
  212. package/src/wirings/http/http-runner.ts +0 -563
  213. package/src/wirings/http/http.types.ts +0 -378
  214. package/src/wirings/http/index.ts +0 -25
  215. package/src/wirings/http/log-http-routes.ts +0 -22
  216. package/src/wirings/http/pikku-fetch-http-request.test.ts +0 -237
  217. package/src/wirings/http/pikku-fetch-http-request.ts +0 -166
  218. package/src/wirings/http/pikku-fetch-http-response.test.ts +0 -82
  219. package/src/wirings/http/pikku-fetch-http-response.ts +0 -147
  220. package/src/wirings/http/routers/http-router.ts +0 -13
  221. package/src/wirings/http/routers/path-to-regex.test.ts +0 -319
  222. package/src/wirings/http/routers/path-to-regex.ts +0 -126
  223. package/src/wirings/mcp/index.ts +0 -27
  224. package/src/wirings/mcp/mcp-endpoint-registry.test.ts +0 -389
  225. package/src/wirings/mcp/mcp-endpoint-registry.ts +0 -159
  226. package/src/wirings/mcp/mcp-runner.ts +0 -305
  227. package/src/wirings/mcp/mcp.types.ts +0 -216
  228. package/src/wirings/node/index.ts +0 -2
  229. package/src/wirings/node/node.types.ts +0 -23
  230. package/src/wirings/oauth2/index.ts +0 -3
  231. package/src/wirings/oauth2/oauth2-client.test.ts +0 -929
  232. package/src/wirings/oauth2/oauth2-client.ts +0 -335
  233. package/src/wirings/oauth2/oauth2.types.ts +0 -69
  234. package/src/wirings/oauth2/wire-oauth2-credential.ts +0 -23
  235. package/src/wirings/queue/index.ts +0 -31
  236. package/src/wirings/queue/queue-runner.test.ts +0 -710
  237. package/src/wirings/queue/queue-runner.ts +0 -192
  238. package/src/wirings/queue/queue.types.ts +0 -189
  239. package/src/wirings/queue/register-queue-helper.ts +0 -60
  240. package/src/wirings/queue/validate-worker-config.test.ts +0 -108
  241. package/src/wirings/queue/validate-worker-config.ts +0 -116
  242. package/src/wirings/rpc/index.ts +0 -4
  243. package/src/wirings/rpc/rpc-runner.ts +0 -439
  244. package/src/wirings/rpc/rpc-types.ts +0 -51
  245. package/src/wirings/rpc/wire-addon.ts +0 -20
  246. package/src/wirings/scheduler/index.ts +0 -11
  247. package/src/wirings/scheduler/log-schedulers.ts +0 -20
  248. package/src/wirings/scheduler/scheduler-runner.test.ts +0 -660
  249. package/src/wirings/scheduler/scheduler-runner.ts +0 -132
  250. package/src/wirings/scheduler/scheduler.types.ts +0 -53
  251. package/src/wirings/secret/index.ts +0 -9
  252. package/src/wirings/secret/secret.types.ts +0 -32
  253. package/src/wirings/secret/validate-secret-definitions.test.ts +0 -140
  254. package/src/wirings/secret/validate-secret-definitions.ts +0 -82
  255. package/src/wirings/trigger/index.ts +0 -10
  256. package/src/wirings/trigger/pikku-trigger-service.ts +0 -112
  257. package/src/wirings/trigger/trigger-runner.test.ts +0 -79
  258. package/src/wirings/trigger/trigger-runner.ts +0 -135
  259. package/src/wirings/trigger/trigger.types.ts +0 -178
  260. package/src/wirings/variable/index.ts +0 -8
  261. package/src/wirings/variable/validate-variable-definitions.test.ts +0 -91
  262. package/src/wirings/variable/validate-variable-definitions.ts +0 -69
  263. package/src/wirings/variable/variable.types.ts +0 -22
  264. package/src/wirings/workflow/dsl/index.ts +0 -31
  265. package/src/wirings/workflow/dsl/workflow-dsl.types.ts +0 -320
  266. package/src/wirings/workflow/dsl/workflow-runner.ts +0 -28
  267. package/src/wirings/workflow/graph/graph-node.ts +0 -222
  268. package/src/wirings/workflow/graph/graph-runner.test.ts +0 -487
  269. package/src/wirings/workflow/graph/graph-runner.ts +0 -816
  270. package/src/wirings/workflow/graph/index.ts +0 -14
  271. package/src/wirings/workflow/graph/template.test.ts +0 -49
  272. package/src/wirings/workflow/graph/template.ts +0 -42
  273. package/src/wirings/workflow/graph/wire-workflow-graph.ts +0 -29
  274. package/src/wirings/workflow/graph/workflow-graph.types.ts +0 -104
  275. package/src/wirings/workflow/index.ts +0 -81
  276. package/src/wirings/workflow/pikku-workflow-service.test.ts +0 -200
  277. package/src/wirings/workflow/pikku-workflow-service.ts +0 -1165
  278. package/src/wirings/workflow/workflow-helpers.test.ts +0 -129
  279. package/src/wirings/workflow/workflow-helpers.ts +0 -79
  280. package/src/wirings/workflow/workflow.types.ts +0 -266
  281. package/tsconfig.json +0 -14
  282. package/tsconfig.tsbuildinfo +0 -1
@@ -1,487 +0,0 @@
1
- import { describe, test } from 'node:test'
2
- import assert from 'node:assert/strict'
3
-
4
- import { InMemoryWorkflowService } from '../../../services/in-memory-workflow-service.js'
5
- import {
6
- continueGraph,
7
- executeGraphStep,
8
- runWorkflowGraph,
9
- } from './graph-runner.js'
10
- import type { WorkflowRuntimeMeta } from '../workflow.types.js'
11
- import { pikkuState } from '../../../pikku-state.js'
12
- import { RPCNotFoundError } from '../../rpc/rpc-runner.js'
13
-
14
- describe('graph-runner bugs', () => {
15
- test('continueGraph should NOT mark workflow completed while nodes are still running', async () => {
16
- const ws = new InMemoryWorkflowService()
17
-
18
- const meta: WorkflowRuntimeMeta = {
19
- name: 'testPrematureCompletion',
20
- pikkuFuncId: 'testPrematureCompletion',
21
- source: 'graph',
22
- entryNodeIds: ['a'],
23
- graphHash: 'test-hash',
24
- nodes: {
25
- a: { nodeId: 'a', rpcName: 'doA', next: 'b' },
26
- b: { nodeId: 'b', rpcName: 'doB' },
27
- },
28
- }
29
-
30
- const runId = await ws.createRun(
31
- 'testPrematureCompletion',
32
- {},
33
- false,
34
- 'test-hash',
35
- { type: 'test' }
36
- )
37
-
38
- const stepA = await ws.insertStepState(runId, 'a', 'doA', {})
39
- await ws.setStepRunning(stepA.stepId)
40
- await ws.setStepResult(stepA.stepId, { ok: true })
41
-
42
- const stepB = await ws.insertStepState(runId, 'b', 'doB', {})
43
- await ws.setStepRunning(stepB.stepId)
44
-
45
- await continueGraph(ws, runId, 'testPrematureCompletion', meta)
46
-
47
- const run = await ws.getRun(runId)
48
- assert.notEqual(
49
- run?.status,
50
- 'completed',
51
- 'workflow should NOT be completed while node b is still running'
52
- )
53
- assert.equal(run?.status, 'running')
54
- })
55
-
56
- test('runWorkflowGraph should throw and not create a run for unknown input refs', async () => {
57
- const ws = new InMemoryWorkflowService()
58
-
59
- const metaState = pikkuState(null, 'workflows', 'meta')
60
- metaState['testOrphanedRun'] = {
61
- name: 'testOrphanedRun',
62
- pikkuFuncId: 'testOrphanedRun',
63
- source: 'graph',
64
- entryNodeIds: ['a'],
65
- graphHash: 'orphan-hash',
66
- nodes: {
67
- a: {
68
- nodeId: 'a',
69
- rpcName: 'doA',
70
- input: { dep: { $ref: 'someOtherNode', path: 'value' } },
71
- },
72
- },
73
- }
74
-
75
- await assert.rejects(() => runWorkflowGraph(ws, 'testOrphanedRun', {}), {
76
- message: /references unknown node 'someOtherNode' in input/,
77
- })
78
-
79
- const runs: string[] = [...(ws as any).runs.keys()]
80
- assert.equal(
81
- runs.length,
82
- 0,
83
- 'no run should be created when entry nodes have unsatisfied dependencies'
84
- )
85
-
86
- delete metaState['testOrphanedRun']
87
- })
88
-
89
- test('runWorkflowGraph should throw and not create a run for unknown next targets', async () => {
90
- const ws = new InMemoryWorkflowService()
91
-
92
- const metaState = pikkuState(null, 'workflows', 'meta')
93
- metaState['testUnknownNextTarget'] = {
94
- name: 'testUnknownNextTarget',
95
- pikkuFuncId: 'testUnknownNextTarget',
96
- source: 'graph',
97
- entryNodeIds: ['a'],
98
- graphHash: 'unknown-next-hash',
99
- nodes: {
100
- a: { nodeId: 'a', rpcName: 'doA', next: 'missingNode' },
101
- },
102
- }
103
-
104
- await assert.rejects(
105
- () => runWorkflowGraph(ws, 'testUnknownNextTarget', {}),
106
- {
107
- message: /routes to unknown node 'missingNode'/,
108
- }
109
- )
110
-
111
- const runs: string[] = [...(ws as any).runs.keys()]
112
- assert.equal(
113
- runs.length,
114
- 0,
115
- 'no run should be created for invalid next targets'
116
- )
117
-
118
- delete metaState['testUnknownNextTarget']
119
- })
120
-
121
- test('continueGraph should throw for ambiguous template step remapping', async () => {
122
- const ws = new InMemoryWorkflowService()
123
-
124
- const meta: WorkflowRuntimeMeta = {
125
- name: 'testAmbiguousTemplateStepRemap',
126
- pikkuFuncId: 'testAmbiguousTemplateStepRemap',
127
- source: 'graph',
128
- entryNodeIds: ['start'],
129
- graphHash: 'ambiguous-step-remap-hash',
130
- nodes: {
131
- start: { nodeId: 'start', rpcName: 'doStart' },
132
- 'task-${id}': { nodeId: 'task-${id}', rpcName: 'doTaskById' },
133
- 'task-${name}': { nodeId: 'task-${name}', rpcName: 'doTaskByName' },
134
- },
135
- }
136
-
137
- const runId = await ws.createRun(
138
- 'testAmbiguousTemplateStepRemap',
139
- {},
140
- false,
141
- 'ambiguous-step-remap-hash',
142
- { type: 'test' }
143
- )
144
-
145
- const step = await ws.insertStepState(runId, 'task-123', 'doTask', {})
146
- await ws.setStepRunning(step.stepId)
147
- await ws.setStepResult(step.stepId, { ok: true })
148
-
149
- await assert.rejects(
150
- () => continueGraph(ws, runId, 'testAmbiguousTemplateStepRemap', meta),
151
- {
152
- message: /ambiguous template node match for 'task-123'/i,
153
- }
154
- )
155
- })
156
-
157
- test('continueGraph should throw for ambiguous template branch key remapping', async () => {
158
- const ws = new InMemoryWorkflowService()
159
-
160
- const meta: WorkflowRuntimeMeta = {
161
- name: 'testAmbiguousTemplateBranchRemap',
162
- pikkuFuncId: 'testAmbiguousTemplateBranchRemap',
163
- source: 'graph',
164
- entryNodeIds: ['start'],
165
- graphHash: 'ambiguous-branch-remap-hash',
166
- nodes: {
167
- start: { nodeId: 'start', rpcName: 'doStart' },
168
- 'branch-${id}': { nodeId: 'branch-${id}', rpcName: 'doBranchById' },
169
- 'branch-${name}': {
170
- nodeId: 'branch-${name}',
171
- rpcName: 'doBranchByName',
172
- },
173
- },
174
- }
175
-
176
- const runId = await ws.createRun(
177
- 'testAmbiguousTemplateBranchRemap',
178
- {},
179
- false,
180
- 'ambiguous-branch-remap-hash',
181
- { type: 'test' }
182
- )
183
-
184
- const step = await ws.insertStepState(runId, 'branch-1', 'doBranch', {})
185
- await ws.setBranchTaken(step.stepId, 'next')
186
-
187
- await assert.rejects(
188
- () => continueGraph(ws, runId, 'testAmbiguousTemplateBranchRemap', meta),
189
- {
190
- message: /ambiguous template branch key match for 'branch-1'/i,
191
- }
192
- )
193
- })
194
-
195
- test('continueGraph should queue converging next node only once', async () => {
196
- const ws = new InMemoryWorkflowService()
197
- const queuedNodes: string[] = []
198
-
199
- pikkuState(null, 'package', 'singletonServices', {
200
- queueService: {
201
- add: async (_queueName: string, data: any) => {
202
- if (data?.stepName) {
203
- queuedNodes.push(data.stepName)
204
- }
205
- },
206
- },
207
- } as any)
208
-
209
- const meta: WorkflowRuntimeMeta = {
210
- name: 'testConvergingNextNode',
211
- pikkuFuncId: 'testConvergingNextNode',
212
- source: 'graph',
213
- entryNodeIds: ['a', 'b'],
214
- graphHash: 'converging-hash',
215
- nodes: {
216
- a: { nodeId: 'a', rpcName: 'doA', next: 'c' },
217
- b: { nodeId: 'b', rpcName: 'doB', next: 'c' },
218
- c: { nodeId: 'c', rpcName: 'doC' },
219
- },
220
- }
221
-
222
- const runId = await ws.createRun(
223
- 'testConvergingNextNode',
224
- {},
225
- false,
226
- 'converging-hash',
227
- { type: 'test' }
228
- )
229
-
230
- const stepA = await ws.insertStepState(runId, 'a', 'doA', {})
231
- await ws.setStepRunning(stepA.stepId)
232
- await ws.setStepResult(stepA.stepId, { ok: true })
233
-
234
- const stepB = await ws.insertStepState(runId, 'b', 'doB', {})
235
- await ws.setStepRunning(stepB.stepId)
236
- await ws.setStepResult(stepB.stepId, { ok: true })
237
-
238
- await continueGraph(ws, runId, 'testConvergingNextNode', meta)
239
-
240
- assert.deepEqual(queuedNodes, ['c'])
241
- })
242
-
243
- test('inline graph should execute converging next node only once', async () => {
244
- const ws = new InMemoryWorkflowService()
245
- let cCalls = 0
246
-
247
- const mockRpcService = {
248
- rpcWithWire: async (rpcName: string) => {
249
- if (rpcName === 'doA' || rpcName === 'doB') {
250
- return { ok: true }
251
- }
252
- if (rpcName === 'doC') {
253
- cCalls += 1
254
- return { ok: true }
255
- }
256
- return {}
257
- },
258
- }
259
-
260
- const metaState = pikkuState(null, 'workflows', 'meta')
261
- metaState['testInlineConvergingSingleExecution'] = {
262
- name: 'testInlineConvergingSingleExecution',
263
- pikkuFuncId: 'testInlineConvergingSingleExecution',
264
- source: 'graph',
265
- entryNodeIds: ['a', 'b'],
266
- graphHash: 'inline-converging-hash',
267
- nodes: {
268
- a: { nodeId: 'a', rpcName: 'doA', next: 'c' },
269
- b: { nodeId: 'b', rpcName: 'doB', next: 'c' },
270
- c: { nodeId: 'c', rpcName: 'doC' },
271
- },
272
- }
273
-
274
- await runWorkflowGraph(
275
- ws,
276
- 'testInlineConvergingSingleExecution',
277
- {},
278
- mockRpcService,
279
- true
280
- )
281
-
282
- assert.equal(cCalls, 1)
283
-
284
- delete metaState['testInlineConvergingSingleExecution']
285
- })
286
-
287
- test('inline graph node failure should mark workflow as failed', async () => {
288
- const ws = new InMemoryWorkflowService()
289
-
290
- const mockRpcService = {
291
- rpcWithWire: async (rpcName: string, _data: any, _wire: any) => {
292
- if (rpcName === 'doA') return { ok: true }
293
- if (rpcName === 'doB') throw new Error('doB exploded')
294
- return {}
295
- },
296
- }
297
-
298
- const metaState = pikkuState(null, 'workflows', 'meta')
299
- metaState['testInlineFailure'] = {
300
- name: 'testInlineFailure',
301
- pikkuFuncId: 'testInlineFailure',
302
- source: 'graph',
303
- entryNodeIds: ['a'],
304
- graphHash: 'inline-fail-hash',
305
- nodes: {
306
- a: { nodeId: 'a', rpcName: 'doA', next: 'b' },
307
- b: { nodeId: 'b', rpcName: 'doB' },
308
- },
309
- }
310
-
311
- let runId: string | undefined
312
- try {
313
- const result = await runWorkflowGraph(
314
- ws,
315
- 'testInlineFailure',
316
- {},
317
- mockRpcService,
318
- true
319
- )
320
- runId = result.runId
321
- } catch {
322
- const runs = (ws as any).runs as Map<string, any>
323
- for (const [id] of runs) {
324
- runId = id
325
- break
326
- }
327
- }
328
-
329
- assert.ok(runId, 'should have created a run')
330
- const run = await ws.getRun(runId!)
331
- assert.equal(
332
- run?.status,
333
- 'failed',
334
- 'workflow should be failed after inline node error, not left running'
335
- )
336
-
337
- delete metaState['testInlineFailure']
338
- })
339
-
340
- test('executeGraphStep should throw after queueing onError nodes', async () => {
341
- const ws = new InMemoryWorkflowService()
342
-
343
- pikkuState(null, 'package', 'singletonServices', {
344
- queueService: {
345
- add: async () => {},
346
- },
347
- } as any)
348
-
349
- const metaState = pikkuState(null, 'workflows', 'meta')
350
- metaState['testQueuedOnErrorThrow'] = {
351
- name: 'testQueuedOnErrorThrow',
352
- pikkuFuncId: 'testQueuedOnErrorThrow',
353
- source: 'graph',
354
- entryNodeIds: ['a'],
355
- graphHash: 'queued-on-error-hash',
356
- nodes: {
357
- a: { nodeId: 'a', rpcName: 'doA', onError: 'onErr' },
358
- onErr: { nodeId: 'onErr', rpcName: 'handleErr' },
359
- },
360
- }
361
-
362
- const runId = await ws.createRun(
363
- 'testQueuedOnErrorThrow',
364
- {},
365
- false,
366
- 'queued-on-error-hash',
367
- { type: 'test' }
368
- )
369
- const step = await ws.insertStepState(runId, 'a', 'doA', {})
370
-
371
- const rpcService = {
372
- rpcWithWire: async () => {
373
- throw new Error('boom')
374
- },
375
- }
376
-
377
- await assert.rejects(
378
- () =>
379
- executeGraphStep(
380
- ws,
381
- rpcService,
382
- runId,
383
- step.stepId,
384
- 'a',
385
- 'doA',
386
- {},
387
- 'testQueuedOnErrorThrow'
388
- ),
389
- /boom/
390
- )
391
-
392
- const errorStep = await ws.getStepState(runId, 'onErr')
393
- assert.notEqual(
394
- errorStep.stepId,
395
- '',
396
- 'onError node should be queued as a step'
397
- )
398
-
399
- delete metaState['testQueuedOnErrorThrow']
400
- })
401
-
402
- test('executeWorkflowStep should mark graph step failed and suspend run on RPCNotFoundError', async () => {
403
- const ws = new InMemoryWorkflowService()
404
-
405
- const metaState = pikkuState(null, 'workflows', 'meta')
406
- metaState['testQueuedRpcMissing'] = {
407
- name: 'testQueuedRpcMissing',
408
- pikkuFuncId: 'testQueuedRpcMissing',
409
- source: 'graph',
410
- entryNodeIds: ['a'],
411
- graphHash: 'queued-rpc-missing-hash',
412
- nodes: {
413
- a: { nodeId: 'a', rpcName: 'missingRpc' },
414
- },
415
- }
416
-
417
- const runId = await ws.createRun(
418
- 'testQueuedRpcMissing',
419
- {},
420
- false,
421
- 'queued-rpc-missing-hash',
422
- { type: 'test' }
423
- )
424
- await ws.insertStepState(runId, 'a', 'missingRpc', {})
425
-
426
- const rpcService = {
427
- rpcWithWire: async () => {
428
- throw new RPCNotFoundError('missingRpc')
429
- },
430
- }
431
-
432
- await ws.executeWorkflowStep(runId, 'a', 'missingRpc', {}, rpcService)
433
-
434
- const step = await ws.getStepState(runId, 'a')
435
- const run = await ws.getRun(runId)
436
-
437
- assert.equal(step.status, 'failed')
438
- assert.equal(step.error?.message, 'RPC function not found: missingRpc')
439
- assert.equal(run?.status, 'suspended')
440
- assert.equal(run?.error?.code, 'RPC_NOT_FOUND')
441
-
442
- delete metaState['testQueuedRpcMissing']
443
- })
444
-
445
- test('inline graph missing RPC should mark step failed and suspend run', async () => {
446
- const ws = new InMemoryWorkflowService()
447
-
448
- const metaState = pikkuState(null, 'workflows', 'meta')
449
- metaState['testInlineRpcMissing'] = {
450
- name: 'testInlineRpcMissing',
451
- pikkuFuncId: 'testInlineRpcMissing',
452
- source: 'graph',
453
- entryNodeIds: ['a'],
454
- graphHash: 'inline-rpc-missing-hash',
455
- nodes: {
456
- a: { nodeId: 'a', rpcName: 'missingInlineRpc' },
457
- },
458
- }
459
-
460
- const rpcService = {
461
- rpcWithWire: async () => {
462
- throw new RPCNotFoundError('missingInlineRpc')
463
- },
464
- }
465
-
466
- const { runId } = await runWorkflowGraph(
467
- ws,
468
- 'testInlineRpcMissing',
469
- {},
470
- rpcService,
471
- true
472
- )
473
-
474
- const step = await ws.getStepState(runId, 'a')
475
- const run = await ws.getRun(runId)
476
-
477
- assert.equal(step.status, 'failed')
478
- assert.equal(
479
- step.error?.message,
480
- 'RPC function not found: missingInlineRpc'
481
- )
482
- assert.equal(run?.status, 'suspended')
483
- assert.equal(run?.error?.code, 'RPC_NOT_FOUND')
484
-
485
- delete metaState['testInlineRpcMissing']
486
- })
487
- })