@hexabot-ai/agentic 3.4.0-beta.2 → 3.5.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 +67 -15
- package/dist/cjs/action/abstract-action.js +13 -1
- package/dist/cjs/checkpoint.js +301 -0
- package/dist/cjs/context.js +11 -27
- package/dist/cjs/dsl.types.js +3 -0
- package/dist/cjs/errors.js +116 -9
- package/dist/cjs/index.js +15 -6
- package/dist/cjs/resume-payload.js +257 -0
- package/dist/cjs/runner-runtime-control.js +181 -306
- package/dist/cjs/step-executors/conditional-executor.js +27 -29
- package/dist/cjs/step-executors/loop-executor.js +53 -62
- package/dist/cjs/step-executors/parallel-executor.js +169 -102
- package/dist/cjs/step-executors/task-executor.js +180 -96
- package/dist/cjs/utils/clone.js +73 -0
- package/dist/cjs/workflow-fingerprint.js +138 -0
- package/dist/cjs/workflow-runner.js +220 -155
- package/dist/cjs/workflow.js +24 -12
- package/dist/esm/action/abstract-action.js +14 -2
- package/dist/esm/checkpoint.js +293 -0
- package/dist/esm/context.js +11 -27
- package/dist/esm/dsl.types.js +3 -0
- package/dist/esm/errors.js +105 -6
- package/dist/esm/index.js +3 -3
- package/dist/esm/resume-payload.js +250 -0
- package/dist/esm/runner-runtime-control.js +179 -303
- package/dist/esm/step-executors/conditional-executor.js +27 -29
- package/dist/esm/step-executors/loop-executor.js +53 -62
- package/dist/esm/step-executors/parallel-executor.js +165 -98
- package/dist/esm/step-executors/task-executor.js +181 -97
- package/dist/esm/utils/clone.js +67 -0
- package/dist/esm/workflow-fingerprint.js +134 -0
- package/dist/esm/workflow-runner.js +220 -155
- package/dist/esm/workflow.js +24 -12
- package/dist/types/action/abstract-action.d.ts.map +1 -1
- package/dist/types/action/action.types.d.ts +0 -14
- package/dist/types/action/action.types.d.ts.map +1 -1
- package/dist/types/checkpoint.d.ts +188 -0
- package/dist/types/checkpoint.d.ts.map +1 -0
- package/dist/types/context.d.ts +45 -11
- package/dist/types/context.d.ts.map +1 -1
- package/dist/types/dsl.types.d.ts.map +1 -1
- package/dist/types/errors.d.ts +77 -3
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/index.d.ts +6 -7
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/resume-payload.d.ts +69 -0
- package/dist/types/resume-payload.d.ts.map +1 -0
- package/dist/types/runner-runtime-control.d.ts +63 -51
- package/dist/types/runner-runtime-control.d.ts.map +1 -1
- package/dist/types/step-executors/conditional-executor.d.ts +6 -3
- package/dist/types/step-executors/conditional-executor.d.ts.map +1 -1
- package/dist/types/step-executors/loop-executor.d.ts +6 -4
- package/dist/types/step-executors/loop-executor.d.ts.map +1 -1
- package/dist/types/step-executors/parallel-executor.d.ts +11 -3
- package/dist/types/step-executors/parallel-executor.d.ts.map +1 -1
- package/dist/types/step-executors/task-executor.d.ts +11 -4
- package/dist/types/step-executors/task-executor.d.ts.map +1 -1
- package/dist/types/step-executors/types.d.ts +21 -13
- package/dist/types/step-executors/types.d.ts.map +1 -1
- package/dist/types/utils/clone.d.ts +33 -0
- package/dist/types/utils/clone.d.ts.map +1 -0
- package/dist/types/workflow-event-emitter.d.ts +29 -5
- package/dist/types/workflow-event-emitter.d.ts.map +1 -1
- package/dist/types/workflow-fingerprint.d.ts +14 -0
- package/dist/types/workflow-fingerprint.d.ts.map +1 -0
- package/dist/types/workflow-runner.d.ts +83 -41
- package/dist/types/workflow-runner.d.ts.map +1 -1
- package/dist/types/workflow-types.d.ts +25 -54
- package/dist/types/workflow-types.d.ts.map +1 -1
- package/dist/types/workflow.d.ts +24 -9
- package/dist/types/workflow.d.ts.map +1 -1
- package/examples/defs-bindings-agent/bindings.ts +1 -1
- package/examples/defs-bindings-agent/workflow.ts +3 -2
- package/examples/full/actions/await-user-input.ts +3 -2
- package/examples/full/actions/call-llm.ts +18 -18
- package/examples/full/actions/create-ticket.ts +1 -2
- package/examples/full/actions/decision-router.ts +6 -2
- package/examples/full/actions/get-calendar-events.ts +1 -2
- package/examples/full/actions/get-user-profile.ts +1 -2
- package/examples/full/actions/query-memory.ts +1 -2
- package/examples/full/actions/search-web.ts +1 -2
- package/examples/full/actions/send-email.ts +3 -2
- package/examples/full/workflow.ts +3 -2
- package/examples/loop/actions/await-reply.ts +2 -7
- package/examples/loop/workflow.ts +4 -2
- package/examples/suspend-resume/actions/wait-for-user.ts +11 -9
- package/examples/suspend-resume/workflow.ts +51 -11
- package/package.json +3 -3
- package/src/__tests__/checkpoint.test.ts +2568 -0
- package/src/__tests__/resume-payload.test.ts +245 -0
- package/src/__tests__/runner-runtime-control.test.ts +265 -0
- package/src/__tests__/workflow-fingerprint.test.ts +165 -0
- package/src/__tests__/workflow-runner.test.ts +167 -144
- package/src/__tests__/workflow.test.ts +97 -6
- package/src/action/abstract-action.ts +21 -2
- package/src/action/action.types.ts +0 -12
- package/src/checkpoint.ts +561 -0
- package/src/context.ts +51 -41
- package/src/dsl.types.ts +3 -0
- package/src/errors.ts +161 -8
- package/src/index.ts +33 -14
- package/src/resume-payload.ts +326 -0
- package/src/runner-runtime-control.ts +222 -456
- package/src/step-executors/conditional-executor.test.ts +77 -46
- package/src/step-executors/conditional-executor.ts +47 -40
- package/src/step-executors/loop-executor.test.ts +106 -92
- package/src/step-executors/loop-executor.ts +84 -101
- package/src/step-executors/parallel-executor.test.ts +300 -89
- package/src/step-executors/parallel-executor.ts +243 -125
- package/src/step-executors/task-executor.test.ts +321 -51
- package/src/step-executors/task-executor.ts +232 -145
- package/src/step-executors/types.ts +23 -22
- package/src/utils/clone.ts +75 -0
- package/src/workflow-event-emitter.ts +32 -6
- package/src/workflow-fingerprint.ts +159 -0
- package/src/workflow-runner.ts +325 -209
- package/src/workflow-types.ts +25 -56
- package/src/workflow.ts +41 -34
- package/dist/cjs/step-executors/suspension-continuation.js +0 -27
- package/dist/cjs/suspension-rebuilder.js +0 -265
- package/dist/cjs/utils/deferred.js +0 -17
- package/dist/esm/step-executors/suspension-continuation.js +0 -24
- package/dist/esm/suspension-rebuilder.js +0 -260
- package/dist/esm/utils/deferred.js +0 -14
- package/dist/types/step-executors/suspension-continuation.d.ts +0 -10
- package/dist/types/step-executors/suspension-continuation.d.ts.map +0 -1
- package/dist/types/suspension-rebuilder.d.ts +0 -67
- package/dist/types/suspension-rebuilder.d.ts.map +0 -1
- package/dist/types/utils/deferred.d.ts +0 -7
- package/dist/types/utils/deferred.d.ts.map +0 -1
- package/src/__tests__/suspension-rebuilder.test.ts +0 -404
- package/src/step-executors/suspension-continuation.ts +0 -31
- package/src/suspension-rebuilder.ts +0 -446
- package/src/utils/deferred.ts +0 -23
|
@@ -5,9 +5,13 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import type { Action } from '../action/action.types';
|
|
8
|
+
import type { TaskFrame } from '../checkpoint';
|
|
8
9
|
import { BaseWorkflowContext, type StepExecutionRecord } from '../context';
|
|
9
|
-
import
|
|
10
|
-
|
|
10
|
+
import {
|
|
11
|
+
NonDeterministicWorkflowError,
|
|
12
|
+
WorkflowResumeRejectedError,
|
|
13
|
+
} from '../errors';
|
|
14
|
+
import { RunnerRuntimeControl } from '../runner-runtime-control';
|
|
11
15
|
import {
|
|
12
16
|
type EventEmitterLike,
|
|
13
17
|
type StepInfo,
|
|
@@ -74,11 +78,17 @@ const createEnv = (
|
|
|
74
78
|
stepInfo: StepInfo,
|
|
75
79
|
): StepExecutorEnv => {
|
|
76
80
|
const stepRecords: Record<string, StepExecutionRecord> = {};
|
|
81
|
+
const context = new TestContext();
|
|
82
|
+
const runtime = new RunnerRuntimeControl();
|
|
83
|
+
context.attachWorkflowRuntime(runtime);
|
|
77
84
|
const env = {
|
|
78
85
|
compiled,
|
|
79
|
-
context
|
|
86
|
+
context,
|
|
80
87
|
signal: new AbortController().signal,
|
|
81
88
|
runId: 'run-123',
|
|
89
|
+
runtime,
|
|
90
|
+
resolutions: new Map<string, unknown>(),
|
|
91
|
+
rejectResume: jest.fn(),
|
|
82
92
|
buildInstanceStepInfo: jest.fn().mockReturnValue(stepInfo),
|
|
83
93
|
markSnapshot: jest.fn(),
|
|
84
94
|
recordStepExecution: jest.fn((step, update) => {
|
|
@@ -107,14 +117,6 @@ const createEnv = (
|
|
|
107
117
|
return nextRecord;
|
|
108
118
|
}),
|
|
109
119
|
emit: jest.fn(),
|
|
110
|
-
setCurrentStep: jest.fn(),
|
|
111
|
-
waitForStepSuspension: jest
|
|
112
|
-
.fn()
|
|
113
|
-
.mockImplementation(
|
|
114
|
-
() => new Promise<RuntimeSuspensionRequest>(() => undefined),
|
|
115
|
-
),
|
|
116
|
-
clearStepSuspensions: jest.fn(),
|
|
117
|
-
primeStepResumeData: jest.fn(),
|
|
118
120
|
captureTaskOutput: jest.fn().mockResolvedValue(undefined),
|
|
119
121
|
executeFlow: jest.fn(),
|
|
120
122
|
executeStep: jest.fn(),
|
|
@@ -155,9 +157,8 @@ describe('executeTaskStep', () => {
|
|
|
155
157
|
env.context,
|
|
156
158
|
task.settings,
|
|
157
159
|
task.bindings,
|
|
158
|
-
|
|
160
|
+
expect.any(AbortSignal),
|
|
159
161
|
);
|
|
160
|
-
expect(env.setCurrentStep).toHaveBeenNthCalledWith(1, stepInfo);
|
|
161
162
|
expect(env.markSnapshot).toHaveBeenNthCalledWith(1, stepInfo, 'running');
|
|
162
163
|
expect(env.markSnapshot).toHaveBeenNthCalledWith(2, stepInfo, 'completed');
|
|
163
164
|
expect(env.recordStepExecution).toHaveBeenNthCalledWith(
|
|
@@ -200,7 +201,6 @@ describe('executeTaskStep', () => {
|
|
|
200
201
|
status: 'completed',
|
|
201
202
|
}),
|
|
202
203
|
});
|
|
203
|
-
expect(env.setCurrentStep).toHaveBeenLastCalledWith(undefined);
|
|
204
204
|
});
|
|
205
205
|
|
|
206
206
|
it('throws when the task is missing', async () => {
|
|
@@ -215,43 +215,38 @@ describe('executeTaskStep', () => {
|
|
|
215
215
|
expect(env.buildInstanceStepInfo).not.toHaveBeenCalled();
|
|
216
216
|
});
|
|
217
217
|
|
|
218
|
-
it('
|
|
219
|
-
const request: RuntimeSuspensionRequest = {
|
|
220
|
-
stepId: step.id,
|
|
221
|
-
stepExecId: `${step.id}#1`,
|
|
222
|
-
suspendIndex: 1,
|
|
223
|
-
suspendKey: 'index:1',
|
|
224
|
-
reason: 'awaiting_user',
|
|
225
|
-
data: { channel: 'sms' },
|
|
226
|
-
awaitResults: {},
|
|
227
|
-
resume: createDeferred<unknown>(),
|
|
228
|
-
};
|
|
218
|
+
it('returns a frame on suspension and re-runs the body once its wait is resolved', async () => {
|
|
229
219
|
const task = createTask(
|
|
230
|
-
jest.fn().mockImplementation(async () => {
|
|
231
|
-
const
|
|
220
|
+
jest.fn().mockImplementation(async (_inputs, context, ...rest) => {
|
|
221
|
+
const signal = rest[2] as AbortSignal;
|
|
222
|
+
const resumed = (await context.workflow.suspend({
|
|
223
|
+
reason: 'awaiting_user',
|
|
224
|
+
data: { channel: 'sms' },
|
|
225
|
+
})) as { reply: string };
|
|
232
226
|
|
|
233
|
-
return { reply: resumed.reply.toUpperCase() };
|
|
227
|
+
return { reply: resumed.reply.toUpperCase(), aborted: signal.aborted };
|
|
234
228
|
}),
|
|
235
229
|
);
|
|
236
230
|
const compiled = createCompiled(task);
|
|
237
231
|
const env = createEnv(compiled, stepInfo);
|
|
238
232
|
const state = createState();
|
|
233
|
+
const frame = await executeTaskStep(env, step, state, []);
|
|
239
234
|
|
|
240
|
-
(
|
|
241
|
-
|
|
242
|
-
.
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
expect(suspension).toEqual(
|
|
249
|
-
expect.objectContaining({
|
|
235
|
+
expect(frame).toEqual({
|
|
236
|
+
kind: 'task',
|
|
237
|
+
stepId: step.id,
|
|
238
|
+
inputs: { payload: 123 },
|
|
239
|
+
awaitResults: {},
|
|
240
|
+
wait: {
|
|
241
|
+
waitId: '0:test_task@index:1',
|
|
250
242
|
step: stepInfo,
|
|
243
|
+
suspendKey: 'index:1',
|
|
251
244
|
reason: 'awaiting_user',
|
|
252
245
|
data: { channel: 'sms' },
|
|
253
|
-
}
|
|
254
|
-
);
|
|
246
|
+
},
|
|
247
|
+
});
|
|
248
|
+
const [, , , , signal] = (task.action.run as jest.Mock).mock.calls[0];
|
|
249
|
+
expect((signal as AbortSignal).aborted).toBe(true);
|
|
255
250
|
expect(env.markSnapshot).toHaveBeenCalledWith(
|
|
256
251
|
stepInfo,
|
|
257
252
|
'suspended',
|
|
@@ -260,26 +255,38 @@ describe('executeTaskStep', () => {
|
|
|
260
255
|
expect(env.emit).toHaveBeenCalledWith('hook:step:suspended', {
|
|
261
256
|
runId: 'run-123',
|
|
262
257
|
step: stepInfo,
|
|
258
|
+
wait: (frame as TaskFrame).wait,
|
|
263
259
|
stepExecution: expect.objectContaining({
|
|
264
260
|
id: stepInfo.id,
|
|
265
261
|
status: 'suspended',
|
|
266
262
|
}),
|
|
267
|
-
reason: 'awaiting_user',
|
|
268
|
-
data: { channel: 'sms' },
|
|
269
263
|
});
|
|
270
264
|
|
|
271
|
-
|
|
265
|
+
const resumedEnv = {
|
|
266
|
+
...env,
|
|
267
|
+
resolutions: new Map([['0:test_task@index:1', { reply: 'Sure' }]]),
|
|
268
|
+
};
|
|
269
|
+
const result = await executeTaskStep(
|
|
270
|
+
resumedEnv,
|
|
271
|
+
step,
|
|
272
|
+
state,
|
|
273
|
+
[],
|
|
274
|
+
frame as TaskFrame,
|
|
275
|
+
);
|
|
272
276
|
|
|
277
|
+
expect(result).toBeUndefined();
|
|
278
|
+
expect(task.action.run).toHaveBeenCalledTimes(2);
|
|
273
279
|
expect(env.captureTaskOutput).toHaveBeenCalledWith(task, state, {
|
|
274
280
|
reply: 'SURE',
|
|
281
|
+
aborted: false,
|
|
282
|
+
});
|
|
283
|
+
expect(env.emit).toHaveBeenCalledWith('hook:step:resumed', {
|
|
284
|
+
runId: 'run-123',
|
|
285
|
+
step: stepInfo,
|
|
286
|
+
stepExecution: expect.objectContaining({ status: 'running' }),
|
|
287
|
+
wait: (frame as TaskFrame).wait,
|
|
288
|
+
resumeData: { reply: 'Sure' },
|
|
275
289
|
});
|
|
276
|
-
expect(env.recordStepExecution).toHaveBeenCalledWith(
|
|
277
|
-
stepInfo,
|
|
278
|
-
expect.objectContaining({
|
|
279
|
-
status: 'completed',
|
|
280
|
-
output: { reply: 'SURE' },
|
|
281
|
-
}),
|
|
282
|
-
);
|
|
283
290
|
expect(env.emit).toHaveBeenCalledWith('hook:step:success', {
|
|
284
291
|
runId: 'run-123',
|
|
285
292
|
step: stepInfo,
|
|
@@ -290,6 +297,270 @@ describe('executeTaskStep', () => {
|
|
|
290
297
|
});
|
|
291
298
|
});
|
|
292
299
|
|
|
300
|
+
it('leaves a parked frame untouched when this pass does not resolve its wait', async () => {
|
|
301
|
+
const task = createTask(jest.fn());
|
|
302
|
+
const env = createEnv(createCompiled(task), stepInfo);
|
|
303
|
+
const frame: TaskFrame = {
|
|
304
|
+
kind: 'task',
|
|
305
|
+
stepId: step.id,
|
|
306
|
+
inputs: { payload: 123 },
|
|
307
|
+
awaitResults: {},
|
|
308
|
+
wait: {
|
|
309
|
+
waitId: '0:test_task@index:1',
|
|
310
|
+
step: stepInfo,
|
|
311
|
+
suspendKey: 'index:1',
|
|
312
|
+
},
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
await expect(
|
|
316
|
+
executeTaskStep(env, step, createState(), [], frame),
|
|
317
|
+
).resolves.toBe(frame);
|
|
318
|
+
expect(task.action.run).not.toHaveBeenCalled();
|
|
319
|
+
expect(env.markSnapshot).not.toHaveBeenCalled();
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it('re-runs a resumed body with the inputs recorded in its frame', async () => {
|
|
323
|
+
const task = createTask(
|
|
324
|
+
jest.fn().mockImplementation(async (inputs, context) => ({
|
|
325
|
+
inputs,
|
|
326
|
+
reply: await context.workflow.suspend(),
|
|
327
|
+
})),
|
|
328
|
+
);
|
|
329
|
+
const env = {
|
|
330
|
+
...createEnv(createCompiled(task), stepInfo),
|
|
331
|
+
resolutions: new Map([['0:test_task@index:1', 'yes']]),
|
|
332
|
+
};
|
|
333
|
+
const state = createState();
|
|
334
|
+
const frame: TaskFrame = {
|
|
335
|
+
kind: 'task',
|
|
336
|
+
stepId: step.id,
|
|
337
|
+
// Differs from the compiled `{ payload: 123 }` on purpose.
|
|
338
|
+
inputs: { payload: 'recorded' },
|
|
339
|
+
awaitResults: {},
|
|
340
|
+
wait: {
|
|
341
|
+
waitId: '0:test_task@index:1',
|
|
342
|
+
step: stepInfo,
|
|
343
|
+
suspendKey: 'index:1',
|
|
344
|
+
},
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
await expect(
|
|
348
|
+
executeTaskStep(env, step, state, [], frame),
|
|
349
|
+
).resolves.toBeUndefined();
|
|
350
|
+
expect(task.action.run).toHaveBeenCalledWith(
|
|
351
|
+
{ payload: 'recorded' },
|
|
352
|
+
env.context,
|
|
353
|
+
task.settings,
|
|
354
|
+
task.bindings,
|
|
355
|
+
expect.any(AbortSignal),
|
|
356
|
+
);
|
|
357
|
+
expect(env.captureTaskOutput).toHaveBeenCalledWith(task, state, {
|
|
358
|
+
inputs: { payload: 'recorded' },
|
|
359
|
+
reply: 'yes',
|
|
360
|
+
});
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
it('fails a resumed body that completes without reaching its suspension', async () => {
|
|
364
|
+
const task = createTask(jest.fn().mockResolvedValue('done'));
|
|
365
|
+
const env = {
|
|
366
|
+
...createEnv(createCompiled(task), stepInfo),
|
|
367
|
+
resolutions: new Map([['0:test_task@index:1', 'yes']]),
|
|
368
|
+
};
|
|
369
|
+
const frame: TaskFrame = {
|
|
370
|
+
kind: 'task',
|
|
371
|
+
stepId: step.id,
|
|
372
|
+
inputs: { payload: 123 },
|
|
373
|
+
awaitResults: {},
|
|
374
|
+
wait: {
|
|
375
|
+
waitId: '0:test_task@index:1',
|
|
376
|
+
step: stepInfo,
|
|
377
|
+
suspendKey: 'index:1',
|
|
378
|
+
},
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
await expect(
|
|
382
|
+
executeTaskStep(env, step, createState(), [], frame),
|
|
383
|
+
).rejects.toThrow(NonDeterministicWorkflowError);
|
|
384
|
+
expect(env.captureTaskOutput).not.toHaveBeenCalled();
|
|
385
|
+
expect(env.markSnapshot).toHaveBeenLastCalledWith(
|
|
386
|
+
stepInfo,
|
|
387
|
+
'failed',
|
|
388
|
+
expect.stringContaining('completed without reaching suspension'),
|
|
389
|
+
);
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
it('keeps the wait open when a resumed body refuses its payload', async () => {
|
|
393
|
+
const refusal = new WorkflowResumeRejectedError('Unknown order.');
|
|
394
|
+
const task = createTask(
|
|
395
|
+
jest.fn().mockImplementation(async (_inputs, context) => {
|
|
396
|
+
await context.workflow.suspend({ reason: 'awaiting_order' });
|
|
397
|
+
throw refusal;
|
|
398
|
+
}),
|
|
399
|
+
);
|
|
400
|
+
const env = {
|
|
401
|
+
...createEnv(createCompiled(task), stepInfo),
|
|
402
|
+
resolutions: new Map([['0:test_task@index:1', 'order-404']]),
|
|
403
|
+
};
|
|
404
|
+
const frame: TaskFrame = {
|
|
405
|
+
kind: 'task',
|
|
406
|
+
stepId: step.id,
|
|
407
|
+
inputs: { payload: 123 },
|
|
408
|
+
awaitResults: {},
|
|
409
|
+
wait: {
|
|
410
|
+
waitId: '0:test_task@index:1',
|
|
411
|
+
step: stepInfo,
|
|
412
|
+
suspendKey: 'index:1',
|
|
413
|
+
reason: 'awaiting_order',
|
|
414
|
+
},
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
await expect(
|
|
418
|
+
executeTaskStep(env, step, createState(), [], frame),
|
|
419
|
+
).resolves.toBe(frame);
|
|
420
|
+
expect(env.rejectResume).toHaveBeenCalledWith({
|
|
421
|
+
waitId: '0:test_task@index:1',
|
|
422
|
+
error: refusal,
|
|
423
|
+
});
|
|
424
|
+
expect(env.captureTaskOutput).not.toHaveBeenCalled();
|
|
425
|
+
expect(env.markSnapshot).toHaveBeenLastCalledWith(
|
|
426
|
+
stepInfo,
|
|
427
|
+
'suspended',
|
|
428
|
+
'awaiting_order',
|
|
429
|
+
);
|
|
430
|
+
expect(env.emit).toHaveBeenLastCalledWith('hook:step:resume_rejected', {
|
|
431
|
+
runId: 'run-123',
|
|
432
|
+
step: stepInfo,
|
|
433
|
+
stepExecution: expect.objectContaining({ status: 'suspended' }),
|
|
434
|
+
wait: frame.wait,
|
|
435
|
+
error: refusal,
|
|
436
|
+
});
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
it('fails a body that refuses a payload it has not read', async () => {
|
|
440
|
+
const refuse = jest
|
|
441
|
+
.fn()
|
|
442
|
+
.mockRejectedValue(new WorkflowResumeRejectedError('Too early.'));
|
|
443
|
+
const frame: TaskFrame = {
|
|
444
|
+
kind: 'task',
|
|
445
|
+
stepId: step.id,
|
|
446
|
+
inputs: { payload: 123 },
|
|
447
|
+
awaitResults: {},
|
|
448
|
+
wait: {
|
|
449
|
+
waitId: '0:test_task@index:1',
|
|
450
|
+
step: stepInfo,
|
|
451
|
+
suspendKey: 'index:1',
|
|
452
|
+
},
|
|
453
|
+
};
|
|
454
|
+
// Resumed, but refusing before reaching the resolved suspend() call.
|
|
455
|
+
const resumedTask = createTask(refuse);
|
|
456
|
+
const resumedEnv = {
|
|
457
|
+
...createEnv(createCompiled(resumedTask), stepInfo),
|
|
458
|
+
resolutions: new Map([['0:test_task@index:1', 'yes']]),
|
|
459
|
+
};
|
|
460
|
+
await expect(
|
|
461
|
+
executeTaskStep(resumedEnv, step, createState(), [], frame),
|
|
462
|
+
).rejects.toThrow('Too early.');
|
|
463
|
+
expect(resumedEnv.rejectResume).not.toHaveBeenCalled();
|
|
464
|
+
expect(resumedEnv.markSnapshot).toHaveBeenLastCalledWith(
|
|
465
|
+
stepInfo,
|
|
466
|
+
'failed',
|
|
467
|
+
'Too early.',
|
|
468
|
+
);
|
|
469
|
+
|
|
470
|
+
// Not resumed at all.
|
|
471
|
+
const freshEnv = createEnv(createCompiled(createTask(refuse)), stepInfo);
|
|
472
|
+
await expect(
|
|
473
|
+
executeTaskStep(freshEnv, step, createState(), []),
|
|
474
|
+
).rejects.toThrow('Too early.');
|
|
475
|
+
expect(freshEnv.rejectResume).not.toHaveBeenCalled();
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
it('does not start the action when the run is already aborted', async () => {
|
|
479
|
+
const task = createTask(jest.fn());
|
|
480
|
+
const controller = new AbortController();
|
|
481
|
+
controller.abort(new Error('stopped'));
|
|
482
|
+
const env = {
|
|
483
|
+
...createEnv(createCompiled(task), stepInfo),
|
|
484
|
+
signal: controller.signal,
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
await expect(executeTaskStep(env, step, createState(), [])).rejects.toThrow(
|
|
488
|
+
'stopped',
|
|
489
|
+
);
|
|
490
|
+
expect(task.action.run).not.toHaveBeenCalled();
|
|
491
|
+
expect(env.markSnapshot).toHaveBeenCalledWith(
|
|
492
|
+
stepInfo,
|
|
493
|
+
'cancelled',
|
|
494
|
+
'stopped',
|
|
495
|
+
);
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
it('reports the wait a cancelled resume drops', async () => {
|
|
499
|
+
const task = createTask(jest.fn());
|
|
500
|
+
const controller = new AbortController();
|
|
501
|
+
controller.abort(new Error('stopped'));
|
|
502
|
+
const frame: TaskFrame = {
|
|
503
|
+
kind: 'task',
|
|
504
|
+
stepId: step.id,
|
|
505
|
+
inputs: { payload: 123 },
|
|
506
|
+
awaitResults: {},
|
|
507
|
+
wait: {
|
|
508
|
+
waitId: '0:test_task@index:1',
|
|
509
|
+
step: stepInfo,
|
|
510
|
+
suspendKey: 'index:1',
|
|
511
|
+
},
|
|
512
|
+
};
|
|
513
|
+
const env = {
|
|
514
|
+
...createEnv(createCompiled(task), stepInfo),
|
|
515
|
+
signal: controller.signal,
|
|
516
|
+
resolutions: new Map([['0:test_task@index:1', 'yes']]),
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
await expect(
|
|
520
|
+
executeTaskStep(env, step, createState(), [], frame),
|
|
521
|
+
).rejects.toThrow('stopped');
|
|
522
|
+
expect(env.emit).toHaveBeenCalledWith(
|
|
523
|
+
'hook:step:cancelled',
|
|
524
|
+
expect.objectContaining({ step: stepInfo, wait: frame.wait }),
|
|
525
|
+
);
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
it('records a cancellation when the run is aborted while the action runs', async () => {
|
|
529
|
+
const task = createTask(
|
|
530
|
+
jest.fn().mockImplementation(() => new Promise(() => undefined)),
|
|
531
|
+
);
|
|
532
|
+
const controller = new AbortController();
|
|
533
|
+
const env = {
|
|
534
|
+
...createEnv(createCompiled(task), stepInfo),
|
|
535
|
+
signal: controller.signal,
|
|
536
|
+
};
|
|
537
|
+
const execution = executeTaskStep(env, step, createState(), []);
|
|
538
|
+
|
|
539
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
540
|
+
expect(task.action.run).toHaveBeenCalledTimes(1);
|
|
541
|
+
controller.abort(new Error('stopped'));
|
|
542
|
+
|
|
543
|
+
await expect(execution).rejects.toThrow('stopped');
|
|
544
|
+
expect(env.recordStepExecution).toHaveBeenLastCalledWith(
|
|
545
|
+
stepInfo,
|
|
546
|
+
expect.objectContaining({
|
|
547
|
+
status: 'cancelled',
|
|
548
|
+
error: { message: 'stopped', stack: expect.any(String) },
|
|
549
|
+
}),
|
|
550
|
+
);
|
|
551
|
+
expect(env.markSnapshot).toHaveBeenLastCalledWith(
|
|
552
|
+
stepInfo,
|
|
553
|
+
'cancelled',
|
|
554
|
+
'stopped',
|
|
555
|
+
);
|
|
556
|
+
expect(env.emit).toHaveBeenCalledWith('hook:step:cancelled', {
|
|
557
|
+
runId: 'run-123',
|
|
558
|
+
step: stepInfo,
|
|
559
|
+
stepExecution: expect.objectContaining({ status: 'cancelled' }),
|
|
560
|
+
error: expect.objectContaining({ message: 'stopped' }),
|
|
561
|
+
});
|
|
562
|
+
});
|
|
563
|
+
|
|
293
564
|
it('marks failure and rethrows errors from the task', async () => {
|
|
294
565
|
const task = createTask(jest.fn().mockRejectedValue(new Error('boom')));
|
|
295
566
|
const compiled = createCompiled(task);
|
|
@@ -316,6 +587,5 @@ describe('executeTaskStep', () => {
|
|
|
316
587
|
}),
|
|
317
588
|
error: expect.any(Error),
|
|
318
589
|
});
|
|
319
|
-
expect(env.setCurrentStep).toHaveBeenLastCalledWith(undefined);
|
|
320
590
|
});
|
|
321
591
|
});
|