@pikku/core 0.12.3 → 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 (218) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/services/in-memory-workflow-service.d.ts +15 -2
  3. package/dist/services/in-memory-workflow-service.js +49 -0
  4. package/lcov.info +18891 -0
  5. package/package.json +1 -1
  6. package/src/crypto-utils.test.ts +0 -214
  7. package/src/crypto-utils.ts +0 -213
  8. package/src/errors/error-handler.ts +0 -62
  9. package/src/errors/error.test.ts +0 -195
  10. package/src/errors/errors.ts +0 -374
  11. package/src/errors/index.ts +0 -2
  12. package/src/factory-functions.test.ts +0 -109
  13. package/src/function/function-runner.test.ts +0 -536
  14. package/src/function/function-runner.ts +0 -365
  15. package/src/function/functions.types.ts +0 -304
  16. package/src/function/index.ts +0 -5
  17. package/src/handle-error.test.ts +0 -424
  18. package/src/handle-error.ts +0 -69
  19. package/src/index.ts +0 -118
  20. package/src/internal.ts +0 -6
  21. package/src/middleware/auth-apikey.test.ts +0 -363
  22. package/src/middleware/auth-apikey.ts +0 -47
  23. package/src/middleware/auth-bearer.test.ts +0 -450
  24. package/src/middleware/auth-bearer.ts +0 -72
  25. package/src/middleware/auth-cookie.test.ts +0 -528
  26. package/src/middleware/auth-cookie.ts +0 -80
  27. package/src/middleware/cors.test.ts +0 -424
  28. package/src/middleware/cors.ts +0 -104
  29. package/src/middleware/index.ts +0 -5
  30. package/src/middleware/remote-auth.test.ts +0 -488
  31. package/src/middleware/remote-auth.ts +0 -68
  32. package/src/middleware/timeout.ts +0 -15
  33. package/src/middleware-runner.test.ts +0 -418
  34. package/src/middleware-runner.ts +0 -234
  35. package/src/permissions.test.ts +0 -434
  36. package/src/permissions.ts +0 -319
  37. package/src/pikku-request.ts +0 -23
  38. package/src/pikku-response.ts +0 -5
  39. package/src/pikku-state.test.ts +0 -224
  40. package/src/pikku-state.ts +0 -216
  41. package/src/run-tests-script.test.ts +0 -49
  42. package/src/schema.test.ts +0 -249
  43. package/src/schema.ts +0 -151
  44. package/src/services/ai-agent-runner-service.ts +0 -41
  45. package/src/services/ai-run-state-service.ts +0 -20
  46. package/src/services/ai-storage-service.ts +0 -39
  47. package/src/services/content-service.ts +0 -76
  48. package/src/services/deployment-service.ts +0 -22
  49. package/src/services/gateway-service.ts +0 -20
  50. package/src/services/gopass-secrets.ts +0 -98
  51. package/src/services/in-memory-ai-run-state-service.ts +0 -73
  52. package/src/services/in-memory-trigger-service.ts +0 -64
  53. package/src/services/in-memory-workflow-service.test.ts +0 -351
  54. package/src/services/in-memory-workflow-service.ts +0 -438
  55. package/src/services/index.ts +0 -56
  56. package/src/services/jwt-service.ts +0 -30
  57. package/src/services/local-content.ts +0 -120
  58. package/src/services/local-gateway-service.ts +0 -62
  59. package/src/services/local-secrets.test.ts +0 -80
  60. package/src/services/local-secrets.ts +0 -94
  61. package/src/services/local-variables.test.ts +0 -61
  62. package/src/services/local-variables.ts +0 -39
  63. package/src/services/logger-console.test.ts +0 -118
  64. package/src/services/logger-console.ts +0 -98
  65. package/src/services/logger.ts +0 -57
  66. package/src/services/scheduler-service.ts +0 -86
  67. package/src/services/schema-service.ts +0 -33
  68. package/src/services/scoped-secret-service.test.ts +0 -74
  69. package/src/services/scoped-secret-service.ts +0 -41
  70. package/src/services/secret-service.ts +0 -38
  71. package/src/services/trigger-service.ts +0 -17
  72. package/src/services/typed-secret-service.test.ts +0 -93
  73. package/src/services/typed-secret-service.ts +0 -70
  74. package/src/services/typed-variables-service.test.ts +0 -73
  75. package/src/services/typed-variables-service.ts +0 -81
  76. package/src/services/user-session-service.test.ts +0 -113
  77. package/src/services/user-session-service.ts +0 -86
  78. package/src/services/variables-service.ts +0 -11
  79. package/src/services/workflow-service.ts +0 -95
  80. package/src/testing/index.ts +0 -2
  81. package/src/testing/service-tests.ts +0 -873
  82. package/src/time-utils.test.ts +0 -56
  83. package/src/time-utils.ts +0 -107
  84. package/src/types/core.types.ts +0 -478
  85. package/src/types/state.types.ts +0 -188
  86. package/src/utils/hash.test.ts +0 -68
  87. package/src/utils/hash.ts +0 -26
  88. package/src/utils.test.ts +0 -350
  89. package/src/utils.ts +0 -129
  90. package/src/version.test.ts +0 -80
  91. package/src/version.ts +0 -25
  92. package/src/wirings/ai-agent/agent-dynamic-workflow.ts +0 -469
  93. package/src/wirings/ai-agent/ai-agent-helpers.test.ts +0 -152
  94. package/src/wirings/ai-agent/ai-agent-helpers.ts +0 -76
  95. package/src/wirings/ai-agent/ai-agent-memory.ts +0 -310
  96. package/src/wirings/ai-agent/ai-agent-model-config.test.ts +0 -115
  97. package/src/wirings/ai-agent/ai-agent-model-config.ts +0 -43
  98. package/src/wirings/ai-agent/ai-agent-prepare.ts +0 -636
  99. package/src/wirings/ai-agent/ai-agent-registry.test.ts +0 -37
  100. package/src/wirings/ai-agent/ai-agent-registry.ts +0 -82
  101. package/src/wirings/ai-agent/ai-agent-runner.test.ts +0 -319
  102. package/src/wirings/ai-agent/ai-agent-runner.ts +0 -773
  103. package/src/wirings/ai-agent/ai-agent-stream.test.ts +0 -859
  104. package/src/wirings/ai-agent/ai-agent-stream.ts +0 -1153
  105. package/src/wirings/ai-agent/ai-agent.types.ts +0 -382
  106. package/src/wirings/ai-agent/index.ts +0 -37
  107. package/src/wirings/channel/channel-common.ts +0 -90
  108. package/src/wirings/channel/channel-handler.ts +0 -250
  109. package/src/wirings/channel/channel-middleware-runner.ts +0 -120
  110. package/src/wirings/channel/channel-runner.ts +0 -166
  111. package/src/wirings/channel/channel-store.ts +0 -29
  112. package/src/wirings/channel/channel.types.ts +0 -172
  113. package/src/wirings/channel/define-channel-routes.ts +0 -25
  114. package/src/wirings/channel/eventhub-service.ts +0 -34
  115. package/src/wirings/channel/eventhub-store.ts +0 -13
  116. package/src/wirings/channel/index.ts +0 -24
  117. package/src/wirings/channel/local/index.ts +0 -3
  118. package/src/wirings/channel/local/local-channel-handler.ts +0 -81
  119. package/src/wirings/channel/local/local-channel-runner.test.ts +0 -215
  120. package/src/wirings/channel/local/local-channel-runner.ts +0 -210
  121. package/src/wirings/channel/local/local-eventhub-service.test.ts +0 -95
  122. package/src/wirings/channel/local/local-eventhub-service.ts +0 -101
  123. package/src/wirings/channel/log-channels.ts +0 -20
  124. package/src/wirings/channel/pikku-abstract-channel-handler.test.ts +0 -54
  125. package/src/wirings/channel/pikku-abstract-channel-handler.ts +0 -45
  126. package/src/wirings/channel/serverless/index.ts +0 -5
  127. package/src/wirings/channel/serverless/serverless-channel-runner.ts +0 -289
  128. package/src/wirings/cli/channel/cli-channel-runner.ts +0 -136
  129. package/src/wirings/cli/channel/index.ts +0 -1
  130. package/src/wirings/cli/cli-runner.test.ts +0 -403
  131. package/src/wirings/cli/cli-runner.ts +0 -529
  132. package/src/wirings/cli/cli.types.ts +0 -358
  133. package/src/wirings/cli/command-parser.test.ts +0 -445
  134. package/src/wirings/cli/command-parser.ts +0 -504
  135. package/src/wirings/cli/define-cli-commands.ts +0 -24
  136. package/src/wirings/cli/index.ts +0 -19
  137. package/src/wirings/gateway/gateway-runner.test.ts +0 -474
  138. package/src/wirings/gateway/gateway-runner.ts +0 -411
  139. package/src/wirings/gateway/gateway.types.ts +0 -149
  140. package/src/wirings/gateway/index.ts +0 -13
  141. package/src/wirings/http/http-routes.test.ts +0 -322
  142. package/src/wirings/http/http-routes.ts +0 -197
  143. package/src/wirings/http/http-runner.test.ts +0 -144
  144. package/src/wirings/http/http-runner.ts +0 -588
  145. package/src/wirings/http/http.types.ts +0 -369
  146. package/src/wirings/http/index.ts +0 -28
  147. package/src/wirings/http/log-http-routes.ts +0 -22
  148. package/src/wirings/http/pikku-fetch-http-request.test.ts +0 -237
  149. package/src/wirings/http/pikku-fetch-http-request.ts +0 -170
  150. package/src/wirings/http/pikku-fetch-http-response.test.ts +0 -82
  151. package/src/wirings/http/pikku-fetch-http-response.ts +0 -147
  152. package/src/wirings/http/routers/http-router.ts +0 -13
  153. package/src/wirings/http/routers/path-to-regex.test.ts +0 -319
  154. package/src/wirings/http/routers/path-to-regex.ts +0 -126
  155. package/src/wirings/http/web-request.test.ts +0 -236
  156. package/src/wirings/http/web-request.ts +0 -104
  157. package/src/wirings/mcp/index.ts +0 -27
  158. package/src/wirings/mcp/mcp-endpoint-registry.test.ts +0 -389
  159. package/src/wirings/mcp/mcp-endpoint-registry.ts +0 -159
  160. package/src/wirings/mcp/mcp-runner.ts +0 -323
  161. package/src/wirings/mcp/mcp.types.ts +0 -216
  162. package/src/wirings/node/index.ts +0 -2
  163. package/src/wirings/node/node.types.ts +0 -23
  164. package/src/wirings/oauth2/index.ts +0 -3
  165. package/src/wirings/oauth2/oauth2-client.test.ts +0 -929
  166. package/src/wirings/oauth2/oauth2-client.ts +0 -335
  167. package/src/wirings/oauth2/oauth2.types.ts +0 -69
  168. package/src/wirings/oauth2/wire-oauth2-credential.ts +0 -23
  169. package/src/wirings/queue/index.ts +0 -31
  170. package/src/wirings/queue/queue-runner.test.ts +0 -710
  171. package/src/wirings/queue/queue-runner.ts +0 -192
  172. package/src/wirings/queue/queue.types.ts +0 -189
  173. package/src/wirings/queue/register-queue-helper.ts +0 -60
  174. package/src/wirings/queue/validate-worker-config.test.ts +0 -108
  175. package/src/wirings/queue/validate-worker-config.ts +0 -116
  176. package/src/wirings/rpc/index.ts +0 -4
  177. package/src/wirings/rpc/rpc-runner.ts +0 -460
  178. package/src/wirings/rpc/rpc-types.ts +0 -56
  179. package/src/wirings/rpc/wire-addon.ts +0 -21
  180. package/src/wirings/scheduler/index.ts +0 -11
  181. package/src/wirings/scheduler/log-schedulers.ts +0 -20
  182. package/src/wirings/scheduler/scheduler-runner.test.ts +0 -660
  183. package/src/wirings/scheduler/scheduler-runner.ts +0 -133
  184. package/src/wirings/scheduler/scheduler.types.ts +0 -53
  185. package/src/wirings/secret/index.ts +0 -9
  186. package/src/wirings/secret/secret.types.ts +0 -32
  187. package/src/wirings/secret/validate-secret-definitions.test.ts +0 -140
  188. package/src/wirings/secret/validate-secret-definitions.ts +0 -82
  189. package/src/wirings/trigger/index.ts +0 -10
  190. package/src/wirings/trigger/pikku-trigger-service.ts +0 -112
  191. package/src/wirings/trigger/trigger-runner.test.ts +0 -79
  192. package/src/wirings/trigger/trigger-runner.ts +0 -135
  193. package/src/wirings/trigger/trigger.types.ts +0 -178
  194. package/src/wirings/variable/index.ts +0 -8
  195. package/src/wirings/variable/validate-variable-definitions.test.ts +0 -91
  196. package/src/wirings/variable/validate-variable-definitions.ts +0 -69
  197. package/src/wirings/variable/variable.types.ts +0 -22
  198. package/src/wirings/workflow/dsl/index.ts +0 -31
  199. package/src/wirings/workflow/dsl/workflow-dsl.types.ts +0 -320
  200. package/src/wirings/workflow/dsl/workflow-runner.ts +0 -28
  201. package/src/wirings/workflow/graph/graph-node.ts +0 -222
  202. package/src/wirings/workflow/graph/graph-runner.test.ts +0 -487
  203. package/src/wirings/workflow/graph/graph-runner.ts +0 -816
  204. package/src/wirings/workflow/graph/graph-validation.test.ts +0 -170
  205. package/src/wirings/workflow/graph/graph-validation.ts +0 -237
  206. package/src/wirings/workflow/graph/index.ts +0 -19
  207. package/src/wirings/workflow/graph/template.test.ts +0 -49
  208. package/src/wirings/workflow/graph/template.ts +0 -42
  209. package/src/wirings/workflow/graph/wire-workflow-graph.ts +0 -29
  210. package/src/wirings/workflow/graph/workflow-graph.types.ts +0 -104
  211. package/src/wirings/workflow/index.ts +0 -82
  212. package/src/wirings/workflow/pikku-workflow-service.test.ts +0 -200
  213. package/src/wirings/workflow/pikku-workflow-service.ts +0 -1176
  214. package/src/wirings/workflow/workflow-helpers.test.ts +0 -129
  215. package/src/wirings/workflow/workflow-helpers.ts +0 -79
  216. package/src/wirings/workflow/workflow.types.ts +0 -274
  217. package/tsconfig.json +0 -14
  218. 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
- })