@mastra/inngest 0.0.0-ai-v5-20250626003446 → 0.0.0-ai-v5-20250718021026
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 +223 -3
- package/LICENSE.md +11 -42
- package/dist/_tsup-dts-rollup.d.cts +62 -17
- package/dist/_tsup-dts-rollup.d.ts +62 -17
- package/dist/index.cjs +233 -25
- package/dist/index.js +233 -25
- package/docker-compose.yaml +3 -3
- package/package.json +15 -14
- package/src/index.test.ts +1276 -338
- package/src/index.ts +301 -26
- package/vitest.config.ts +6 -0
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' });
|
|
@@ -568,12 +859,206 @@ describe('MastraInngestWorkflow', () => {
|
|
|
568
859
|
inputSchema: z.object({}),
|
|
569
860
|
outputSchema: z.object({
|
|
570
861
|
result: z.string(),
|
|
571
|
-
resumed: z.any(),
|
|
862
|
+
resumed: z.any(),
|
|
863
|
+
}),
|
|
864
|
+
steps: [step1],
|
|
865
|
+
});
|
|
866
|
+
|
|
867
|
+
workflow.then(step1).waitForEvent('hello-event', step2, { timeout: 1000 }).commit();
|
|
868
|
+
|
|
869
|
+
const mastra = new Mastra({
|
|
870
|
+
storage: new DefaultStorage({
|
|
871
|
+
url: ':memory:',
|
|
872
|
+
}),
|
|
873
|
+
workflows: {
|
|
874
|
+
'test-workflow': workflow,
|
|
875
|
+
},
|
|
876
|
+
server: {
|
|
877
|
+
apiRoutes: [
|
|
878
|
+
{
|
|
879
|
+
path: '/inngest/api',
|
|
880
|
+
method: 'ALL',
|
|
881
|
+
createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
|
|
882
|
+
},
|
|
883
|
+
],
|
|
884
|
+
},
|
|
885
|
+
});
|
|
886
|
+
|
|
887
|
+
const app = await createHonoServer(mastra);
|
|
888
|
+
|
|
889
|
+
const srv = (globServer = serve({
|
|
890
|
+
fetch: app.fetch,
|
|
891
|
+
port: (ctx as any).handlerPort,
|
|
892
|
+
}));
|
|
893
|
+
await resetInngest();
|
|
894
|
+
|
|
895
|
+
const run = await workflow.createRunAsync();
|
|
896
|
+
const startTime = Date.now();
|
|
897
|
+
const result = await run.start({ inputData: {} });
|
|
898
|
+
const endTime = Date.now();
|
|
899
|
+
|
|
900
|
+
expect(execute).toHaveBeenCalled();
|
|
901
|
+
expect(result.steps['step1']).toMatchObject({
|
|
902
|
+
status: 'success',
|
|
903
|
+
output: { result: 'success' },
|
|
904
|
+
// payload: {},
|
|
905
|
+
// startedAt: expect.any(Number),
|
|
906
|
+
// endedAt: expect.any(Number),
|
|
907
|
+
});
|
|
908
|
+
|
|
909
|
+
expect(result.steps['step2']).toMatchObject({
|
|
910
|
+
status: 'failed',
|
|
911
|
+
error: expect.any(String),
|
|
912
|
+
payload: { result: 'success' },
|
|
913
|
+
startedAt: expect.any(Number),
|
|
914
|
+
endedAt: expect.any(Number),
|
|
915
|
+
});
|
|
916
|
+
|
|
917
|
+
expect(endTime - startTime).toBeGreaterThan(1000);
|
|
918
|
+
|
|
919
|
+
srv.close();
|
|
920
|
+
});
|
|
921
|
+
});
|
|
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(),
|
|
572
1057
|
}),
|
|
573
|
-
steps: [step1],
|
|
1058
|
+
steps: [step1, step2],
|
|
574
1059
|
});
|
|
575
1060
|
|
|
576
|
-
workflow.then(step1).
|
|
1061
|
+
workflow.then(step1).then(step2).commit();
|
|
577
1062
|
|
|
578
1063
|
const mastra = new Mastra({
|
|
579
1064
|
storage: new DefaultStorage({
|
|
@@ -595,37 +1080,40 @@ describe('MastraInngestWorkflow', () => {
|
|
|
595
1080
|
|
|
596
1081
|
const app = await createHonoServer(mastra);
|
|
597
1082
|
|
|
598
|
-
const srv = serve({
|
|
1083
|
+
const srv = (globServer = serve({
|
|
599
1084
|
fetch: app.fetch,
|
|
600
1085
|
port: (ctx as any).handlerPort,
|
|
601
|
-
});
|
|
602
|
-
await
|
|
1086
|
+
}));
|
|
1087
|
+
await resetInngest();
|
|
603
1088
|
|
|
604
|
-
const run = workflow.
|
|
605
|
-
const
|
|
606
|
-
const result = await run.start({ inputData: {} });
|
|
607
|
-
const endTime = Date.now();
|
|
1089
|
+
const run = await workflow.createRunAsync();
|
|
1090
|
+
const p = run.start({ inputData: { value: 'test' } });
|
|
608
1091
|
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
output: { result: 'success' },
|
|
613
|
-
// payload: {},
|
|
614
|
-
// startedAt: expect.any(Number),
|
|
615
|
-
// endedAt: expect.any(Number),
|
|
616
|
-
});
|
|
1092
|
+
setTimeout(() => {
|
|
1093
|
+
run.cancel();
|
|
1094
|
+
}, 1000);
|
|
617
1095
|
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
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' },
|
|
622
1106
|
startedAt: expect.any(Number),
|
|
623
1107
|
endedAt: expect.any(Number),
|
|
624
1108
|
});
|
|
625
1109
|
|
|
626
|
-
expect(
|
|
627
|
-
|
|
628
|
-
|
|
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
|
+
// });
|
|
629
1117
|
});
|
|
630
1118
|
});
|
|
631
1119
|
|
|
@@ -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
|
+
}));
|
|
688
1176
|
|
|
689
|
-
|
|
1177
|
+
await resetInngest();
|
|
1178
|
+
|
|
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,8 +4257,6 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3750
4257
|
});
|
|
3751
4258
|
|
|
3752
4259
|
expect(promptAgentAction).toHaveBeenCalledTimes(2);
|
|
3753
|
-
|
|
3754
|
-
srv.close();
|
|
3755
4260
|
});
|
|
3756
4261
|
});
|
|
3757
4262
|
|
|
@@ -3797,14 +4302,14 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3797
4302
|
|
|
3798
4303
|
const app = await createHonoServer(mastra);
|
|
3799
4304
|
|
|
3800
|
-
const srv = serve({
|
|
4305
|
+
const srv = (globServer = serve({
|
|
3801
4306
|
fetch: app.fetch,
|
|
3802
4307
|
port: (ctx as any).handlerPort,
|
|
3803
|
-
});
|
|
3804
|
-
await
|
|
4308
|
+
}));
|
|
4309
|
+
await resetInngest();
|
|
3805
4310
|
|
|
3806
4311
|
// Access new instance properties directly - should work without warning
|
|
3807
|
-
const run = workflow.
|
|
4312
|
+
const run = await workflow.createRunAsync();
|
|
3808
4313
|
await run.start({ inputData: {} });
|
|
3809
4314
|
|
|
3810
4315
|
expect(telemetry).toBeDefined();
|
|
@@ -3901,13 +4406,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3901
4406
|
|
|
3902
4407
|
const app = await createHonoServer(mastra);
|
|
3903
4408
|
|
|
3904
|
-
const srv = serve({
|
|
4409
|
+
const srv = (globServer = serve({
|
|
3905
4410
|
fetch: app.fetch,
|
|
3906
4411
|
port: (ctx as any).handlerPort,
|
|
3907
|
-
});
|
|
3908
|
-
await
|
|
4412
|
+
}));
|
|
4413
|
+
await resetInngest();
|
|
3909
4414
|
|
|
3910
|
-
const run = workflow.
|
|
4415
|
+
const run = await workflow.createRunAsync();
|
|
3911
4416
|
const result = await run.start({
|
|
3912
4417
|
inputData: { prompt1: 'Capital of France, just the name', prompt2: 'Capital of UK, just the name' },
|
|
3913
4418
|
});
|
|
@@ -4038,13 +4543,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
4038
4543
|
|
|
4039
4544
|
const app = await createHonoServer(mastra);
|
|
4040
4545
|
|
|
4041
|
-
const srv = serve({
|
|
4546
|
+
const srv = (globServer = serve({
|
|
4042
4547
|
fetch: app.fetch,
|
|
4043
4548
|
port: (ctx as any).handlerPort,
|
|
4044
|
-
});
|
|
4045
|
-
await
|
|
4549
|
+
}));
|
|
4550
|
+
await resetInngest();
|
|
4046
4551
|
|
|
4047
|
-
const run = workflow.
|
|
4552
|
+
const run = await workflow.createRunAsync();
|
|
4048
4553
|
const result = await run.start({
|
|
4049
4554
|
inputData: { prompt1: 'Capital of France, just the name', prompt2: 'Capital of UK, just the name' },
|
|
4050
4555
|
});
|
|
@@ -4181,13 +4686,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
4181
4686
|
|
|
4182
4687
|
const app = await createHonoServer(mastra);
|
|
4183
4688
|
|
|
4184
|
-
const srv = serve({
|
|
4689
|
+
const srv = (globServer = serve({
|
|
4185
4690
|
fetch: app.fetch,
|
|
4186
4691
|
port: (ctx as any).handlerPort,
|
|
4187
|
-
});
|
|
4188
|
-
await
|
|
4692
|
+
}));
|
|
4693
|
+
await resetInngest();
|
|
4189
4694
|
|
|
4190
|
-
const run = counterWorkflow.
|
|
4695
|
+
const run = await counterWorkflow.createRunAsync();
|
|
4191
4696
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
4192
4697
|
|
|
4193
4698
|
srv.close();
|
|
@@ -4333,13 +4838,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
4333
4838
|
|
|
4334
4839
|
const app = await createHonoServer(mastra);
|
|
4335
4840
|
|
|
4336
|
-
const srv = serve({
|
|
4841
|
+
const srv = (globServer = serve({
|
|
4337
4842
|
fetch: app.fetch,
|
|
4338
4843
|
port: (ctx as any).handlerPort,
|
|
4339
|
-
});
|
|
4340
|
-
await
|
|
4844
|
+
}));
|
|
4845
|
+
await resetInngest();
|
|
4341
4846
|
|
|
4342
|
-
const run = counterWorkflow.
|
|
4847
|
+
const run = await counterWorkflow.createRunAsync();
|
|
4343
4848
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
4344
4849
|
|
|
4345
4850
|
srv.close();
|
|
@@ -4493,12 +4998,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
4493
4998
|
await next();
|
|
4494
4999
|
});
|
|
4495
5000
|
|
|
4496
|
-
const srv = serve({
|
|
5001
|
+
const srv = (globServer = serve({
|
|
4497
5002
|
fetch: app.fetch,
|
|
4498
5003
|
port: (ctx as any).handlerPort,
|
|
4499
|
-
});
|
|
5004
|
+
}));
|
|
5005
|
+
await resetInngest();
|
|
4500
5006
|
|
|
4501
|
-
const run = counterWorkflow.
|
|
5007
|
+
const run = await counterWorkflow.createRunAsync();
|
|
4502
5008
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
4503
5009
|
|
|
4504
5010
|
srv.close();
|
|
@@ -4652,12 +5158,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
4652
5158
|
await next();
|
|
4653
5159
|
});
|
|
4654
5160
|
|
|
4655
|
-
const srv = serve({
|
|
5161
|
+
const srv = (globServer = serve({
|
|
4656
5162
|
fetch: app.fetch,
|
|
4657
5163
|
port: (ctx as any).handlerPort,
|
|
4658
|
-
});
|
|
5164
|
+
}));
|
|
5165
|
+
await resetInngest();
|
|
4659
5166
|
|
|
4660
|
-
const run = counterWorkflow.
|
|
5167
|
+
const run = await counterWorkflow.createRunAsync();
|
|
4661
5168
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
4662
5169
|
|
|
4663
5170
|
srv.close();
|
|
@@ -4849,12 +5356,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
4849
5356
|
await next();
|
|
4850
5357
|
});
|
|
4851
5358
|
|
|
4852
|
-
const srv = serve({
|
|
5359
|
+
const srv = (globServer = serve({
|
|
4853
5360
|
fetch: app.fetch,
|
|
4854
5361
|
port: (ctx as any).handlerPort,
|
|
4855
|
-
});
|
|
5362
|
+
}));
|
|
5363
|
+
await resetInngest();
|
|
4856
5364
|
|
|
4857
|
-
const run = counterWorkflow.
|
|
5365
|
+
const run = await counterWorkflow.createRunAsync();
|
|
4858
5366
|
const result = await run.start({ inputData: { startValue: 1 } });
|
|
4859
5367
|
|
|
4860
5368
|
srv.close();
|
|
@@ -5002,13 +5510,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5002
5510
|
|
|
5003
5511
|
const app = await createHonoServer(mastra);
|
|
5004
5512
|
|
|
5005
|
-
const srv = serve({
|
|
5513
|
+
const srv = (globServer = serve({
|
|
5006
5514
|
fetch: app.fetch,
|
|
5007
5515
|
port: (ctx as any).handlerPort,
|
|
5008
|
-
});
|
|
5009
|
-
await
|
|
5516
|
+
}));
|
|
5517
|
+
await resetInngest();
|
|
5010
5518
|
|
|
5011
|
-
const run = counterWorkflow.
|
|
5519
|
+
const run = await counterWorkflow.createRunAsync();
|
|
5012
5520
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
5013
5521
|
|
|
5014
5522
|
expect(begin).toHaveBeenCalledTimes(1);
|
|
@@ -5153,12 +5661,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5153
5661
|
await next();
|
|
5154
5662
|
});
|
|
5155
5663
|
|
|
5156
|
-
const srv = serve({
|
|
5664
|
+
const srv = (globServer = serve({
|
|
5157
5665
|
fetch: app.fetch,
|
|
5158
5666
|
port: (ctx as any).handlerPort,
|
|
5159
|
-
});
|
|
5667
|
+
}));
|
|
5668
|
+
await resetInngest();
|
|
5160
5669
|
|
|
5161
|
-
const run = counterWorkflow.
|
|
5670
|
+
const run = await counterWorkflow.createRunAsync();
|
|
5162
5671
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
5163
5672
|
const results = result.steps;
|
|
5164
5673
|
|
|
@@ -5334,13 +5843,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5334
5843
|
|
|
5335
5844
|
const app = await createHonoServer(mastra);
|
|
5336
5845
|
|
|
5337
|
-
const srv = serve({
|
|
5846
|
+
const srv = (globServer = serve({
|
|
5338
5847
|
fetch: app.fetch,
|
|
5339
5848
|
port: (ctx as any).handlerPort,
|
|
5340
|
-
});
|
|
5341
|
-
await
|
|
5849
|
+
}));
|
|
5850
|
+
await resetInngest();
|
|
5342
5851
|
|
|
5343
|
-
const run = counterWorkflow.
|
|
5852
|
+
const run = await counterWorkflow.createRunAsync();
|
|
5344
5853
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
5345
5854
|
|
|
5346
5855
|
expect(passthroughStep.execute).toHaveBeenCalledTimes(2);
|
|
@@ -5496,13 +6005,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5496
6005
|
|
|
5497
6006
|
const app = await createHonoServer(mastra);
|
|
5498
6007
|
|
|
5499
|
-
const srv = serve({
|
|
6008
|
+
const srv = (globServer = serve({
|
|
5500
6009
|
fetch: app.fetch,
|
|
5501
6010
|
port: (ctx as any).handlerPort,
|
|
5502
|
-
});
|
|
5503
|
-
await
|
|
6011
|
+
}));
|
|
6012
|
+
await resetInngest();
|
|
5504
6013
|
|
|
5505
|
-
const run = counterWorkflow.
|
|
6014
|
+
const run = await counterWorkflow.createRunAsync();
|
|
5506
6015
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
5507
6016
|
|
|
5508
6017
|
srv.close();
|
|
@@ -5571,14 +6080,14 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5571
6080
|
|
|
5572
6081
|
const app = await createHonoServer(mastra);
|
|
5573
6082
|
|
|
5574
|
-
const srv = serve({
|
|
6083
|
+
const srv = (globServer = serve({
|
|
5575
6084
|
fetch: app.fetch,
|
|
5576
6085
|
port: (ctx as any).handlerPort,
|
|
5577
|
-
});
|
|
5578
|
-
await
|
|
6086
|
+
}));
|
|
6087
|
+
await resetInngest();
|
|
5579
6088
|
|
|
5580
6089
|
// Access new instance properties directly - should work without warning
|
|
5581
|
-
const run = workflow.
|
|
6090
|
+
const run = await workflow.createRunAsync();
|
|
5582
6091
|
await run.start({ inputData: {} });
|
|
5583
6092
|
|
|
5584
6093
|
srv.close();
|
|
@@ -5634,12 +6143,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5634
6143
|
|
|
5635
6144
|
const app = await createHonoServer(mastra);
|
|
5636
6145
|
|
|
5637
|
-
const srv = serve({
|
|
6146
|
+
const srv = (globServer = serve({
|
|
5638
6147
|
fetch: app.fetch,
|
|
5639
6148
|
port: (ctx as any).handlerPort,
|
|
5640
|
-
});
|
|
6149
|
+
}));
|
|
6150
|
+
await resetInngest();
|
|
5641
6151
|
|
|
5642
|
-
const run = workflow.
|
|
6152
|
+
const run = await workflow.createRunAsync();
|
|
5643
6153
|
const result = await run.start({ runtimeContext });
|
|
5644
6154
|
|
|
5645
6155
|
srv.close();
|
|
@@ -5648,7 +6158,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5648
6158
|
expect(result.steps.step1.output.injectedValue).toBe(testValue);
|
|
5649
6159
|
});
|
|
5650
6160
|
|
|
5651
|
-
it('should inject runtimeContext dependencies into steps during resume', async ctx => {
|
|
6161
|
+
it.skip('should inject runtimeContext dependencies into steps during resume', async ctx => {
|
|
5652
6162
|
const inngest = new Inngest({
|
|
5653
6163
|
id: 'mastra',
|
|
5654
6164
|
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
@@ -5692,7 +6202,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5692
6202
|
});
|
|
5693
6203
|
workflow.then(step).commit();
|
|
5694
6204
|
|
|
5695
|
-
const run = workflow.
|
|
6205
|
+
const run = await workflow.createRunAsync();
|
|
5696
6206
|
await run.start({ runtimeContext });
|
|
5697
6207
|
|
|
5698
6208
|
const resumeruntimeContext = new RuntimeContext();
|
|
@@ -5709,6 +6219,176 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5709
6219
|
// @ts-ignore
|
|
5710
6220
|
expect(result?.steps.step1.output.injectedValue).toBe(testValue + '2');
|
|
5711
6221
|
});
|
|
6222
|
+
|
|
6223
|
+
it('should have access to runtimeContext from before suspension during workflow resume', async ctx => {
|
|
6224
|
+
const inngest = new Inngest({
|
|
6225
|
+
id: 'mastra',
|
|
6226
|
+
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
6227
|
+
});
|
|
6228
|
+
|
|
6229
|
+
const { createWorkflow, createStep } = init(inngest);
|
|
6230
|
+
|
|
6231
|
+
const testValue = 'test-dependency';
|
|
6232
|
+
const resumeStep = createStep({
|
|
6233
|
+
id: 'resume',
|
|
6234
|
+
inputSchema: z.object({ value: z.number() }),
|
|
6235
|
+
outputSchema: z.object({ value: z.number() }),
|
|
6236
|
+
resumeSchema: z.object({ value: z.number() }),
|
|
6237
|
+
suspendSchema: z.object({ message: z.string() }),
|
|
6238
|
+
execute: async ({ inputData, resumeData, suspend }) => {
|
|
6239
|
+
const finalValue = (resumeData?.value ?? 0) + inputData.value;
|
|
6240
|
+
|
|
6241
|
+
if (!resumeData?.value || finalValue < 10) {
|
|
6242
|
+
return await suspend({
|
|
6243
|
+
message: `Please provide additional information. now value is ${inputData.value}`,
|
|
6244
|
+
});
|
|
6245
|
+
}
|
|
6246
|
+
|
|
6247
|
+
return { value: finalValue };
|
|
6248
|
+
},
|
|
6249
|
+
});
|
|
6250
|
+
|
|
6251
|
+
const incrementStep = createStep({
|
|
6252
|
+
id: 'increment',
|
|
6253
|
+
inputSchema: z.object({
|
|
6254
|
+
value: z.number(),
|
|
6255
|
+
}),
|
|
6256
|
+
outputSchema: z.object({
|
|
6257
|
+
value: z.number(),
|
|
6258
|
+
}),
|
|
6259
|
+
execute: async ({ inputData, runtimeContext }) => {
|
|
6260
|
+
runtimeContext.set('testKey', testValue);
|
|
6261
|
+
return {
|
|
6262
|
+
value: inputData.value + 1,
|
|
6263
|
+
};
|
|
6264
|
+
},
|
|
6265
|
+
});
|
|
6266
|
+
|
|
6267
|
+
const incrementWorkflow = createWorkflow({
|
|
6268
|
+
id: 'increment-workflow',
|
|
6269
|
+
inputSchema: z.object({ value: z.number() }),
|
|
6270
|
+
outputSchema: z.object({ value: z.number() }),
|
|
6271
|
+
})
|
|
6272
|
+
.then(incrementStep)
|
|
6273
|
+
.then(resumeStep)
|
|
6274
|
+
.then(
|
|
6275
|
+
createStep({
|
|
6276
|
+
id: 'final',
|
|
6277
|
+
inputSchema: z.object({ value: z.number() }),
|
|
6278
|
+
outputSchema: z.object({ value: z.number() }),
|
|
6279
|
+
execute: async ({ inputData, runtimeContext }) => {
|
|
6280
|
+
const testKey = runtimeContext.get('testKey');
|
|
6281
|
+
expect(testKey).toBe(testValue);
|
|
6282
|
+
return { value: inputData.value };
|
|
6283
|
+
},
|
|
6284
|
+
}),
|
|
6285
|
+
)
|
|
6286
|
+
.commit();
|
|
6287
|
+
|
|
6288
|
+
new Mastra({
|
|
6289
|
+
logger: false,
|
|
6290
|
+
storage: testStorage,
|
|
6291
|
+
workflows: { incrementWorkflow },
|
|
6292
|
+
});
|
|
6293
|
+
|
|
6294
|
+
const run = await incrementWorkflow.createRunAsync();
|
|
6295
|
+
const result = await run.start({ inputData: { value: 0 } });
|
|
6296
|
+
expect(result.status).toBe('suspended');
|
|
6297
|
+
|
|
6298
|
+
const resumeResult = await run.resume({
|
|
6299
|
+
resumeData: { value: 21 },
|
|
6300
|
+
step: ['resume'],
|
|
6301
|
+
});
|
|
6302
|
+
|
|
6303
|
+
expect(resumeResult.status).toBe('success');
|
|
6304
|
+
});
|
|
6305
|
+
|
|
6306
|
+
it('should not show removed runtimeContext values in subsequent steps', async ctx => {
|
|
6307
|
+
const inngest = new Inngest({
|
|
6308
|
+
id: 'mastra',
|
|
6309
|
+
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
6310
|
+
});
|
|
6311
|
+
|
|
6312
|
+
const { createWorkflow, createStep } = init(inngest);
|
|
6313
|
+
const testValue = 'test-dependency';
|
|
6314
|
+
const resumeStep = createStep({
|
|
6315
|
+
id: 'resume',
|
|
6316
|
+
inputSchema: z.object({ value: z.number() }),
|
|
6317
|
+
outputSchema: z.object({ value: z.number() }),
|
|
6318
|
+
resumeSchema: z.object({ value: z.number() }),
|
|
6319
|
+
suspendSchema: z.object({ message: z.string() }),
|
|
6320
|
+
execute: async ({ inputData, resumeData, suspend, runtimeContext }) => {
|
|
6321
|
+
const finalValue = (resumeData?.value ?? 0) + inputData.value;
|
|
6322
|
+
|
|
6323
|
+
if (!resumeData?.value || finalValue < 10) {
|
|
6324
|
+
return await suspend({
|
|
6325
|
+
message: `Please provide additional information. now value is ${inputData.value}`,
|
|
6326
|
+
});
|
|
6327
|
+
}
|
|
6328
|
+
|
|
6329
|
+
const testKey = runtimeContext.get('testKey');
|
|
6330
|
+
expect(testKey).toBe(testValue);
|
|
6331
|
+
|
|
6332
|
+
runtimeContext.delete('testKey');
|
|
6333
|
+
|
|
6334
|
+
return { value: finalValue };
|
|
6335
|
+
},
|
|
6336
|
+
});
|
|
6337
|
+
|
|
6338
|
+
const incrementStep = createStep({
|
|
6339
|
+
id: 'increment',
|
|
6340
|
+
inputSchema: z.object({
|
|
6341
|
+
value: z.number(),
|
|
6342
|
+
}),
|
|
6343
|
+
outputSchema: z.object({
|
|
6344
|
+
value: z.number(),
|
|
6345
|
+
}),
|
|
6346
|
+
execute: async ({ inputData, runtimeContext }) => {
|
|
6347
|
+
runtimeContext.set('testKey', testValue);
|
|
6348
|
+
return {
|
|
6349
|
+
value: inputData.value + 1,
|
|
6350
|
+
};
|
|
6351
|
+
},
|
|
6352
|
+
});
|
|
6353
|
+
|
|
6354
|
+
const incrementWorkflow = createWorkflow({
|
|
6355
|
+
id: 'increment-workflow',
|
|
6356
|
+
inputSchema: z.object({ value: z.number() }),
|
|
6357
|
+
outputSchema: z.object({ value: z.number() }),
|
|
6358
|
+
})
|
|
6359
|
+
.then(incrementStep)
|
|
6360
|
+
.then(resumeStep)
|
|
6361
|
+
.then(
|
|
6362
|
+
createStep({
|
|
6363
|
+
id: 'final',
|
|
6364
|
+
inputSchema: z.object({ value: z.number() }),
|
|
6365
|
+
outputSchema: z.object({ value: z.number() }),
|
|
6366
|
+
execute: async ({ inputData, runtimeContext }) => {
|
|
6367
|
+
const testKey = runtimeContext.get('testKey');
|
|
6368
|
+
expect(testKey).toBeUndefined();
|
|
6369
|
+
return { value: inputData.value };
|
|
6370
|
+
},
|
|
6371
|
+
}),
|
|
6372
|
+
)
|
|
6373
|
+
.commit();
|
|
6374
|
+
|
|
6375
|
+
new Mastra({
|
|
6376
|
+
logger: false,
|
|
6377
|
+
storage: testStorage,
|
|
6378
|
+
workflows: { incrementWorkflow },
|
|
6379
|
+
});
|
|
6380
|
+
|
|
6381
|
+
const run = await incrementWorkflow.createRunAsync();
|
|
6382
|
+
const result = await run.start({ inputData: { value: 0 } });
|
|
6383
|
+
expect(result.status).toBe('suspended');
|
|
6384
|
+
|
|
6385
|
+
const resumeResult = await run.resume({
|
|
6386
|
+
resumeData: { value: 21 },
|
|
6387
|
+
step: ['resume'],
|
|
6388
|
+
});
|
|
6389
|
+
|
|
6390
|
+
expect(resumeResult.status).toBe('success');
|
|
6391
|
+
});
|
|
5712
6392
|
});
|
|
5713
6393
|
|
|
5714
6394
|
describe('Access to inngest step primitives', () => {
|
|
@@ -5733,11 +6413,81 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5733
6413
|
const workflow = createWorkflow({
|
|
5734
6414
|
id: 'test-workflow',
|
|
5735
6415
|
inputSchema: z.object({}),
|
|
5736
|
-
outputSchema: z.object({
|
|
5737
|
-
hasEngine: z.boolean(),
|
|
5738
|
-
}),
|
|
6416
|
+
outputSchema: z.object({
|
|
6417
|
+
hasEngine: z.boolean(),
|
|
6418
|
+
}),
|
|
6419
|
+
});
|
|
6420
|
+
workflow.then(step).commit();
|
|
6421
|
+
|
|
6422
|
+
const mastra = new Mastra({
|
|
6423
|
+
storage: new DefaultStorage({
|
|
6424
|
+
url: ':memory:',
|
|
6425
|
+
}),
|
|
6426
|
+
workflows: {
|
|
6427
|
+
'test-workflow': workflow,
|
|
6428
|
+
},
|
|
6429
|
+
server: {
|
|
6430
|
+
apiRoutes: [
|
|
6431
|
+
{
|
|
6432
|
+
path: '/inngest/api',
|
|
6433
|
+
method: 'ALL',
|
|
6434
|
+
createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
|
|
6435
|
+
},
|
|
6436
|
+
],
|
|
6437
|
+
},
|
|
6438
|
+
});
|
|
6439
|
+
|
|
6440
|
+
const app = await createHonoServer(mastra);
|
|
6441
|
+
|
|
6442
|
+
const srv = (globServer = serve({
|
|
6443
|
+
fetch: app.fetch,
|
|
6444
|
+
port: (ctx as any).handlerPort,
|
|
6445
|
+
}));
|
|
6446
|
+
await resetInngest();
|
|
6447
|
+
|
|
6448
|
+
const run = await workflow.createRunAsync();
|
|
6449
|
+
const result = await run.start({});
|
|
6450
|
+
|
|
6451
|
+
srv.close();
|
|
6452
|
+
|
|
6453
|
+
// @ts-ignore
|
|
6454
|
+
expect(result?.steps.step1.output.hasEngine).toBe(true);
|
|
6455
|
+
});
|
|
6456
|
+
});
|
|
6457
|
+
|
|
6458
|
+
describe('Streaming', () => {
|
|
6459
|
+
it('should generate a stream', async ctx => {
|
|
6460
|
+
const inngest = new Inngest({
|
|
6461
|
+
id: 'mastra',
|
|
6462
|
+
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
6463
|
+
middleware: [realtimeMiddleware()],
|
|
6464
|
+
});
|
|
6465
|
+
|
|
6466
|
+
const { createWorkflow, createStep } = init(inngest);
|
|
6467
|
+
|
|
6468
|
+
const step1Action = vi.fn<any>().mockResolvedValue({ result: 'success1' });
|
|
6469
|
+
const step2Action = vi.fn<any>().mockResolvedValue({ result: 'success2' });
|
|
6470
|
+
|
|
6471
|
+
const step1 = createStep({
|
|
6472
|
+
id: 'step1',
|
|
6473
|
+
execute: step1Action,
|
|
6474
|
+
inputSchema: z.object({}),
|
|
6475
|
+
outputSchema: z.object({ value: z.string() }),
|
|
6476
|
+
});
|
|
6477
|
+
const step2 = createStep({
|
|
6478
|
+
id: 'step2',
|
|
6479
|
+
execute: step2Action,
|
|
6480
|
+
inputSchema: z.object({ value: z.string() }),
|
|
6481
|
+
outputSchema: z.object({}),
|
|
6482
|
+
});
|
|
6483
|
+
|
|
6484
|
+
const workflow = createWorkflow({
|
|
6485
|
+
id: 'test-workflow',
|
|
6486
|
+
inputSchema: z.object({}),
|
|
6487
|
+
outputSchema: z.object({}),
|
|
6488
|
+
steps: [step1, step2],
|
|
5739
6489
|
});
|
|
5740
|
-
workflow.then(
|
|
6490
|
+
workflow.then(step1).then(step2).commit();
|
|
5741
6491
|
|
|
5742
6492
|
const mastra = new Mastra({
|
|
5743
6493
|
storage: new DefaultStorage({
|
|
@@ -5759,23 +6509,126 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5759
6509
|
|
|
5760
6510
|
const app = await createHonoServer(mastra);
|
|
5761
6511
|
|
|
5762
|
-
const srv = serve({
|
|
6512
|
+
const srv = (globServer = serve({
|
|
5763
6513
|
fetch: app.fetch,
|
|
5764
6514
|
port: (ctx as any).handlerPort,
|
|
6515
|
+
}));
|
|
6516
|
+
await resetInngest();
|
|
6517
|
+
|
|
6518
|
+
const runId = 'test-run-id';
|
|
6519
|
+
let watchData: StreamEvent[] = [];
|
|
6520
|
+
const run = await workflow.createRunAsync({
|
|
6521
|
+
runId,
|
|
5765
6522
|
});
|
|
5766
6523
|
|
|
5767
|
-
|
|
5768
|
-
|
|
6524
|
+
await resetInngest();
|
|
6525
|
+
|
|
6526
|
+
const { stream, getWorkflowState } = run.stream({ inputData: {} });
|
|
6527
|
+
|
|
6528
|
+
// Start watching the workflow
|
|
6529
|
+
const collectedStreamData: StreamEvent[] = [];
|
|
6530
|
+
for await (const data of stream) {
|
|
6531
|
+
collectedStreamData.push(JSON.parse(JSON.stringify(data)));
|
|
6532
|
+
}
|
|
6533
|
+
watchData = collectedStreamData;
|
|
6534
|
+
|
|
6535
|
+
const executionResult = await getWorkflowState();
|
|
6536
|
+
|
|
6537
|
+
await resetInngest();
|
|
5769
6538
|
|
|
5770
6539
|
srv.close();
|
|
5771
6540
|
|
|
5772
|
-
|
|
5773
|
-
expect(
|
|
6541
|
+
expect(watchData.length).toBe(8);
|
|
6542
|
+
expect(watchData).toMatchObject([
|
|
6543
|
+
{
|
|
6544
|
+
payload: {
|
|
6545
|
+
runId: 'test-run-id',
|
|
6546
|
+
},
|
|
6547
|
+
type: 'start',
|
|
6548
|
+
},
|
|
6549
|
+
{
|
|
6550
|
+
payload: {
|
|
6551
|
+
id: 'step1',
|
|
6552
|
+
status: 'running',
|
|
6553
|
+
},
|
|
6554
|
+
type: 'step-start',
|
|
6555
|
+
},
|
|
6556
|
+
{
|
|
6557
|
+
payload: {
|
|
6558
|
+
id: 'step1',
|
|
6559
|
+
endedAt: expect.any(Number),
|
|
6560
|
+
startedAt: expect.any(Number),
|
|
6561
|
+
payload: {},
|
|
6562
|
+
output: {
|
|
6563
|
+
result: 'success1',
|
|
6564
|
+
},
|
|
6565
|
+
status: 'success',
|
|
6566
|
+
},
|
|
6567
|
+
type: 'step-result',
|
|
6568
|
+
},
|
|
6569
|
+
{
|
|
6570
|
+
payload: {
|
|
6571
|
+
id: 'step1',
|
|
6572
|
+
metadata: {},
|
|
6573
|
+
},
|
|
6574
|
+
type: 'step-finish',
|
|
6575
|
+
},
|
|
6576
|
+
{
|
|
6577
|
+
payload: {
|
|
6578
|
+
id: 'step2',
|
|
6579
|
+
status: 'running',
|
|
6580
|
+
},
|
|
6581
|
+
type: 'step-start',
|
|
6582
|
+
},
|
|
6583
|
+
{
|
|
6584
|
+
payload: {
|
|
6585
|
+
id: 'step2',
|
|
6586
|
+
endedAt: expect.any(Number),
|
|
6587
|
+
startedAt: expect.any(Number),
|
|
6588
|
+
payload: {
|
|
6589
|
+
result: 'success1',
|
|
6590
|
+
},
|
|
6591
|
+
output: {
|
|
6592
|
+
result: 'success2',
|
|
6593
|
+
},
|
|
6594
|
+
status: 'success',
|
|
6595
|
+
},
|
|
6596
|
+
type: 'step-result',
|
|
6597
|
+
},
|
|
6598
|
+
{
|
|
6599
|
+
payload: {
|
|
6600
|
+
id: 'step2',
|
|
6601
|
+
metadata: {},
|
|
6602
|
+
},
|
|
6603
|
+
type: 'step-finish',
|
|
6604
|
+
},
|
|
6605
|
+
{
|
|
6606
|
+
payload: {
|
|
6607
|
+
runId: 'test-run-id',
|
|
6608
|
+
},
|
|
6609
|
+
type: 'finish',
|
|
6610
|
+
},
|
|
6611
|
+
]);
|
|
6612
|
+
// Verify execution completed successfully
|
|
6613
|
+
expect(executionResult.steps.step1).toMatchObject({
|
|
6614
|
+
status: 'success',
|
|
6615
|
+
output: { result: 'success1' },
|
|
6616
|
+
payload: {},
|
|
6617
|
+
startedAt: expect.any(Number),
|
|
6618
|
+
endedAt: expect.any(Number),
|
|
6619
|
+
});
|
|
6620
|
+
expect(executionResult.steps.step2).toMatchObject({
|
|
6621
|
+
status: 'success',
|
|
6622
|
+
output: { result: 'success2' },
|
|
6623
|
+
payload: {
|
|
6624
|
+
result: 'success1',
|
|
6625
|
+
},
|
|
6626
|
+
startedAt: expect.any(Number),
|
|
6627
|
+
endedAt: expect.any(Number),
|
|
6628
|
+
});
|
|
5774
6629
|
});
|
|
5775
|
-
});
|
|
5776
6630
|
|
|
5777
|
-
|
|
5778
|
-
it('should generate a stream', async ctx => {
|
|
6631
|
+
it('should handle basic sleep waiting flow', async ctx => {
|
|
5779
6632
|
const inngest = new Inngest({
|
|
5780
6633
|
id: 'mastra',
|
|
5781
6634
|
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
@@ -5806,7 +6659,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5806
6659
|
outputSchema: z.object({}),
|
|
5807
6660
|
steps: [step1, step2],
|
|
5808
6661
|
});
|
|
5809
|
-
workflow.then(step1).then(step2).commit();
|
|
6662
|
+
workflow.then(step1).sleep(1000).then(step2).commit();
|
|
5810
6663
|
|
|
5811
6664
|
const mastra = new Mastra({
|
|
5812
6665
|
storage: new DefaultStorage({
|
|
@@ -5828,18 +6681,19 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5828
6681
|
|
|
5829
6682
|
const app = await createHonoServer(mastra);
|
|
5830
6683
|
|
|
5831
|
-
const srv = serve({
|
|
6684
|
+
const srv = (globServer = serve({
|
|
5832
6685
|
fetch: app.fetch,
|
|
5833
6686
|
port: (ctx as any).handlerPort,
|
|
5834
|
-
});
|
|
6687
|
+
}));
|
|
6688
|
+
await resetInngest();
|
|
5835
6689
|
|
|
5836
6690
|
const runId = 'test-run-id';
|
|
5837
6691
|
let watchData: StreamEvent[] = [];
|
|
5838
|
-
const run = workflow.
|
|
6692
|
+
const run = await workflow.createRunAsync({
|
|
5839
6693
|
runId,
|
|
5840
6694
|
});
|
|
5841
6695
|
|
|
5842
|
-
await
|
|
6696
|
+
await resetInngest();
|
|
5843
6697
|
|
|
5844
6698
|
const { stream, getWorkflowState } = run.stream({ inputData: {} });
|
|
5845
6699
|
|
|
@@ -5852,73 +6706,112 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5852
6706
|
|
|
5853
6707
|
const executionResult = await getWorkflowState();
|
|
5854
6708
|
|
|
5855
|
-
await
|
|
6709
|
+
await resetInngest();
|
|
5856
6710
|
|
|
5857
6711
|
srv.close();
|
|
5858
6712
|
|
|
5859
|
-
expect(watchData.length).toBe(
|
|
5860
|
-
expect(watchData).
|
|
5861
|
-
|
|
5862
|
-
{
|
|
5863
|
-
|
|
5864
|
-
"runId": "test-run-id",
|
|
5865
|
-
},
|
|
5866
|
-
"type": "start",
|
|
6713
|
+
expect(watchData.length).toBe(11);
|
|
6714
|
+
expect(watchData).toMatchObject([
|
|
6715
|
+
{
|
|
6716
|
+
payload: {
|
|
6717
|
+
runId: 'test-run-id',
|
|
5867
6718
|
},
|
|
5868
|
-
|
|
5869
|
-
|
|
5870
|
-
|
|
5871
|
-
|
|
5872
|
-
|
|
6719
|
+
type: 'start',
|
|
6720
|
+
},
|
|
6721
|
+
{
|
|
6722
|
+
payload: {
|
|
6723
|
+
id: 'step1',
|
|
6724
|
+
startedAt: expect.any(Number),
|
|
6725
|
+
status: 'running',
|
|
6726
|
+
payload: {},
|
|
5873
6727
|
},
|
|
5874
|
-
|
|
5875
|
-
|
|
5876
|
-
|
|
5877
|
-
|
|
5878
|
-
|
|
5879
|
-
|
|
5880
|
-
|
|
6728
|
+
type: 'step-start',
|
|
6729
|
+
},
|
|
6730
|
+
{
|
|
6731
|
+
payload: {
|
|
6732
|
+
id: 'step1',
|
|
6733
|
+
output: {
|
|
6734
|
+
result: 'success1',
|
|
5881
6735
|
},
|
|
5882
|
-
|
|
6736
|
+
endedAt: expect.any(Number),
|
|
6737
|
+
status: 'success',
|
|
5883
6738
|
},
|
|
5884
|
-
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
|
|
6739
|
+
type: 'step-result',
|
|
6740
|
+
},
|
|
6741
|
+
{
|
|
6742
|
+
payload: {
|
|
6743
|
+
id: 'step1',
|
|
6744
|
+
metadata: {},
|
|
5890
6745
|
},
|
|
5891
|
-
|
|
5892
|
-
|
|
5893
|
-
|
|
6746
|
+
type: 'step-finish',
|
|
6747
|
+
},
|
|
6748
|
+
{
|
|
6749
|
+
payload: {
|
|
6750
|
+
id: expect.any(String),
|
|
6751
|
+
startedAt: expect.any(Number),
|
|
6752
|
+
status: 'waiting',
|
|
6753
|
+
payload: {
|
|
6754
|
+
result: 'success1',
|
|
5894
6755
|
},
|
|
5895
|
-
"type": "step-start",
|
|
5896
6756
|
},
|
|
5897
|
-
|
|
5898
|
-
|
|
5899
|
-
|
|
5900
|
-
|
|
5901
|
-
|
|
5902
|
-
|
|
5903
|
-
|
|
6757
|
+
type: 'step-waiting',
|
|
6758
|
+
},
|
|
6759
|
+
{
|
|
6760
|
+
payload: {
|
|
6761
|
+
id: expect.any(String),
|
|
6762
|
+
endedAt: expect.any(Number),
|
|
6763
|
+
startedAt: expect.any(Number),
|
|
6764
|
+
status: 'success',
|
|
6765
|
+
output: {
|
|
6766
|
+
result: 'success1',
|
|
5904
6767
|
},
|
|
5905
|
-
"type": "step-result",
|
|
5906
6768
|
},
|
|
5907
|
-
|
|
5908
|
-
|
|
5909
|
-
|
|
5910
|
-
|
|
6769
|
+
type: 'step-result',
|
|
6770
|
+
},
|
|
6771
|
+
{
|
|
6772
|
+
type: 'step-finish',
|
|
6773
|
+
payload: {
|
|
6774
|
+
id: expect.any(String),
|
|
6775
|
+
metadata: {},
|
|
6776
|
+
},
|
|
6777
|
+
},
|
|
6778
|
+
{
|
|
6779
|
+
payload: {
|
|
6780
|
+
id: 'step2',
|
|
6781
|
+
payload: {
|
|
6782
|
+
result: 'success1',
|
|
5911
6783
|
},
|
|
5912
|
-
|
|
6784
|
+
startedAt: expect.any(Number),
|
|
6785
|
+
status: 'running',
|
|
5913
6786
|
},
|
|
5914
|
-
|
|
5915
|
-
|
|
5916
|
-
|
|
6787
|
+
type: 'step-start',
|
|
6788
|
+
},
|
|
6789
|
+
{
|
|
6790
|
+
payload: {
|
|
6791
|
+
id: 'step2',
|
|
6792
|
+
output: {
|
|
6793
|
+
result: 'success2',
|
|
5917
6794
|
},
|
|
5918
|
-
|
|
6795
|
+
endedAt: expect.any(Number),
|
|
6796
|
+
status: 'success',
|
|
6797
|
+
},
|
|
6798
|
+
type: 'step-result',
|
|
6799
|
+
},
|
|
6800
|
+
{
|
|
6801
|
+
payload: {
|
|
6802
|
+
id: 'step2',
|
|
6803
|
+
metadata: {},
|
|
6804
|
+
},
|
|
6805
|
+
type: 'step-finish',
|
|
6806
|
+
},
|
|
6807
|
+
{
|
|
6808
|
+
payload: {
|
|
6809
|
+
runId: 'test-run-id',
|
|
5919
6810
|
},
|
|
5920
|
-
|
|
5921
|
-
|
|
6811
|
+
type: 'finish',
|
|
6812
|
+
},
|
|
6813
|
+
]);
|
|
6814
|
+
|
|
5922
6815
|
// Verify execution completed successfully
|
|
5923
6816
|
expect(executionResult.steps.step1).toMatchObject({
|
|
5924
6817
|
status: 'success',
|
|
@@ -5938,7 +6831,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5938
6831
|
});
|
|
5939
6832
|
});
|
|
5940
6833
|
|
|
5941
|
-
it('should handle basic sleep waiting flow', async ctx => {
|
|
6834
|
+
it('should handle basic sleep waiting flow with fn parameter', async ctx => {
|
|
5942
6835
|
const inngest = new Inngest({
|
|
5943
6836
|
id: 'mastra',
|
|
5944
6837
|
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
@@ -5947,19 +6840,19 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5947
6840
|
|
|
5948
6841
|
const { createWorkflow, createStep } = init(inngest);
|
|
5949
6842
|
|
|
5950
|
-
const step1Action = vi.fn<any>().mockResolvedValue({
|
|
5951
|
-
const step2Action = vi.fn<any>().mockResolvedValue({
|
|
6843
|
+
const step1Action = vi.fn<any>().mockResolvedValue({ value: 1000 });
|
|
6844
|
+
const step2Action = vi.fn<any>().mockResolvedValue({ value: 2000 });
|
|
5952
6845
|
|
|
5953
6846
|
const step1 = createStep({
|
|
5954
6847
|
id: 'step1',
|
|
5955
6848
|
execute: step1Action,
|
|
5956
6849
|
inputSchema: z.object({}),
|
|
5957
|
-
outputSchema: z.object({ value: z.
|
|
6850
|
+
outputSchema: z.object({ value: z.number() }),
|
|
5958
6851
|
});
|
|
5959
6852
|
const step2 = createStep({
|
|
5960
6853
|
id: 'step2',
|
|
5961
6854
|
execute: step2Action,
|
|
5962
|
-
inputSchema: z.object({ value: z.
|
|
6855
|
+
inputSchema: z.object({ value: z.number() }),
|
|
5963
6856
|
outputSchema: z.object({}),
|
|
5964
6857
|
});
|
|
5965
6858
|
|
|
@@ -5969,7 +6862,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5969
6862
|
outputSchema: z.object({}),
|
|
5970
6863
|
steps: [step1, step2],
|
|
5971
6864
|
});
|
|
5972
|
-
workflow
|
|
6865
|
+
workflow
|
|
6866
|
+
.then(step1)
|
|
6867
|
+
.sleep(async ({ inputData }) => {
|
|
6868
|
+
return inputData.value;
|
|
6869
|
+
})
|
|
6870
|
+
.then(step2)
|
|
6871
|
+
.commit();
|
|
5973
6872
|
|
|
5974
6873
|
const mastra = new Mastra({
|
|
5975
6874
|
storage: new DefaultStorage({
|
|
@@ -5991,18 +6890,19 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5991
6890
|
|
|
5992
6891
|
const app = await createHonoServer(mastra);
|
|
5993
6892
|
|
|
5994
|
-
const srv = serve({
|
|
6893
|
+
const srv = (globServer = serve({
|
|
5995
6894
|
fetch: app.fetch,
|
|
5996
6895
|
port: (ctx as any).handlerPort,
|
|
5997
|
-
});
|
|
6896
|
+
}));
|
|
6897
|
+
await resetInngest();
|
|
5998
6898
|
|
|
5999
6899
|
const runId = 'test-run-id';
|
|
6000
6900
|
let watchData: StreamEvent[] = [];
|
|
6001
|
-
const run = workflow.
|
|
6901
|
+
const run = await workflow.createRunAsync({
|
|
6002
6902
|
runId,
|
|
6003
6903
|
});
|
|
6004
6904
|
|
|
6005
|
-
await
|
|
6905
|
+
await resetInngest();
|
|
6006
6906
|
|
|
6007
6907
|
const { stream, getWorkflowState } = run.stream({ inputData: {} });
|
|
6008
6908
|
|
|
@@ -6015,11 +6915,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6015
6915
|
|
|
6016
6916
|
const executionResult = await getWorkflowState();
|
|
6017
6917
|
|
|
6018
|
-
await
|
|
6918
|
+
await resetInngest();
|
|
6019
6919
|
|
|
6020
6920
|
srv.close();
|
|
6021
6921
|
|
|
6022
|
-
expect(watchData.length).toBe(
|
|
6922
|
+
expect(watchData.length).toBe(11);
|
|
6023
6923
|
expect(watchData).toMatchObject([
|
|
6024
6924
|
{
|
|
6025
6925
|
payload: {
|
|
@@ -6030,6 +6930,9 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6030
6930
|
{
|
|
6031
6931
|
payload: {
|
|
6032
6932
|
id: 'step1',
|
|
6933
|
+
startedAt: expect.any(Number),
|
|
6934
|
+
status: 'running',
|
|
6935
|
+
payload: {},
|
|
6033
6936
|
},
|
|
6034
6937
|
type: 'step-start',
|
|
6035
6938
|
},
|
|
@@ -6037,8 +6940,9 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6037
6940
|
payload: {
|
|
6038
6941
|
id: 'step1',
|
|
6039
6942
|
output: {
|
|
6040
|
-
|
|
6943
|
+
value: 1000,
|
|
6041
6944
|
},
|
|
6945
|
+
endedAt: expect.any(Number),
|
|
6042
6946
|
status: 'success',
|
|
6043
6947
|
},
|
|
6044
6948
|
type: 'step-result',
|
|
@@ -6051,12 +6955,43 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6051
6955
|
type: 'step-finish',
|
|
6052
6956
|
},
|
|
6053
6957
|
{
|
|
6054
|
-
payload: {
|
|
6958
|
+
payload: {
|
|
6959
|
+
id: expect.any(String),
|
|
6960
|
+
startedAt: expect.any(Number),
|
|
6961
|
+
status: 'waiting',
|
|
6962
|
+
payload: {
|
|
6963
|
+
value: 1000,
|
|
6964
|
+
},
|
|
6965
|
+
},
|
|
6055
6966
|
type: 'step-waiting',
|
|
6056
6967
|
},
|
|
6968
|
+
{
|
|
6969
|
+
payload: {
|
|
6970
|
+
id: expect.any(String),
|
|
6971
|
+
endedAt: expect.any(Number),
|
|
6972
|
+
startedAt: expect.any(Number),
|
|
6973
|
+
status: 'success',
|
|
6974
|
+
output: {
|
|
6975
|
+
value: 1000,
|
|
6976
|
+
},
|
|
6977
|
+
},
|
|
6978
|
+
type: 'step-result',
|
|
6979
|
+
},
|
|
6980
|
+
{
|
|
6981
|
+
type: 'step-finish',
|
|
6982
|
+
payload: {
|
|
6983
|
+
id: expect.any(String),
|
|
6984
|
+
metadata: {},
|
|
6985
|
+
},
|
|
6986
|
+
},
|
|
6057
6987
|
{
|
|
6058
6988
|
payload: {
|
|
6059
6989
|
id: 'step2',
|
|
6990
|
+
payload: {
|
|
6991
|
+
value: 1000,
|
|
6992
|
+
},
|
|
6993
|
+
startedAt: expect.any(Number),
|
|
6994
|
+
status: 'running',
|
|
6060
6995
|
},
|
|
6061
6996
|
type: 'step-start',
|
|
6062
6997
|
},
|
|
@@ -6064,8 +6999,9 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6064
6999
|
payload: {
|
|
6065
7000
|
id: 'step2',
|
|
6066
7001
|
output: {
|
|
6067
|
-
|
|
7002
|
+
value: 2000,
|
|
6068
7003
|
},
|
|
7004
|
+
endedAt: expect.any(Number),
|
|
6069
7005
|
status: 'success',
|
|
6070
7006
|
},
|
|
6071
7007
|
type: 'step-result',
|
|
@@ -6084,19 +7020,20 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6084
7020
|
type: 'finish',
|
|
6085
7021
|
},
|
|
6086
7022
|
]);
|
|
7023
|
+
|
|
6087
7024
|
// Verify execution completed successfully
|
|
6088
7025
|
expect(executionResult.steps.step1).toMatchObject({
|
|
6089
7026
|
status: 'success',
|
|
6090
|
-
output: {
|
|
7027
|
+
output: { value: 1000 },
|
|
6091
7028
|
payload: {},
|
|
6092
7029
|
startedAt: expect.any(Number),
|
|
6093
7030
|
endedAt: expect.any(Number),
|
|
6094
7031
|
});
|
|
6095
7032
|
expect(executionResult.steps.step2).toMatchObject({
|
|
6096
7033
|
status: 'success',
|
|
6097
|
-
output: {
|
|
7034
|
+
output: { value: 2000 },
|
|
6098
7035
|
payload: {
|
|
6099
|
-
|
|
7036
|
+
value: 1000,
|
|
6100
7037
|
},
|
|
6101
7038
|
startedAt: expect.any(Number),
|
|
6102
7039
|
endedAt: expect.any(Number),
|
|
@@ -6156,18 +7093,19 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6156
7093
|
|
|
6157
7094
|
const app = await createHonoServer(mastra);
|
|
6158
7095
|
|
|
6159
|
-
const srv = serve({
|
|
7096
|
+
const srv = (globServer = serve({
|
|
6160
7097
|
fetch: app.fetch,
|
|
6161
7098
|
port: (ctx as any).handlerPort,
|
|
6162
|
-
});
|
|
7099
|
+
}));
|
|
7100
|
+
await resetInngest();
|
|
6163
7101
|
|
|
6164
7102
|
const runId = 'test-run-id';
|
|
6165
7103
|
let watchData: StreamEvent[] = [];
|
|
6166
|
-
const run = workflow.
|
|
7104
|
+
const run = await workflow.createRunAsync({
|
|
6167
7105
|
runId,
|
|
6168
7106
|
});
|
|
6169
7107
|
|
|
6170
|
-
await
|
|
7108
|
+
await resetInngest();
|
|
6171
7109
|
|
|
6172
7110
|
const { stream, getWorkflowState } = run.stream({ inputData: {} });
|
|
6173
7111
|
|
|
@@ -6187,7 +7125,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6187
7125
|
|
|
6188
7126
|
const executionResult = await getWorkflowState();
|
|
6189
7127
|
|
|
6190
|
-
await
|
|
7128
|
+
await resetInngest();
|
|
6191
7129
|
|
|
6192
7130
|
srv.close();
|
|
6193
7131
|
|
|
@@ -6381,14 +7319,14 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6381
7319
|
|
|
6382
7320
|
const app = await createHonoServer(mastra);
|
|
6383
7321
|
|
|
6384
|
-
const srv = serve({
|
|
7322
|
+
const srv = (globServer = serve({
|
|
6385
7323
|
fetch: app.fetch,
|
|
6386
7324
|
port: (ctx as any).handlerPort,
|
|
6387
|
-
});
|
|
7325
|
+
}));
|
|
6388
7326
|
|
|
6389
|
-
await
|
|
7327
|
+
await resetInngest();
|
|
6390
7328
|
|
|
6391
|
-
const run = promptEvalWorkflow.
|
|
7329
|
+
const run = await promptEvalWorkflow.createRunAsync();
|
|
6392
7330
|
|
|
6393
7331
|
const { stream, getWorkflowState } = run.stream({ inputData: { input: 'test' } });
|
|
6394
7332
|
|
|
@@ -6570,17 +7508,17 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6570
7508
|
|
|
6571
7509
|
const app = await createHonoServer(mastra);
|
|
6572
7510
|
|
|
6573
|
-
const srv = serve({
|
|
7511
|
+
const srv = (globServer = serve({
|
|
6574
7512
|
fetch: app.fetch,
|
|
6575
7513
|
port: (ctx as any).handlerPort,
|
|
6576
|
-
});
|
|
7514
|
+
}));
|
|
6577
7515
|
|
|
6578
|
-
await
|
|
7516
|
+
await resetInngest();
|
|
6579
7517
|
|
|
6580
|
-
const run = workflow.
|
|
7518
|
+
const run = await workflow.createRunAsync({
|
|
6581
7519
|
runId: 'test-run-id',
|
|
6582
7520
|
});
|
|
6583
|
-
const { stream } =
|
|
7521
|
+
const { stream } = run.stream({
|
|
6584
7522
|
inputData: {
|
|
6585
7523
|
prompt1: 'Capital of France, just the name',
|
|
6586
7524
|
prompt2: 'Capital of UK, just the name',
|