@hexabot-ai/agentic 3.5.0 → 3.6.0-beta.0
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.
- package/README.md +12 -3
- package/dist/cjs/action/abstract-action.js +51 -35
- package/dist/cjs/bindings/base-binding.js +229 -211
- package/dist/cjs/checkpoint.js +1 -1
- package/dist/cjs/context.js +2 -3
- package/dist/cjs/dsl.types.js +44 -90
- package/dist/cjs/errors.js +13 -1
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/resume-payload.js +11 -1
- package/dist/cjs/runner-runtime-control.js +39 -27
- package/dist/cjs/step-executors/conditional-executor.js +2 -7
- package/dist/cjs/step-executors/loop-executor.js +14 -28
- package/dist/cjs/step-executors/parallel-executor.js +14 -25
- package/dist/cjs/step-executors/scope.js +25 -0
- package/dist/cjs/step-executors/skip-helpers.js +26 -34
- package/dist/cjs/step-executors/task-executor.js +58 -69
- package/dist/cjs/utils/flow-steps.js +41 -0
- package/dist/cjs/utils/naming.js +10 -10
- package/dist/cjs/utils/object-path.js +51 -0
- package/dist/cjs/utils/timeout.js +16 -39
- package/dist/cjs/validation-issue.js +14 -1
- package/dist/cjs/workflow-compiler.js +52 -96
- package/dist/cjs/workflow-fingerprint.js +22 -11
- package/dist/cjs/workflow-runner.js +19 -25
- package/dist/cjs/workflow-values.js +9 -7
- package/dist/cjs/workflow.js +44 -103
- package/dist/esm/action/abstract-action.js +51 -35
- package/dist/esm/bindings/base-binding.js +229 -211
- package/dist/esm/checkpoint.js +2 -2
- package/dist/esm/context.js +2 -3
- package/dist/esm/dsl.types.js +42 -88
- package/dist/esm/errors.js +11 -0
- package/dist/esm/index.js +2 -2
- package/dist/esm/resume-payload.js +10 -1
- package/dist/esm/runner-runtime-control.js +39 -27
- package/dist/esm/step-executors/conditional-executor.js +2 -7
- package/dist/esm/step-executors/loop-executor.js +14 -28
- package/dist/esm/step-executors/parallel-executor.js +14 -25
- package/dist/esm/step-executors/scope.js +21 -0
- package/dist/esm/step-executors/skip-helpers.js +27 -35
- package/dist/esm/step-executors/task-executor.js +58 -69
- package/dist/esm/utils/flow-steps.js +37 -0
- package/dist/esm/utils/naming.js +9 -9
- package/dist/esm/utils/object-path.js +46 -0
- package/dist/esm/utils/timeout.js +16 -39
- package/dist/esm/validation-issue.js +11 -0
- package/dist/esm/workflow-compiler.js +50 -95
- package/dist/esm/workflow-fingerprint.js +22 -11
- package/dist/esm/workflow-runner.js +21 -27
- package/dist/esm/workflow-values.js +7 -6
- package/dist/esm/workflow.js +43 -103
- package/dist/types/action/abstract-action.d.ts +7 -1
- package/dist/types/action/abstract-action.d.ts.map +1 -1
- package/dist/types/bindings/base-binding.d.ts +10 -0
- package/dist/types/bindings/base-binding.d.ts.map +1 -1
- package/dist/types/context.d.ts +2 -3
- package/dist/types/context.d.ts.map +1 -1
- package/dist/types/dsl.types.d.ts +7 -12
- package/dist/types/dsl.types.d.ts.map +1 -1
- package/dist/types/errors.d.ts +9 -0
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/resume-payload.d.ts +7 -0
- package/dist/types/resume-payload.d.ts.map +1 -1
- package/dist/types/runner-runtime-control.d.ts.map +1 -1
- package/dist/types/step-executors/conditional-executor.d.ts.map +1 -1
- package/dist/types/step-executors/loop-executor.d.ts +2 -4
- package/dist/types/step-executors/loop-executor.d.ts.map +1 -1
- package/dist/types/step-executors/parallel-executor.d.ts.map +1 -1
- package/dist/types/step-executors/scope.d.ts +12 -0
- package/dist/types/step-executors/scope.d.ts.map +1 -0
- package/dist/types/step-executors/skip-helpers.d.ts +2 -8
- package/dist/types/step-executors/skip-helpers.d.ts.map +1 -1
- package/dist/types/step-executors/task-executor.d.ts.map +1 -1
- package/dist/types/utils/flow-steps.d.ts +16 -0
- package/dist/types/utils/flow-steps.d.ts.map +1 -0
- package/dist/types/utils/naming.d.ts +7 -7
- package/dist/types/utils/naming.d.ts.map +1 -1
- package/dist/types/utils/object-path.d.ts +11 -0
- package/dist/types/utils/object-path.d.ts.map +1 -0
- package/dist/types/utils/timeout.d.ts.map +1 -1
- package/dist/types/validation-issue.d.ts +13 -0
- package/dist/types/validation-issue.d.ts.map +1 -1
- package/dist/types/workflow-compiler.d.ts +15 -1
- package/dist/types/workflow-compiler.d.ts.map +1 -1
- package/dist/types/workflow-fingerprint.d.ts.map +1 -1
- package/dist/types/workflow-runner.d.ts +2 -0
- package/dist/types/workflow-runner.d.ts.map +1 -1
- package/dist/types/workflow-values.d.ts +2 -0
- package/dist/types/workflow-values.d.ts.map +1 -1
- package/dist/types/workflow.d.ts +2 -1
- package/dist/types/workflow.d.ts.map +1 -1
- package/examples/defs-bindings-agent/actions/ai-agent.ts +5 -3
- package/examples/defs-bindings-agent/actions/{caculate-score.ts → calculate-score.ts} +8 -8
- package/examples/defs-bindings-agent/actions/index.ts +2 -2
- package/examples/defs-bindings-agent/workflow.yml +2 -2
- package/examples/full/workflow.yml +20 -15
- package/examples/suspend-resume/workflow.yml +6 -3
- package/package.json +8 -5
- package/src/__tests__/checkpoint.test.ts +6 -1
- package/src/__tests__/resume-payload.test.ts +29 -0
- package/src/__tests__/test-helpers.ts +1 -1
- package/src/__tests__/validation.test.ts +330 -0
- package/src/__tests__/workflow-compiler.test.ts +278 -3
- package/src/__tests__/workflow-definition-path.test.ts +2 -0
- package/src/__tests__/workflow-fingerprint.test.ts +65 -0
- package/src/__tests__/workflow-runner.test.ts +280 -5
- package/src/__tests__/workflow-values.test.ts +13 -0
- package/src/__tests__/workflow.test.ts +4 -2
- package/src/action/__tests__/abstract-action-timing.test.ts +92 -0
- package/src/action/abstract-action.ts +67 -40
- package/src/bindings/base-binding.test.ts +470 -0
- package/src/bindings/base-binding.ts +344 -267
- package/src/checkpoint.ts +2 -4
- package/src/context.ts +2 -3
- package/src/dsl.types.ts +75 -154
- package/src/errors.ts +15 -0
- package/src/index.ts +2 -0
- package/src/resume-payload.ts +13 -3
- package/src/runner-runtime-control.ts +52 -29
- package/src/step-executors/conditional-executor.ts +3 -7
- package/src/step-executors/loop-executor.test.ts +55 -0
- package/src/step-executors/loop-executor.ts +16 -50
- package/src/step-executors/parallel-executor.ts +14 -37
- package/src/step-executors/scope.ts +30 -0
- package/src/step-executors/skip-helpers.test.ts +133 -0
- package/src/step-executors/skip-helpers.ts +43 -76
- package/src/step-executors/task-executor.test.ts +130 -1
- package/src/step-executors/task-executor.ts +109 -79
- package/src/utils/flow-steps.test.ts +121 -0
- package/src/utils/flow-steps.ts +62 -0
- package/src/utils/naming.test.ts +50 -0
- package/src/utils/naming.ts +11 -11
- package/src/utils/object-path.test.ts +70 -0
- package/src/utils/object-path.ts +67 -0
- package/src/utils/timeout.test.ts +152 -0
- package/src/utils/timeout.ts +26 -44
- package/src/validation-issue.test.ts +70 -0
- package/src/validation-issue.ts +27 -0
- package/src/workflow-compiler.ts +118 -180
- package/src/workflow-fingerprint.ts +23 -12
- package/src/workflow-runner.ts +28 -27
- package/src/workflow-values.ts +9 -7
- package/src/workflow.ts +58 -140
|
@@ -14,10 +14,9 @@ import type {
|
|
|
14
14
|
} from '../workflow-types';
|
|
15
15
|
import { evaluateValue } from '../workflow-values';
|
|
16
16
|
|
|
17
|
+
import { buildEvaluationScope } from './scope';
|
|
17
18
|
import type { StepExecutorEnv } from './types';
|
|
18
19
|
|
|
19
|
-
type LoopScope = EvaluationScope;
|
|
20
|
-
|
|
21
20
|
/**
|
|
22
21
|
* Execute a loop step by iterating over input items and executing child steps.
|
|
23
22
|
*
|
|
@@ -85,12 +84,10 @@ async function executeForEachLoop(
|
|
|
85
84
|
};
|
|
86
85
|
}
|
|
87
86
|
|
|
88
|
-
const postScope =
|
|
89
|
-
|
|
90
|
-
iterationState,
|
|
91
|
-
{ item, index },
|
|
87
|
+
const postScope = buildEvaluationScope(env, iterationState, {
|
|
88
|
+
iteration: { item, index },
|
|
92
89
|
accumulator,
|
|
93
|
-
);
|
|
90
|
+
});
|
|
94
91
|
|
|
95
92
|
accumulator = await updateAccumulator(step, postScope, accumulator);
|
|
96
93
|
|
|
@@ -124,12 +121,10 @@ async function executeWhileLoop(
|
|
|
124
121
|
|
|
125
122
|
// The guard of a resumed iteration already passed before it suspended.
|
|
126
123
|
if (!resumedChild) {
|
|
127
|
-
const conditionScope =
|
|
128
|
-
|
|
129
|
-
state,
|
|
130
|
-
{ item: undefined, index },
|
|
124
|
+
const conditionScope = buildEvaluationScope(env, state, {
|
|
125
|
+
iteration: { item: undefined, index },
|
|
131
126
|
accumulator,
|
|
132
|
-
);
|
|
127
|
+
});
|
|
133
128
|
const shouldContinue = await evaluateValue(step.while, conditionScope);
|
|
134
129
|
if (!Boolean(shouldContinue)) {
|
|
135
130
|
break;
|
|
@@ -153,12 +148,10 @@ async function executeWhileLoop(
|
|
|
153
148
|
return { kind: 'loop', stepId: step.id, index, accumulator, child };
|
|
154
149
|
}
|
|
155
150
|
|
|
156
|
-
const postScope =
|
|
157
|
-
|
|
158
|
-
iterationState,
|
|
159
|
-
{ item: undefined, index },
|
|
151
|
+
const postScope = buildEvaluationScope(env, iterationState, {
|
|
152
|
+
iteration: { item: undefined, index },
|
|
160
153
|
accumulator,
|
|
161
|
-
);
|
|
154
|
+
});
|
|
162
155
|
|
|
163
156
|
accumulator = await updateAccumulator(step, postScope, accumulator);
|
|
164
157
|
state.output = iterationState.output;
|
|
@@ -174,13 +167,10 @@ async function resolveItems(
|
|
|
174
167
|
step: ForEachLoopStep,
|
|
175
168
|
state: ExecutionState,
|
|
176
169
|
): Promise<unknown[]> {
|
|
177
|
-
const items = await evaluateValue(
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
iteration: state.iteration,
|
|
182
|
-
accumulator: state.accumulator,
|
|
183
|
-
});
|
|
170
|
+
const items = await evaluateValue(
|
|
171
|
+
step.forEach.in,
|
|
172
|
+
buildEvaluationScope(env, state),
|
|
173
|
+
);
|
|
184
174
|
|
|
185
175
|
return Array.isArray(items) ? items : [];
|
|
186
176
|
}
|
|
@@ -209,7 +199,7 @@ function finalizeAccumulatorState(
|
|
|
209
199
|
*/
|
|
210
200
|
export async function updateAccumulator(
|
|
211
201
|
step: LoopStep,
|
|
212
|
-
scope:
|
|
202
|
+
scope: EvaluationScope,
|
|
213
203
|
previous: unknown,
|
|
214
204
|
): Promise<unknown> {
|
|
215
205
|
if (!step.accumulate) {
|
|
@@ -231,7 +221,7 @@ export async function updateAccumulator(
|
|
|
231
221
|
*/
|
|
232
222
|
export async function shouldStopLoop(
|
|
233
223
|
step: LoopStep,
|
|
234
|
-
scope:
|
|
224
|
+
scope: EvaluationScope,
|
|
235
225
|
): Promise<boolean> {
|
|
236
226
|
if (step.loopType !== 'for_each' || !step.until) {
|
|
237
227
|
return false;
|
|
@@ -241,27 +231,3 @@ export async function shouldStopLoop(
|
|
|
241
231
|
|
|
242
232
|
return Boolean(result);
|
|
243
233
|
}
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Build the evaluation scope for loop iteration and accumulator updates.
|
|
247
|
-
*
|
|
248
|
-
* @param env Executor environment with workflow context.
|
|
249
|
-
* @param state Execution state for the current iteration.
|
|
250
|
-
* @param iteration The current iteration item and index.
|
|
251
|
-
* @param accumulator Accumulator value to expose to expressions.
|
|
252
|
-
* @returns An evaluation scope object.
|
|
253
|
-
*/
|
|
254
|
-
function buildScope(
|
|
255
|
-
env: StepExecutorEnv,
|
|
256
|
-
state: ExecutionState,
|
|
257
|
-
iteration: { item: unknown; index: number },
|
|
258
|
-
accumulator: unknown,
|
|
259
|
-
): LoopScope {
|
|
260
|
-
return {
|
|
261
|
-
input: state.input,
|
|
262
|
-
context: env.context.state,
|
|
263
|
-
output: state.output,
|
|
264
|
-
iteration,
|
|
265
|
-
accumulator,
|
|
266
|
-
};
|
|
267
|
-
}
|
|
@@ -112,11 +112,7 @@ export async function executeParallel(
|
|
|
112
112
|
}),
|
|
113
113
|
);
|
|
114
114
|
|
|
115
|
-
|
|
116
|
-
return executeWaitAny(env, step, branches, outcomes, state);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return executeWaitAll(env, step, branches, outcomes, state);
|
|
115
|
+
return settleBlock(env, step, branches, outcomes, state);
|
|
120
116
|
}
|
|
121
117
|
|
|
122
118
|
/**
|
|
@@ -149,7 +145,13 @@ function keepRecordedBranch(
|
|
|
149
145
|
};
|
|
150
146
|
}
|
|
151
147
|
|
|
152
|
-
|
|
148
|
+
/**
|
|
149
|
+
* Collect branch results as they settle. A failed or cancelled branch fails
|
|
150
|
+
* the block; under `wait_any` the first fulfilled branch wins it. Otherwise
|
|
151
|
+
* the block suspends once every branch settled with at least one suspended,
|
|
152
|
+
* and completes when all of them fulfilled.
|
|
153
|
+
*/
|
|
154
|
+
async function settleBlock(
|
|
153
155
|
env: StepExecutorEnv,
|
|
154
156
|
step: ParallelStep,
|
|
155
157
|
branches: BranchHandle[],
|
|
@@ -167,34 +169,8 @@ async function executeWaitAll(
|
|
|
167
169
|
await abandonBranches(env, branches, pending, outcomes, result.error);
|
|
168
170
|
throw result.error;
|
|
169
171
|
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (hasSuspendedBranch(outcomes)) {
|
|
173
|
-
return buildParallelFrame(step, outcomes);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
mergeBranchOutputs(state, outcomes);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
async function executeWaitAny(
|
|
180
|
-
env: StepExecutorEnv,
|
|
181
|
-
step: ParallelStep,
|
|
182
|
-
branches: BranchHandle[],
|
|
183
|
-
outcomes: Map<number, BranchResult>,
|
|
184
|
-
state: ExecutionState,
|
|
185
|
-
): Promise<ParallelFrame | void> {
|
|
186
|
-
const pending = new Set(branches);
|
|
187
|
-
|
|
188
|
-
while (pending.size > 0) {
|
|
189
|
-
const { branch, result } = await raceNext(pending);
|
|
190
|
-
pending.delete(branch);
|
|
191
|
-
outcomes.set(result.index, result);
|
|
192
|
-
|
|
193
|
-
if (result.status === 'suspended') {
|
|
194
|
-
continue;
|
|
195
|
-
}
|
|
196
172
|
|
|
197
|
-
if (result.status === 'fulfilled') {
|
|
173
|
+
if (result.status === 'fulfilled' && step.strategy === 'wait_any') {
|
|
198
174
|
// Parked losers will never be resumed; drop their waits with the race.
|
|
199
175
|
await abandonBranches(
|
|
200
176
|
env,
|
|
@@ -208,13 +184,14 @@ async function executeWaitAny(
|
|
|
208
184
|
|
|
209
185
|
return undefined;
|
|
210
186
|
}
|
|
187
|
+
}
|
|
211
188
|
|
|
212
|
-
|
|
213
|
-
|
|
189
|
+
// Without a winner, every branch of a wait_any block is suspended.
|
|
190
|
+
if (hasSuspendedBranch(outcomes)) {
|
|
191
|
+
return buildParallelFrame(step, outcomes);
|
|
214
192
|
}
|
|
215
193
|
|
|
216
|
-
|
|
217
|
-
return buildParallelFrame(step, outcomes);
|
|
194
|
+
mergeBranchOutputs(state, outcomes);
|
|
218
195
|
}
|
|
219
196
|
|
|
220
197
|
/**
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Hexabot — Fair Core License (FCL-1.0-ALv2)
|
|
3
|
+
* Copyright (c) 2026 Hexastack.
|
|
4
|
+
* Full terms: see LICENSE.md.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { EvaluationScope, ExecutionState } from '../workflow-types';
|
|
8
|
+
|
|
9
|
+
import type { StepExecutorEnv } from './types';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Expose the live state of a step to its expressions.
|
|
13
|
+
*
|
|
14
|
+
* @param env Executor environment, for the context state.
|
|
15
|
+
* @param state Execution state of the step.
|
|
16
|
+
* @param overrides The iteration and accumulator a loop evaluates with.
|
|
17
|
+
* @returns The scope expressions are evaluated against.
|
|
18
|
+
*/
|
|
19
|
+
export const buildEvaluationScope = (
|
|
20
|
+
env: Pick<StepExecutorEnv, 'context'>,
|
|
21
|
+
state: ExecutionState,
|
|
22
|
+
overrides: Pick<EvaluationScope, 'iteration' | 'accumulator'> = {},
|
|
23
|
+
): EvaluationScope => ({
|
|
24
|
+
input: state.input,
|
|
25
|
+
context: env.context.state,
|
|
26
|
+
output: state.output,
|
|
27
|
+
iteration: state.iteration,
|
|
28
|
+
accumulator: state.accumulator,
|
|
29
|
+
...overrides,
|
|
30
|
+
});
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Hexabot — Fair Core License (FCL-1.0-ALv2)
|
|
3
|
+
* Copyright (c) 2026 Hexastack.
|
|
4
|
+
* Full terms: see LICENSE.md.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { StepType, type StepInfo } from '../workflow-event-emitter';
|
|
8
|
+
import type { CompiledStep } from '../workflow-types';
|
|
9
|
+
|
|
10
|
+
import { markStepsCancelled, markStepsSkipped } from './skip-helpers';
|
|
11
|
+
|
|
12
|
+
const task = (id: string): CompiledStep => ({
|
|
13
|
+
id,
|
|
14
|
+
type: StepType.Task,
|
|
15
|
+
label: id,
|
|
16
|
+
taskName: id,
|
|
17
|
+
});
|
|
18
|
+
// parallel(task a, conditional(task b | loop(task d))), task e
|
|
19
|
+
const steps: CompiledStep[] = [
|
|
20
|
+
{
|
|
21
|
+
id: 'p',
|
|
22
|
+
type: StepType.Parallel,
|
|
23
|
+
label: 'p',
|
|
24
|
+
strategy: 'wait_all',
|
|
25
|
+
steps: [
|
|
26
|
+
task('a'),
|
|
27
|
+
{
|
|
28
|
+
id: 'c',
|
|
29
|
+
type: StepType.Conditional,
|
|
30
|
+
label: 'c',
|
|
31
|
+
branches: [
|
|
32
|
+
{ id: 'c-0', steps: [task('b')] },
|
|
33
|
+
{
|
|
34
|
+
id: 'c-1',
|
|
35
|
+
steps: [
|
|
36
|
+
{
|
|
37
|
+
id: 'l',
|
|
38
|
+
type: StepType.Loop,
|
|
39
|
+
label: 'l',
|
|
40
|
+
loopType: 'while',
|
|
41
|
+
while: { kind: 'literal', value: false },
|
|
42
|
+
steps: [task('d')],
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
task('e'),
|
|
51
|
+
];
|
|
52
|
+
const createEnv = () => ({
|
|
53
|
+
runId: 'run-1',
|
|
54
|
+
buildInstanceStepInfo: jest.fn(
|
|
55
|
+
(step: CompiledStep, iterationStack: number[]): StepInfo => ({
|
|
56
|
+
id: `${step.id}[${iterationStack.join('.')}]`,
|
|
57
|
+
name: step.label,
|
|
58
|
+
type: step.type,
|
|
59
|
+
}),
|
|
60
|
+
),
|
|
61
|
+
markSnapshot: jest.fn(),
|
|
62
|
+
emit: jest.fn(),
|
|
63
|
+
});
|
|
64
|
+
const VISITED = ['p', 'a', 'c', 'b', 'l', 'e'];
|
|
65
|
+
|
|
66
|
+
describe('markStepsSkipped', () => {
|
|
67
|
+
it('marks steps and the steps nested in their branches, but not loop bodies', () => {
|
|
68
|
+
const env = createEnv();
|
|
69
|
+
|
|
70
|
+
markStepsSkipped(env, steps, [2], 'branch not taken');
|
|
71
|
+
|
|
72
|
+
expect(env.markSnapshot.mock.calls).toEqual(
|
|
73
|
+
VISITED.map((id) => [
|
|
74
|
+
{ id: `${id}[2]`, name: id, type: expect.any(String) },
|
|
75
|
+
'skipped',
|
|
76
|
+
'branch not taken',
|
|
77
|
+
]),
|
|
78
|
+
);
|
|
79
|
+
expect(env.emit.mock.calls).toEqual(
|
|
80
|
+
VISITED.map((id) => [
|
|
81
|
+
'hook:step:skipped',
|
|
82
|
+
{
|
|
83
|
+
runId: 'run-1',
|
|
84
|
+
step: expect.objectContaining({ id: `${id}[2]` }),
|
|
85
|
+
reason: 'branch not taken',
|
|
86
|
+
},
|
|
87
|
+
]),
|
|
88
|
+
);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('markStepsCancelled', () => {
|
|
93
|
+
it('marks steps and the steps nested in their branches, but not loop bodies', () => {
|
|
94
|
+
const env = createEnv();
|
|
95
|
+
|
|
96
|
+
markStepsCancelled(env, steps, [], 'lost the race');
|
|
97
|
+
|
|
98
|
+
expect(env.markSnapshot.mock.calls).toEqual(
|
|
99
|
+
VISITED.map((id) => [
|
|
100
|
+
expect.objectContaining({ id: `${id}[]` }),
|
|
101
|
+
'cancelled',
|
|
102
|
+
'lost the race',
|
|
103
|
+
]),
|
|
104
|
+
);
|
|
105
|
+
expect(env.emit.mock.calls).toEqual(
|
|
106
|
+
VISITED.map((id) => [
|
|
107
|
+
'hook:step:cancelled',
|
|
108
|
+
{
|
|
109
|
+
runId: 'run-1',
|
|
110
|
+
step: expect.objectContaining({ id: `${id}[]` }),
|
|
111
|
+
error: new Error('lost the race'),
|
|
112
|
+
},
|
|
113
|
+
]),
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('falls back to a generic error without a reason', () => {
|
|
118
|
+
const env = createEnv();
|
|
119
|
+
|
|
120
|
+
markStepsCancelled(env, [task('a')], []);
|
|
121
|
+
|
|
122
|
+
expect(env.markSnapshot).toHaveBeenCalledWith(
|
|
123
|
+
expect.objectContaining({ id: 'a[]' }),
|
|
124
|
+
'cancelled',
|
|
125
|
+
undefined,
|
|
126
|
+
);
|
|
127
|
+
expect(env.emit).toHaveBeenCalledWith('hook:step:cancelled', {
|
|
128
|
+
runId: 'run-1',
|
|
129
|
+
step: expect.objectContaining({ id: 'a[]' }),
|
|
130
|
+
error: new Error('Step execution was cancelled.'),
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
});
|
|
@@ -4,90 +4,49 @@
|
|
|
4
4
|
* Full terms: see LICENSE.md.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import type
|
|
8
|
-
import {
|
|
9
|
-
StepType,
|
|
10
|
-
type StepInfo,
|
|
11
|
-
type WorkflowEventMap,
|
|
12
|
-
} from '../workflow-event-emitter';
|
|
7
|
+
import { StepType, type StepInfo } from '../workflow-event-emitter';
|
|
13
8
|
import type { CompiledStep } from '../workflow-types';
|
|
14
9
|
|
|
15
|
-
type
|
|
16
|
-
runId?: string;
|
|
17
|
-
buildInstanceStepInfo: (
|
|
18
|
-
step: CompiledStep,
|
|
19
|
-
iterationStack: number[],
|
|
20
|
-
) => StepInfo;
|
|
21
|
-
markSnapshot: (
|
|
22
|
-
step: StepInfo,
|
|
23
|
-
status: ActionSnapshot['status'],
|
|
24
|
-
reason?: string,
|
|
25
|
-
) => void;
|
|
26
|
-
emit: <K extends keyof WorkflowEventMap>(
|
|
27
|
-
event: K,
|
|
28
|
-
payload: WorkflowEventMap[K],
|
|
29
|
-
) => void;
|
|
30
|
-
};
|
|
10
|
+
import type { StepExecutorEnv } from './types';
|
|
31
11
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
12
|
+
type SkipStepEnv = Pick<
|
|
13
|
+
StepExecutorEnv,
|
|
14
|
+
'runId' | 'buildInstanceStepInfo' | 'markSnapshot' | 'emit'
|
|
15
|
+
>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Visit steps depth first, entering parallel and conditional children. Loop
|
|
19
|
+
* bodies are not entered: their step instances depend on iterations that
|
|
20
|
+
* never ran.
|
|
21
|
+
*/
|
|
22
|
+
const forEachStepInTree = (
|
|
23
|
+
steps: CompiledStep[],
|
|
24
|
+
visit: (step: CompiledStep) => void,
|
|
25
|
+
): void => {
|
|
26
|
+
for (const step of steps) {
|
|
27
|
+
visit(step);
|
|
41
28
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
break;
|
|
48
|
-
case StepType.Conditional:
|
|
49
|
-
step.branches.forEach((branch) =>
|
|
50
|
-
branch.steps.forEach((child) =>
|
|
51
|
-
markStepSkipped(env, child, iterationStack, reason),
|
|
52
|
-
),
|
|
53
|
-
);
|
|
54
|
-
break;
|
|
55
|
-
case StepType.Loop:
|
|
56
|
-
case StepType.Task:
|
|
57
|
-
break;
|
|
29
|
+
if (step.type === StepType.Parallel) {
|
|
30
|
+
forEachStepInTree(step.steps, visit);
|
|
31
|
+
} else if (step.type === StepType.Conditional) {
|
|
32
|
+
step.branches.forEach((branch) => forEachStepInTree(branch.steps, visit));
|
|
33
|
+
}
|
|
58
34
|
}
|
|
59
35
|
};
|
|
60
|
-
|
|
36
|
+
/** Mark every step of the tree with `status`, then announce it. */
|
|
37
|
+
const markStepTree = (
|
|
61
38
|
env: SkipStepEnv,
|
|
62
|
-
|
|
39
|
+
steps: CompiledStep[],
|
|
63
40
|
iterationStack: number[],
|
|
64
|
-
|
|
41
|
+
status: 'skipped' | 'cancelled',
|
|
42
|
+
reason: string | undefined,
|
|
43
|
+
announce: (stepInfo: StepInfo) => void,
|
|
65
44
|
) => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
step: stepInfo,
|
|
71
|
-
error: new Error(reason ?? 'Step execution was cancelled.'),
|
|
45
|
+
forEachStepInTree(steps, (step) => {
|
|
46
|
+
const stepInfo = env.buildInstanceStepInfo(step, iterationStack);
|
|
47
|
+
env.markSnapshot(stepInfo, status, reason);
|
|
48
|
+
announce(stepInfo);
|
|
72
49
|
});
|
|
73
|
-
|
|
74
|
-
switch (step.type) {
|
|
75
|
-
case StepType.Parallel:
|
|
76
|
-
step.steps.forEach((child) =>
|
|
77
|
-
markStepCancelled(env, child, iterationStack, reason),
|
|
78
|
-
);
|
|
79
|
-
break;
|
|
80
|
-
case StepType.Conditional:
|
|
81
|
-
step.branches.forEach((branch) =>
|
|
82
|
-
branch.steps.forEach((child) =>
|
|
83
|
-
markStepCancelled(env, child, iterationStack, reason),
|
|
84
|
-
),
|
|
85
|
-
);
|
|
86
|
-
break;
|
|
87
|
-
case StepType.Loop:
|
|
88
|
-
case StepType.Task:
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
50
|
};
|
|
92
51
|
|
|
93
52
|
export const markStepsSkipped = (
|
|
@@ -96,7 +55,9 @@ export const markStepsSkipped = (
|
|
|
96
55
|
iterationStack: number[],
|
|
97
56
|
reason?: string,
|
|
98
57
|
) => {
|
|
99
|
-
|
|
58
|
+
markStepTree(env, steps, iterationStack, 'skipped', reason, (stepInfo) =>
|
|
59
|
+
env.emit('hook:step:skipped', { runId: env.runId, step: stepInfo, reason }),
|
|
60
|
+
);
|
|
100
61
|
};
|
|
101
62
|
|
|
102
63
|
export const markStepsCancelled = (
|
|
@@ -105,5 +66,11 @@ export const markStepsCancelled = (
|
|
|
105
66
|
iterationStack: number[],
|
|
106
67
|
reason?: string,
|
|
107
68
|
) => {
|
|
108
|
-
|
|
69
|
+
markStepTree(env, steps, iterationStack, 'cancelled', reason, (stepInfo) =>
|
|
70
|
+
env.emit('hook:step:cancelled', {
|
|
71
|
+
runId: env.runId,
|
|
72
|
+
step: stepInfo,
|
|
73
|
+
error: new Error(reason ?? 'Step execution was cancelled.'),
|
|
74
|
+
}),
|
|
75
|
+
);
|
|
109
76
|
};
|
|
@@ -23,6 +23,7 @@ import type {
|
|
|
23
23
|
ExecutionState,
|
|
24
24
|
TaskStep,
|
|
25
25
|
} from '../workflow-types';
|
|
26
|
+
import { compileValue } from '../workflow-values';
|
|
26
27
|
|
|
27
28
|
import { executeTaskStep } from './task-executor';
|
|
28
29
|
import type { StepExecutorEnv } from './types';
|
|
@@ -160,7 +161,12 @@ describe('executeTaskStep', () => {
|
|
|
160
161
|
expect.any(AbortSignal),
|
|
161
162
|
);
|
|
162
163
|
expect(env.markSnapshot).toHaveBeenNthCalledWith(1, stepInfo, 'running');
|
|
163
|
-
expect(env.markSnapshot).toHaveBeenNthCalledWith(
|
|
164
|
+
expect(env.markSnapshot).toHaveBeenNthCalledWith(
|
|
165
|
+
2,
|
|
166
|
+
stepInfo,
|
|
167
|
+
'completed',
|
|
168
|
+
undefined,
|
|
169
|
+
);
|
|
164
170
|
expect(env.recordStepExecution).toHaveBeenNthCalledWith(
|
|
165
171
|
1,
|
|
166
172
|
stepInfo,
|
|
@@ -588,4 +594,127 @@ describe('executeTaskStep', () => {
|
|
|
588
594
|
error: expect.any(Error),
|
|
589
595
|
});
|
|
590
596
|
});
|
|
597
|
+
it('does not start the action when the run is aborted while its inputs are evaluated', async () => {
|
|
598
|
+
const controller = new AbortController();
|
|
599
|
+
const task = {
|
|
600
|
+
...createTask(jest.fn()),
|
|
601
|
+
inputs: {
|
|
602
|
+
payload: compileValue('=$stopRun()', {
|
|
603
|
+
jsonataFunctions: {
|
|
604
|
+
stopRun: () => {
|
|
605
|
+
controller.abort(new Error('stopped'));
|
|
606
|
+
|
|
607
|
+
return 1;
|
|
608
|
+
},
|
|
609
|
+
},
|
|
610
|
+
}),
|
|
611
|
+
},
|
|
612
|
+
};
|
|
613
|
+
const env = {
|
|
614
|
+
...createEnv(createCompiled(task), stepInfo),
|
|
615
|
+
signal: controller.signal,
|
|
616
|
+
};
|
|
617
|
+
|
|
618
|
+
await expect(executeTaskStep(env, step, createState(), [])).rejects.toThrow(
|
|
619
|
+
'stopped',
|
|
620
|
+
);
|
|
621
|
+
expect(task.action.run).not.toHaveBeenCalled();
|
|
622
|
+
expect(env.recordStepExecution).toHaveBeenCalledTimes(1);
|
|
623
|
+
expect(env.recordStepExecution).toHaveBeenCalledWith(
|
|
624
|
+
stepInfo,
|
|
625
|
+
expect.objectContaining({ status: 'cancelled' }),
|
|
626
|
+
);
|
|
627
|
+
expect(env.markSnapshot).toHaveBeenCalledWith(
|
|
628
|
+
stepInfo,
|
|
629
|
+
'cancelled',
|
|
630
|
+
'stopped',
|
|
631
|
+
);
|
|
632
|
+
});
|
|
633
|
+
|
|
634
|
+
it('releases the step when the run is aborted before its action starts', async () => {
|
|
635
|
+
const task = createTask(jest.fn());
|
|
636
|
+
const controller = new AbortController();
|
|
637
|
+
const env = {
|
|
638
|
+
...createEnv(createCompiled(task), stepInfo),
|
|
639
|
+
signal: controller.signal,
|
|
640
|
+
};
|
|
641
|
+
const endStep = jest.spyOn(env.runtime, 'endStep');
|
|
642
|
+
env.emit = jest.fn((event) => {
|
|
643
|
+
if (event === 'hook:step:start') {
|
|
644
|
+
controller.abort(new Error('stopped'));
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
|
|
648
|
+
await expect(executeTaskStep(env, step, createState(), [])).rejects.toThrow(
|
|
649
|
+
'stopped',
|
|
650
|
+
);
|
|
651
|
+
expect(task.action.run).not.toHaveBeenCalled();
|
|
652
|
+
expect(endStep).toHaveBeenCalledTimes(1);
|
|
653
|
+
expect(env.runtime.hasRecordedResult()).toBe(false);
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
it('records a failure that is not an Error by its string form', async () => {
|
|
657
|
+
const task = createTask(jest.fn().mockRejectedValue('boom'));
|
|
658
|
+
const env = createEnv(createCompiled(task), stepInfo);
|
|
659
|
+
|
|
660
|
+
await expect(executeTaskStep(env, step, createState(), [])).rejects.toBe(
|
|
661
|
+
'boom',
|
|
662
|
+
);
|
|
663
|
+
expect(env.recordStepExecution).toHaveBeenCalledWith(
|
|
664
|
+
stepInfo,
|
|
665
|
+
expect.objectContaining({
|
|
666
|
+
status: 'failed',
|
|
667
|
+
error: { message: 'boom' },
|
|
668
|
+
}),
|
|
669
|
+
);
|
|
670
|
+
expect(env.markSnapshot).toHaveBeenCalledWith(stepInfo, 'failed', 'boom');
|
|
671
|
+
expect(env.emit).toHaveBeenCalledWith(
|
|
672
|
+
'hook:step:error',
|
|
673
|
+
expect.objectContaining({ error: 'boom' }),
|
|
674
|
+
);
|
|
675
|
+
});
|
|
676
|
+
it('does not evaluate the inputs of a step whose run is already aborted', async () => {
|
|
677
|
+
const evaluated = jest.fn(() => 1);
|
|
678
|
+
const task = {
|
|
679
|
+
...createTask(jest.fn()),
|
|
680
|
+
inputs: {
|
|
681
|
+
payload: compileValue('=$probe()', {
|
|
682
|
+
jsonataFunctions: { probe: evaluated },
|
|
683
|
+
}),
|
|
684
|
+
},
|
|
685
|
+
};
|
|
686
|
+
const controller = new AbortController();
|
|
687
|
+
controller.abort(new Error('stopped'));
|
|
688
|
+
const env = {
|
|
689
|
+
...createEnv(createCompiled(task), stepInfo),
|
|
690
|
+
signal: controller.signal,
|
|
691
|
+
};
|
|
692
|
+
|
|
693
|
+
await expect(executeTaskStep(env, step, createState(), [])).rejects.toThrow(
|
|
694
|
+
'stopped',
|
|
695
|
+
);
|
|
696
|
+
expect(evaluated).not.toHaveBeenCalled();
|
|
697
|
+
});
|
|
698
|
+
|
|
699
|
+
it('detaches the action signal from the run once the step is over', async () => {
|
|
700
|
+
let actionSignal: AbortSignal | undefined;
|
|
701
|
+
const task = createTask(
|
|
702
|
+
jest.fn(async (_input, _context, _settings, _bindings, signal) => {
|
|
703
|
+
actionSignal = signal;
|
|
704
|
+
|
|
705
|
+
return { ok: true };
|
|
706
|
+
}),
|
|
707
|
+
);
|
|
708
|
+
const controller = new AbortController();
|
|
709
|
+
const env = {
|
|
710
|
+
...createEnv(createCompiled(task), stepInfo),
|
|
711
|
+
signal: controller.signal,
|
|
712
|
+
};
|
|
713
|
+
|
|
714
|
+
await executeTaskStep(env, step, createState(), []);
|
|
715
|
+
controller.abort(new Error('later'));
|
|
716
|
+
|
|
717
|
+
expect(actionSignal).toBeDefined();
|
|
718
|
+
expect(actionSignal?.aborted).toBe(false);
|
|
719
|
+
});
|
|
591
720
|
});
|