@mastra/inngest 0.0.0-working-memory-per-user-20250620163010 → 0.0.0-zod-v4-compat-part-2-20250820135355
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/CHANGELOG.md +364 -3
- package/LICENSE.md +11 -42
- package/dist/index.cjs +281 -30
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +282 -7
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +282 -31
- package/dist/index.js.map +1 -0
- package/docker-compose.yaml +3 -3
- package/package.json +15 -14
- package/src/index.test.ts +1371 -315
- package/src/index.ts +353 -30
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +1 -1
- package/tsup.config.ts +22 -0
- package/vitest.config.ts +6 -0
- package/dist/_tsup-dts-rollup.d.cts +0 -265
- package/dist/_tsup-dts-rollup.d.ts +0 -265
- package/dist/index.d.cts +0 -7
package/src/index.test.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { randomUUID } from 'crypto';
|
|
2
1
|
import fs from 'fs';
|
|
3
2
|
import path from 'path';
|
|
4
3
|
import { openai } from '@ai-sdk/openai';
|
|
@@ -12,9 +11,8 @@ import { createHonoServer } from '@mastra/deployer/server';
|
|
|
12
11
|
import { DefaultStorage } from '@mastra/libsql';
|
|
13
12
|
import { MockLanguageModelV1, simulateReadableStream } from 'ai/test';
|
|
14
13
|
import { $ } from 'execa';
|
|
15
|
-
import getPort from 'get-port';
|
|
16
14
|
import { Inngest } from 'inngest';
|
|
17
|
-
import { afterAll,
|
|
15
|
+
import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
18
16
|
|
|
19
17
|
import { z } from 'zod';
|
|
20
18
|
import { init, serve as inngestServe } from './index';
|
|
@@ -22,28 +20,133 @@ import { init, serve as inngestServe } from './index';
|
|
|
22
20
|
interface LocalTestContext {
|
|
23
21
|
inngestPort: number;
|
|
24
22
|
handlerPort: number;
|
|
25
|
-
|
|
23
|
+
srv?: any;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function resetInngest() {
|
|
27
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
28
|
+
await $`docker-compose restart`;
|
|
29
|
+
await new Promise(resolve => setTimeout(resolve, 1500));
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
describe('MastraInngestWorkflow', () => {
|
|
33
|
+
let globServer: any;
|
|
34
|
+
|
|
29
35
|
beforeEach<LocalTestContext>(async ctx => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const containerName = randomUUID();
|
|
33
|
-
await $`docker run --rm -d --name ${containerName} -p ${inngestPort}:${inngestPort} inngest/inngest:v1.5.10 inngest dev -p ${inngestPort} -u http://host.docker.internal:${handlerPort}/inngest/api`;
|
|
36
|
+
ctx.inngestPort = 4000;
|
|
37
|
+
ctx.handlerPort = 4001;
|
|
34
38
|
|
|
35
|
-
|
|
36
|
-
ctx.handlerPort = handlerPort;
|
|
37
|
-
ctx.containerName = containerName;
|
|
39
|
+
globServer?.close();
|
|
38
40
|
|
|
39
41
|
vi.restoreAllMocks();
|
|
40
42
|
});
|
|
41
43
|
|
|
42
|
-
afterEach<LocalTestContext>(async ctx => {
|
|
43
|
-
await $`docker stop ${ctx.containerName}`;
|
|
44
|
-
});
|
|
45
|
-
|
|
46
44
|
describe.sequential('Basic Workflow Execution', () => {
|
|
45
|
+
it('should be able to bail workflow execution', async ctx => {
|
|
46
|
+
const inngest = new Inngest({
|
|
47
|
+
id: 'mastra',
|
|
48
|
+
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
49
|
+
middleware: [realtimeMiddleware()],
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const { createWorkflow, createStep } = init(inngest);
|
|
53
|
+
|
|
54
|
+
const step1 = createStep({
|
|
55
|
+
id: 'step1',
|
|
56
|
+
execute: async ({ bail, inputData }) => {
|
|
57
|
+
if (inputData.value === 'bail') {
|
|
58
|
+
return bail({ result: 'bailed' });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return { result: 'step1: ' + inputData.value };
|
|
62
|
+
},
|
|
63
|
+
inputSchema: z.object({ value: z.string() }),
|
|
64
|
+
outputSchema: z.object({ result: z.string() }),
|
|
65
|
+
});
|
|
66
|
+
const step2 = createStep({
|
|
67
|
+
id: 'step2',
|
|
68
|
+
execute: async ({ inputData }) => {
|
|
69
|
+
return { result: 'step2: ' + inputData.result };
|
|
70
|
+
},
|
|
71
|
+
inputSchema: z.object({ result: z.string() }),
|
|
72
|
+
outputSchema: z.object({ result: z.string() }),
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const workflow = createWorkflow({
|
|
76
|
+
id: 'test-workflow',
|
|
77
|
+
inputSchema: z.object({ value: z.string() }),
|
|
78
|
+
outputSchema: z.object({
|
|
79
|
+
result: z.string(),
|
|
80
|
+
}),
|
|
81
|
+
steps: [step1, step2],
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
workflow.then(step1).then(step2).commit();
|
|
85
|
+
|
|
86
|
+
const mastra = new Mastra({
|
|
87
|
+
storage: new DefaultStorage({
|
|
88
|
+
url: ':memory:',
|
|
89
|
+
}),
|
|
90
|
+
workflows: {
|
|
91
|
+
'test-workflow': workflow,
|
|
92
|
+
},
|
|
93
|
+
server: {
|
|
94
|
+
apiRoutes: [
|
|
95
|
+
{
|
|
96
|
+
path: '/inngest/api',
|
|
97
|
+
method: 'ALL',
|
|
98
|
+
createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const app = await createHonoServer(mastra);
|
|
105
|
+
|
|
106
|
+
const srv = (globServer = serve({
|
|
107
|
+
fetch: app.fetch,
|
|
108
|
+
port: (ctx as any).handlerPort,
|
|
109
|
+
}));
|
|
110
|
+
|
|
111
|
+
await resetInngest();
|
|
112
|
+
|
|
113
|
+
const run = await workflow.createRunAsync();
|
|
114
|
+
console.log('running');
|
|
115
|
+
const result = await run.start({ inputData: { value: 'bail' } });
|
|
116
|
+
console.log('result', result);
|
|
117
|
+
|
|
118
|
+
expect(result.steps['step1']).toEqual({
|
|
119
|
+
status: 'success',
|
|
120
|
+
output: { result: 'bailed' },
|
|
121
|
+
payload: { value: 'bail' },
|
|
122
|
+
startedAt: expect.any(Number),
|
|
123
|
+
endedAt: expect.any(Number),
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
expect(result.steps['step2']).toBeUndefined();
|
|
127
|
+
|
|
128
|
+
const run2 = await workflow.createRunAsync();
|
|
129
|
+
const result2 = await run2.start({ inputData: { value: 'no-bail' } });
|
|
130
|
+
|
|
131
|
+
srv.close();
|
|
132
|
+
|
|
133
|
+
expect(result2.steps['step1']).toEqual({
|
|
134
|
+
status: 'success',
|
|
135
|
+
output: { result: 'step1: no-bail' },
|
|
136
|
+
payload: { value: 'no-bail' },
|
|
137
|
+
startedAt: expect.any(Number),
|
|
138
|
+
endedAt: expect.any(Number),
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
expect(result2.steps['step2']).toEqual({
|
|
142
|
+
status: 'success',
|
|
143
|
+
output: { result: 'step2: step1: no-bail' },
|
|
144
|
+
payload: { result: 'step1: no-bail' },
|
|
145
|
+
startedAt: expect.any(Number),
|
|
146
|
+
endedAt: expect.any(Number),
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
47
150
|
it('should execute a single step workflow successfully', async ctx => {
|
|
48
151
|
const inngest = new Inngest({
|
|
49
152
|
id: 'mastra',
|
|
@@ -89,13 +192,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
89
192
|
|
|
90
193
|
const app = await createHonoServer(mastra);
|
|
91
194
|
|
|
92
|
-
const srv = serve({
|
|
195
|
+
const srv = (globServer = serve({
|
|
93
196
|
fetch: app.fetch,
|
|
94
197
|
port: (ctx as any).handlerPort,
|
|
95
|
-
});
|
|
96
|
-
await
|
|
198
|
+
}));
|
|
199
|
+
await resetInngest();
|
|
97
200
|
|
|
98
|
-
const run = workflow.
|
|
201
|
+
const run = await workflow.createRunAsync();
|
|
99
202
|
const result = await run.start({ inputData: {} });
|
|
100
203
|
|
|
101
204
|
expect(execute).toHaveBeenCalled();
|
|
@@ -164,13 +267,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
164
267
|
|
|
165
268
|
const app = await createHonoServer(mastra);
|
|
166
269
|
|
|
167
|
-
const srv = serve({
|
|
270
|
+
const srv = (globServer = serve({
|
|
168
271
|
fetch: app.fetch,
|
|
169
272
|
port: (ctx as any).handlerPort,
|
|
170
|
-
});
|
|
171
|
-
await
|
|
273
|
+
}));
|
|
274
|
+
await resetInngest();
|
|
172
275
|
|
|
173
|
-
const run = workflow.
|
|
276
|
+
const run = await workflow.createRunAsync();
|
|
174
277
|
const result = await run.start({ inputData: {} });
|
|
175
278
|
|
|
176
279
|
expect(step1Action).toHaveBeenCalled();
|
|
@@ -245,13 +348,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
245
348
|
|
|
246
349
|
const app = await createHonoServer(mastra);
|
|
247
350
|
|
|
248
|
-
const srv = serve({
|
|
351
|
+
const srv = (globServer = serve({
|
|
249
352
|
fetch: app.fetch,
|
|
250
353
|
port: (ctx as any).handlerPort,
|
|
251
|
-
});
|
|
252
|
-
await
|
|
354
|
+
}));
|
|
355
|
+
await resetInngest();
|
|
253
356
|
|
|
254
|
-
const run = workflow.
|
|
357
|
+
const run = await workflow.createRunAsync();
|
|
255
358
|
const result = await run.start({ inputData: {} });
|
|
256
359
|
|
|
257
360
|
expect(executionOrder).toMatchObject(['step1', 'step2']);
|
|
@@ -264,7 +367,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
264
367
|
srv.close();
|
|
265
368
|
});
|
|
266
369
|
|
|
267
|
-
it('should execute a
|
|
370
|
+
it('should execute a sleep step', async ctx => {
|
|
268
371
|
const inngest = new Inngest({
|
|
269
372
|
id: 'mastra',
|
|
270
373
|
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
@@ -319,13 +422,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
319
422
|
|
|
320
423
|
const app = await createHonoServer(mastra);
|
|
321
424
|
|
|
322
|
-
const srv = serve({
|
|
425
|
+
const srv = (globServer = serve({
|
|
323
426
|
fetch: app.fetch,
|
|
324
427
|
port: (ctx as any).handlerPort,
|
|
325
|
-
});
|
|
326
|
-
await
|
|
428
|
+
}));
|
|
429
|
+
await resetInngest();
|
|
327
430
|
|
|
328
|
-
const run = workflow.
|
|
431
|
+
const run = await workflow.createRunAsync();
|
|
329
432
|
const startTime = Date.now();
|
|
330
433
|
const result = await run.start({ inputData: {} });
|
|
331
434
|
const endTime = Date.now();
|
|
@@ -352,6 +455,100 @@ describe('MastraInngestWorkflow', () => {
|
|
|
352
455
|
srv.close();
|
|
353
456
|
});
|
|
354
457
|
|
|
458
|
+
it('should execute a sleep step with fn parameter', async ctx => {
|
|
459
|
+
const inngest = new Inngest({
|
|
460
|
+
id: 'mastra',
|
|
461
|
+
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
const { createWorkflow, createStep } = init(inngest);
|
|
465
|
+
|
|
466
|
+
const execute = vi.fn<any>().mockResolvedValue({ value: 1000 });
|
|
467
|
+
const step1 = createStep({
|
|
468
|
+
id: 'step1',
|
|
469
|
+
execute,
|
|
470
|
+
inputSchema: z.object({}),
|
|
471
|
+
outputSchema: z.object({ value: z.number() }),
|
|
472
|
+
});
|
|
473
|
+
const step2 = createStep({
|
|
474
|
+
id: 'step2',
|
|
475
|
+
execute: async ({ inputData }) => {
|
|
476
|
+
return { value: inputData.value + 1000 };
|
|
477
|
+
},
|
|
478
|
+
inputSchema: z.object({ value: z.number() }),
|
|
479
|
+
outputSchema: z.object({ value: z.number() }),
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
const workflow = createWorkflow({
|
|
483
|
+
id: 'test-workflow',
|
|
484
|
+
inputSchema: z.object({}),
|
|
485
|
+
outputSchema: z.object({
|
|
486
|
+
value: z.number(),
|
|
487
|
+
}),
|
|
488
|
+
steps: [step1],
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
workflow
|
|
492
|
+
.then(step1)
|
|
493
|
+
.sleep(async ({ inputData }) => {
|
|
494
|
+
return inputData.value;
|
|
495
|
+
})
|
|
496
|
+
.then(step2)
|
|
497
|
+
.commit();
|
|
498
|
+
|
|
499
|
+
const mastra = new Mastra({
|
|
500
|
+
storage: new DefaultStorage({
|
|
501
|
+
url: ':memory:',
|
|
502
|
+
}),
|
|
503
|
+
workflows: {
|
|
504
|
+
'test-workflow': workflow,
|
|
505
|
+
},
|
|
506
|
+
server: {
|
|
507
|
+
apiRoutes: [
|
|
508
|
+
{
|
|
509
|
+
path: '/inngest/api',
|
|
510
|
+
method: 'ALL',
|
|
511
|
+
createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
|
|
512
|
+
},
|
|
513
|
+
],
|
|
514
|
+
},
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
const app = await createHonoServer(mastra);
|
|
518
|
+
|
|
519
|
+
const srv = (globServer = serve({
|
|
520
|
+
fetch: app.fetch,
|
|
521
|
+
port: (ctx as any).handlerPort,
|
|
522
|
+
}));
|
|
523
|
+
await resetInngest();
|
|
524
|
+
|
|
525
|
+
const run = await workflow.createRunAsync();
|
|
526
|
+
const startTime = Date.now();
|
|
527
|
+
const result = await run.start({ inputData: {} });
|
|
528
|
+
const endTime = Date.now();
|
|
529
|
+
|
|
530
|
+
expect(execute).toHaveBeenCalled();
|
|
531
|
+
expect(result.steps['step1']).toMatchObject({
|
|
532
|
+
status: 'success',
|
|
533
|
+
output: { value: 1000 },
|
|
534
|
+
// payload: {},
|
|
535
|
+
// startedAt: expect.any(Number),
|
|
536
|
+
// endedAt: expect.any(Number),
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
expect(result.steps['step2']).toMatchObject({
|
|
540
|
+
status: 'success',
|
|
541
|
+
output: { value: 2000 },
|
|
542
|
+
// payload: { result: 'success' },
|
|
543
|
+
// startedAt: expect.any(Number),
|
|
544
|
+
// endedAt: expect.any(Number),
|
|
545
|
+
});
|
|
546
|
+
|
|
547
|
+
expect(endTime - startTime).toBeGreaterThan(1000);
|
|
548
|
+
|
|
549
|
+
srv.close();
|
|
550
|
+
});
|
|
551
|
+
|
|
355
552
|
it('should execute a a sleep until step', async ctx => {
|
|
356
553
|
const inngest = new Inngest({
|
|
357
554
|
id: 'mastra',
|
|
@@ -411,13 +608,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
411
608
|
|
|
412
609
|
const app = await createHonoServer(mastra);
|
|
413
610
|
|
|
414
|
-
const srv = serve({
|
|
611
|
+
const srv = (globServer = serve({
|
|
415
612
|
fetch: app.fetch,
|
|
416
613
|
port: (ctx as any).handlerPort,
|
|
417
|
-
});
|
|
418
|
-
await
|
|
614
|
+
}));
|
|
615
|
+
await resetInngest();
|
|
419
616
|
|
|
420
|
-
const run = workflow.
|
|
617
|
+
const run = await workflow.createRunAsync();
|
|
421
618
|
const startTime = Date.now();
|
|
422
619
|
const result = await run.start({ inputData: {} });
|
|
423
620
|
const endTime = Date.now();
|
|
@@ -444,6 +641,100 @@ describe('MastraInngestWorkflow', () => {
|
|
|
444
641
|
srv.close();
|
|
445
642
|
});
|
|
446
643
|
|
|
644
|
+
it('should execute a sleep until step with fn parameter', async ctx => {
|
|
645
|
+
const inngest = new Inngest({
|
|
646
|
+
id: 'mastra',
|
|
647
|
+
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
648
|
+
});
|
|
649
|
+
|
|
650
|
+
const { createWorkflow, createStep } = init(inngest);
|
|
651
|
+
|
|
652
|
+
const execute = vi.fn<any>().mockResolvedValue({ value: 1000 });
|
|
653
|
+
const step1 = createStep({
|
|
654
|
+
id: 'step1',
|
|
655
|
+
execute,
|
|
656
|
+
inputSchema: z.object({}),
|
|
657
|
+
outputSchema: z.object({ value: z.number() }),
|
|
658
|
+
});
|
|
659
|
+
const step2 = createStep({
|
|
660
|
+
id: 'step2',
|
|
661
|
+
execute: async ({ inputData }) => {
|
|
662
|
+
return { value: inputData.value + 1000 };
|
|
663
|
+
},
|
|
664
|
+
inputSchema: z.object({ value: z.number() }),
|
|
665
|
+
outputSchema: z.object({ value: z.number() }),
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
const workflow = createWorkflow({
|
|
669
|
+
id: 'test-workflow',
|
|
670
|
+
inputSchema: z.object({}),
|
|
671
|
+
outputSchema: z.object({
|
|
672
|
+
value: z.number(),
|
|
673
|
+
}),
|
|
674
|
+
steps: [step1],
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
workflow
|
|
678
|
+
.then(step1)
|
|
679
|
+
.sleepUntil(async ({ inputData }) => {
|
|
680
|
+
return new Date(Date.now() + inputData.value);
|
|
681
|
+
})
|
|
682
|
+
.then(step2)
|
|
683
|
+
.commit();
|
|
684
|
+
|
|
685
|
+
const mastra = new Mastra({
|
|
686
|
+
storage: new DefaultStorage({
|
|
687
|
+
url: ':memory:',
|
|
688
|
+
}),
|
|
689
|
+
workflows: {
|
|
690
|
+
'test-workflow': workflow,
|
|
691
|
+
},
|
|
692
|
+
server: {
|
|
693
|
+
apiRoutes: [
|
|
694
|
+
{
|
|
695
|
+
path: '/inngest/api',
|
|
696
|
+
method: 'ALL',
|
|
697
|
+
createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
|
|
698
|
+
},
|
|
699
|
+
],
|
|
700
|
+
},
|
|
701
|
+
});
|
|
702
|
+
|
|
703
|
+
const app = await createHonoServer(mastra);
|
|
704
|
+
|
|
705
|
+
const srv = (globServer = serve({
|
|
706
|
+
fetch: app.fetch,
|
|
707
|
+
port: (ctx as any).handlerPort,
|
|
708
|
+
}));
|
|
709
|
+
await resetInngest();
|
|
710
|
+
|
|
711
|
+
const run = await workflow.createRunAsync();
|
|
712
|
+
const startTime = Date.now();
|
|
713
|
+
const result = await run.start({ inputData: {} });
|
|
714
|
+
const endTime = Date.now();
|
|
715
|
+
|
|
716
|
+
expect(execute).toHaveBeenCalled();
|
|
717
|
+
expect(result.steps['step1']).toMatchObject({
|
|
718
|
+
status: 'success',
|
|
719
|
+
output: { value: 1000 },
|
|
720
|
+
// payload: {},
|
|
721
|
+
// startedAt: expect.any(Number),
|
|
722
|
+
// endedAt: expect.any(Number),
|
|
723
|
+
});
|
|
724
|
+
|
|
725
|
+
expect(result.steps['step2']).toMatchObject({
|
|
726
|
+
status: 'success',
|
|
727
|
+
output: { value: 2000 },
|
|
728
|
+
// payload: { result: 'success' },
|
|
729
|
+
// startedAt: expect.any(Number),
|
|
730
|
+
// endedAt: expect.any(Number),
|
|
731
|
+
});
|
|
732
|
+
|
|
733
|
+
expect(endTime - startTime).toBeGreaterThan(1000);
|
|
734
|
+
|
|
735
|
+
srv.close();
|
|
736
|
+
});
|
|
737
|
+
|
|
447
738
|
it('should execute a a waitForEvent step', async ctx => {
|
|
448
739
|
const inngest = new Inngest({
|
|
449
740
|
id: 'mastra',
|
|
@@ -501,13 +792,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
501
792
|
|
|
502
793
|
const app = await createHonoServer(mastra);
|
|
503
794
|
|
|
504
|
-
const srv = serve({
|
|
795
|
+
const srv = (globServer = serve({
|
|
505
796
|
fetch: app.fetch,
|
|
506
797
|
port: (ctx as any).handlerPort,
|
|
507
|
-
});
|
|
508
|
-
await
|
|
798
|
+
}));
|
|
799
|
+
await resetInngest();
|
|
509
800
|
|
|
510
|
-
const run = workflow.
|
|
801
|
+
const run = await workflow.createRunAsync();
|
|
511
802
|
const startTime = Date.now();
|
|
512
803
|
setTimeout(() => {
|
|
513
804
|
run.sendEvent('hello-event', { data: 'hello' });
|
|
@@ -595,13 +886,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
595
886
|
|
|
596
887
|
const app = await createHonoServer(mastra);
|
|
597
888
|
|
|
598
|
-
const srv = serve({
|
|
889
|
+
const srv = (globServer = serve({
|
|
599
890
|
fetch: app.fetch,
|
|
600
891
|
port: (ctx as any).handlerPort,
|
|
601
|
-
});
|
|
602
|
-
await
|
|
892
|
+
}));
|
|
893
|
+
await resetInngest();
|
|
603
894
|
|
|
604
|
-
const run = workflow.
|
|
895
|
+
const run = await workflow.createRunAsync();
|
|
605
896
|
const startTime = Date.now();
|
|
606
897
|
const result = await run.start({ inputData: {} });
|
|
607
898
|
const endTime = Date.now();
|
|
@@ -629,6 +920,203 @@ describe('MastraInngestWorkflow', () => {
|
|
|
629
920
|
});
|
|
630
921
|
});
|
|
631
922
|
|
|
923
|
+
describe('abort', () => {
|
|
924
|
+
it('should be able to abort workflow execution in between steps', async ctx => {
|
|
925
|
+
const inngest = new Inngest({
|
|
926
|
+
id: 'mastra',
|
|
927
|
+
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
928
|
+
middleware: [realtimeMiddleware()],
|
|
929
|
+
});
|
|
930
|
+
|
|
931
|
+
const { createWorkflow, createStep } = init(inngest);
|
|
932
|
+
|
|
933
|
+
const step1 = createStep({
|
|
934
|
+
id: 'step1',
|
|
935
|
+
execute: async ({ inputData }) => {
|
|
936
|
+
return { result: 'step1: ' + inputData.value };
|
|
937
|
+
},
|
|
938
|
+
inputSchema: z.object({ value: z.string() }),
|
|
939
|
+
outputSchema: z.object({ result: z.string() }),
|
|
940
|
+
});
|
|
941
|
+
const step2 = createStep({
|
|
942
|
+
id: 'step2',
|
|
943
|
+
execute: async ({ inputData }) => {
|
|
944
|
+
return { result: 'step2: ' + inputData.result };
|
|
945
|
+
},
|
|
946
|
+
inputSchema: z.object({ result: z.string() }),
|
|
947
|
+
outputSchema: z.object({ result: z.string() }),
|
|
948
|
+
});
|
|
949
|
+
|
|
950
|
+
const workflow = createWorkflow({
|
|
951
|
+
id: 'test-workflow',
|
|
952
|
+
inputSchema: z.object({}),
|
|
953
|
+
outputSchema: z.object({
|
|
954
|
+
result: z.string(),
|
|
955
|
+
}),
|
|
956
|
+
steps: [step1, step2],
|
|
957
|
+
});
|
|
958
|
+
|
|
959
|
+
workflow.then(step1).sleep(2000).then(step2).commit();
|
|
960
|
+
|
|
961
|
+
const mastra = new Mastra({
|
|
962
|
+
storage: new DefaultStorage({
|
|
963
|
+
url: ':memory:',
|
|
964
|
+
}),
|
|
965
|
+
workflows: {
|
|
966
|
+
'test-workflow': workflow,
|
|
967
|
+
},
|
|
968
|
+
server: {
|
|
969
|
+
apiRoutes: [
|
|
970
|
+
{
|
|
971
|
+
path: '/inngest/api',
|
|
972
|
+
method: 'ALL',
|
|
973
|
+
createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
|
|
974
|
+
},
|
|
975
|
+
],
|
|
976
|
+
},
|
|
977
|
+
});
|
|
978
|
+
|
|
979
|
+
const app = await createHonoServer(mastra);
|
|
980
|
+
|
|
981
|
+
const srv = (globServer = serve({
|
|
982
|
+
fetch: app.fetch,
|
|
983
|
+
port: (ctx as any).handlerPort,
|
|
984
|
+
}));
|
|
985
|
+
await resetInngest();
|
|
986
|
+
|
|
987
|
+
const run = await workflow.createRunAsync();
|
|
988
|
+
const p = run.start({ inputData: { value: 'test' } });
|
|
989
|
+
|
|
990
|
+
setTimeout(() => {
|
|
991
|
+
run.cancel();
|
|
992
|
+
}, 1000);
|
|
993
|
+
|
|
994
|
+
const result = await p;
|
|
995
|
+
|
|
996
|
+
srv.close();
|
|
997
|
+
|
|
998
|
+
expect(result.status).toBe('canceled');
|
|
999
|
+
expect(result.steps['step1']).toEqual({
|
|
1000
|
+
status: 'success',
|
|
1001
|
+
output: { result: 'step1: test' },
|
|
1002
|
+
payload: { value: 'test' },
|
|
1003
|
+
startedAt: expect.any(Number),
|
|
1004
|
+
endedAt: expect.any(Number),
|
|
1005
|
+
});
|
|
1006
|
+
|
|
1007
|
+
expect(result.steps['step2']).toBeUndefined();
|
|
1008
|
+
});
|
|
1009
|
+
|
|
1010
|
+
it('should be able to abort workflow execution during a step', async ctx => {
|
|
1011
|
+
const inngest = new Inngest({
|
|
1012
|
+
id: 'mastra',
|
|
1013
|
+
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
1014
|
+
middleware: [realtimeMiddleware()],
|
|
1015
|
+
});
|
|
1016
|
+
|
|
1017
|
+
const { createWorkflow, createStep } = init(inngest);
|
|
1018
|
+
|
|
1019
|
+
const step1 = createStep({
|
|
1020
|
+
id: 'step1',
|
|
1021
|
+
execute: async ({ inputData }) => {
|
|
1022
|
+
return { result: 'step1: ' + inputData.value };
|
|
1023
|
+
},
|
|
1024
|
+
inputSchema: z.object({ value: z.string() }),
|
|
1025
|
+
outputSchema: z.object({ result: z.string() }),
|
|
1026
|
+
});
|
|
1027
|
+
const step2 = createStep({
|
|
1028
|
+
id: 'step2',
|
|
1029
|
+
execute: async ({ inputData, abortSignal, abort }) => {
|
|
1030
|
+
console.log('abort signal', abortSignal);
|
|
1031
|
+
const timeout: Promise<string> = new Promise((resolve, _reject) => {
|
|
1032
|
+
const ref = setTimeout(() => {
|
|
1033
|
+
resolve('step2: ' + inputData.result);
|
|
1034
|
+
}, 5000);
|
|
1035
|
+
|
|
1036
|
+
abortSignal.addEventListener('abort', () => {
|
|
1037
|
+
resolve('');
|
|
1038
|
+
clearTimeout(ref);
|
|
1039
|
+
});
|
|
1040
|
+
});
|
|
1041
|
+
|
|
1042
|
+
const result = await timeout;
|
|
1043
|
+
if (abortSignal.aborted) {
|
|
1044
|
+
return abort();
|
|
1045
|
+
}
|
|
1046
|
+
return { result };
|
|
1047
|
+
},
|
|
1048
|
+
inputSchema: z.object({ result: z.string() }),
|
|
1049
|
+
outputSchema: z.object({ result: z.string() }),
|
|
1050
|
+
});
|
|
1051
|
+
|
|
1052
|
+
const workflow = createWorkflow({
|
|
1053
|
+
id: 'test-workflow',
|
|
1054
|
+
inputSchema: z.object({}),
|
|
1055
|
+
outputSchema: z.object({
|
|
1056
|
+
result: z.string(),
|
|
1057
|
+
}),
|
|
1058
|
+
steps: [step1, step2],
|
|
1059
|
+
});
|
|
1060
|
+
|
|
1061
|
+
workflow.then(step1).then(step2).commit();
|
|
1062
|
+
|
|
1063
|
+
const mastra = new Mastra({
|
|
1064
|
+
storage: new DefaultStorage({
|
|
1065
|
+
url: ':memory:',
|
|
1066
|
+
}),
|
|
1067
|
+
workflows: {
|
|
1068
|
+
'test-workflow': workflow,
|
|
1069
|
+
},
|
|
1070
|
+
server: {
|
|
1071
|
+
apiRoutes: [
|
|
1072
|
+
{
|
|
1073
|
+
path: '/inngest/api',
|
|
1074
|
+
method: 'ALL',
|
|
1075
|
+
createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
|
|
1076
|
+
},
|
|
1077
|
+
],
|
|
1078
|
+
},
|
|
1079
|
+
});
|
|
1080
|
+
|
|
1081
|
+
const app = await createHonoServer(mastra);
|
|
1082
|
+
|
|
1083
|
+
const srv = (globServer = serve({
|
|
1084
|
+
fetch: app.fetch,
|
|
1085
|
+
port: (ctx as any).handlerPort,
|
|
1086
|
+
}));
|
|
1087
|
+
await resetInngest();
|
|
1088
|
+
|
|
1089
|
+
const run = await workflow.createRunAsync();
|
|
1090
|
+
const p = run.start({ inputData: { value: 'test' } });
|
|
1091
|
+
|
|
1092
|
+
setTimeout(() => {
|
|
1093
|
+
run.cancel();
|
|
1094
|
+
}, 1000);
|
|
1095
|
+
|
|
1096
|
+
const result = await p;
|
|
1097
|
+
console.log('result', result);
|
|
1098
|
+
|
|
1099
|
+
srv.close();
|
|
1100
|
+
|
|
1101
|
+
expect(result.status).toBe('canceled');
|
|
1102
|
+
expect(result.steps['step1']).toEqual({
|
|
1103
|
+
status: 'success',
|
|
1104
|
+
output: { result: 'step1: test' },
|
|
1105
|
+
payload: { value: 'test' },
|
|
1106
|
+
startedAt: expect.any(Number),
|
|
1107
|
+
endedAt: expect.any(Number),
|
|
1108
|
+
});
|
|
1109
|
+
|
|
1110
|
+
// expect(result.steps['step2']).toEqual({
|
|
1111
|
+
// status: 'canceled',
|
|
1112
|
+
// payload: { result: 'step1: test' },
|
|
1113
|
+
// output: undefined,
|
|
1114
|
+
// startedAt: expect.any(Number),
|
|
1115
|
+
// endedAt: expect.any(Number),
|
|
1116
|
+
// });
|
|
1117
|
+
});
|
|
1118
|
+
});
|
|
1119
|
+
|
|
632
1120
|
describe('Variable Resolution', () => {
|
|
633
1121
|
it('should resolve trigger data', async ctx => {
|
|
634
1122
|
const inngest = new Inngest({
|
|
@@ -681,12 +1169,14 @@ describe('MastraInngestWorkflow', () => {
|
|
|
681
1169
|
|
|
682
1170
|
const app = await createHonoServer(mastra);
|
|
683
1171
|
|
|
684
|
-
const srv = serve({
|
|
1172
|
+
const srv = (globServer = serve({
|
|
685
1173
|
fetch: app.fetch,
|
|
686
1174
|
port: (ctx as any).handlerPort,
|
|
687
|
-
});
|
|
1175
|
+
}));
|
|
1176
|
+
|
|
1177
|
+
await resetInngest();
|
|
688
1178
|
|
|
689
|
-
const run = workflow.
|
|
1179
|
+
const run = await workflow.createRunAsync();
|
|
690
1180
|
const result = await run.start({ inputData: { inputData: 'test-input' } });
|
|
691
1181
|
|
|
692
1182
|
expect(result.steps.step1).toMatchObject({ status: 'success', output: { result: 'success' } });
|
|
@@ -768,12 +1258,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
768
1258
|
|
|
769
1259
|
const app = await createHonoServer(mastra);
|
|
770
1260
|
|
|
771
|
-
const srv = serve({
|
|
1261
|
+
const srv = (globServer = serve({
|
|
772
1262
|
fetch: app.fetch,
|
|
773
1263
|
port: (ctx as any).handlerPort,
|
|
774
|
-
});
|
|
1264
|
+
}));
|
|
1265
|
+
await resetInngest();
|
|
775
1266
|
|
|
776
|
-
const run = workflow.
|
|
1267
|
+
const run = await workflow.createRunAsync();
|
|
777
1268
|
const result = await run.start({ inputData: { inputValue: 'test-input' } });
|
|
778
1269
|
|
|
779
1270
|
expect(step1Action).toHaveBeenCalled();
|
|
@@ -835,12 +1326,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
835
1326
|
|
|
836
1327
|
const app = await createHonoServer(mastra);
|
|
837
1328
|
|
|
838
|
-
const srv = serve({
|
|
1329
|
+
const srv = (globServer = serve({
|
|
839
1330
|
fetch: app.fetch,
|
|
840
1331
|
port: (ctx as any).handlerPort,
|
|
841
|
-
});
|
|
1332
|
+
}));
|
|
1333
|
+
await resetInngest();
|
|
842
1334
|
|
|
843
|
-
const run = workflow.
|
|
1335
|
+
const run = await workflow.createRunAsync();
|
|
844
1336
|
await run.start({ inputData: { inputData: 'test-input' } });
|
|
845
1337
|
|
|
846
1338
|
expect(execute).toHaveBeenCalledWith(
|
|
@@ -910,12 +1402,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
910
1402
|
|
|
911
1403
|
const app = await createHonoServer(mastra);
|
|
912
1404
|
|
|
913
|
-
const srv = serve({
|
|
1405
|
+
const srv = (globServer = serve({
|
|
914
1406
|
fetch: app.fetch,
|
|
915
1407
|
port: (ctx as any).handlerPort,
|
|
916
|
-
});
|
|
1408
|
+
}));
|
|
1409
|
+
await resetInngest();
|
|
917
1410
|
|
|
918
|
-
const run = workflow.
|
|
1411
|
+
const run = await workflow.createRunAsync();
|
|
919
1412
|
const result = await run.start({ inputData: { cool: 'test-input' } });
|
|
920
1413
|
|
|
921
1414
|
expect(execute).toHaveBeenCalledWith(
|
|
@@ -992,12 +1485,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
992
1485
|
|
|
993
1486
|
const app = await createHonoServer(mastra);
|
|
994
1487
|
|
|
995
|
-
const srv = serve({
|
|
1488
|
+
const srv = (globServer = serve({
|
|
996
1489
|
fetch: app.fetch,
|
|
997
1490
|
port: (ctx as any).handlerPort,
|
|
998
|
-
});
|
|
1491
|
+
}));
|
|
1492
|
+
await resetInngest();
|
|
999
1493
|
|
|
1000
|
-
const run = workflow.
|
|
1494
|
+
const run = await workflow.createRunAsync();
|
|
1001
1495
|
await run.start({ inputData: {} });
|
|
1002
1496
|
|
|
1003
1497
|
expect(step2Action).toHaveBeenCalledWith(
|
|
@@ -1095,12 +1589,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1095
1589
|
|
|
1096
1590
|
const app = await createHonoServer(mastra);
|
|
1097
1591
|
|
|
1098
|
-
const srv = serve({
|
|
1592
|
+
const srv = (globServer = serve({
|
|
1099
1593
|
fetch: app.fetch,
|
|
1100
1594
|
port: (ctx as any).handlerPort,
|
|
1101
|
-
});
|
|
1595
|
+
}));
|
|
1596
|
+
await resetInngest();
|
|
1102
1597
|
|
|
1103
|
-
const run = workflow.
|
|
1598
|
+
const run = await workflow.createRunAsync();
|
|
1104
1599
|
const result = await run.start({ inputData: { status: 'success' } });
|
|
1105
1600
|
srv.close();
|
|
1106
1601
|
|
|
@@ -1171,12 +1666,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1171
1666
|
|
|
1172
1667
|
const app = await createHonoServer(mastra);
|
|
1173
1668
|
|
|
1174
|
-
const srv = serve({
|
|
1669
|
+
const srv = (globServer = serve({
|
|
1175
1670
|
fetch: app.fetch,
|
|
1176
1671
|
port: (ctx as any).handlerPort,
|
|
1177
|
-
});
|
|
1672
|
+
}));
|
|
1673
|
+
await resetInngest();
|
|
1178
1674
|
|
|
1179
|
-
const run = workflow.
|
|
1675
|
+
const run = await workflow.createRunAsync();
|
|
1180
1676
|
let result: Awaited<ReturnType<typeof run.start>> | undefined = undefined;
|
|
1181
1677
|
try {
|
|
1182
1678
|
result = await run.start({ inputData: {} });
|
|
@@ -1276,12 +1772,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1276
1772
|
|
|
1277
1773
|
const app = await createHonoServer(mastra);
|
|
1278
1774
|
|
|
1279
|
-
const srv = serve({
|
|
1775
|
+
const srv = (globServer = serve({
|
|
1280
1776
|
fetch: app.fetch,
|
|
1281
1777
|
port: (ctx as any).handlerPort,
|
|
1282
|
-
});
|
|
1778
|
+
}));
|
|
1779
|
+
await resetInngest();
|
|
1283
1780
|
|
|
1284
|
-
const run = workflow.
|
|
1781
|
+
const run = await workflow.createRunAsync();
|
|
1285
1782
|
const result = await run.start({ inputData: { status: 'success' } });
|
|
1286
1783
|
srv.close();
|
|
1287
1784
|
|
|
@@ -1359,12 +1856,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1359
1856
|
|
|
1360
1857
|
const app = await createHonoServer(mastra);
|
|
1361
1858
|
|
|
1362
|
-
const srv = serve({
|
|
1859
|
+
const srv = (globServer = serve({
|
|
1363
1860
|
fetch: app.fetch,
|
|
1364
1861
|
port: (ctx as any).handlerPort,
|
|
1365
|
-
});
|
|
1862
|
+
}));
|
|
1863
|
+
await resetInngest();
|
|
1366
1864
|
|
|
1367
|
-
const run = workflow.
|
|
1865
|
+
const run = await workflow.createRunAsync();
|
|
1368
1866
|
const result = await run.start({ inputData: { count: 5 } });
|
|
1369
1867
|
srv.close();
|
|
1370
1868
|
|
|
@@ -1426,13 +1924,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1426
1924
|
|
|
1427
1925
|
const app = await createHonoServer(mastra);
|
|
1428
1926
|
|
|
1429
|
-
const srv = serve({
|
|
1927
|
+
const srv = (globServer = serve({
|
|
1430
1928
|
fetch: app.fetch,
|
|
1431
1929
|
port: (ctx as any).handlerPort,
|
|
1432
|
-
});
|
|
1433
|
-
await
|
|
1930
|
+
}));
|
|
1931
|
+
await resetInngest();
|
|
1434
1932
|
|
|
1435
|
-
const run = workflow.
|
|
1933
|
+
const run = await workflow.createRunAsync();
|
|
1436
1934
|
|
|
1437
1935
|
await expect(run.start({ inputData: {} })).resolves.toMatchObject({
|
|
1438
1936
|
steps: {
|
|
@@ -1510,13 +2008,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1510
2008
|
|
|
1511
2009
|
const app = await createHonoServer(mastra);
|
|
1512
2010
|
|
|
1513
|
-
const srv = serve({
|
|
2011
|
+
const srv = (globServer = serve({
|
|
1514
2012
|
fetch: app.fetch,
|
|
1515
2013
|
port: (ctx as any).handlerPort,
|
|
1516
|
-
});
|
|
1517
|
-
await
|
|
2014
|
+
}));
|
|
2015
|
+
await resetInngest();
|
|
1518
2016
|
|
|
1519
|
-
const run = workflow.
|
|
2017
|
+
const run = await workflow.createRunAsync();
|
|
1520
2018
|
const result = await run.start({ inputData: {} });
|
|
1521
2019
|
|
|
1522
2020
|
expect(result.steps).toMatchObject({
|
|
@@ -1604,13 +2102,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1604
2102
|
|
|
1605
2103
|
const app = await createHonoServer(mastra);
|
|
1606
2104
|
|
|
1607
|
-
const srv = serve({
|
|
2105
|
+
const srv = (globServer = serve({
|
|
1608
2106
|
fetch: app.fetch,
|
|
1609
2107
|
port: (ctx as any).handlerPort,
|
|
1610
|
-
});
|
|
1611
|
-
await
|
|
2108
|
+
}));
|
|
2109
|
+
await resetInngest();
|
|
1612
2110
|
|
|
1613
|
-
const run = mainWorkflow.
|
|
2111
|
+
const run = await mainWorkflow.createRunAsync();
|
|
1614
2112
|
const result = await run.start({ inputData: {} });
|
|
1615
2113
|
|
|
1616
2114
|
expect(result.steps).toMatchObject({
|
|
@@ -1732,13 +2230,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1732
2230
|
|
|
1733
2231
|
const app = await createHonoServer(mastra);
|
|
1734
2232
|
|
|
1735
|
-
const srv = serve({
|
|
2233
|
+
const srv = (globServer = serve({
|
|
1736
2234
|
fetch: app.fetch,
|
|
1737
2235
|
port: (ctx as any).handlerPort,
|
|
1738
|
-
});
|
|
1739
|
-
await
|
|
2236
|
+
}));
|
|
2237
|
+
await resetInngest();
|
|
1740
2238
|
|
|
1741
|
-
const run = workflow.
|
|
2239
|
+
const run = await workflow.createRunAsync();
|
|
1742
2240
|
const result = await run.start({ inputData: {} });
|
|
1743
2241
|
|
|
1744
2242
|
expect(step2Action).toHaveBeenCalled();
|
|
@@ -1834,13 +2332,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1834
2332
|
|
|
1835
2333
|
const app = await createHonoServer(mastra);
|
|
1836
2334
|
|
|
1837
|
-
const srv = serve({
|
|
2335
|
+
const srv = (globServer = serve({
|
|
1838
2336
|
fetch: app.fetch,
|
|
1839
2337
|
port: (ctx as any).handlerPort,
|
|
1840
|
-
});
|
|
1841
|
-
await
|
|
2338
|
+
}));
|
|
2339
|
+
await resetInngest();
|
|
1842
2340
|
|
|
1843
|
-
const run = counterWorkflow.
|
|
2341
|
+
const run = await counterWorkflow.createRunAsync();
|
|
1844
2342
|
const result = await run.start({ inputData: { target: 10, value: 0 } });
|
|
1845
2343
|
|
|
1846
2344
|
expect(increment).toHaveBeenCalledTimes(12);
|
|
@@ -1937,13 +2435,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1937
2435
|
|
|
1938
2436
|
const app = await createHonoServer(mastra);
|
|
1939
2437
|
|
|
1940
|
-
const srv = serve({
|
|
2438
|
+
const srv = (globServer = serve({
|
|
1941
2439
|
fetch: app.fetch,
|
|
1942
2440
|
port: (ctx as any).handlerPort,
|
|
1943
|
-
});
|
|
1944
|
-
await
|
|
2441
|
+
}));
|
|
2442
|
+
await resetInngest();
|
|
1945
2443
|
|
|
1946
|
-
const run = counterWorkflow.
|
|
2444
|
+
const run = await counterWorkflow.createRunAsync();
|
|
1947
2445
|
const result = await run.start({ inputData: { target: 10, value: 0 } });
|
|
1948
2446
|
|
|
1949
2447
|
expect(increment).toHaveBeenCalledTimes(12);
|
|
@@ -2026,13 +2524,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2026
2524
|
|
|
2027
2525
|
const app = await createHonoServer(mastra);
|
|
2028
2526
|
|
|
2029
|
-
const srv = serve({
|
|
2527
|
+
const srv = (globServer = serve({
|
|
2030
2528
|
fetch: app.fetch,
|
|
2031
2529
|
port: (ctx as any).handlerPort,
|
|
2032
|
-
});
|
|
2033
|
-
await
|
|
2530
|
+
}));
|
|
2531
|
+
await resetInngest();
|
|
2034
2532
|
|
|
2035
|
-
const run = counterWorkflow.
|
|
2533
|
+
const run = await counterWorkflow.createRunAsync();
|
|
2036
2534
|
const result = await run.start({ inputData: [{ value: 1 }, { value: 22 }, { value: 333 }] });
|
|
2037
2535
|
|
|
2038
2536
|
const endTime = Date.now();
|
|
@@ -2179,13 +2677,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2179
2677
|
|
|
2180
2678
|
const app = await createHonoServer(mastra);
|
|
2181
2679
|
|
|
2182
|
-
const srv = serve({
|
|
2680
|
+
const srv = (globServer = serve({
|
|
2183
2681
|
fetch: app.fetch,
|
|
2184
2682
|
port: (ctx as any).handlerPort,
|
|
2185
|
-
});
|
|
2186
|
-
await
|
|
2683
|
+
}));
|
|
2684
|
+
await resetInngest();
|
|
2187
2685
|
|
|
2188
|
-
const run = counterWorkflow.
|
|
2686
|
+
const run = await counterWorkflow.createRunAsync();
|
|
2189
2687
|
const result = await run.start({ inputData: { startValue: 1 } });
|
|
2190
2688
|
|
|
2191
2689
|
expect(start).toHaveBeenCalledTimes(1);
|
|
@@ -2328,15 +2826,17 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2328
2826
|
|
|
2329
2827
|
const app = await createHonoServer(mastra);
|
|
2330
2828
|
|
|
2331
|
-
const srv = serve({
|
|
2829
|
+
const srv = (globServer = serve({
|
|
2332
2830
|
fetch: app.fetch,
|
|
2333
2831
|
port: (ctx as any).handlerPort,
|
|
2334
|
-
});
|
|
2335
|
-
await
|
|
2832
|
+
}));
|
|
2833
|
+
await resetInngest();
|
|
2336
2834
|
|
|
2337
|
-
const run = counterWorkflow.
|
|
2835
|
+
const run = await counterWorkflow.createRunAsync();
|
|
2338
2836
|
const result = await run.start({ inputData: { startValue: 6 } });
|
|
2339
2837
|
|
|
2838
|
+
srv.close();
|
|
2839
|
+
|
|
2340
2840
|
expect(start).toHaveBeenCalledTimes(1);
|
|
2341
2841
|
expect(other).toHaveBeenCalledTimes(1);
|
|
2342
2842
|
expect(final).toHaveBeenCalledTimes(1);
|
|
@@ -2344,8 +2844,6 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2344
2844
|
expect(result.steps['else-branch'].output).toMatchObject({ finalValue: 26 + 6 + 1 });
|
|
2345
2845
|
// @ts-ignore
|
|
2346
2846
|
expect(result.steps.start.output).toMatchObject({ newValue: 7 });
|
|
2347
|
-
|
|
2348
|
-
srv.close();
|
|
2349
2847
|
});
|
|
2350
2848
|
});
|
|
2351
2849
|
|
|
@@ -2400,7 +2898,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2400
2898
|
).rejects.toThrow();
|
|
2401
2899
|
|
|
2402
2900
|
// Should pass validation
|
|
2403
|
-
const run = workflow.
|
|
2901
|
+
const run = await workflow.createRunAsync();
|
|
2404
2902
|
await run.start({
|
|
2405
2903
|
inputData: {
|
|
2406
2904
|
required: 'test',
|
|
@@ -2500,19 +2998,19 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2500
2998
|
|
|
2501
2999
|
const app = await createHonoServer(mastra);
|
|
2502
3000
|
|
|
2503
|
-
const srv = serve({
|
|
3001
|
+
const srv = (globServer = serve({
|
|
2504
3002
|
fetch: app.fetch,
|
|
2505
3003
|
port: (ctx as any).handlerPort,
|
|
2506
|
-
});
|
|
2507
|
-
await
|
|
3004
|
+
}));
|
|
3005
|
+
await resetInngest();
|
|
2508
3006
|
|
|
2509
|
-
const run = workflow.
|
|
3007
|
+
const run = await workflow.createRunAsync();
|
|
2510
3008
|
const result = await run.start({ inputData: {} });
|
|
2511
3009
|
|
|
3010
|
+
srv.close();
|
|
3011
|
+
|
|
2512
3012
|
expect(result.steps['nested-a']).toMatchObject({ status: 'success', output: { result: 'success3' } });
|
|
2513
3013
|
expect(result.steps['nested-b']).toMatchObject({ status: 'success', output: { result: 'success5' } });
|
|
2514
|
-
|
|
2515
|
-
srv.close();
|
|
2516
3014
|
});
|
|
2517
3015
|
});
|
|
2518
3016
|
|
|
@@ -2566,21 +3064,21 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2566
3064
|
|
|
2567
3065
|
const app = await createHonoServer(mastra);
|
|
2568
3066
|
|
|
2569
|
-
const srv = serve({
|
|
3067
|
+
const srv = (globServer = serve({
|
|
2570
3068
|
fetch: app.fetch,
|
|
2571
3069
|
port: (ctx as any).handlerPort,
|
|
2572
|
-
});
|
|
2573
|
-
await
|
|
3070
|
+
}));
|
|
3071
|
+
await resetInngest();
|
|
2574
3072
|
|
|
2575
|
-
const run = workflow.
|
|
3073
|
+
const run = await workflow.createRunAsync();
|
|
2576
3074
|
const result = await run.start({ inputData: {} });
|
|
2577
3075
|
|
|
3076
|
+
srv.close();
|
|
3077
|
+
|
|
2578
3078
|
expect(result.steps.step1).toMatchObject({ status: 'success', output: { result: 'success' } });
|
|
2579
3079
|
expect(result.steps.step2).toMatchObject({ status: 'failed', error: 'Step failed' });
|
|
2580
3080
|
expect(step1.execute).toHaveBeenCalledTimes(1);
|
|
2581
3081
|
expect(step2.execute).toHaveBeenCalledTimes(1); // 0 retries + 1 initial call
|
|
2582
|
-
|
|
2583
|
-
srv.close();
|
|
2584
3082
|
});
|
|
2585
3083
|
|
|
2586
3084
|
// Need to fix so we can throw for inngest to recognize retries
|
|
@@ -2629,7 +3127,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2629
3127
|
|
|
2630
3128
|
workflow.then(step1).then(step2).commit();
|
|
2631
3129
|
|
|
2632
|
-
const run = workflow.
|
|
3130
|
+
const run = await workflow.createRunAsync();
|
|
2633
3131
|
const result = await run.start({ inputData: {} });
|
|
2634
3132
|
|
|
2635
3133
|
expect(result.steps.step1).toMatchObject({ status: 'success', output: { result: 'success' } });
|
|
@@ -2698,13 +3196,14 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2698
3196
|
|
|
2699
3197
|
const app = await createHonoServer(mastra);
|
|
2700
3198
|
|
|
2701
|
-
const srv = serve({
|
|
3199
|
+
const srv = (globServer = serve({
|
|
2702
3200
|
fetch: app.fetch,
|
|
2703
3201
|
port: (ctx as any).handlerPort,
|
|
2704
|
-
});
|
|
2705
|
-
await
|
|
3202
|
+
}));
|
|
3203
|
+
await resetInngest();
|
|
2706
3204
|
|
|
2707
|
-
const
|
|
3205
|
+
const run = await workflow.createRunAsync();
|
|
3206
|
+
const result = await run.start({ inputData: {} });
|
|
2708
3207
|
|
|
2709
3208
|
srv.close();
|
|
2710
3209
|
|
|
@@ -2769,13 +3268,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2769
3268
|
|
|
2770
3269
|
const app = await createHonoServer(mastra);
|
|
2771
3270
|
|
|
2772
|
-
const srv = serve({
|
|
3271
|
+
const srv = (globServer = serve({
|
|
2773
3272
|
fetch: app.fetch,
|
|
2774
3273
|
port: (ctx as any).handlerPort,
|
|
2775
|
-
});
|
|
2776
|
-
await
|
|
3274
|
+
}));
|
|
3275
|
+
await resetInngest();
|
|
2777
3276
|
|
|
2778
|
-
const run = workflow.
|
|
3277
|
+
const run = await workflow.createRunAsync();
|
|
2779
3278
|
|
|
2780
3279
|
// Start watching the workflow
|
|
2781
3280
|
let cnt = 0;
|
|
@@ -2786,7 +3285,9 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2786
3285
|
});
|
|
2787
3286
|
|
|
2788
3287
|
const executionResult = await run.start({ inputData: {} });
|
|
2789
|
-
await new Promise(resolve => setTimeout(resolve,
|
|
3288
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
3289
|
+
|
|
3290
|
+
srv.close();
|
|
2790
3291
|
|
|
2791
3292
|
expect(cnt).toBe(5);
|
|
2792
3293
|
expect(resps.length).toBe(5);
|
|
@@ -2898,8 +3399,6 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2898
3399
|
status: 'success',
|
|
2899
3400
|
output: { result: 'success2' },
|
|
2900
3401
|
});
|
|
2901
|
-
|
|
2902
|
-
srv.close();
|
|
2903
3402
|
});
|
|
2904
3403
|
|
|
2905
3404
|
it('should unsubscribe from transitions when unwatch is called', async ctx => {
|
|
@@ -2955,16 +3454,16 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2955
3454
|
|
|
2956
3455
|
const app = await createHonoServer(mastra);
|
|
2957
3456
|
|
|
2958
|
-
const srv = serve({
|
|
3457
|
+
const srv = (globServer = serve({
|
|
2959
3458
|
fetch: app.fetch,
|
|
2960
3459
|
port: (ctx as any).handlerPort,
|
|
2961
|
-
});
|
|
2962
|
-
await
|
|
3460
|
+
}));
|
|
3461
|
+
await resetInngest();
|
|
2963
3462
|
|
|
2964
3463
|
const onTransition = vi.fn();
|
|
2965
3464
|
const onTransition2 = vi.fn();
|
|
2966
3465
|
|
|
2967
|
-
const run = workflow.
|
|
3466
|
+
const run = await workflow.createRunAsync();
|
|
2968
3467
|
|
|
2969
3468
|
run.watch(onTransition);
|
|
2970
3469
|
run.watch(onTransition2);
|
|
@@ -2974,7 +3473,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2974
3473
|
expect(onTransition).toHaveBeenCalledTimes(5);
|
|
2975
3474
|
expect(onTransition2).toHaveBeenCalledTimes(5);
|
|
2976
3475
|
|
|
2977
|
-
const run2 = workflow.
|
|
3476
|
+
const run2 = await workflow.createRunAsync();
|
|
2978
3477
|
|
|
2979
3478
|
run2.watch(onTransition2);
|
|
2980
3479
|
|
|
@@ -2983,7 +3482,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2983
3482
|
expect(onTransition).toHaveBeenCalledTimes(5);
|
|
2984
3483
|
expect(onTransition2).toHaveBeenCalledTimes(10);
|
|
2985
3484
|
|
|
2986
|
-
const run3 = workflow.
|
|
3485
|
+
const run3 = await workflow.createRunAsync();
|
|
2987
3486
|
|
|
2988
3487
|
run3.watch(onTransition);
|
|
2989
3488
|
|
|
@@ -3018,8 +3517,8 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3018
3517
|
outputSchema: z.object({}),
|
|
3019
3518
|
steps: [],
|
|
3020
3519
|
});
|
|
3021
|
-
const run = workflow.
|
|
3022
|
-
const run2 = workflow.
|
|
3520
|
+
const run = await workflow.createRunAsync();
|
|
3521
|
+
const run2 = await workflow.createRunAsync({ runId: run.runId });
|
|
3023
3522
|
|
|
3024
3523
|
expect(run.runId).toBeDefined();
|
|
3025
3524
|
expect(run2.runId).toBeDefined();
|
|
@@ -3127,13 +3626,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3127
3626
|
|
|
3128
3627
|
const app = await createHonoServer(mastra);
|
|
3129
3628
|
|
|
3130
|
-
const srv = serve({
|
|
3629
|
+
const srv = (globServer = serve({
|
|
3131
3630
|
fetch: app.fetch,
|
|
3132
3631
|
port: (ctx as any).handlerPort,
|
|
3133
|
-
});
|
|
3134
|
-
await
|
|
3632
|
+
}));
|
|
3633
|
+
await resetInngest();
|
|
3135
3634
|
|
|
3136
|
-
const run = promptEvalWorkflow.
|
|
3635
|
+
const run = await promptEvalWorkflow.createRunAsync();
|
|
3137
3636
|
|
|
3138
3637
|
// Create a promise to track when the workflow is ready to resume
|
|
3139
3638
|
let resolveWorkflowSuspended: (value: unknown) => void;
|
|
@@ -3277,13 +3776,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3277
3776
|
|
|
3278
3777
|
const app = await createHonoServer(mastra);
|
|
3279
3778
|
|
|
3280
|
-
const srv = serve({
|
|
3779
|
+
const srv = (globServer = serve({
|
|
3281
3780
|
fetch: app.fetch,
|
|
3282
3781
|
port: (ctx as any).handlerPort,
|
|
3283
|
-
});
|
|
3284
|
-
await
|
|
3782
|
+
}));
|
|
3783
|
+
await resetInngest();
|
|
3285
3784
|
|
|
3286
|
-
const run = workflow.
|
|
3785
|
+
const run = await workflow.createRunAsync();
|
|
3287
3786
|
|
|
3288
3787
|
const started = run.start({ inputData: { input: 'test' } });
|
|
3289
3788
|
|
|
@@ -3315,13 +3814,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3315
3814
|
|
|
3316
3815
|
const initialResult = await started;
|
|
3317
3816
|
|
|
3817
|
+
srv.close();
|
|
3818
|
+
|
|
3318
3819
|
expect(initialResult.steps.humanIntervention.status).toBe('suspended');
|
|
3319
3820
|
expect(initialResult.steps.explainResponse).toBeUndefined();
|
|
3320
3821
|
expect(humanInterventionAction).toHaveBeenCalledTimes(2);
|
|
3321
3822
|
expect(explainResponseAction).not.toHaveBeenCalled();
|
|
3322
3823
|
|
|
3323
|
-
srv.close();
|
|
3324
|
-
|
|
3325
3824
|
if (!result) {
|
|
3326
3825
|
throw new Error('Resume failed to return a result');
|
|
3327
3826
|
}
|
|
@@ -3479,13 +3978,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3479
3978
|
|
|
3480
3979
|
const app = await createHonoServer(mastra);
|
|
3481
3980
|
|
|
3482
|
-
const srv = serve({
|
|
3981
|
+
const srv = (globServer = serve({
|
|
3483
3982
|
fetch: app.fetch,
|
|
3484
3983
|
port: (ctx as any).handlerPort,
|
|
3485
|
-
});
|
|
3486
|
-
await
|
|
3984
|
+
}));
|
|
3985
|
+
await resetInngest();
|
|
3487
3986
|
|
|
3488
|
-
const run = workflow.
|
|
3987
|
+
const run = await workflow.createRunAsync();
|
|
3489
3988
|
const started = run.start({ inputData: { input: 'test' } });
|
|
3490
3989
|
let improvedResponseResultPromise: Promise<any | undefined>;
|
|
3491
3990
|
|
|
@@ -3536,11 +4035,12 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3536
4035
|
// @ts-ignore
|
|
3537
4036
|
const improvedResponseResult = await improvedResponseResultPromise;
|
|
3538
4037
|
|
|
4038
|
+
srv.close();
|
|
4039
|
+
|
|
3539
4040
|
expect(improvedResponseResult?.steps.humanIntervention.status).toBe('suspended');
|
|
3540
4041
|
expect(improvedResponseResult?.steps.improveResponse.status).toBe('success');
|
|
3541
4042
|
expect(improvedResponseResult?.steps.evaluateImprovedResponse.status).toBe('success');
|
|
3542
4043
|
|
|
3543
|
-
srv.close();
|
|
3544
4044
|
if (!result) {
|
|
3545
4045
|
throw new Error('Resume failed to return a result');
|
|
3546
4046
|
}
|
|
@@ -3673,13 +4173,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3673
4173
|
|
|
3674
4174
|
const app = await createHonoServer(mastra);
|
|
3675
4175
|
|
|
3676
|
-
const srv = serve({
|
|
4176
|
+
const srv = (globServer = serve({
|
|
3677
4177
|
fetch: app.fetch,
|
|
3678
4178
|
port: (ctx as any).handlerPort,
|
|
3679
|
-
});
|
|
3680
|
-
await
|
|
4179
|
+
}));
|
|
4180
|
+
await resetInngest();
|
|
3681
4181
|
|
|
3682
|
-
const run = promptEvalWorkflow.
|
|
4182
|
+
const run = await promptEvalWorkflow.createRunAsync();
|
|
3683
4183
|
|
|
3684
4184
|
const initialResult = await run.start({ inputData: { input: 'test' } });
|
|
3685
4185
|
expect(initialResult.steps.promptAgent.status).toBe('suspended');
|
|
@@ -3690,7 +4190,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3690
4190
|
expect(initialResult.steps).toMatchObject({
|
|
3691
4191
|
input: { input: 'test' },
|
|
3692
4192
|
getUserInput: { status: 'success', output: { userInput: 'test input' } },
|
|
3693
|
-
promptAgent: {
|
|
4193
|
+
promptAgent: {
|
|
4194
|
+
status: 'suspended',
|
|
4195
|
+
suspendedPayload: { testPayload: 'hello' },
|
|
4196
|
+
payload: { userInput: 'test input' },
|
|
4197
|
+
},
|
|
3694
4198
|
});
|
|
3695
4199
|
|
|
3696
4200
|
const newCtx = {
|
|
@@ -3728,6 +4232,9 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3728
4232
|
completenessScore: { score: 0.7 },
|
|
3729
4233
|
},
|
|
3730
4234
|
});
|
|
4235
|
+
|
|
4236
|
+
srv.close();
|
|
4237
|
+
|
|
3731
4238
|
if (!secondResumeResult) {
|
|
3732
4239
|
throw new Error('Resume failed to return a result');
|
|
3733
4240
|
}
|
|
@@ -3750,6 +4257,122 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3750
4257
|
});
|
|
3751
4258
|
|
|
3752
4259
|
expect(promptAgentAction).toHaveBeenCalledTimes(2);
|
|
4260
|
+
});
|
|
4261
|
+
|
|
4262
|
+
it('should handle consecutive nested workflows with suspend/resume', async ctx => {
|
|
4263
|
+
const inngest = new Inngest({
|
|
4264
|
+
id: 'mastra',
|
|
4265
|
+
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
4266
|
+
middleware: [realtimeMiddleware()],
|
|
4267
|
+
});
|
|
4268
|
+
|
|
4269
|
+
const { createWorkflow, createStep } = init(inngest);
|
|
4270
|
+
|
|
4271
|
+
const step1 = vi.fn().mockImplementation(async ({ resumeData, suspend }) => {
|
|
4272
|
+
if (!resumeData?.suspect) {
|
|
4273
|
+
return await suspend({ message: 'What is the suspect?' });
|
|
4274
|
+
}
|
|
4275
|
+
return { suspect: resumeData.suspect };
|
|
4276
|
+
});
|
|
4277
|
+
const step1Definition = createStep({
|
|
4278
|
+
id: 'step-1',
|
|
4279
|
+
inputSchema: z.object({ suspect: z.string() }),
|
|
4280
|
+
outputSchema: z.object({ suspect: z.string() }),
|
|
4281
|
+
suspendSchema: z.object({ message: z.string() }),
|
|
4282
|
+
resumeSchema: z.object({ suspect: z.string() }),
|
|
4283
|
+
execute: step1,
|
|
4284
|
+
});
|
|
4285
|
+
|
|
4286
|
+
const step2 = vi.fn().mockImplementation(async ({ resumeData, suspend }) => {
|
|
4287
|
+
if (!resumeData?.suspect) {
|
|
4288
|
+
return await suspend({ message: 'What is the second suspect?' });
|
|
4289
|
+
}
|
|
4290
|
+
return { suspect: resumeData.suspect };
|
|
4291
|
+
});
|
|
4292
|
+
const step2Definition = createStep({
|
|
4293
|
+
id: 'step-2',
|
|
4294
|
+
inputSchema: z.object({ suspect: z.string() }),
|
|
4295
|
+
outputSchema: z.object({ suspect: z.string() }),
|
|
4296
|
+
suspendSchema: z.object({ message: z.string() }),
|
|
4297
|
+
resumeSchema: z.object({ suspect: z.string() }),
|
|
4298
|
+
execute: step2,
|
|
4299
|
+
});
|
|
4300
|
+
|
|
4301
|
+
const subWorkflow1 = createWorkflow({
|
|
4302
|
+
id: 'sub-workflow-1',
|
|
4303
|
+
inputSchema: z.object({ suspect: z.string() }),
|
|
4304
|
+
outputSchema: z.object({ suspect: z.string() }),
|
|
4305
|
+
})
|
|
4306
|
+
.then(step1Definition)
|
|
4307
|
+
.commit();
|
|
4308
|
+
|
|
4309
|
+
const subWorkflow2 = createWorkflow({
|
|
4310
|
+
id: 'sub-workflow-2',
|
|
4311
|
+
inputSchema: z.object({ suspect: z.string() }),
|
|
4312
|
+
outputSchema: z.object({ suspect: z.string() }),
|
|
4313
|
+
})
|
|
4314
|
+
.then(step2Definition)
|
|
4315
|
+
.commit();
|
|
4316
|
+
|
|
4317
|
+
const mainWorkflow = createWorkflow({
|
|
4318
|
+
id: 'main-workflow',
|
|
4319
|
+
inputSchema: z.object({ suspect: z.string() }),
|
|
4320
|
+
outputSchema: z.object({ suspect: z.string() }),
|
|
4321
|
+
})
|
|
4322
|
+
.then(subWorkflow1)
|
|
4323
|
+
.then(subWorkflow2)
|
|
4324
|
+
.commit();
|
|
4325
|
+
|
|
4326
|
+
const mastra = new Mastra({
|
|
4327
|
+
logger: false,
|
|
4328
|
+
storage: new DefaultStorage({
|
|
4329
|
+
url: ':memory:',
|
|
4330
|
+
}),
|
|
4331
|
+
workflows: { mainWorkflow },
|
|
4332
|
+
server: {
|
|
4333
|
+
apiRoutes: [
|
|
4334
|
+
{
|
|
4335
|
+
path: '/inngest/api',
|
|
4336
|
+
method: 'ALL',
|
|
4337
|
+
createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
|
|
4338
|
+
},
|
|
4339
|
+
],
|
|
4340
|
+
},
|
|
4341
|
+
});
|
|
4342
|
+
|
|
4343
|
+
const app = await createHonoServer(mastra);
|
|
4344
|
+
|
|
4345
|
+
const srv = (globServer = serve({
|
|
4346
|
+
fetch: app.fetch,
|
|
4347
|
+
port: (ctx as any).handlerPort,
|
|
4348
|
+
}));
|
|
4349
|
+
await resetInngest();
|
|
4350
|
+
|
|
4351
|
+
const run = await mainWorkflow.createRunAsync();
|
|
4352
|
+
|
|
4353
|
+
const initialResult = await run.start({ inputData: { suspect: 'initial-suspect' } });
|
|
4354
|
+
expect(initialResult.status).toBe('suspended');
|
|
4355
|
+
|
|
4356
|
+
const firstResumeResult = await run.resume({
|
|
4357
|
+
step: ['sub-workflow-1', 'step-1'],
|
|
4358
|
+
resumeData: { suspect: 'first-suspect' },
|
|
4359
|
+
});
|
|
4360
|
+
expect(firstResumeResult.status).toBe('suspended');
|
|
4361
|
+
|
|
4362
|
+
const secondResumeResult = await run.resume({
|
|
4363
|
+
step: ['sub-workflow-2', 'step-2'],
|
|
4364
|
+
resumeData: { suspect: 'second-suspect' },
|
|
4365
|
+
});
|
|
4366
|
+
|
|
4367
|
+
expect(step1).toHaveBeenCalledTimes(2);
|
|
4368
|
+
expect(step2).toHaveBeenCalledTimes(2);
|
|
4369
|
+
expect(secondResumeResult.status).toBe('success');
|
|
4370
|
+
expect(secondResumeResult.steps['sub-workflow-1']).toMatchObject({
|
|
4371
|
+
status: 'success',
|
|
4372
|
+
});
|
|
4373
|
+
expect(secondResumeResult.steps['sub-workflow-2']).toMatchObject({
|
|
4374
|
+
status: 'success',
|
|
4375
|
+
});
|
|
3753
4376
|
|
|
3754
4377
|
srv.close();
|
|
3755
4378
|
});
|
|
@@ -3797,14 +4420,14 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3797
4420
|
|
|
3798
4421
|
const app = await createHonoServer(mastra);
|
|
3799
4422
|
|
|
3800
|
-
const srv = serve({
|
|
4423
|
+
const srv = (globServer = serve({
|
|
3801
4424
|
fetch: app.fetch,
|
|
3802
4425
|
port: (ctx as any).handlerPort,
|
|
3803
|
-
});
|
|
3804
|
-
await
|
|
4426
|
+
}));
|
|
4427
|
+
await resetInngest();
|
|
3805
4428
|
|
|
3806
4429
|
// Access new instance properties directly - should work without warning
|
|
3807
|
-
const run = workflow.
|
|
4430
|
+
const run = await workflow.createRunAsync();
|
|
3808
4431
|
await run.start({ inputData: {} });
|
|
3809
4432
|
|
|
3810
4433
|
expect(telemetry).toBeDefined();
|
|
@@ -3901,13 +4524,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3901
4524
|
|
|
3902
4525
|
const app = await createHonoServer(mastra);
|
|
3903
4526
|
|
|
3904
|
-
const srv = serve({
|
|
4527
|
+
const srv = (globServer = serve({
|
|
3905
4528
|
fetch: app.fetch,
|
|
3906
4529
|
port: (ctx as any).handlerPort,
|
|
3907
|
-
});
|
|
3908
|
-
await
|
|
4530
|
+
}));
|
|
4531
|
+
await resetInngest();
|
|
3909
4532
|
|
|
3910
|
-
const run = workflow.
|
|
4533
|
+
const run = await workflow.createRunAsync();
|
|
3911
4534
|
const result = await run.start({
|
|
3912
4535
|
inputData: { prompt1: 'Capital of France, just the name', prompt2: 'Capital of UK, just the name' },
|
|
3913
4536
|
});
|
|
@@ -4038,13 +4661,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
4038
4661
|
|
|
4039
4662
|
const app = await createHonoServer(mastra);
|
|
4040
4663
|
|
|
4041
|
-
const srv = serve({
|
|
4664
|
+
const srv = (globServer = serve({
|
|
4042
4665
|
fetch: app.fetch,
|
|
4043
4666
|
port: (ctx as any).handlerPort,
|
|
4044
|
-
});
|
|
4045
|
-
await
|
|
4667
|
+
}));
|
|
4668
|
+
await resetInngest();
|
|
4046
4669
|
|
|
4047
|
-
const run = workflow.
|
|
4670
|
+
const run = await workflow.createRunAsync();
|
|
4048
4671
|
const result = await run.start({
|
|
4049
4672
|
inputData: { prompt1: 'Capital of France, just the name', prompt2: 'Capital of UK, just the name' },
|
|
4050
4673
|
});
|
|
@@ -4181,13 +4804,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
4181
4804
|
|
|
4182
4805
|
const app = await createHonoServer(mastra);
|
|
4183
4806
|
|
|
4184
|
-
const srv = serve({
|
|
4807
|
+
const srv = (globServer = serve({
|
|
4185
4808
|
fetch: app.fetch,
|
|
4186
4809
|
port: (ctx as any).handlerPort,
|
|
4187
|
-
});
|
|
4188
|
-
await
|
|
4810
|
+
}));
|
|
4811
|
+
await resetInngest();
|
|
4189
4812
|
|
|
4190
|
-
const run = counterWorkflow.
|
|
4813
|
+
const run = await counterWorkflow.createRunAsync();
|
|
4191
4814
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
4192
4815
|
|
|
4193
4816
|
srv.close();
|
|
@@ -4333,13 +4956,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
4333
4956
|
|
|
4334
4957
|
const app = await createHonoServer(mastra);
|
|
4335
4958
|
|
|
4336
|
-
const srv = serve({
|
|
4959
|
+
const srv = (globServer = serve({
|
|
4337
4960
|
fetch: app.fetch,
|
|
4338
4961
|
port: (ctx as any).handlerPort,
|
|
4339
|
-
});
|
|
4340
|
-
await
|
|
4962
|
+
}));
|
|
4963
|
+
await resetInngest();
|
|
4341
4964
|
|
|
4342
|
-
const run = counterWorkflow.
|
|
4965
|
+
const run = await counterWorkflow.createRunAsync();
|
|
4343
4966
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
4344
4967
|
|
|
4345
4968
|
srv.close();
|
|
@@ -4493,12 +5116,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
4493
5116
|
await next();
|
|
4494
5117
|
});
|
|
4495
5118
|
|
|
4496
|
-
const srv = serve({
|
|
5119
|
+
const srv = (globServer = serve({
|
|
4497
5120
|
fetch: app.fetch,
|
|
4498
5121
|
port: (ctx as any).handlerPort,
|
|
4499
|
-
});
|
|
5122
|
+
}));
|
|
5123
|
+
await resetInngest();
|
|
4500
5124
|
|
|
4501
|
-
const run = counterWorkflow.
|
|
5125
|
+
const run = await counterWorkflow.createRunAsync();
|
|
4502
5126
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
4503
5127
|
|
|
4504
5128
|
srv.close();
|
|
@@ -4652,12 +5276,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
4652
5276
|
await next();
|
|
4653
5277
|
});
|
|
4654
5278
|
|
|
4655
|
-
const srv = serve({
|
|
5279
|
+
const srv = (globServer = serve({
|
|
4656
5280
|
fetch: app.fetch,
|
|
4657
5281
|
port: (ctx as any).handlerPort,
|
|
4658
|
-
});
|
|
5282
|
+
}));
|
|
5283
|
+
await resetInngest();
|
|
4659
5284
|
|
|
4660
|
-
const run = counterWorkflow.
|
|
5285
|
+
const run = await counterWorkflow.createRunAsync();
|
|
4661
5286
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
4662
5287
|
|
|
4663
5288
|
srv.close();
|
|
@@ -4849,12 +5474,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
4849
5474
|
await next();
|
|
4850
5475
|
});
|
|
4851
5476
|
|
|
4852
|
-
const srv = serve({
|
|
5477
|
+
const srv = (globServer = serve({
|
|
4853
5478
|
fetch: app.fetch,
|
|
4854
5479
|
port: (ctx as any).handlerPort,
|
|
4855
|
-
});
|
|
5480
|
+
}));
|
|
5481
|
+
await resetInngest();
|
|
4856
5482
|
|
|
4857
|
-
const run = counterWorkflow.
|
|
5483
|
+
const run = await counterWorkflow.createRunAsync();
|
|
4858
5484
|
const result = await run.start({ inputData: { startValue: 1 } });
|
|
4859
5485
|
|
|
4860
5486
|
srv.close();
|
|
@@ -5002,13 +5628,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5002
5628
|
|
|
5003
5629
|
const app = await createHonoServer(mastra);
|
|
5004
5630
|
|
|
5005
|
-
const srv = serve({
|
|
5631
|
+
const srv = (globServer = serve({
|
|
5006
5632
|
fetch: app.fetch,
|
|
5007
5633
|
port: (ctx as any).handlerPort,
|
|
5008
|
-
});
|
|
5009
|
-
await
|
|
5634
|
+
}));
|
|
5635
|
+
await resetInngest();
|
|
5010
5636
|
|
|
5011
|
-
const run = counterWorkflow.
|
|
5637
|
+
const run = await counterWorkflow.createRunAsync();
|
|
5012
5638
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
5013
5639
|
|
|
5014
5640
|
expect(begin).toHaveBeenCalledTimes(1);
|
|
@@ -5153,12 +5779,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5153
5779
|
await next();
|
|
5154
5780
|
});
|
|
5155
5781
|
|
|
5156
|
-
const srv = serve({
|
|
5782
|
+
const srv = (globServer = serve({
|
|
5157
5783
|
fetch: app.fetch,
|
|
5158
5784
|
port: (ctx as any).handlerPort,
|
|
5159
|
-
});
|
|
5785
|
+
}));
|
|
5786
|
+
await resetInngest();
|
|
5160
5787
|
|
|
5161
|
-
const run = counterWorkflow.
|
|
5788
|
+
const run = await counterWorkflow.createRunAsync();
|
|
5162
5789
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
5163
5790
|
const results = result.steps;
|
|
5164
5791
|
|
|
@@ -5334,13 +5961,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5334
5961
|
|
|
5335
5962
|
const app = await createHonoServer(mastra);
|
|
5336
5963
|
|
|
5337
|
-
const srv = serve({
|
|
5964
|
+
const srv = (globServer = serve({
|
|
5338
5965
|
fetch: app.fetch,
|
|
5339
5966
|
port: (ctx as any).handlerPort,
|
|
5340
|
-
});
|
|
5341
|
-
await
|
|
5967
|
+
}));
|
|
5968
|
+
await resetInngest();
|
|
5342
5969
|
|
|
5343
|
-
const run = counterWorkflow.
|
|
5970
|
+
const run = await counterWorkflow.createRunAsync();
|
|
5344
5971
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
5345
5972
|
|
|
5346
5973
|
expect(passthroughStep.execute).toHaveBeenCalledTimes(2);
|
|
@@ -5496,13 +6123,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5496
6123
|
|
|
5497
6124
|
const app = await createHonoServer(mastra);
|
|
5498
6125
|
|
|
5499
|
-
const srv = serve({
|
|
6126
|
+
const srv = (globServer = serve({
|
|
5500
6127
|
fetch: app.fetch,
|
|
5501
6128
|
port: (ctx as any).handlerPort,
|
|
5502
|
-
});
|
|
5503
|
-
await
|
|
6129
|
+
}));
|
|
6130
|
+
await resetInngest();
|
|
5504
6131
|
|
|
5505
|
-
const run = counterWorkflow.
|
|
6132
|
+
const run = await counterWorkflow.createRunAsync();
|
|
5506
6133
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
5507
6134
|
|
|
5508
6135
|
srv.close();
|
|
@@ -5571,14 +6198,14 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5571
6198
|
|
|
5572
6199
|
const app = await createHonoServer(mastra);
|
|
5573
6200
|
|
|
5574
|
-
const srv = serve({
|
|
6201
|
+
const srv = (globServer = serve({
|
|
5575
6202
|
fetch: app.fetch,
|
|
5576
6203
|
port: (ctx as any).handlerPort,
|
|
5577
|
-
});
|
|
5578
|
-
await
|
|
6204
|
+
}));
|
|
6205
|
+
await resetInngest();
|
|
5579
6206
|
|
|
5580
6207
|
// Access new instance properties directly - should work without warning
|
|
5581
|
-
const run = workflow.
|
|
6208
|
+
const run = await workflow.createRunAsync();
|
|
5582
6209
|
await run.start({ inputData: {} });
|
|
5583
6210
|
|
|
5584
6211
|
srv.close();
|
|
@@ -5634,12 +6261,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5634
6261
|
|
|
5635
6262
|
const app = await createHonoServer(mastra);
|
|
5636
6263
|
|
|
5637
|
-
const srv = serve({
|
|
6264
|
+
const srv = (globServer = serve({
|
|
5638
6265
|
fetch: app.fetch,
|
|
5639
6266
|
port: (ctx as any).handlerPort,
|
|
5640
|
-
});
|
|
6267
|
+
}));
|
|
6268
|
+
await resetInngest();
|
|
5641
6269
|
|
|
5642
|
-
const run = workflow.
|
|
6270
|
+
const run = await workflow.createRunAsync();
|
|
5643
6271
|
const result = await run.start({ runtimeContext });
|
|
5644
6272
|
|
|
5645
6273
|
srv.close();
|
|
@@ -5648,7 +6276,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5648
6276
|
expect(result.steps.step1.output.injectedValue).toBe(testValue);
|
|
5649
6277
|
});
|
|
5650
6278
|
|
|
5651
|
-
it('should inject runtimeContext dependencies into steps during resume', async ctx => {
|
|
6279
|
+
it.skip('should inject runtimeContext dependencies into steps during resume', async ctx => {
|
|
5652
6280
|
const inngest = new Inngest({
|
|
5653
6281
|
id: 'mastra',
|
|
5654
6282
|
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
@@ -5692,7 +6320,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5692
6320
|
});
|
|
5693
6321
|
workflow.then(step).commit();
|
|
5694
6322
|
|
|
5695
|
-
const run = workflow.
|
|
6323
|
+
const run = await workflow.createRunAsync();
|
|
5696
6324
|
await run.start({ runtimeContext });
|
|
5697
6325
|
|
|
5698
6326
|
const resumeruntimeContext = new RuntimeContext();
|
|
@@ -5709,6 +6337,176 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5709
6337
|
// @ts-ignore
|
|
5710
6338
|
expect(result?.steps.step1.output.injectedValue).toBe(testValue + '2');
|
|
5711
6339
|
});
|
|
6340
|
+
|
|
6341
|
+
it('should have access to runtimeContext from before suspension during workflow resume', async ctx => {
|
|
6342
|
+
const inngest = new Inngest({
|
|
6343
|
+
id: 'mastra',
|
|
6344
|
+
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
6345
|
+
});
|
|
6346
|
+
|
|
6347
|
+
const { createWorkflow, createStep } = init(inngest);
|
|
6348
|
+
|
|
6349
|
+
const testValue = 'test-dependency';
|
|
6350
|
+
const resumeStep = createStep({
|
|
6351
|
+
id: 'resume',
|
|
6352
|
+
inputSchema: z.object({ value: z.number() }),
|
|
6353
|
+
outputSchema: z.object({ value: z.number() }),
|
|
6354
|
+
resumeSchema: z.object({ value: z.number() }),
|
|
6355
|
+
suspendSchema: z.object({ message: z.string() }),
|
|
6356
|
+
execute: async ({ inputData, resumeData, suspend }) => {
|
|
6357
|
+
const finalValue = (resumeData?.value ?? 0) + inputData.value;
|
|
6358
|
+
|
|
6359
|
+
if (!resumeData?.value || finalValue < 10) {
|
|
6360
|
+
return await suspend({
|
|
6361
|
+
message: `Please provide additional information. now value is ${inputData.value}`,
|
|
6362
|
+
});
|
|
6363
|
+
}
|
|
6364
|
+
|
|
6365
|
+
return { value: finalValue };
|
|
6366
|
+
},
|
|
6367
|
+
});
|
|
6368
|
+
|
|
6369
|
+
const incrementStep = createStep({
|
|
6370
|
+
id: 'increment',
|
|
6371
|
+
inputSchema: z.object({
|
|
6372
|
+
value: z.number(),
|
|
6373
|
+
}),
|
|
6374
|
+
outputSchema: z.object({
|
|
6375
|
+
value: z.number(),
|
|
6376
|
+
}),
|
|
6377
|
+
execute: async ({ inputData, runtimeContext }) => {
|
|
6378
|
+
runtimeContext.set('testKey', testValue);
|
|
6379
|
+
return {
|
|
6380
|
+
value: inputData.value + 1,
|
|
6381
|
+
};
|
|
6382
|
+
},
|
|
6383
|
+
});
|
|
6384
|
+
|
|
6385
|
+
const incrementWorkflow = createWorkflow({
|
|
6386
|
+
id: 'increment-workflow',
|
|
6387
|
+
inputSchema: z.object({ value: z.number() }),
|
|
6388
|
+
outputSchema: z.object({ value: z.number() }),
|
|
6389
|
+
})
|
|
6390
|
+
.then(incrementStep)
|
|
6391
|
+
.then(resumeStep)
|
|
6392
|
+
.then(
|
|
6393
|
+
createStep({
|
|
6394
|
+
id: 'final',
|
|
6395
|
+
inputSchema: z.object({ value: z.number() }),
|
|
6396
|
+
outputSchema: z.object({ value: z.number() }),
|
|
6397
|
+
execute: async ({ inputData, runtimeContext }) => {
|
|
6398
|
+
const testKey = runtimeContext.get('testKey');
|
|
6399
|
+
expect(testKey).toBe(testValue);
|
|
6400
|
+
return { value: inputData.value };
|
|
6401
|
+
},
|
|
6402
|
+
}),
|
|
6403
|
+
)
|
|
6404
|
+
.commit();
|
|
6405
|
+
|
|
6406
|
+
new Mastra({
|
|
6407
|
+
logger: false,
|
|
6408
|
+
storage: testStorage,
|
|
6409
|
+
workflows: { incrementWorkflow },
|
|
6410
|
+
});
|
|
6411
|
+
|
|
6412
|
+
const run = await incrementWorkflow.createRunAsync();
|
|
6413
|
+
const result = await run.start({ inputData: { value: 0 } });
|
|
6414
|
+
expect(result.status).toBe('suspended');
|
|
6415
|
+
|
|
6416
|
+
const resumeResult = await run.resume({
|
|
6417
|
+
resumeData: { value: 21 },
|
|
6418
|
+
step: ['resume'],
|
|
6419
|
+
});
|
|
6420
|
+
|
|
6421
|
+
expect(resumeResult.status).toBe('success');
|
|
6422
|
+
});
|
|
6423
|
+
|
|
6424
|
+
it('should not show removed runtimeContext values in subsequent steps', async ctx => {
|
|
6425
|
+
const inngest = new Inngest({
|
|
6426
|
+
id: 'mastra',
|
|
6427
|
+
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
6428
|
+
});
|
|
6429
|
+
|
|
6430
|
+
const { createWorkflow, createStep } = init(inngest);
|
|
6431
|
+
const testValue = 'test-dependency';
|
|
6432
|
+
const resumeStep = createStep({
|
|
6433
|
+
id: 'resume',
|
|
6434
|
+
inputSchema: z.object({ value: z.number() }),
|
|
6435
|
+
outputSchema: z.object({ value: z.number() }),
|
|
6436
|
+
resumeSchema: z.object({ value: z.number() }),
|
|
6437
|
+
suspendSchema: z.object({ message: z.string() }),
|
|
6438
|
+
execute: async ({ inputData, resumeData, suspend, runtimeContext }) => {
|
|
6439
|
+
const finalValue = (resumeData?.value ?? 0) + inputData.value;
|
|
6440
|
+
|
|
6441
|
+
if (!resumeData?.value || finalValue < 10) {
|
|
6442
|
+
return await suspend({
|
|
6443
|
+
message: `Please provide additional information. now value is ${inputData.value}`,
|
|
6444
|
+
});
|
|
6445
|
+
}
|
|
6446
|
+
|
|
6447
|
+
const testKey = runtimeContext.get('testKey');
|
|
6448
|
+
expect(testKey).toBe(testValue);
|
|
6449
|
+
|
|
6450
|
+
runtimeContext.delete('testKey');
|
|
6451
|
+
|
|
6452
|
+
return { value: finalValue };
|
|
6453
|
+
},
|
|
6454
|
+
});
|
|
6455
|
+
|
|
6456
|
+
const incrementStep = createStep({
|
|
6457
|
+
id: 'increment',
|
|
6458
|
+
inputSchema: z.object({
|
|
6459
|
+
value: z.number(),
|
|
6460
|
+
}),
|
|
6461
|
+
outputSchema: z.object({
|
|
6462
|
+
value: z.number(),
|
|
6463
|
+
}),
|
|
6464
|
+
execute: async ({ inputData, runtimeContext }) => {
|
|
6465
|
+
runtimeContext.set('testKey', testValue);
|
|
6466
|
+
return {
|
|
6467
|
+
value: inputData.value + 1,
|
|
6468
|
+
};
|
|
6469
|
+
},
|
|
6470
|
+
});
|
|
6471
|
+
|
|
6472
|
+
const incrementWorkflow = createWorkflow({
|
|
6473
|
+
id: 'increment-workflow',
|
|
6474
|
+
inputSchema: z.object({ value: z.number() }),
|
|
6475
|
+
outputSchema: z.object({ value: z.number() }),
|
|
6476
|
+
})
|
|
6477
|
+
.then(incrementStep)
|
|
6478
|
+
.then(resumeStep)
|
|
6479
|
+
.then(
|
|
6480
|
+
createStep({
|
|
6481
|
+
id: 'final',
|
|
6482
|
+
inputSchema: z.object({ value: z.number() }),
|
|
6483
|
+
outputSchema: z.object({ value: z.number() }),
|
|
6484
|
+
execute: async ({ inputData, runtimeContext }) => {
|
|
6485
|
+
const testKey = runtimeContext.get('testKey');
|
|
6486
|
+
expect(testKey).toBeUndefined();
|
|
6487
|
+
return { value: inputData.value };
|
|
6488
|
+
},
|
|
6489
|
+
}),
|
|
6490
|
+
)
|
|
6491
|
+
.commit();
|
|
6492
|
+
|
|
6493
|
+
new Mastra({
|
|
6494
|
+
logger: false,
|
|
6495
|
+
storage: testStorage,
|
|
6496
|
+
workflows: { incrementWorkflow },
|
|
6497
|
+
});
|
|
6498
|
+
|
|
6499
|
+
const run = await incrementWorkflow.createRunAsync();
|
|
6500
|
+
const result = await run.start({ inputData: { value: 0 } });
|
|
6501
|
+
expect(result.status).toBe('suspended');
|
|
6502
|
+
|
|
6503
|
+
const resumeResult = await run.resume({
|
|
6504
|
+
resumeData: { value: 21 },
|
|
6505
|
+
step: ['resume'],
|
|
6506
|
+
});
|
|
6507
|
+
|
|
6508
|
+
expect(resumeResult.status).toBe('success');
|
|
6509
|
+
});
|
|
5712
6510
|
});
|
|
5713
6511
|
|
|
5714
6512
|
describe('Access to inngest step primitives', () => {
|
|
@@ -5733,11 +6531,81 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5733
6531
|
const workflow = createWorkflow({
|
|
5734
6532
|
id: 'test-workflow',
|
|
5735
6533
|
inputSchema: z.object({}),
|
|
5736
|
-
outputSchema: z.object({
|
|
5737
|
-
hasEngine: z.boolean(),
|
|
5738
|
-
}),
|
|
6534
|
+
outputSchema: z.object({
|
|
6535
|
+
hasEngine: z.boolean(),
|
|
6536
|
+
}),
|
|
6537
|
+
});
|
|
6538
|
+
workflow.then(step).commit();
|
|
6539
|
+
|
|
6540
|
+
const mastra = new Mastra({
|
|
6541
|
+
storage: new DefaultStorage({
|
|
6542
|
+
url: ':memory:',
|
|
6543
|
+
}),
|
|
6544
|
+
workflows: {
|
|
6545
|
+
'test-workflow': workflow,
|
|
6546
|
+
},
|
|
6547
|
+
server: {
|
|
6548
|
+
apiRoutes: [
|
|
6549
|
+
{
|
|
6550
|
+
path: '/inngest/api',
|
|
6551
|
+
method: 'ALL',
|
|
6552
|
+
createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
|
|
6553
|
+
},
|
|
6554
|
+
],
|
|
6555
|
+
},
|
|
6556
|
+
});
|
|
6557
|
+
|
|
6558
|
+
const app = await createHonoServer(mastra);
|
|
6559
|
+
|
|
6560
|
+
const srv = (globServer = serve({
|
|
6561
|
+
fetch: app.fetch,
|
|
6562
|
+
port: (ctx as any).handlerPort,
|
|
6563
|
+
}));
|
|
6564
|
+
await resetInngest();
|
|
6565
|
+
|
|
6566
|
+
const run = await workflow.createRunAsync();
|
|
6567
|
+
const result = await run.start({});
|
|
6568
|
+
|
|
6569
|
+
srv.close();
|
|
6570
|
+
|
|
6571
|
+
// @ts-ignore
|
|
6572
|
+
expect(result?.steps.step1.output.hasEngine).toBe(true);
|
|
6573
|
+
});
|
|
6574
|
+
});
|
|
6575
|
+
|
|
6576
|
+
describe('Streaming', () => {
|
|
6577
|
+
it('should generate a stream', async ctx => {
|
|
6578
|
+
const inngest = new Inngest({
|
|
6579
|
+
id: 'mastra',
|
|
6580
|
+
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
6581
|
+
middleware: [realtimeMiddleware()],
|
|
6582
|
+
});
|
|
6583
|
+
|
|
6584
|
+
const { createWorkflow, createStep } = init(inngest);
|
|
6585
|
+
|
|
6586
|
+
const step1Action = vi.fn<any>().mockResolvedValue({ result: 'success1' });
|
|
6587
|
+
const step2Action = vi.fn<any>().mockResolvedValue({ result: 'success2' });
|
|
6588
|
+
|
|
6589
|
+
const step1 = createStep({
|
|
6590
|
+
id: 'step1',
|
|
6591
|
+
execute: step1Action,
|
|
6592
|
+
inputSchema: z.object({}),
|
|
6593
|
+
outputSchema: z.object({ value: z.string() }),
|
|
6594
|
+
});
|
|
6595
|
+
const step2 = createStep({
|
|
6596
|
+
id: 'step2',
|
|
6597
|
+
execute: step2Action,
|
|
6598
|
+
inputSchema: z.object({ value: z.string() }),
|
|
6599
|
+
outputSchema: z.object({}),
|
|
6600
|
+
});
|
|
6601
|
+
|
|
6602
|
+
const workflow = createWorkflow({
|
|
6603
|
+
id: 'test-workflow',
|
|
6604
|
+
inputSchema: z.object({}),
|
|
6605
|
+
outputSchema: z.object({}),
|
|
6606
|
+
steps: [step1, step2],
|
|
5739
6607
|
});
|
|
5740
|
-
workflow.then(
|
|
6608
|
+
workflow.then(step1).then(step2).commit();
|
|
5741
6609
|
|
|
5742
6610
|
const mastra = new Mastra({
|
|
5743
6611
|
storage: new DefaultStorage({
|
|
@@ -5759,23 +6627,126 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5759
6627
|
|
|
5760
6628
|
const app = await createHonoServer(mastra);
|
|
5761
6629
|
|
|
5762
|
-
const srv = serve({
|
|
6630
|
+
const srv = (globServer = serve({
|
|
5763
6631
|
fetch: app.fetch,
|
|
5764
6632
|
port: (ctx as any).handlerPort,
|
|
6633
|
+
}));
|
|
6634
|
+
await resetInngest();
|
|
6635
|
+
|
|
6636
|
+
const runId = 'test-run-id';
|
|
6637
|
+
let watchData: StreamEvent[] = [];
|
|
6638
|
+
const run = await workflow.createRunAsync({
|
|
6639
|
+
runId,
|
|
5765
6640
|
});
|
|
5766
6641
|
|
|
5767
|
-
|
|
5768
|
-
|
|
6642
|
+
await resetInngest();
|
|
6643
|
+
|
|
6644
|
+
const { stream, getWorkflowState } = run.stream({ inputData: {} });
|
|
6645
|
+
|
|
6646
|
+
// Start watching the workflow
|
|
6647
|
+
const collectedStreamData: StreamEvent[] = [];
|
|
6648
|
+
for await (const data of stream) {
|
|
6649
|
+
collectedStreamData.push(JSON.parse(JSON.stringify(data)));
|
|
6650
|
+
}
|
|
6651
|
+
watchData = collectedStreamData;
|
|
6652
|
+
|
|
6653
|
+
const executionResult = await getWorkflowState();
|
|
6654
|
+
|
|
6655
|
+
await resetInngest();
|
|
5769
6656
|
|
|
5770
6657
|
srv.close();
|
|
5771
6658
|
|
|
5772
|
-
|
|
5773
|
-
expect(
|
|
6659
|
+
expect(watchData.length).toBe(8);
|
|
6660
|
+
expect(watchData).toMatchObject([
|
|
6661
|
+
{
|
|
6662
|
+
payload: {
|
|
6663
|
+
runId: 'test-run-id',
|
|
6664
|
+
},
|
|
6665
|
+
type: 'start',
|
|
6666
|
+
},
|
|
6667
|
+
{
|
|
6668
|
+
payload: {
|
|
6669
|
+
id: 'step1',
|
|
6670
|
+
status: 'running',
|
|
6671
|
+
},
|
|
6672
|
+
type: 'step-start',
|
|
6673
|
+
},
|
|
6674
|
+
{
|
|
6675
|
+
payload: {
|
|
6676
|
+
id: 'step1',
|
|
6677
|
+
endedAt: expect.any(Number),
|
|
6678
|
+
startedAt: expect.any(Number),
|
|
6679
|
+
payload: {},
|
|
6680
|
+
output: {
|
|
6681
|
+
result: 'success1',
|
|
6682
|
+
},
|
|
6683
|
+
status: 'success',
|
|
6684
|
+
},
|
|
6685
|
+
type: 'step-result',
|
|
6686
|
+
},
|
|
6687
|
+
{
|
|
6688
|
+
payload: {
|
|
6689
|
+
id: 'step1',
|
|
6690
|
+
metadata: {},
|
|
6691
|
+
},
|
|
6692
|
+
type: 'step-finish',
|
|
6693
|
+
},
|
|
6694
|
+
{
|
|
6695
|
+
payload: {
|
|
6696
|
+
id: 'step2',
|
|
6697
|
+
status: 'running',
|
|
6698
|
+
},
|
|
6699
|
+
type: 'step-start',
|
|
6700
|
+
},
|
|
6701
|
+
{
|
|
6702
|
+
payload: {
|
|
6703
|
+
id: 'step2',
|
|
6704
|
+
endedAt: expect.any(Number),
|
|
6705
|
+
startedAt: expect.any(Number),
|
|
6706
|
+
payload: {
|
|
6707
|
+
result: 'success1',
|
|
6708
|
+
},
|
|
6709
|
+
output: {
|
|
6710
|
+
result: 'success2',
|
|
6711
|
+
},
|
|
6712
|
+
status: 'success',
|
|
6713
|
+
},
|
|
6714
|
+
type: 'step-result',
|
|
6715
|
+
},
|
|
6716
|
+
{
|
|
6717
|
+
payload: {
|
|
6718
|
+
id: 'step2',
|
|
6719
|
+
metadata: {},
|
|
6720
|
+
},
|
|
6721
|
+
type: 'step-finish',
|
|
6722
|
+
},
|
|
6723
|
+
{
|
|
6724
|
+
payload: {
|
|
6725
|
+
runId: 'test-run-id',
|
|
6726
|
+
},
|
|
6727
|
+
type: 'finish',
|
|
6728
|
+
},
|
|
6729
|
+
]);
|
|
6730
|
+
// Verify execution completed successfully
|
|
6731
|
+
expect(executionResult.steps.step1).toMatchObject({
|
|
6732
|
+
status: 'success',
|
|
6733
|
+
output: { result: 'success1' },
|
|
6734
|
+
payload: {},
|
|
6735
|
+
startedAt: expect.any(Number),
|
|
6736
|
+
endedAt: expect.any(Number),
|
|
6737
|
+
});
|
|
6738
|
+
expect(executionResult.steps.step2).toMatchObject({
|
|
6739
|
+
status: 'success',
|
|
6740
|
+
output: { result: 'success2' },
|
|
6741
|
+
payload: {
|
|
6742
|
+
result: 'success1',
|
|
6743
|
+
},
|
|
6744
|
+
startedAt: expect.any(Number),
|
|
6745
|
+
endedAt: expect.any(Number),
|
|
6746
|
+
});
|
|
5774
6747
|
});
|
|
5775
|
-
});
|
|
5776
6748
|
|
|
5777
|
-
|
|
5778
|
-
it('should generate a stream', async ctx => {
|
|
6749
|
+
it('should handle basic sleep waiting flow', async ctx => {
|
|
5779
6750
|
const inngest = new Inngest({
|
|
5780
6751
|
id: 'mastra',
|
|
5781
6752
|
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
@@ -5806,7 +6777,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5806
6777
|
outputSchema: z.object({}),
|
|
5807
6778
|
steps: [step1, step2],
|
|
5808
6779
|
});
|
|
5809
|
-
workflow.then(step1).then(step2).commit();
|
|
6780
|
+
workflow.then(step1).sleep(1000).then(step2).commit();
|
|
5810
6781
|
|
|
5811
6782
|
const mastra = new Mastra({
|
|
5812
6783
|
storage: new DefaultStorage({
|
|
@@ -5828,18 +6799,19 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5828
6799
|
|
|
5829
6800
|
const app = await createHonoServer(mastra);
|
|
5830
6801
|
|
|
5831
|
-
const srv = serve({
|
|
6802
|
+
const srv = (globServer = serve({
|
|
5832
6803
|
fetch: app.fetch,
|
|
5833
6804
|
port: (ctx as any).handlerPort,
|
|
5834
|
-
});
|
|
6805
|
+
}));
|
|
6806
|
+
await resetInngest();
|
|
5835
6807
|
|
|
5836
6808
|
const runId = 'test-run-id';
|
|
5837
6809
|
let watchData: StreamEvent[] = [];
|
|
5838
|
-
const run = workflow.
|
|
6810
|
+
const run = await workflow.createRunAsync({
|
|
5839
6811
|
runId,
|
|
5840
6812
|
});
|
|
5841
6813
|
|
|
5842
|
-
await
|
|
6814
|
+
await resetInngest();
|
|
5843
6815
|
|
|
5844
6816
|
const { stream, getWorkflowState } = run.stream({ inputData: {} });
|
|
5845
6817
|
|
|
@@ -5852,73 +6824,112 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5852
6824
|
|
|
5853
6825
|
const executionResult = await getWorkflowState();
|
|
5854
6826
|
|
|
5855
|
-
await
|
|
6827
|
+
await resetInngest();
|
|
5856
6828
|
|
|
5857
6829
|
srv.close();
|
|
5858
6830
|
|
|
5859
|
-
expect(watchData.length).toBe(
|
|
5860
|
-
expect(watchData).
|
|
5861
|
-
|
|
5862
|
-
{
|
|
5863
|
-
|
|
5864
|
-
"runId": "test-run-id",
|
|
5865
|
-
},
|
|
5866
|
-
"type": "start",
|
|
6831
|
+
expect(watchData.length).toBe(11);
|
|
6832
|
+
expect(watchData).toMatchObject([
|
|
6833
|
+
{
|
|
6834
|
+
payload: {
|
|
6835
|
+
runId: 'test-run-id',
|
|
5867
6836
|
},
|
|
5868
|
-
|
|
5869
|
-
|
|
5870
|
-
|
|
5871
|
-
|
|
5872
|
-
|
|
6837
|
+
type: 'start',
|
|
6838
|
+
},
|
|
6839
|
+
{
|
|
6840
|
+
payload: {
|
|
6841
|
+
id: 'step1',
|
|
6842
|
+
startedAt: expect.any(Number),
|
|
6843
|
+
status: 'running',
|
|
6844
|
+
payload: {},
|
|
5873
6845
|
},
|
|
5874
|
-
|
|
5875
|
-
|
|
5876
|
-
|
|
5877
|
-
|
|
5878
|
-
|
|
5879
|
-
|
|
5880
|
-
|
|
6846
|
+
type: 'step-start',
|
|
6847
|
+
},
|
|
6848
|
+
{
|
|
6849
|
+
payload: {
|
|
6850
|
+
id: 'step1',
|
|
6851
|
+
output: {
|
|
6852
|
+
result: 'success1',
|
|
5881
6853
|
},
|
|
5882
|
-
|
|
6854
|
+
endedAt: expect.any(Number),
|
|
6855
|
+
status: 'success',
|
|
5883
6856
|
},
|
|
5884
|
-
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
|
|
6857
|
+
type: 'step-result',
|
|
6858
|
+
},
|
|
6859
|
+
{
|
|
6860
|
+
payload: {
|
|
6861
|
+
id: 'step1',
|
|
6862
|
+
metadata: {},
|
|
5890
6863
|
},
|
|
5891
|
-
|
|
5892
|
-
|
|
5893
|
-
|
|
6864
|
+
type: 'step-finish',
|
|
6865
|
+
},
|
|
6866
|
+
{
|
|
6867
|
+
payload: {
|
|
6868
|
+
id: expect.any(String),
|
|
6869
|
+
startedAt: expect.any(Number),
|
|
6870
|
+
status: 'waiting',
|
|
6871
|
+
payload: {
|
|
6872
|
+
result: 'success1',
|
|
5894
6873
|
},
|
|
5895
|
-
"type": "step-start",
|
|
5896
6874
|
},
|
|
5897
|
-
|
|
5898
|
-
|
|
5899
|
-
|
|
5900
|
-
|
|
5901
|
-
|
|
5902
|
-
|
|
5903
|
-
|
|
6875
|
+
type: 'step-waiting',
|
|
6876
|
+
},
|
|
6877
|
+
{
|
|
6878
|
+
payload: {
|
|
6879
|
+
id: expect.any(String),
|
|
6880
|
+
endedAt: expect.any(Number),
|
|
6881
|
+
startedAt: expect.any(Number),
|
|
6882
|
+
status: 'success',
|
|
6883
|
+
output: {
|
|
6884
|
+
result: 'success1',
|
|
5904
6885
|
},
|
|
5905
|
-
"type": "step-result",
|
|
5906
6886
|
},
|
|
5907
|
-
|
|
5908
|
-
|
|
5909
|
-
|
|
5910
|
-
|
|
6887
|
+
type: 'step-result',
|
|
6888
|
+
},
|
|
6889
|
+
{
|
|
6890
|
+
type: 'step-finish',
|
|
6891
|
+
payload: {
|
|
6892
|
+
id: expect.any(String),
|
|
6893
|
+
metadata: {},
|
|
6894
|
+
},
|
|
6895
|
+
},
|
|
6896
|
+
{
|
|
6897
|
+
payload: {
|
|
6898
|
+
id: 'step2',
|
|
6899
|
+
payload: {
|
|
6900
|
+
result: 'success1',
|
|
5911
6901
|
},
|
|
5912
|
-
|
|
6902
|
+
startedAt: expect.any(Number),
|
|
6903
|
+
status: 'running',
|
|
5913
6904
|
},
|
|
5914
|
-
|
|
5915
|
-
|
|
5916
|
-
|
|
6905
|
+
type: 'step-start',
|
|
6906
|
+
},
|
|
6907
|
+
{
|
|
6908
|
+
payload: {
|
|
6909
|
+
id: 'step2',
|
|
6910
|
+
output: {
|
|
6911
|
+
result: 'success2',
|
|
5917
6912
|
},
|
|
5918
|
-
|
|
6913
|
+
endedAt: expect.any(Number),
|
|
6914
|
+
status: 'success',
|
|
6915
|
+
},
|
|
6916
|
+
type: 'step-result',
|
|
6917
|
+
},
|
|
6918
|
+
{
|
|
6919
|
+
payload: {
|
|
6920
|
+
id: 'step2',
|
|
6921
|
+
metadata: {},
|
|
6922
|
+
},
|
|
6923
|
+
type: 'step-finish',
|
|
6924
|
+
},
|
|
6925
|
+
{
|
|
6926
|
+
payload: {
|
|
6927
|
+
runId: 'test-run-id',
|
|
5919
6928
|
},
|
|
5920
|
-
|
|
5921
|
-
|
|
6929
|
+
type: 'finish',
|
|
6930
|
+
},
|
|
6931
|
+
]);
|
|
6932
|
+
|
|
5922
6933
|
// Verify execution completed successfully
|
|
5923
6934
|
expect(executionResult.steps.step1).toMatchObject({
|
|
5924
6935
|
status: 'success',
|
|
@@ -5938,7 +6949,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5938
6949
|
});
|
|
5939
6950
|
});
|
|
5940
6951
|
|
|
5941
|
-
it('should handle basic sleep waiting flow', async ctx => {
|
|
6952
|
+
it('should handle basic sleep waiting flow with fn parameter', async ctx => {
|
|
5942
6953
|
const inngest = new Inngest({
|
|
5943
6954
|
id: 'mastra',
|
|
5944
6955
|
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
@@ -5947,19 +6958,19 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5947
6958
|
|
|
5948
6959
|
const { createWorkflow, createStep } = init(inngest);
|
|
5949
6960
|
|
|
5950
|
-
const step1Action = vi.fn<any>().mockResolvedValue({
|
|
5951
|
-
const step2Action = vi.fn<any>().mockResolvedValue({
|
|
6961
|
+
const step1Action = vi.fn<any>().mockResolvedValue({ value: 1000 });
|
|
6962
|
+
const step2Action = vi.fn<any>().mockResolvedValue({ value: 2000 });
|
|
5952
6963
|
|
|
5953
6964
|
const step1 = createStep({
|
|
5954
6965
|
id: 'step1',
|
|
5955
6966
|
execute: step1Action,
|
|
5956
6967
|
inputSchema: z.object({}),
|
|
5957
|
-
outputSchema: z.object({ value: z.
|
|
6968
|
+
outputSchema: z.object({ value: z.number() }),
|
|
5958
6969
|
});
|
|
5959
6970
|
const step2 = createStep({
|
|
5960
6971
|
id: 'step2',
|
|
5961
6972
|
execute: step2Action,
|
|
5962
|
-
inputSchema: z.object({ value: z.
|
|
6973
|
+
inputSchema: z.object({ value: z.number() }),
|
|
5963
6974
|
outputSchema: z.object({}),
|
|
5964
6975
|
});
|
|
5965
6976
|
|
|
@@ -5969,7 +6980,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5969
6980
|
outputSchema: z.object({}),
|
|
5970
6981
|
steps: [step1, step2],
|
|
5971
6982
|
});
|
|
5972
|
-
workflow
|
|
6983
|
+
workflow
|
|
6984
|
+
.then(step1)
|
|
6985
|
+
.sleep(async ({ inputData }) => {
|
|
6986
|
+
return inputData.value;
|
|
6987
|
+
})
|
|
6988
|
+
.then(step2)
|
|
6989
|
+
.commit();
|
|
5973
6990
|
|
|
5974
6991
|
const mastra = new Mastra({
|
|
5975
6992
|
storage: new DefaultStorage({
|
|
@@ -5991,18 +7008,19 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5991
7008
|
|
|
5992
7009
|
const app = await createHonoServer(mastra);
|
|
5993
7010
|
|
|
5994
|
-
const srv = serve({
|
|
7011
|
+
const srv = (globServer = serve({
|
|
5995
7012
|
fetch: app.fetch,
|
|
5996
7013
|
port: (ctx as any).handlerPort,
|
|
5997
|
-
});
|
|
7014
|
+
}));
|
|
7015
|
+
await resetInngest();
|
|
5998
7016
|
|
|
5999
7017
|
const runId = 'test-run-id';
|
|
6000
7018
|
let watchData: StreamEvent[] = [];
|
|
6001
|
-
const run = workflow.
|
|
7019
|
+
const run = await workflow.createRunAsync({
|
|
6002
7020
|
runId,
|
|
6003
7021
|
});
|
|
6004
7022
|
|
|
6005
|
-
await
|
|
7023
|
+
await resetInngest();
|
|
6006
7024
|
|
|
6007
7025
|
const { stream, getWorkflowState } = run.stream({ inputData: {} });
|
|
6008
7026
|
|
|
@@ -6015,11 +7033,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6015
7033
|
|
|
6016
7034
|
const executionResult = await getWorkflowState();
|
|
6017
7035
|
|
|
6018
|
-
await
|
|
7036
|
+
await resetInngest();
|
|
6019
7037
|
|
|
6020
7038
|
srv.close();
|
|
6021
7039
|
|
|
6022
|
-
expect(watchData.length).toBe(
|
|
7040
|
+
expect(watchData.length).toBe(11);
|
|
6023
7041
|
expect(watchData).toMatchObject([
|
|
6024
7042
|
{
|
|
6025
7043
|
payload: {
|
|
@@ -6030,6 +7048,9 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6030
7048
|
{
|
|
6031
7049
|
payload: {
|
|
6032
7050
|
id: 'step1',
|
|
7051
|
+
startedAt: expect.any(Number),
|
|
7052
|
+
status: 'running',
|
|
7053
|
+
payload: {},
|
|
6033
7054
|
},
|
|
6034
7055
|
type: 'step-start',
|
|
6035
7056
|
},
|
|
@@ -6037,8 +7058,9 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6037
7058
|
payload: {
|
|
6038
7059
|
id: 'step1',
|
|
6039
7060
|
output: {
|
|
6040
|
-
|
|
7061
|
+
value: 1000,
|
|
6041
7062
|
},
|
|
7063
|
+
endedAt: expect.any(Number),
|
|
6042
7064
|
status: 'success',
|
|
6043
7065
|
},
|
|
6044
7066
|
type: 'step-result',
|
|
@@ -6051,12 +7073,43 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6051
7073
|
type: 'step-finish',
|
|
6052
7074
|
},
|
|
6053
7075
|
{
|
|
6054
|
-
payload: {
|
|
7076
|
+
payload: {
|
|
7077
|
+
id: expect.any(String),
|
|
7078
|
+
startedAt: expect.any(Number),
|
|
7079
|
+
status: 'waiting',
|
|
7080
|
+
payload: {
|
|
7081
|
+
value: 1000,
|
|
7082
|
+
},
|
|
7083
|
+
},
|
|
6055
7084
|
type: 'step-waiting',
|
|
6056
7085
|
},
|
|
7086
|
+
{
|
|
7087
|
+
payload: {
|
|
7088
|
+
id: expect.any(String),
|
|
7089
|
+
endedAt: expect.any(Number),
|
|
7090
|
+
startedAt: expect.any(Number),
|
|
7091
|
+
status: 'success',
|
|
7092
|
+
output: {
|
|
7093
|
+
value: 1000,
|
|
7094
|
+
},
|
|
7095
|
+
},
|
|
7096
|
+
type: 'step-result',
|
|
7097
|
+
},
|
|
7098
|
+
{
|
|
7099
|
+
type: 'step-finish',
|
|
7100
|
+
payload: {
|
|
7101
|
+
id: expect.any(String),
|
|
7102
|
+
metadata: {},
|
|
7103
|
+
},
|
|
7104
|
+
},
|
|
6057
7105
|
{
|
|
6058
7106
|
payload: {
|
|
6059
7107
|
id: 'step2',
|
|
7108
|
+
payload: {
|
|
7109
|
+
value: 1000,
|
|
7110
|
+
},
|
|
7111
|
+
startedAt: expect.any(Number),
|
|
7112
|
+
status: 'running',
|
|
6060
7113
|
},
|
|
6061
7114
|
type: 'step-start',
|
|
6062
7115
|
},
|
|
@@ -6064,8 +7117,9 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6064
7117
|
payload: {
|
|
6065
7118
|
id: 'step2',
|
|
6066
7119
|
output: {
|
|
6067
|
-
|
|
7120
|
+
value: 2000,
|
|
6068
7121
|
},
|
|
7122
|
+
endedAt: expect.any(Number),
|
|
6069
7123
|
status: 'success',
|
|
6070
7124
|
},
|
|
6071
7125
|
type: 'step-result',
|
|
@@ -6084,19 +7138,20 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6084
7138
|
type: 'finish',
|
|
6085
7139
|
},
|
|
6086
7140
|
]);
|
|
7141
|
+
|
|
6087
7142
|
// Verify execution completed successfully
|
|
6088
7143
|
expect(executionResult.steps.step1).toMatchObject({
|
|
6089
7144
|
status: 'success',
|
|
6090
|
-
output: {
|
|
7145
|
+
output: { value: 1000 },
|
|
6091
7146
|
payload: {},
|
|
6092
7147
|
startedAt: expect.any(Number),
|
|
6093
7148
|
endedAt: expect.any(Number),
|
|
6094
7149
|
});
|
|
6095
7150
|
expect(executionResult.steps.step2).toMatchObject({
|
|
6096
7151
|
status: 'success',
|
|
6097
|
-
output: {
|
|
7152
|
+
output: { value: 2000 },
|
|
6098
7153
|
payload: {
|
|
6099
|
-
|
|
7154
|
+
value: 1000,
|
|
6100
7155
|
},
|
|
6101
7156
|
startedAt: expect.any(Number),
|
|
6102
7157
|
endedAt: expect.any(Number),
|
|
@@ -6156,18 +7211,19 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6156
7211
|
|
|
6157
7212
|
const app = await createHonoServer(mastra);
|
|
6158
7213
|
|
|
6159
|
-
const srv = serve({
|
|
7214
|
+
const srv = (globServer = serve({
|
|
6160
7215
|
fetch: app.fetch,
|
|
6161
7216
|
port: (ctx as any).handlerPort,
|
|
6162
|
-
});
|
|
7217
|
+
}));
|
|
7218
|
+
await resetInngest();
|
|
6163
7219
|
|
|
6164
7220
|
const runId = 'test-run-id';
|
|
6165
7221
|
let watchData: StreamEvent[] = [];
|
|
6166
|
-
const run = workflow.
|
|
7222
|
+
const run = await workflow.createRunAsync({
|
|
6167
7223
|
runId,
|
|
6168
7224
|
});
|
|
6169
7225
|
|
|
6170
|
-
await
|
|
7226
|
+
await resetInngest();
|
|
6171
7227
|
|
|
6172
7228
|
const { stream, getWorkflowState } = run.stream({ inputData: {} });
|
|
6173
7229
|
|
|
@@ -6187,7 +7243,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6187
7243
|
|
|
6188
7244
|
const executionResult = await getWorkflowState();
|
|
6189
7245
|
|
|
6190
|
-
await
|
|
7246
|
+
await resetInngest();
|
|
6191
7247
|
|
|
6192
7248
|
srv.close();
|
|
6193
7249
|
|
|
@@ -6381,14 +7437,14 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6381
7437
|
|
|
6382
7438
|
const app = await createHonoServer(mastra);
|
|
6383
7439
|
|
|
6384
|
-
const srv = serve({
|
|
7440
|
+
const srv = (globServer = serve({
|
|
6385
7441
|
fetch: app.fetch,
|
|
6386
7442
|
port: (ctx as any).handlerPort,
|
|
6387
|
-
});
|
|
7443
|
+
}));
|
|
6388
7444
|
|
|
6389
|
-
await
|
|
7445
|
+
await resetInngest();
|
|
6390
7446
|
|
|
6391
|
-
const run = promptEvalWorkflow.
|
|
7447
|
+
const run = await promptEvalWorkflow.createRunAsync();
|
|
6392
7448
|
|
|
6393
7449
|
const { stream, getWorkflowState } = run.stream({ inputData: { input: 'test' } });
|
|
6394
7450
|
|
|
@@ -6570,17 +7626,17 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6570
7626
|
|
|
6571
7627
|
const app = await createHonoServer(mastra);
|
|
6572
7628
|
|
|
6573
|
-
const srv = serve({
|
|
7629
|
+
const srv = (globServer = serve({
|
|
6574
7630
|
fetch: app.fetch,
|
|
6575
7631
|
port: (ctx as any).handlerPort,
|
|
6576
|
-
});
|
|
7632
|
+
}));
|
|
6577
7633
|
|
|
6578
|
-
await
|
|
7634
|
+
await resetInngest();
|
|
6579
7635
|
|
|
6580
|
-
const run = workflow.
|
|
7636
|
+
const run = await workflow.createRunAsync({
|
|
6581
7637
|
runId: 'test-run-id',
|
|
6582
7638
|
});
|
|
6583
|
-
const { stream } =
|
|
7639
|
+
const { stream } = run.stream({
|
|
6584
7640
|
inputData: {
|
|
6585
7641
|
prompt1: 'Capital of France, just the name',
|
|
6586
7642
|
prompt2: 'Capital of UK, just the name',
|