@mastra/inngest 0.0.0-custom-instrumentation-20250626084921 → 0.0.0-declaration-maps-20250729202623
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 +253 -3
- package/LICENSE.md +11 -42
- package/dist/index.cjs +254 -46
- 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 +255 -47
- package/dist/index.js.map +1 -0
- package/docker-compose.yaml +3 -3
- package/package.json +14 -13
- package/src/index.test.ts +1319 -371
- package/src/index.ts +313 -42
- package/tsconfig.build.json +9 -0
- package/vitest.config.ts +6 -0
- package/dist/_tsup-dts-rollup.d.cts +0 -269
- package/dist/_tsup-dts-rollup.d.ts +0 -269
- 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,27 +20,27 @@ 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', () => {
|
|
47
45
|
it('should be able to bail workflow execution', async ctx => {
|
|
48
46
|
const inngest = new Inngest({
|
|
@@ -105,15 +103,17 @@ describe('MastraInngestWorkflow', () => {
|
|
|
105
103
|
|
|
106
104
|
const app = await createHonoServer(mastra);
|
|
107
105
|
|
|
108
|
-
const srv = serve({
|
|
106
|
+
const srv = (globServer = serve({
|
|
109
107
|
fetch: app.fetch,
|
|
110
108
|
port: (ctx as any).handlerPort,
|
|
111
|
-
});
|
|
109
|
+
}));
|
|
110
|
+
|
|
111
|
+
await resetInngest();
|
|
112
112
|
|
|
113
113
|
const run = await workflow.createRunAsync();
|
|
114
|
+
console.log('running');
|
|
114
115
|
const result = await run.start({ inputData: { value: 'bail' } });
|
|
115
|
-
|
|
116
|
-
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
116
|
+
console.log('result', result);
|
|
117
117
|
|
|
118
118
|
expect(result.steps['step1']).toEqual({
|
|
119
119
|
status: 'success',
|
|
@@ -192,11 +192,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
192
192
|
|
|
193
193
|
const app = await createHonoServer(mastra);
|
|
194
194
|
|
|
195
|
-
const srv = serve({
|
|
195
|
+
const srv = (globServer = serve({
|
|
196
196
|
fetch: app.fetch,
|
|
197
197
|
port: (ctx as any).handlerPort,
|
|
198
|
-
});
|
|
199
|
-
await
|
|
198
|
+
}));
|
|
199
|
+
await resetInngest();
|
|
200
200
|
|
|
201
201
|
const run = await workflow.createRunAsync();
|
|
202
202
|
const result = await run.start({ inputData: {} });
|
|
@@ -267,11 +267,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
267
267
|
|
|
268
268
|
const app = await createHonoServer(mastra);
|
|
269
269
|
|
|
270
|
-
const srv = serve({
|
|
270
|
+
const srv = (globServer = serve({
|
|
271
271
|
fetch: app.fetch,
|
|
272
272
|
port: (ctx as any).handlerPort,
|
|
273
|
-
});
|
|
274
|
-
await
|
|
273
|
+
}));
|
|
274
|
+
await resetInngest();
|
|
275
275
|
|
|
276
276
|
const run = await workflow.createRunAsync();
|
|
277
277
|
const result = await run.start({ inputData: {} });
|
|
@@ -348,11 +348,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
348
348
|
|
|
349
349
|
const app = await createHonoServer(mastra);
|
|
350
350
|
|
|
351
|
-
const srv = serve({
|
|
351
|
+
const srv = (globServer = serve({
|
|
352
352
|
fetch: app.fetch,
|
|
353
353
|
port: (ctx as any).handlerPort,
|
|
354
|
-
});
|
|
355
|
-
await
|
|
354
|
+
}));
|
|
355
|
+
await resetInngest();
|
|
356
356
|
|
|
357
357
|
const run = await workflow.createRunAsync();
|
|
358
358
|
const result = await run.start({ inputData: {} });
|
|
@@ -367,7 +367,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
367
367
|
srv.close();
|
|
368
368
|
});
|
|
369
369
|
|
|
370
|
-
it('should execute a
|
|
370
|
+
it('should execute a sleep step', async ctx => {
|
|
371
371
|
const inngest = new Inngest({
|
|
372
372
|
id: 'mastra',
|
|
373
373
|
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
@@ -422,11 +422,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
422
422
|
|
|
423
423
|
const app = await createHonoServer(mastra);
|
|
424
424
|
|
|
425
|
-
const srv = serve({
|
|
425
|
+
const srv = (globServer = serve({
|
|
426
426
|
fetch: app.fetch,
|
|
427
427
|
port: (ctx as any).handlerPort,
|
|
428
|
-
});
|
|
429
|
-
await
|
|
428
|
+
}));
|
|
429
|
+
await resetInngest();
|
|
430
430
|
|
|
431
431
|
const run = await workflow.createRunAsync();
|
|
432
432
|
const startTime = Date.now();
|
|
@@ -455,7 +455,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
455
455
|
srv.close();
|
|
456
456
|
});
|
|
457
457
|
|
|
458
|
-
it('should execute a
|
|
458
|
+
it('should execute a sleep step with fn parameter', async ctx => {
|
|
459
459
|
const inngest = new Inngest({
|
|
460
460
|
id: 'mastra',
|
|
461
461
|
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
@@ -463,34 +463,36 @@ describe('MastraInngestWorkflow', () => {
|
|
|
463
463
|
|
|
464
464
|
const { createWorkflow, createStep } = init(inngest);
|
|
465
465
|
|
|
466
|
-
const execute = vi.fn<any>().mockResolvedValue({
|
|
466
|
+
const execute = vi.fn<any>().mockResolvedValue({ value: 1000 });
|
|
467
467
|
const step1 = createStep({
|
|
468
468
|
id: 'step1',
|
|
469
469
|
execute,
|
|
470
470
|
inputSchema: z.object({}),
|
|
471
|
-
outputSchema: z.object({
|
|
471
|
+
outputSchema: z.object({ value: z.number() }),
|
|
472
472
|
});
|
|
473
473
|
const step2 = createStep({
|
|
474
474
|
id: 'step2',
|
|
475
475
|
execute: async ({ inputData }) => {
|
|
476
|
-
return {
|
|
476
|
+
return { value: inputData.value + 1000 };
|
|
477
477
|
},
|
|
478
|
-
inputSchema: z.object({
|
|
479
|
-
outputSchema: z.object({
|
|
478
|
+
inputSchema: z.object({ value: z.number() }),
|
|
479
|
+
outputSchema: z.object({ value: z.number() }),
|
|
480
480
|
});
|
|
481
481
|
|
|
482
482
|
const workflow = createWorkflow({
|
|
483
483
|
id: 'test-workflow',
|
|
484
484
|
inputSchema: z.object({}),
|
|
485
485
|
outputSchema: z.object({
|
|
486
|
-
|
|
486
|
+
value: z.number(),
|
|
487
487
|
}),
|
|
488
488
|
steps: [step1],
|
|
489
489
|
});
|
|
490
490
|
|
|
491
491
|
workflow
|
|
492
492
|
.then(step1)
|
|
493
|
-
.
|
|
493
|
+
.sleep(async ({ inputData }) => {
|
|
494
|
+
return inputData.value;
|
|
495
|
+
})
|
|
494
496
|
.then(step2)
|
|
495
497
|
.commit();
|
|
496
498
|
|
|
@@ -514,11 +516,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
514
516
|
|
|
515
517
|
const app = await createHonoServer(mastra);
|
|
516
518
|
|
|
517
|
-
const srv = serve({
|
|
519
|
+
const srv = (globServer = serve({
|
|
518
520
|
fetch: app.fetch,
|
|
519
521
|
port: (ctx as any).handlerPort,
|
|
520
|
-
});
|
|
521
|
-
await
|
|
522
|
+
}));
|
|
523
|
+
await resetInngest();
|
|
522
524
|
|
|
523
525
|
const run = await workflow.createRunAsync();
|
|
524
526
|
const startTime = Date.now();
|
|
@@ -528,7 +530,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
528
530
|
expect(execute).toHaveBeenCalled();
|
|
529
531
|
expect(result.steps['step1']).toMatchObject({
|
|
530
532
|
status: 'success',
|
|
531
|
-
output: {
|
|
533
|
+
output: { value: 1000 },
|
|
532
534
|
// payload: {},
|
|
533
535
|
// startedAt: expect.any(Number),
|
|
534
536
|
// endedAt: expect.any(Number),
|
|
@@ -536,7 +538,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
536
538
|
|
|
537
539
|
expect(result.steps['step2']).toMatchObject({
|
|
538
540
|
status: 'success',
|
|
539
|
-
output: {
|
|
541
|
+
output: { value: 2000 },
|
|
540
542
|
// payload: { result: 'success' },
|
|
541
543
|
// startedAt: expect.any(Number),
|
|
542
544
|
// endedAt: expect.any(Number),
|
|
@@ -547,7 +549,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
547
549
|
srv.close();
|
|
548
550
|
});
|
|
549
551
|
|
|
550
|
-
it('should execute a a
|
|
552
|
+
it('should execute a a sleep until step', async ctx => {
|
|
551
553
|
const inngest = new Inngest({
|
|
552
554
|
id: 'mastra',
|
|
553
555
|
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
@@ -564,12 +566,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
564
566
|
});
|
|
565
567
|
const step2 = createStep({
|
|
566
568
|
id: 'step2',
|
|
567
|
-
execute: async ({ inputData
|
|
568
|
-
return { result: inputData.result
|
|
569
|
+
execute: async ({ inputData }) => {
|
|
570
|
+
return { result: 'slept successfully: ' + inputData.result };
|
|
569
571
|
},
|
|
570
572
|
inputSchema: z.object({ result: z.string() }),
|
|
571
|
-
outputSchema: z.object({ result: z.string()
|
|
572
|
-
resumeSchema: z.any(),
|
|
573
|
+
outputSchema: z.object({ result: z.string() }),
|
|
573
574
|
});
|
|
574
575
|
|
|
575
576
|
const workflow = createWorkflow({
|
|
@@ -577,12 +578,15 @@ describe('MastraInngestWorkflow', () => {
|
|
|
577
578
|
inputSchema: z.object({}),
|
|
578
579
|
outputSchema: z.object({
|
|
579
580
|
result: z.string(),
|
|
580
|
-
resumed: z.any(),
|
|
581
581
|
}),
|
|
582
582
|
steps: [step1],
|
|
583
583
|
});
|
|
584
584
|
|
|
585
|
-
workflow
|
|
585
|
+
workflow
|
|
586
|
+
.then(step1)
|
|
587
|
+
.sleepUntil(new Date(Date.now() + 1000))
|
|
588
|
+
.then(step2)
|
|
589
|
+
.commit();
|
|
586
590
|
|
|
587
591
|
const mastra = new Mastra({
|
|
588
592
|
storage: new DefaultStorage({
|
|
@@ -604,17 +608,14 @@ describe('MastraInngestWorkflow', () => {
|
|
|
604
608
|
|
|
605
609
|
const app = await createHonoServer(mastra);
|
|
606
610
|
|
|
607
|
-
const srv = serve({
|
|
611
|
+
const srv = (globServer = serve({
|
|
608
612
|
fetch: app.fetch,
|
|
609
613
|
port: (ctx as any).handlerPort,
|
|
610
|
-
});
|
|
611
|
-
await
|
|
614
|
+
}));
|
|
615
|
+
await resetInngest();
|
|
612
616
|
|
|
613
617
|
const run = await workflow.createRunAsync();
|
|
614
618
|
const startTime = Date.now();
|
|
615
|
-
setTimeout(() => {
|
|
616
|
-
run.sendEvent('hello-event', { data: 'hello' });
|
|
617
|
-
}, 1000);
|
|
618
619
|
const result = await run.start({ inputData: {} });
|
|
619
620
|
const endTime = Date.now();
|
|
620
621
|
|
|
@@ -629,11 +630,10 @@ describe('MastraInngestWorkflow', () => {
|
|
|
629
630
|
|
|
630
631
|
expect(result.steps['step2']).toMatchObject({
|
|
631
632
|
status: 'success',
|
|
632
|
-
output: { result: '
|
|
633
|
-
payload: { result: 'success' },
|
|
634
|
-
//
|
|
635
|
-
|
|
636
|
-
endedAt: expect.any(Number),
|
|
633
|
+
output: { result: 'slept successfully: success' },
|
|
634
|
+
// payload: { result: 'success' },
|
|
635
|
+
// startedAt: expect.any(Number),
|
|
636
|
+
// endedAt: expect.any(Number),
|
|
637
637
|
});
|
|
638
638
|
|
|
639
639
|
expect(endTime - startTime).toBeGreaterThan(1000);
|
|
@@ -641,7 +641,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
641
641
|
srv.close();
|
|
642
642
|
});
|
|
643
643
|
|
|
644
|
-
it('should execute a
|
|
644
|
+
it('should execute a sleep until step with fn parameter', async ctx => {
|
|
645
645
|
const inngest = new Inngest({
|
|
646
646
|
id: 'mastra',
|
|
647
647
|
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
@@ -649,34 +649,38 @@ describe('MastraInngestWorkflow', () => {
|
|
|
649
649
|
|
|
650
650
|
const { createWorkflow, createStep } = init(inngest);
|
|
651
651
|
|
|
652
|
-
const execute = vi.fn<any>().mockResolvedValue({
|
|
652
|
+
const execute = vi.fn<any>().mockResolvedValue({ value: 1000 });
|
|
653
653
|
const step1 = createStep({
|
|
654
654
|
id: 'step1',
|
|
655
655
|
execute,
|
|
656
656
|
inputSchema: z.object({}),
|
|
657
|
-
outputSchema: z.object({
|
|
657
|
+
outputSchema: z.object({ value: z.number() }),
|
|
658
658
|
});
|
|
659
659
|
const step2 = createStep({
|
|
660
660
|
id: 'step2',
|
|
661
|
-
execute: async ({ inputData
|
|
662
|
-
return {
|
|
661
|
+
execute: async ({ inputData }) => {
|
|
662
|
+
return { value: inputData.value + 1000 };
|
|
663
663
|
},
|
|
664
|
-
inputSchema: z.object({
|
|
665
|
-
outputSchema: z.object({
|
|
666
|
-
resumeSchema: z.any(),
|
|
664
|
+
inputSchema: z.object({ value: z.number() }),
|
|
665
|
+
outputSchema: z.object({ value: z.number() }),
|
|
667
666
|
});
|
|
668
667
|
|
|
669
668
|
const workflow = createWorkflow({
|
|
670
669
|
id: 'test-workflow',
|
|
671
670
|
inputSchema: z.object({}),
|
|
672
671
|
outputSchema: z.object({
|
|
673
|
-
|
|
674
|
-
resumed: z.any(),
|
|
672
|
+
value: z.number(),
|
|
675
673
|
}),
|
|
676
674
|
steps: [step1],
|
|
677
675
|
});
|
|
678
676
|
|
|
679
|
-
workflow
|
|
677
|
+
workflow
|
|
678
|
+
.then(step1)
|
|
679
|
+
.sleepUntil(async ({ inputData }) => {
|
|
680
|
+
return new Date(Date.now() + inputData.value);
|
|
681
|
+
})
|
|
682
|
+
.then(step2)
|
|
683
|
+
.commit();
|
|
680
684
|
|
|
681
685
|
const mastra = new Mastra({
|
|
682
686
|
storage: new DefaultStorage({
|
|
@@ -698,11 +702,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
698
702
|
|
|
699
703
|
const app = await createHonoServer(mastra);
|
|
700
704
|
|
|
701
|
-
const srv = serve({
|
|
705
|
+
const srv = (globServer = serve({
|
|
702
706
|
fetch: app.fetch,
|
|
703
707
|
port: (ctx as any).handlerPort,
|
|
704
|
-
});
|
|
705
|
-
await
|
|
708
|
+
}));
|
|
709
|
+
await resetInngest();
|
|
706
710
|
|
|
707
711
|
const run = await workflow.createRunAsync();
|
|
708
712
|
const startTime = Date.now();
|
|
@@ -712,28 +716,26 @@ describe('MastraInngestWorkflow', () => {
|
|
|
712
716
|
expect(execute).toHaveBeenCalled();
|
|
713
717
|
expect(result.steps['step1']).toMatchObject({
|
|
714
718
|
status: 'success',
|
|
715
|
-
output: {
|
|
719
|
+
output: { value: 1000 },
|
|
716
720
|
// payload: {},
|
|
717
721
|
// startedAt: expect.any(Number),
|
|
718
722
|
// endedAt: expect.any(Number),
|
|
719
723
|
});
|
|
720
724
|
|
|
721
725
|
expect(result.steps['step2']).toMatchObject({
|
|
722
|
-
status: '
|
|
723
|
-
|
|
724
|
-
payload: { result: 'success' },
|
|
725
|
-
startedAt: expect.any(Number),
|
|
726
|
-
endedAt: expect.any(Number),
|
|
726
|
+
status: 'success',
|
|
727
|
+
output: { value: 2000 },
|
|
728
|
+
// payload: { result: 'success' },
|
|
729
|
+
// startedAt: expect.any(Number),
|
|
730
|
+
// endedAt: expect.any(Number),
|
|
727
731
|
});
|
|
728
732
|
|
|
729
733
|
expect(endTime - startTime).toBeGreaterThan(1000);
|
|
730
734
|
|
|
731
735
|
srv.close();
|
|
732
736
|
});
|
|
733
|
-
});
|
|
734
737
|
|
|
735
|
-
|
|
736
|
-
it('should resolve trigger data', async ctx => {
|
|
738
|
+
it('should execute a a waitForEvent step', async ctx => {
|
|
737
739
|
const inngest = new Inngest({
|
|
738
740
|
id: 'mastra',
|
|
739
741
|
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
@@ -742,27 +744,33 @@ describe('MastraInngestWorkflow', () => {
|
|
|
742
744
|
const { createWorkflow, createStep } = init(inngest);
|
|
743
745
|
|
|
744
746
|
const execute = vi.fn<any>().mockResolvedValue({ result: 'success' });
|
|
745
|
-
|
|
746
747
|
const step1 = createStep({
|
|
747
748
|
id: 'step1',
|
|
748
749
|
execute,
|
|
749
|
-
inputSchema: z.object({
|
|
750
|
+
inputSchema: z.object({}),
|
|
750
751
|
outputSchema: z.object({ result: z.string() }),
|
|
751
752
|
});
|
|
752
753
|
const step2 = createStep({
|
|
753
754
|
id: 'step2',
|
|
754
|
-
execute,
|
|
755
|
+
execute: async ({ inputData, resumeData }) => {
|
|
756
|
+
return { result: inputData.result, resumed: resumeData };
|
|
757
|
+
},
|
|
755
758
|
inputSchema: z.object({ result: z.string() }),
|
|
756
|
-
outputSchema: z.object({ result: z.string() }),
|
|
759
|
+
outputSchema: z.object({ result: z.string(), resumed: z.any() }),
|
|
760
|
+
resumeSchema: z.any(),
|
|
757
761
|
});
|
|
758
762
|
|
|
759
763
|
const workflow = createWorkflow({
|
|
760
764
|
id: 'test-workflow',
|
|
761
|
-
inputSchema: z.object({
|
|
762
|
-
outputSchema: z.object({
|
|
765
|
+
inputSchema: z.object({}),
|
|
766
|
+
outputSchema: z.object({
|
|
767
|
+
result: z.string(),
|
|
768
|
+
resumed: z.any(),
|
|
769
|
+
}),
|
|
770
|
+
steps: [step1],
|
|
763
771
|
});
|
|
764
772
|
|
|
765
|
-
workflow.then(step1).
|
|
773
|
+
workflow.then(step1).waitForEvent('hello-event', step2).commit();
|
|
766
774
|
|
|
767
775
|
const mastra = new Mastra({
|
|
768
776
|
storage: new DefaultStorage({
|
|
@@ -784,21 +792,44 @@ describe('MastraInngestWorkflow', () => {
|
|
|
784
792
|
|
|
785
793
|
const app = await createHonoServer(mastra);
|
|
786
794
|
|
|
787
|
-
const srv = serve({
|
|
795
|
+
const srv = (globServer = serve({
|
|
788
796
|
fetch: app.fetch,
|
|
789
797
|
port: (ctx as any).handlerPort,
|
|
790
|
-
});
|
|
798
|
+
}));
|
|
799
|
+
await resetInngest();
|
|
791
800
|
|
|
792
801
|
const run = await workflow.createRunAsync();
|
|
793
|
-
const
|
|
802
|
+
const startTime = Date.now();
|
|
803
|
+
setTimeout(() => {
|
|
804
|
+
run.sendEvent('hello-event', { data: 'hello' });
|
|
805
|
+
}, 1000);
|
|
806
|
+
const result = await run.start({ inputData: {} });
|
|
807
|
+
const endTime = Date.now();
|
|
794
808
|
|
|
795
|
-
expect(
|
|
796
|
-
expect(result.steps
|
|
809
|
+
expect(execute).toHaveBeenCalled();
|
|
810
|
+
expect(result.steps['step1']).toMatchObject({
|
|
811
|
+
status: 'success',
|
|
812
|
+
output: { result: 'success' },
|
|
813
|
+
// payload: {},
|
|
814
|
+
// startedAt: expect.any(Number),
|
|
815
|
+
// endedAt: expect.any(Number),
|
|
816
|
+
});
|
|
817
|
+
|
|
818
|
+
expect(result.steps['step2']).toMatchObject({
|
|
819
|
+
status: 'success',
|
|
820
|
+
output: { result: 'success', resumed: { data: 'hello' } },
|
|
821
|
+
payload: { result: 'success' },
|
|
822
|
+
// resumePayload: { data: 'hello' },
|
|
823
|
+
startedAt: expect.any(Number),
|
|
824
|
+
endedAt: expect.any(Number),
|
|
825
|
+
});
|
|
826
|
+
|
|
827
|
+
expect(endTime - startTime).toBeGreaterThan(1000);
|
|
797
828
|
|
|
798
829
|
srv.close();
|
|
799
830
|
});
|
|
800
831
|
|
|
801
|
-
it('should
|
|
832
|
+
it('should execute a a waitForEvent step after timeout', async ctx => {
|
|
802
833
|
const inngest = new Inngest({
|
|
803
834
|
id: 'mastra',
|
|
804
835
|
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
@@ -806,50 +837,34 @@ describe('MastraInngestWorkflow', () => {
|
|
|
806
837
|
|
|
807
838
|
const { createWorkflow, createStep } = init(inngest);
|
|
808
839
|
|
|
809
|
-
const
|
|
810
|
-
// Test accessing trigger data with correct type
|
|
811
|
-
expect(inputData).toMatchObject({ inputValue: 'test-input' });
|
|
812
|
-
return { value: 'step1-result' };
|
|
813
|
-
});
|
|
814
|
-
|
|
815
|
-
const step2Action = vi.fn().mockImplementation(async ({ getStepResult }) => {
|
|
816
|
-
// Test accessing previous step result with type
|
|
817
|
-
const step1Result = getStepResult(step1);
|
|
818
|
-
expect(step1Result).toMatchObject({ value: 'step1-result' });
|
|
819
|
-
|
|
820
|
-
const failedStep = getStepResult(nonExecutedStep);
|
|
821
|
-
expect(failedStep).toBe(null);
|
|
822
|
-
|
|
823
|
-
return { value: 'step2-result' };
|
|
824
|
-
});
|
|
825
|
-
|
|
840
|
+
const execute = vi.fn<any>().mockResolvedValue({ result: 'success' });
|
|
826
841
|
const step1 = createStep({
|
|
827
842
|
id: 'step1',
|
|
828
|
-
execute
|
|
829
|
-
inputSchema: z.object({
|
|
830
|
-
outputSchema: z.object({
|
|
843
|
+
execute,
|
|
844
|
+
inputSchema: z.object({}),
|
|
845
|
+
outputSchema: z.object({ result: z.string() }),
|
|
831
846
|
});
|
|
832
847
|
const step2 = createStep({
|
|
833
848
|
id: 'step2',
|
|
834
|
-
execute:
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
id: 'non-executed-step',
|
|
841
|
-
execute: vi.fn(),
|
|
842
|
-
inputSchema: z.object({}),
|
|
843
|
-
outputSchema: z.object({}),
|
|
849
|
+
execute: async ({ inputData, resumeData }) => {
|
|
850
|
+
return { result: inputData.result, resumed: resumeData };
|
|
851
|
+
},
|
|
852
|
+
inputSchema: z.object({ result: z.string() }),
|
|
853
|
+
outputSchema: z.object({ result: z.string(), resumed: z.any() }),
|
|
854
|
+
resumeSchema: z.any(),
|
|
844
855
|
});
|
|
845
856
|
|
|
846
857
|
const workflow = createWorkflow({
|
|
847
858
|
id: 'test-workflow',
|
|
848
|
-
inputSchema: z.object({
|
|
849
|
-
outputSchema: z.object({
|
|
859
|
+
inputSchema: z.object({}),
|
|
860
|
+
outputSchema: z.object({
|
|
861
|
+
result: z.string(),
|
|
862
|
+
resumed: z.any(),
|
|
863
|
+
}),
|
|
864
|
+
steps: [step1],
|
|
850
865
|
});
|
|
851
866
|
|
|
852
|
-
workflow.then(step1).
|
|
867
|
+
workflow.then(step1).waitForEvent('hello-event', step2, { timeout: 1000 }).commit();
|
|
853
868
|
|
|
854
869
|
const mastra = new Mastra({
|
|
855
870
|
storage: new DefaultStorage({
|
|
@@ -871,52 +886,77 @@ describe('MastraInngestWorkflow', () => {
|
|
|
871
886
|
|
|
872
887
|
const app = await createHonoServer(mastra);
|
|
873
888
|
|
|
874
|
-
const srv = serve({
|
|
889
|
+
const srv = (globServer = serve({
|
|
875
890
|
fetch: app.fetch,
|
|
876
891
|
port: (ctx as any).handlerPort,
|
|
877
|
-
});
|
|
892
|
+
}));
|
|
893
|
+
await resetInngest();
|
|
878
894
|
|
|
879
895
|
const run = await workflow.createRunAsync();
|
|
880
|
-
const
|
|
896
|
+
const startTime = Date.now();
|
|
897
|
+
const result = await run.start({ inputData: {} });
|
|
898
|
+
const endTime = Date.now();
|
|
881
899
|
|
|
882
|
-
expect(
|
|
883
|
-
expect(
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
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),
|
|
888
915
|
});
|
|
889
916
|
|
|
917
|
+
expect(endTime - startTime).toBeGreaterThan(1000);
|
|
918
|
+
|
|
890
919
|
srv.close();
|
|
891
920
|
});
|
|
921
|
+
});
|
|
892
922
|
|
|
893
|
-
|
|
923
|
+
describe('abort', () => {
|
|
924
|
+
it('should be able to abort workflow execution in between steps', async ctx => {
|
|
894
925
|
const inngest = new Inngest({
|
|
895
926
|
id: 'mastra',
|
|
896
927
|
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
928
|
+
middleware: [realtimeMiddleware()],
|
|
897
929
|
});
|
|
898
930
|
|
|
899
931
|
const { createWorkflow, createStep } = init(inngest);
|
|
900
932
|
|
|
901
|
-
const execute = vi.fn<any>().mockResolvedValue({ result: 'success' });
|
|
902
|
-
const triggerSchema = z.object({
|
|
903
|
-
inputData: z.string(),
|
|
904
|
-
});
|
|
905
|
-
|
|
906
933
|
const step1 = createStep({
|
|
907
934
|
id: 'step1',
|
|
908
|
-
execute
|
|
909
|
-
|
|
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() }),
|
|
910
947
|
outputSchema: z.object({ result: z.string() }),
|
|
911
948
|
});
|
|
912
949
|
|
|
913
950
|
const workflow = createWorkflow({
|
|
914
951
|
id: 'test-workflow',
|
|
915
|
-
inputSchema:
|
|
916
|
-
outputSchema: z.object({
|
|
952
|
+
inputSchema: z.object({}),
|
|
953
|
+
outputSchema: z.object({
|
|
954
|
+
result: z.string(),
|
|
955
|
+
}),
|
|
956
|
+
steps: [step1, step2],
|
|
917
957
|
});
|
|
918
958
|
|
|
919
|
-
workflow.then(step1).commit();
|
|
959
|
+
workflow.then(step1).sleep(2000).then(step2).commit();
|
|
920
960
|
|
|
921
961
|
const mastra = new Mastra({
|
|
922
962
|
storage: new DefaultStorage({
|
|
@@ -938,19 +978,368 @@ describe('MastraInngestWorkflow', () => {
|
|
|
938
978
|
|
|
939
979
|
const app = await createHonoServer(mastra);
|
|
940
980
|
|
|
941
|
-
const srv = serve({
|
|
981
|
+
const srv = (globServer = serve({
|
|
942
982
|
fetch: app.fetch,
|
|
943
983
|
port: (ctx as any).handlerPort,
|
|
944
|
-
});
|
|
984
|
+
}));
|
|
985
|
+
await resetInngest();
|
|
945
986
|
|
|
946
987
|
const run = await workflow.createRunAsync();
|
|
947
|
-
|
|
988
|
+
const p = run.start({ inputData: { value: 'test' } });
|
|
948
989
|
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
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
|
+
|
|
1120
|
+
describe('Variable Resolution', () => {
|
|
1121
|
+
it('should resolve trigger data', async ctx => {
|
|
1122
|
+
const inngest = new Inngest({
|
|
1123
|
+
id: 'mastra',
|
|
1124
|
+
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
1125
|
+
});
|
|
1126
|
+
|
|
1127
|
+
const { createWorkflow, createStep } = init(inngest);
|
|
1128
|
+
|
|
1129
|
+
const execute = vi.fn<any>().mockResolvedValue({ result: 'success' });
|
|
1130
|
+
|
|
1131
|
+
const step1 = createStep({
|
|
1132
|
+
id: 'step1',
|
|
1133
|
+
execute,
|
|
1134
|
+
inputSchema: z.object({ inputData: z.string() }),
|
|
1135
|
+
outputSchema: z.object({ result: z.string() }),
|
|
1136
|
+
});
|
|
1137
|
+
const step2 = createStep({
|
|
1138
|
+
id: 'step2',
|
|
1139
|
+
execute,
|
|
1140
|
+
inputSchema: z.object({ result: z.string() }),
|
|
1141
|
+
outputSchema: z.object({ result: z.string() }),
|
|
1142
|
+
});
|
|
1143
|
+
|
|
1144
|
+
const workflow = createWorkflow({
|
|
1145
|
+
id: 'test-workflow',
|
|
1146
|
+
inputSchema: z.object({ inputData: z.string() }),
|
|
1147
|
+
outputSchema: z.object({}),
|
|
1148
|
+
});
|
|
1149
|
+
|
|
1150
|
+
workflow.then(step1).then(step2).commit();
|
|
1151
|
+
|
|
1152
|
+
const mastra = new Mastra({
|
|
1153
|
+
storage: new DefaultStorage({
|
|
1154
|
+
url: ':memory:',
|
|
1155
|
+
}),
|
|
1156
|
+
workflows: {
|
|
1157
|
+
'test-workflow': workflow,
|
|
1158
|
+
},
|
|
1159
|
+
server: {
|
|
1160
|
+
apiRoutes: [
|
|
1161
|
+
{
|
|
1162
|
+
path: '/inngest/api',
|
|
1163
|
+
method: 'ALL',
|
|
1164
|
+
createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
|
|
1165
|
+
},
|
|
1166
|
+
],
|
|
1167
|
+
},
|
|
1168
|
+
});
|
|
1169
|
+
|
|
1170
|
+
const app = await createHonoServer(mastra);
|
|
1171
|
+
|
|
1172
|
+
const srv = (globServer = serve({
|
|
1173
|
+
fetch: app.fetch,
|
|
1174
|
+
port: (ctx as any).handlerPort,
|
|
1175
|
+
}));
|
|
1176
|
+
|
|
1177
|
+
await resetInngest();
|
|
1178
|
+
|
|
1179
|
+
const run = await workflow.createRunAsync();
|
|
1180
|
+
const result = await run.start({ inputData: { inputData: 'test-input' } });
|
|
1181
|
+
|
|
1182
|
+
expect(result.steps.step1).toMatchObject({ status: 'success', output: { result: 'success' } });
|
|
1183
|
+
expect(result.steps.step2).toMatchObject({ status: 'success', output: { result: 'success' } });
|
|
1184
|
+
|
|
1185
|
+
srv.close();
|
|
1186
|
+
});
|
|
1187
|
+
|
|
1188
|
+
it('should provide access to step results and trigger data via getStepResult helper', async ctx => {
|
|
1189
|
+
const inngest = new Inngest({
|
|
1190
|
+
id: 'mastra',
|
|
1191
|
+
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
1192
|
+
});
|
|
1193
|
+
|
|
1194
|
+
const { createWorkflow, createStep } = init(inngest);
|
|
1195
|
+
|
|
1196
|
+
const step1Action = vi.fn().mockImplementation(async ({ inputData }) => {
|
|
1197
|
+
// Test accessing trigger data with correct type
|
|
1198
|
+
expect(inputData).toMatchObject({ inputValue: 'test-input' });
|
|
1199
|
+
return { value: 'step1-result' };
|
|
1200
|
+
});
|
|
1201
|
+
|
|
1202
|
+
const step2Action = vi.fn().mockImplementation(async ({ getStepResult }) => {
|
|
1203
|
+
// Test accessing previous step result with type
|
|
1204
|
+
const step1Result = getStepResult(step1);
|
|
1205
|
+
expect(step1Result).toMatchObject({ value: 'step1-result' });
|
|
1206
|
+
|
|
1207
|
+
const failedStep = getStepResult(nonExecutedStep);
|
|
1208
|
+
expect(failedStep).toBe(null);
|
|
1209
|
+
|
|
1210
|
+
return { value: 'step2-result' };
|
|
1211
|
+
});
|
|
1212
|
+
|
|
1213
|
+
const step1 = createStep({
|
|
1214
|
+
id: 'step1',
|
|
1215
|
+
execute: step1Action,
|
|
1216
|
+
inputSchema: z.object({ inputValue: z.string() }),
|
|
1217
|
+
outputSchema: z.object({ value: z.string() }),
|
|
1218
|
+
});
|
|
1219
|
+
const step2 = createStep({
|
|
1220
|
+
id: 'step2',
|
|
1221
|
+
execute: step2Action,
|
|
1222
|
+
inputSchema: z.object({ value: z.string() }),
|
|
1223
|
+
outputSchema: z.object({ value: z.string() }),
|
|
1224
|
+
});
|
|
1225
|
+
|
|
1226
|
+
const nonExecutedStep = createStep({
|
|
1227
|
+
id: 'non-executed-step',
|
|
1228
|
+
execute: vi.fn(),
|
|
1229
|
+
inputSchema: z.object({}),
|
|
1230
|
+
outputSchema: z.object({}),
|
|
1231
|
+
});
|
|
1232
|
+
|
|
1233
|
+
const workflow = createWorkflow({
|
|
1234
|
+
id: 'test-workflow',
|
|
1235
|
+
inputSchema: z.object({ inputValue: z.string() }),
|
|
1236
|
+
outputSchema: z.object({ value: z.string() }),
|
|
1237
|
+
});
|
|
1238
|
+
|
|
1239
|
+
workflow.then(step1).then(step2).commit();
|
|
1240
|
+
|
|
1241
|
+
const mastra = new Mastra({
|
|
1242
|
+
storage: new DefaultStorage({
|
|
1243
|
+
url: ':memory:',
|
|
1244
|
+
}),
|
|
1245
|
+
workflows: {
|
|
1246
|
+
'test-workflow': workflow,
|
|
1247
|
+
},
|
|
1248
|
+
server: {
|
|
1249
|
+
apiRoutes: [
|
|
1250
|
+
{
|
|
1251
|
+
path: '/inngest/api',
|
|
1252
|
+
method: 'ALL',
|
|
1253
|
+
createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
|
|
1254
|
+
},
|
|
1255
|
+
],
|
|
1256
|
+
},
|
|
1257
|
+
});
|
|
1258
|
+
|
|
1259
|
+
const app = await createHonoServer(mastra);
|
|
1260
|
+
|
|
1261
|
+
const srv = (globServer = serve({
|
|
1262
|
+
fetch: app.fetch,
|
|
1263
|
+
port: (ctx as any).handlerPort,
|
|
1264
|
+
}));
|
|
1265
|
+
await resetInngest();
|
|
1266
|
+
|
|
1267
|
+
const run = await workflow.createRunAsync();
|
|
1268
|
+
const result = await run.start({ inputData: { inputValue: 'test-input' } });
|
|
1269
|
+
|
|
1270
|
+
expect(step1Action).toHaveBeenCalled();
|
|
1271
|
+
expect(step2Action).toHaveBeenCalled();
|
|
1272
|
+
expect(result.steps).toMatchObject({
|
|
1273
|
+
input: { inputValue: 'test-input' },
|
|
1274
|
+
step1: { status: 'success', output: { value: 'step1-result' } },
|
|
1275
|
+
step2: { status: 'success', output: { value: 'step2-result' } },
|
|
1276
|
+
});
|
|
1277
|
+
|
|
1278
|
+
srv.close();
|
|
1279
|
+
});
|
|
1280
|
+
|
|
1281
|
+
it('should resolve trigger data from context', async ctx => {
|
|
1282
|
+
const inngest = new Inngest({
|
|
1283
|
+
id: 'mastra',
|
|
1284
|
+
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
1285
|
+
});
|
|
1286
|
+
|
|
1287
|
+
const { createWorkflow, createStep } = init(inngest);
|
|
1288
|
+
|
|
1289
|
+
const execute = vi.fn<any>().mockResolvedValue({ result: 'success' });
|
|
1290
|
+
const triggerSchema = z.object({
|
|
1291
|
+
inputData: z.string(),
|
|
1292
|
+
});
|
|
1293
|
+
|
|
1294
|
+
const step1 = createStep({
|
|
1295
|
+
id: 'step1',
|
|
1296
|
+
execute,
|
|
1297
|
+
inputSchema: triggerSchema,
|
|
1298
|
+
outputSchema: z.object({ result: z.string() }),
|
|
1299
|
+
});
|
|
1300
|
+
|
|
1301
|
+
const workflow = createWorkflow({
|
|
1302
|
+
id: 'test-workflow',
|
|
1303
|
+
inputSchema: triggerSchema,
|
|
1304
|
+
outputSchema: z.object({ result: z.string() }),
|
|
1305
|
+
});
|
|
1306
|
+
|
|
1307
|
+
workflow.then(step1).commit();
|
|
1308
|
+
|
|
1309
|
+
const mastra = new Mastra({
|
|
1310
|
+
storage: new DefaultStorage({
|
|
1311
|
+
url: ':memory:',
|
|
1312
|
+
}),
|
|
1313
|
+
workflows: {
|
|
1314
|
+
'test-workflow': workflow,
|
|
1315
|
+
},
|
|
1316
|
+
server: {
|
|
1317
|
+
apiRoutes: [
|
|
1318
|
+
{
|
|
1319
|
+
path: '/inngest/api',
|
|
1320
|
+
method: 'ALL',
|
|
1321
|
+
createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
|
|
1322
|
+
},
|
|
1323
|
+
],
|
|
1324
|
+
},
|
|
1325
|
+
});
|
|
1326
|
+
|
|
1327
|
+
const app = await createHonoServer(mastra);
|
|
1328
|
+
|
|
1329
|
+
const srv = (globServer = serve({
|
|
1330
|
+
fetch: app.fetch,
|
|
1331
|
+
port: (ctx as any).handlerPort,
|
|
1332
|
+
}));
|
|
1333
|
+
await resetInngest();
|
|
1334
|
+
|
|
1335
|
+
const run = await workflow.createRunAsync();
|
|
1336
|
+
await run.start({ inputData: { inputData: 'test-input' } });
|
|
1337
|
+
|
|
1338
|
+
expect(execute).toHaveBeenCalledWith(
|
|
1339
|
+
expect.objectContaining({
|
|
1340
|
+
inputData: { inputData: 'test-input' },
|
|
1341
|
+
}),
|
|
1342
|
+
);
|
|
954
1343
|
|
|
955
1344
|
srv.close();
|
|
956
1345
|
});
|
|
@@ -1013,10 +1402,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1013
1402
|
|
|
1014
1403
|
const app = await createHonoServer(mastra);
|
|
1015
1404
|
|
|
1016
|
-
const srv = serve({
|
|
1405
|
+
const srv = (globServer = serve({
|
|
1017
1406
|
fetch: app.fetch,
|
|
1018
1407
|
port: (ctx as any).handlerPort,
|
|
1019
|
-
});
|
|
1408
|
+
}));
|
|
1409
|
+
await resetInngest();
|
|
1020
1410
|
|
|
1021
1411
|
const run = await workflow.createRunAsync();
|
|
1022
1412
|
const result = await run.start({ inputData: { cool: 'test-input' } });
|
|
@@ -1095,10 +1485,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1095
1485
|
|
|
1096
1486
|
const app = await createHonoServer(mastra);
|
|
1097
1487
|
|
|
1098
|
-
const srv = serve({
|
|
1488
|
+
const srv = (globServer = serve({
|
|
1099
1489
|
fetch: app.fetch,
|
|
1100
1490
|
port: (ctx as any).handlerPort,
|
|
1101
|
-
});
|
|
1491
|
+
}));
|
|
1492
|
+
await resetInngest();
|
|
1102
1493
|
|
|
1103
1494
|
const run = await workflow.createRunAsync();
|
|
1104
1495
|
await run.start({ inputData: {} });
|
|
@@ -1198,10 +1589,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1198
1589
|
|
|
1199
1590
|
const app = await createHonoServer(mastra);
|
|
1200
1591
|
|
|
1201
|
-
const srv = serve({
|
|
1592
|
+
const srv = (globServer = serve({
|
|
1202
1593
|
fetch: app.fetch,
|
|
1203
1594
|
port: (ctx as any).handlerPort,
|
|
1204
|
-
});
|
|
1595
|
+
}));
|
|
1596
|
+
await resetInngest();
|
|
1205
1597
|
|
|
1206
1598
|
const run = await workflow.createRunAsync();
|
|
1207
1599
|
const result = await run.start({ inputData: { status: 'success' } });
|
|
@@ -1274,10 +1666,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1274
1666
|
|
|
1275
1667
|
const app = await createHonoServer(mastra);
|
|
1276
1668
|
|
|
1277
|
-
const srv = serve({
|
|
1669
|
+
const srv = (globServer = serve({
|
|
1278
1670
|
fetch: app.fetch,
|
|
1279
1671
|
port: (ctx as any).handlerPort,
|
|
1280
|
-
});
|
|
1672
|
+
}));
|
|
1673
|
+
await resetInngest();
|
|
1281
1674
|
|
|
1282
1675
|
const run = await workflow.createRunAsync();
|
|
1283
1676
|
let result: Awaited<ReturnType<typeof run.start>> | undefined = undefined;
|
|
@@ -1379,10 +1772,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1379
1772
|
|
|
1380
1773
|
const app = await createHonoServer(mastra);
|
|
1381
1774
|
|
|
1382
|
-
const srv = serve({
|
|
1775
|
+
const srv = (globServer = serve({
|
|
1383
1776
|
fetch: app.fetch,
|
|
1384
1777
|
port: (ctx as any).handlerPort,
|
|
1385
|
-
});
|
|
1778
|
+
}));
|
|
1779
|
+
await resetInngest();
|
|
1386
1780
|
|
|
1387
1781
|
const run = await workflow.createRunAsync();
|
|
1388
1782
|
const result = await run.start({ inputData: { status: 'success' } });
|
|
@@ -1462,10 +1856,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1462
1856
|
|
|
1463
1857
|
const app = await createHonoServer(mastra);
|
|
1464
1858
|
|
|
1465
|
-
const srv = serve({
|
|
1859
|
+
const srv = (globServer = serve({
|
|
1466
1860
|
fetch: app.fetch,
|
|
1467
1861
|
port: (ctx as any).handlerPort,
|
|
1468
|
-
});
|
|
1862
|
+
}));
|
|
1863
|
+
await resetInngest();
|
|
1469
1864
|
|
|
1470
1865
|
const run = await workflow.createRunAsync();
|
|
1471
1866
|
const result = await run.start({ inputData: { count: 5 } });
|
|
@@ -1529,11 +1924,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1529
1924
|
|
|
1530
1925
|
const app = await createHonoServer(mastra);
|
|
1531
1926
|
|
|
1532
|
-
const srv = serve({
|
|
1927
|
+
const srv = (globServer = serve({
|
|
1533
1928
|
fetch: app.fetch,
|
|
1534
1929
|
port: (ctx as any).handlerPort,
|
|
1535
|
-
});
|
|
1536
|
-
await
|
|
1930
|
+
}));
|
|
1931
|
+
await resetInngest();
|
|
1537
1932
|
|
|
1538
1933
|
const run = await workflow.createRunAsync();
|
|
1539
1934
|
|
|
@@ -1613,11 +2008,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1613
2008
|
|
|
1614
2009
|
const app = await createHonoServer(mastra);
|
|
1615
2010
|
|
|
1616
|
-
const srv = serve({
|
|
2011
|
+
const srv = (globServer = serve({
|
|
1617
2012
|
fetch: app.fetch,
|
|
1618
2013
|
port: (ctx as any).handlerPort,
|
|
1619
|
-
});
|
|
1620
|
-
await
|
|
2014
|
+
}));
|
|
2015
|
+
await resetInngest();
|
|
1621
2016
|
|
|
1622
2017
|
const run = await workflow.createRunAsync();
|
|
1623
2018
|
const result = await run.start({ inputData: {} });
|
|
@@ -1707,11 +2102,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1707
2102
|
|
|
1708
2103
|
const app = await createHonoServer(mastra);
|
|
1709
2104
|
|
|
1710
|
-
const srv = serve({
|
|
2105
|
+
const srv = (globServer = serve({
|
|
1711
2106
|
fetch: app.fetch,
|
|
1712
2107
|
port: (ctx as any).handlerPort,
|
|
1713
|
-
});
|
|
1714
|
-
await
|
|
2108
|
+
}));
|
|
2109
|
+
await resetInngest();
|
|
1715
2110
|
|
|
1716
2111
|
const run = await mainWorkflow.createRunAsync();
|
|
1717
2112
|
const result = await run.start({ inputData: {} });
|
|
@@ -1835,11 +2230,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1835
2230
|
|
|
1836
2231
|
const app = await createHonoServer(mastra);
|
|
1837
2232
|
|
|
1838
|
-
const srv = serve({
|
|
2233
|
+
const srv = (globServer = serve({
|
|
1839
2234
|
fetch: app.fetch,
|
|
1840
2235
|
port: (ctx as any).handlerPort,
|
|
1841
|
-
});
|
|
1842
|
-
await
|
|
2236
|
+
}));
|
|
2237
|
+
await resetInngest();
|
|
1843
2238
|
|
|
1844
2239
|
const run = await workflow.createRunAsync();
|
|
1845
2240
|
const result = await run.start({ inputData: {} });
|
|
@@ -1937,11 +2332,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1937
2332
|
|
|
1938
2333
|
const app = await createHonoServer(mastra);
|
|
1939
2334
|
|
|
1940
|
-
const srv = serve({
|
|
2335
|
+
const srv = (globServer = serve({
|
|
1941
2336
|
fetch: app.fetch,
|
|
1942
2337
|
port: (ctx as any).handlerPort,
|
|
1943
|
-
});
|
|
1944
|
-
await
|
|
2338
|
+
}));
|
|
2339
|
+
await resetInngest();
|
|
1945
2340
|
|
|
1946
2341
|
const run = await counterWorkflow.createRunAsync();
|
|
1947
2342
|
const result = await run.start({ inputData: { target: 10, value: 0 } });
|
|
@@ -2040,11 +2435,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2040
2435
|
|
|
2041
2436
|
const app = await createHonoServer(mastra);
|
|
2042
2437
|
|
|
2043
|
-
const srv = serve({
|
|
2438
|
+
const srv = (globServer = serve({
|
|
2044
2439
|
fetch: app.fetch,
|
|
2045
2440
|
port: (ctx as any).handlerPort,
|
|
2046
|
-
});
|
|
2047
|
-
await
|
|
2441
|
+
}));
|
|
2442
|
+
await resetInngest();
|
|
2048
2443
|
|
|
2049
2444
|
const run = await counterWorkflow.createRunAsync();
|
|
2050
2445
|
const result = await run.start({ inputData: { target: 10, value: 0 } });
|
|
@@ -2129,11 +2524,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2129
2524
|
|
|
2130
2525
|
const app = await createHonoServer(mastra);
|
|
2131
2526
|
|
|
2132
|
-
const srv = serve({
|
|
2527
|
+
const srv = (globServer = serve({
|
|
2133
2528
|
fetch: app.fetch,
|
|
2134
2529
|
port: (ctx as any).handlerPort,
|
|
2135
|
-
});
|
|
2136
|
-
await
|
|
2530
|
+
}));
|
|
2531
|
+
await resetInngest();
|
|
2137
2532
|
|
|
2138
2533
|
const run = await counterWorkflow.createRunAsync();
|
|
2139
2534
|
const result = await run.start({ inputData: [{ value: 1 }, { value: 22 }, { value: 333 }] });
|
|
@@ -2282,11 +2677,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2282
2677
|
|
|
2283
2678
|
const app = await createHonoServer(mastra);
|
|
2284
2679
|
|
|
2285
|
-
const srv = serve({
|
|
2680
|
+
const srv = (globServer = serve({
|
|
2286
2681
|
fetch: app.fetch,
|
|
2287
2682
|
port: (ctx as any).handlerPort,
|
|
2288
|
-
});
|
|
2289
|
-
await
|
|
2683
|
+
}));
|
|
2684
|
+
await resetInngest();
|
|
2290
2685
|
|
|
2291
2686
|
const run = await counterWorkflow.createRunAsync();
|
|
2292
2687
|
const result = await run.start({ inputData: { startValue: 1 } });
|
|
@@ -2431,15 +2826,17 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2431
2826
|
|
|
2432
2827
|
const app = await createHonoServer(mastra);
|
|
2433
2828
|
|
|
2434
|
-
const srv = serve({
|
|
2829
|
+
const srv = (globServer = serve({
|
|
2435
2830
|
fetch: app.fetch,
|
|
2436
2831
|
port: (ctx as any).handlerPort,
|
|
2437
|
-
});
|
|
2438
|
-
await
|
|
2832
|
+
}));
|
|
2833
|
+
await resetInngest();
|
|
2439
2834
|
|
|
2440
2835
|
const run = await counterWorkflow.createRunAsync();
|
|
2441
2836
|
const result = await run.start({ inputData: { startValue: 6 } });
|
|
2442
2837
|
|
|
2838
|
+
srv.close();
|
|
2839
|
+
|
|
2443
2840
|
expect(start).toHaveBeenCalledTimes(1);
|
|
2444
2841
|
expect(other).toHaveBeenCalledTimes(1);
|
|
2445
2842
|
expect(final).toHaveBeenCalledTimes(1);
|
|
@@ -2447,8 +2844,6 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2447
2844
|
expect(result.steps['else-branch'].output).toMatchObject({ finalValue: 26 + 6 + 1 });
|
|
2448
2845
|
// @ts-ignore
|
|
2449
2846
|
expect(result.steps.start.output).toMatchObject({ newValue: 7 });
|
|
2450
|
-
|
|
2451
|
-
srv.close();
|
|
2452
2847
|
});
|
|
2453
2848
|
});
|
|
2454
2849
|
|
|
@@ -2603,19 +2998,19 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2603
2998
|
|
|
2604
2999
|
const app = await createHonoServer(mastra);
|
|
2605
3000
|
|
|
2606
|
-
const srv = serve({
|
|
3001
|
+
const srv = (globServer = serve({
|
|
2607
3002
|
fetch: app.fetch,
|
|
2608
3003
|
port: (ctx as any).handlerPort,
|
|
2609
|
-
});
|
|
2610
|
-
await
|
|
3004
|
+
}));
|
|
3005
|
+
await resetInngest();
|
|
2611
3006
|
|
|
2612
3007
|
const run = await workflow.createRunAsync();
|
|
2613
3008
|
const result = await run.start({ inputData: {} });
|
|
2614
3009
|
|
|
2615
|
-
expect(result.steps['nested-a']).toMatchObject({ status: 'success', output: { result: 'success3' } });
|
|
2616
|
-
expect(result.steps['nested-b']).toMatchObject({ status: 'success', output: { result: 'success5' } });
|
|
2617
|
-
|
|
2618
3010
|
srv.close();
|
|
3011
|
+
|
|
3012
|
+
expect(result.steps['nested-a']).toMatchObject({ status: 'success', output: { result: 'success3' } });
|
|
3013
|
+
expect(result.steps['nested-b']).toMatchObject({ status: 'success', output: { result: 'success5' } });
|
|
2619
3014
|
});
|
|
2620
3015
|
});
|
|
2621
3016
|
|
|
@@ -2669,21 +3064,21 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2669
3064
|
|
|
2670
3065
|
const app = await createHonoServer(mastra);
|
|
2671
3066
|
|
|
2672
|
-
const srv = serve({
|
|
3067
|
+
const srv = (globServer = serve({
|
|
2673
3068
|
fetch: app.fetch,
|
|
2674
3069
|
port: (ctx as any).handlerPort,
|
|
2675
|
-
});
|
|
2676
|
-
await
|
|
3070
|
+
}));
|
|
3071
|
+
await resetInngest();
|
|
2677
3072
|
|
|
2678
3073
|
const run = await workflow.createRunAsync();
|
|
2679
3074
|
const result = await run.start({ inputData: {} });
|
|
2680
3075
|
|
|
3076
|
+
srv.close();
|
|
3077
|
+
|
|
2681
3078
|
expect(result.steps.step1).toMatchObject({ status: 'success', output: { result: 'success' } });
|
|
2682
3079
|
expect(result.steps.step2).toMatchObject({ status: 'failed', error: 'Step failed' });
|
|
2683
3080
|
expect(step1.execute).toHaveBeenCalledTimes(1);
|
|
2684
3081
|
expect(step2.execute).toHaveBeenCalledTimes(1); // 0 retries + 1 initial call
|
|
2685
|
-
|
|
2686
|
-
srv.close();
|
|
2687
3082
|
});
|
|
2688
3083
|
|
|
2689
3084
|
// Need to fix so we can throw for inngest to recognize retries
|
|
@@ -2801,11 +3196,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2801
3196
|
|
|
2802
3197
|
const app = await createHonoServer(mastra);
|
|
2803
3198
|
|
|
2804
|
-
const srv = serve({
|
|
3199
|
+
const srv = (globServer = serve({
|
|
2805
3200
|
fetch: app.fetch,
|
|
2806
3201
|
port: (ctx as any).handlerPort,
|
|
2807
|
-
});
|
|
2808
|
-
await
|
|
3202
|
+
}));
|
|
3203
|
+
await resetInngest();
|
|
2809
3204
|
|
|
2810
3205
|
const run = await workflow.createRunAsync();
|
|
2811
3206
|
const result = await run.start({ inputData: {} });
|
|
@@ -2873,11 +3268,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2873
3268
|
|
|
2874
3269
|
const app = await createHonoServer(mastra);
|
|
2875
3270
|
|
|
2876
|
-
const srv = serve({
|
|
3271
|
+
const srv = (globServer = serve({
|
|
2877
3272
|
fetch: app.fetch,
|
|
2878
3273
|
port: (ctx as any).handlerPort,
|
|
2879
|
-
});
|
|
2880
|
-
await
|
|
3274
|
+
}));
|
|
3275
|
+
await resetInngest();
|
|
2881
3276
|
|
|
2882
3277
|
const run = await workflow.createRunAsync();
|
|
2883
3278
|
|
|
@@ -2890,7 +3285,9 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2890
3285
|
});
|
|
2891
3286
|
|
|
2892
3287
|
const executionResult = await run.start({ inputData: {} });
|
|
2893
|
-
await new Promise(resolve => setTimeout(resolve,
|
|
3288
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
3289
|
+
|
|
3290
|
+
srv.close();
|
|
2894
3291
|
|
|
2895
3292
|
expect(cnt).toBe(5);
|
|
2896
3293
|
expect(resps.length).toBe(5);
|
|
@@ -3002,8 +3399,6 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3002
3399
|
status: 'success',
|
|
3003
3400
|
output: { result: 'success2' },
|
|
3004
3401
|
});
|
|
3005
|
-
|
|
3006
|
-
srv.close();
|
|
3007
3402
|
});
|
|
3008
3403
|
|
|
3009
3404
|
it('should unsubscribe from transitions when unwatch is called', async ctx => {
|
|
@@ -3059,11 +3454,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3059
3454
|
|
|
3060
3455
|
const app = await createHonoServer(mastra);
|
|
3061
3456
|
|
|
3062
|
-
const srv = serve({
|
|
3457
|
+
const srv = (globServer = serve({
|
|
3063
3458
|
fetch: app.fetch,
|
|
3064
3459
|
port: (ctx as any).handlerPort,
|
|
3065
|
-
});
|
|
3066
|
-
await
|
|
3460
|
+
}));
|
|
3461
|
+
await resetInngest();
|
|
3067
3462
|
|
|
3068
3463
|
const onTransition = vi.fn();
|
|
3069
3464
|
const onTransition2 = vi.fn();
|
|
@@ -3231,11 +3626,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3231
3626
|
|
|
3232
3627
|
const app = await createHonoServer(mastra);
|
|
3233
3628
|
|
|
3234
|
-
const srv = serve({
|
|
3629
|
+
const srv = (globServer = serve({
|
|
3235
3630
|
fetch: app.fetch,
|
|
3236
3631
|
port: (ctx as any).handlerPort,
|
|
3237
|
-
});
|
|
3238
|
-
await
|
|
3632
|
+
}));
|
|
3633
|
+
await resetInngest();
|
|
3239
3634
|
|
|
3240
3635
|
const run = await promptEvalWorkflow.createRunAsync();
|
|
3241
3636
|
|
|
@@ -3381,11 +3776,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3381
3776
|
|
|
3382
3777
|
const app = await createHonoServer(mastra);
|
|
3383
3778
|
|
|
3384
|
-
const srv = serve({
|
|
3779
|
+
const srv = (globServer = serve({
|
|
3385
3780
|
fetch: app.fetch,
|
|
3386
3781
|
port: (ctx as any).handlerPort,
|
|
3387
|
-
});
|
|
3388
|
-
await
|
|
3782
|
+
}));
|
|
3783
|
+
await resetInngest();
|
|
3389
3784
|
|
|
3390
3785
|
const run = await workflow.createRunAsync();
|
|
3391
3786
|
|
|
@@ -3419,13 +3814,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3419
3814
|
|
|
3420
3815
|
const initialResult = await started;
|
|
3421
3816
|
|
|
3817
|
+
srv.close();
|
|
3818
|
+
|
|
3422
3819
|
expect(initialResult.steps.humanIntervention.status).toBe('suspended');
|
|
3423
3820
|
expect(initialResult.steps.explainResponse).toBeUndefined();
|
|
3424
3821
|
expect(humanInterventionAction).toHaveBeenCalledTimes(2);
|
|
3425
3822
|
expect(explainResponseAction).not.toHaveBeenCalled();
|
|
3426
3823
|
|
|
3427
|
-
srv.close();
|
|
3428
|
-
|
|
3429
3824
|
if (!result) {
|
|
3430
3825
|
throw new Error('Resume failed to return a result');
|
|
3431
3826
|
}
|
|
@@ -3583,11 +3978,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3583
3978
|
|
|
3584
3979
|
const app = await createHonoServer(mastra);
|
|
3585
3980
|
|
|
3586
|
-
const srv = serve({
|
|
3981
|
+
const srv = (globServer = serve({
|
|
3587
3982
|
fetch: app.fetch,
|
|
3588
3983
|
port: (ctx as any).handlerPort,
|
|
3589
|
-
});
|
|
3590
|
-
await
|
|
3984
|
+
}));
|
|
3985
|
+
await resetInngest();
|
|
3591
3986
|
|
|
3592
3987
|
const run = await workflow.createRunAsync();
|
|
3593
3988
|
const started = run.start({ inputData: { input: 'test' } });
|
|
@@ -3640,11 +4035,12 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3640
4035
|
// @ts-ignore
|
|
3641
4036
|
const improvedResponseResult = await improvedResponseResultPromise;
|
|
3642
4037
|
|
|
4038
|
+
srv.close();
|
|
4039
|
+
|
|
3643
4040
|
expect(improvedResponseResult?.steps.humanIntervention.status).toBe('suspended');
|
|
3644
4041
|
expect(improvedResponseResult?.steps.improveResponse.status).toBe('success');
|
|
3645
4042
|
expect(improvedResponseResult?.steps.evaluateImprovedResponse.status).toBe('success');
|
|
3646
4043
|
|
|
3647
|
-
srv.close();
|
|
3648
4044
|
if (!result) {
|
|
3649
4045
|
throw new Error('Resume failed to return a result');
|
|
3650
4046
|
}
|
|
@@ -3777,11 +4173,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3777
4173
|
|
|
3778
4174
|
const app = await createHonoServer(mastra);
|
|
3779
4175
|
|
|
3780
|
-
const srv = serve({
|
|
4176
|
+
const srv = (globServer = serve({
|
|
3781
4177
|
fetch: app.fetch,
|
|
3782
4178
|
port: (ctx as any).handlerPort,
|
|
3783
|
-
});
|
|
3784
|
-
await
|
|
4179
|
+
}));
|
|
4180
|
+
await resetInngest();
|
|
3785
4181
|
|
|
3786
4182
|
const run = await promptEvalWorkflow.createRunAsync();
|
|
3787
4183
|
|
|
@@ -3836,6 +4232,9 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3836
4232
|
completenessScore: { score: 0.7 },
|
|
3837
4233
|
},
|
|
3838
4234
|
});
|
|
4235
|
+
|
|
4236
|
+
srv.close();
|
|
4237
|
+
|
|
3839
4238
|
if (!secondResumeResult) {
|
|
3840
4239
|
throw new Error('Resume failed to return a result');
|
|
3841
4240
|
}
|
|
@@ -3858,6 +4257,122 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3858
4257
|
});
|
|
3859
4258
|
|
|
3860
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
|
+
});
|
|
3861
4376
|
|
|
3862
4377
|
srv.close();
|
|
3863
4378
|
});
|
|
@@ -3905,11 +4420,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3905
4420
|
|
|
3906
4421
|
const app = await createHonoServer(mastra);
|
|
3907
4422
|
|
|
3908
|
-
const srv = serve({
|
|
4423
|
+
const srv = (globServer = serve({
|
|
3909
4424
|
fetch: app.fetch,
|
|
3910
4425
|
port: (ctx as any).handlerPort,
|
|
3911
|
-
});
|
|
3912
|
-
await
|
|
4426
|
+
}));
|
|
4427
|
+
await resetInngest();
|
|
3913
4428
|
|
|
3914
4429
|
// Access new instance properties directly - should work without warning
|
|
3915
4430
|
const run = await workflow.createRunAsync();
|
|
@@ -4009,11 +4524,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
4009
4524
|
|
|
4010
4525
|
const app = await createHonoServer(mastra);
|
|
4011
4526
|
|
|
4012
|
-
const srv = serve({
|
|
4527
|
+
const srv = (globServer = serve({
|
|
4013
4528
|
fetch: app.fetch,
|
|
4014
4529
|
port: (ctx as any).handlerPort,
|
|
4015
|
-
});
|
|
4016
|
-
await
|
|
4530
|
+
}));
|
|
4531
|
+
await resetInngest();
|
|
4017
4532
|
|
|
4018
4533
|
const run = await workflow.createRunAsync();
|
|
4019
4534
|
const result = await run.start({
|
|
@@ -4146,11 +4661,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
4146
4661
|
|
|
4147
4662
|
const app = await createHonoServer(mastra);
|
|
4148
4663
|
|
|
4149
|
-
const srv = serve({
|
|
4664
|
+
const srv = (globServer = serve({
|
|
4150
4665
|
fetch: app.fetch,
|
|
4151
4666
|
port: (ctx as any).handlerPort,
|
|
4152
|
-
});
|
|
4153
|
-
await
|
|
4667
|
+
}));
|
|
4668
|
+
await resetInngest();
|
|
4154
4669
|
|
|
4155
4670
|
const run = await workflow.createRunAsync();
|
|
4156
4671
|
const result = await run.start({
|
|
@@ -4289,11 +4804,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
4289
4804
|
|
|
4290
4805
|
const app = await createHonoServer(mastra);
|
|
4291
4806
|
|
|
4292
|
-
const srv = serve({
|
|
4807
|
+
const srv = (globServer = serve({
|
|
4293
4808
|
fetch: app.fetch,
|
|
4294
4809
|
port: (ctx as any).handlerPort,
|
|
4295
|
-
});
|
|
4296
|
-
await
|
|
4810
|
+
}));
|
|
4811
|
+
await resetInngest();
|
|
4297
4812
|
|
|
4298
4813
|
const run = await counterWorkflow.createRunAsync();
|
|
4299
4814
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
@@ -4441,11 +4956,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
4441
4956
|
|
|
4442
4957
|
const app = await createHonoServer(mastra);
|
|
4443
4958
|
|
|
4444
|
-
const srv = serve({
|
|
4959
|
+
const srv = (globServer = serve({
|
|
4445
4960
|
fetch: app.fetch,
|
|
4446
4961
|
port: (ctx as any).handlerPort,
|
|
4447
|
-
});
|
|
4448
|
-
await
|
|
4962
|
+
}));
|
|
4963
|
+
await resetInngest();
|
|
4449
4964
|
|
|
4450
4965
|
const run = await counterWorkflow.createRunAsync();
|
|
4451
4966
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
@@ -4601,10 +5116,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
4601
5116
|
await next();
|
|
4602
5117
|
});
|
|
4603
5118
|
|
|
4604
|
-
const srv = serve({
|
|
5119
|
+
const srv = (globServer = serve({
|
|
4605
5120
|
fetch: app.fetch,
|
|
4606
5121
|
port: (ctx as any).handlerPort,
|
|
4607
|
-
});
|
|
5122
|
+
}));
|
|
5123
|
+
await resetInngest();
|
|
4608
5124
|
|
|
4609
5125
|
const run = await counterWorkflow.createRunAsync();
|
|
4610
5126
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
@@ -4760,10 +5276,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
4760
5276
|
await next();
|
|
4761
5277
|
});
|
|
4762
5278
|
|
|
4763
|
-
const srv = serve({
|
|
5279
|
+
const srv = (globServer = serve({
|
|
4764
5280
|
fetch: app.fetch,
|
|
4765
5281
|
port: (ctx as any).handlerPort,
|
|
4766
|
-
});
|
|
5282
|
+
}));
|
|
5283
|
+
await resetInngest();
|
|
4767
5284
|
|
|
4768
5285
|
const run = await counterWorkflow.createRunAsync();
|
|
4769
5286
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
@@ -4957,10 +5474,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
4957
5474
|
await next();
|
|
4958
5475
|
});
|
|
4959
5476
|
|
|
4960
|
-
const srv = serve({
|
|
5477
|
+
const srv = (globServer = serve({
|
|
4961
5478
|
fetch: app.fetch,
|
|
4962
5479
|
port: (ctx as any).handlerPort,
|
|
4963
|
-
});
|
|
5480
|
+
}));
|
|
5481
|
+
await resetInngest();
|
|
4964
5482
|
|
|
4965
5483
|
const run = await counterWorkflow.createRunAsync();
|
|
4966
5484
|
const result = await run.start({ inputData: { startValue: 1 } });
|
|
@@ -5110,11 +5628,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5110
5628
|
|
|
5111
5629
|
const app = await createHonoServer(mastra);
|
|
5112
5630
|
|
|
5113
|
-
const srv = serve({
|
|
5631
|
+
const srv = (globServer = serve({
|
|
5114
5632
|
fetch: app.fetch,
|
|
5115
5633
|
port: (ctx as any).handlerPort,
|
|
5116
|
-
});
|
|
5117
|
-
await
|
|
5634
|
+
}));
|
|
5635
|
+
await resetInngest();
|
|
5118
5636
|
|
|
5119
5637
|
const run = await counterWorkflow.createRunAsync();
|
|
5120
5638
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
@@ -5261,10 +5779,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5261
5779
|
await next();
|
|
5262
5780
|
});
|
|
5263
5781
|
|
|
5264
|
-
const srv = serve({
|
|
5782
|
+
const srv = (globServer = serve({
|
|
5265
5783
|
fetch: app.fetch,
|
|
5266
5784
|
port: (ctx as any).handlerPort,
|
|
5267
|
-
});
|
|
5785
|
+
}));
|
|
5786
|
+
await resetInngest();
|
|
5268
5787
|
|
|
5269
5788
|
const run = await counterWorkflow.createRunAsync();
|
|
5270
5789
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
@@ -5442,11 +5961,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5442
5961
|
|
|
5443
5962
|
const app = await createHonoServer(mastra);
|
|
5444
5963
|
|
|
5445
|
-
const srv = serve({
|
|
5964
|
+
const srv = (globServer = serve({
|
|
5446
5965
|
fetch: app.fetch,
|
|
5447
5966
|
port: (ctx as any).handlerPort,
|
|
5448
|
-
});
|
|
5449
|
-
await
|
|
5967
|
+
}));
|
|
5968
|
+
await resetInngest();
|
|
5450
5969
|
|
|
5451
5970
|
const run = await counterWorkflow.createRunAsync();
|
|
5452
5971
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
@@ -5604,11 +6123,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5604
6123
|
|
|
5605
6124
|
const app = await createHonoServer(mastra);
|
|
5606
6125
|
|
|
5607
|
-
const srv = serve({
|
|
6126
|
+
const srv = (globServer = serve({
|
|
5608
6127
|
fetch: app.fetch,
|
|
5609
6128
|
port: (ctx as any).handlerPort,
|
|
5610
|
-
});
|
|
5611
|
-
await
|
|
6129
|
+
}));
|
|
6130
|
+
await resetInngest();
|
|
5612
6131
|
|
|
5613
6132
|
const run = await counterWorkflow.createRunAsync();
|
|
5614
6133
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
@@ -5679,11 +6198,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5679
6198
|
|
|
5680
6199
|
const app = await createHonoServer(mastra);
|
|
5681
6200
|
|
|
5682
|
-
const srv = serve({
|
|
6201
|
+
const srv = (globServer = serve({
|
|
5683
6202
|
fetch: app.fetch,
|
|
5684
6203
|
port: (ctx as any).handlerPort,
|
|
5685
|
-
});
|
|
5686
|
-
await
|
|
6204
|
+
}));
|
|
6205
|
+
await resetInngest();
|
|
5687
6206
|
|
|
5688
6207
|
// Access new instance properties directly - should work without warning
|
|
5689
6208
|
const run = await workflow.createRunAsync();
|
|
@@ -5742,10 +6261,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5742
6261
|
|
|
5743
6262
|
const app = await createHonoServer(mastra);
|
|
5744
6263
|
|
|
5745
|
-
const srv = serve({
|
|
6264
|
+
const srv = (globServer = serve({
|
|
5746
6265
|
fetch: app.fetch,
|
|
5747
6266
|
port: (ctx as any).handlerPort,
|
|
5748
|
-
});
|
|
6267
|
+
}));
|
|
6268
|
+
await resetInngest();
|
|
5749
6269
|
|
|
5750
6270
|
const run = await workflow.createRunAsync();
|
|
5751
6271
|
const result = await run.start({ runtimeContext });
|
|
@@ -5756,7 +6276,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5756
6276
|
expect(result.steps.step1.output.injectedValue).toBe(testValue);
|
|
5757
6277
|
});
|
|
5758
6278
|
|
|
5759
|
-
it('should inject runtimeContext dependencies into steps during resume', async ctx => {
|
|
6279
|
+
it.skip('should inject runtimeContext dependencies into steps during resume', async ctx => {
|
|
5760
6280
|
const inngest = new Inngest({
|
|
5761
6281
|
id: 'mastra',
|
|
5762
6282
|
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
@@ -5817,6 +6337,176 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5817
6337
|
// @ts-ignore
|
|
5818
6338
|
expect(result?.steps.step1.output.injectedValue).toBe(testValue + '2');
|
|
5819
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
|
+
});
|
|
5820
6510
|
});
|
|
5821
6511
|
|
|
5822
6512
|
describe('Access to inngest step primitives', () => {
|
|
@@ -5841,11 +6531,81 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5841
6531
|
const workflow = createWorkflow({
|
|
5842
6532
|
id: 'test-workflow',
|
|
5843
6533
|
inputSchema: z.object({}),
|
|
5844
|
-
outputSchema: z.object({
|
|
5845
|
-
hasEngine: z.boolean(),
|
|
5846
|
-
}),
|
|
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],
|
|
5847
6607
|
});
|
|
5848
|
-
workflow.then(
|
|
6608
|
+
workflow.then(step1).then(step2).commit();
|
|
5849
6609
|
|
|
5850
6610
|
const mastra = new Mastra({
|
|
5851
6611
|
storage: new DefaultStorage({
|
|
@@ -5867,23 +6627,126 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5867
6627
|
|
|
5868
6628
|
const app = await createHonoServer(mastra);
|
|
5869
6629
|
|
|
5870
|
-
const srv = serve({
|
|
6630
|
+
const srv = (globServer = serve({
|
|
5871
6631
|
fetch: app.fetch,
|
|
5872
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,
|
|
5873
6640
|
});
|
|
5874
6641
|
|
|
5875
|
-
|
|
5876
|
-
|
|
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();
|
|
5877
6656
|
|
|
5878
6657
|
srv.close();
|
|
5879
6658
|
|
|
5880
|
-
|
|
5881
|
-
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
|
+
});
|
|
5882
6747
|
});
|
|
5883
|
-
});
|
|
5884
6748
|
|
|
5885
|
-
|
|
5886
|
-
it('should generate a stream', async ctx => {
|
|
6749
|
+
it('should handle basic sleep waiting flow', async ctx => {
|
|
5887
6750
|
const inngest = new Inngest({
|
|
5888
6751
|
id: 'mastra',
|
|
5889
6752
|
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
@@ -5914,7 +6777,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5914
6777
|
outputSchema: z.object({}),
|
|
5915
6778
|
steps: [step1, step2],
|
|
5916
6779
|
});
|
|
5917
|
-
workflow.then(step1).then(step2).commit();
|
|
6780
|
+
workflow.then(step1).sleep(1000).then(step2).commit();
|
|
5918
6781
|
|
|
5919
6782
|
const mastra = new Mastra({
|
|
5920
6783
|
storage: new DefaultStorage({
|
|
@@ -5936,10 +6799,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5936
6799
|
|
|
5937
6800
|
const app = await createHonoServer(mastra);
|
|
5938
6801
|
|
|
5939
|
-
const srv = serve({
|
|
6802
|
+
const srv = (globServer = serve({
|
|
5940
6803
|
fetch: app.fetch,
|
|
5941
6804
|
port: (ctx as any).handlerPort,
|
|
5942
|
-
});
|
|
6805
|
+
}));
|
|
6806
|
+
await resetInngest();
|
|
5943
6807
|
|
|
5944
6808
|
const runId = 'test-run-id';
|
|
5945
6809
|
let watchData: StreamEvent[] = [];
|
|
@@ -5947,7 +6811,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5947
6811
|
runId,
|
|
5948
6812
|
});
|
|
5949
6813
|
|
|
5950
|
-
await
|
|
6814
|
+
await resetInngest();
|
|
5951
6815
|
|
|
5952
6816
|
const { stream, getWorkflowState } = run.stream({ inputData: {} });
|
|
5953
6817
|
|
|
@@ -5960,73 +6824,112 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5960
6824
|
|
|
5961
6825
|
const executionResult = await getWorkflowState();
|
|
5962
6826
|
|
|
5963
|
-
await
|
|
6827
|
+
await resetInngest();
|
|
5964
6828
|
|
|
5965
6829
|
srv.close();
|
|
5966
6830
|
|
|
5967
|
-
expect(watchData.length).toBe(
|
|
5968
|
-
expect(watchData).
|
|
5969
|
-
|
|
5970
|
-
{
|
|
5971
|
-
|
|
5972
|
-
"runId": "test-run-id",
|
|
5973
|
-
},
|
|
5974
|
-
"type": "start",
|
|
6831
|
+
expect(watchData.length).toBe(11);
|
|
6832
|
+
expect(watchData).toMatchObject([
|
|
6833
|
+
{
|
|
6834
|
+
payload: {
|
|
6835
|
+
runId: 'test-run-id',
|
|
5975
6836
|
},
|
|
5976
|
-
|
|
5977
|
-
|
|
5978
|
-
|
|
5979
|
-
|
|
5980
|
-
|
|
6837
|
+
type: 'start',
|
|
6838
|
+
},
|
|
6839
|
+
{
|
|
6840
|
+
payload: {
|
|
6841
|
+
id: 'step1',
|
|
6842
|
+
startedAt: expect.any(Number),
|
|
6843
|
+
status: 'running',
|
|
6844
|
+
payload: {},
|
|
5981
6845
|
},
|
|
5982
|
-
|
|
5983
|
-
|
|
5984
|
-
|
|
5985
|
-
|
|
5986
|
-
|
|
5987
|
-
|
|
5988
|
-
|
|
6846
|
+
type: 'step-start',
|
|
6847
|
+
},
|
|
6848
|
+
{
|
|
6849
|
+
payload: {
|
|
6850
|
+
id: 'step1',
|
|
6851
|
+
output: {
|
|
6852
|
+
result: 'success1',
|
|
5989
6853
|
},
|
|
5990
|
-
|
|
6854
|
+
endedAt: expect.any(Number),
|
|
6855
|
+
status: 'success',
|
|
5991
6856
|
},
|
|
5992
|
-
|
|
5993
|
-
|
|
5994
|
-
|
|
5995
|
-
|
|
5996
|
-
|
|
5997
|
-
|
|
6857
|
+
type: 'step-result',
|
|
6858
|
+
},
|
|
6859
|
+
{
|
|
6860
|
+
payload: {
|
|
6861
|
+
id: 'step1',
|
|
6862
|
+
metadata: {},
|
|
5998
6863
|
},
|
|
5999
|
-
|
|
6000
|
-
|
|
6001
|
-
|
|
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',
|
|
6002
6873
|
},
|
|
6003
|
-
"type": "step-start",
|
|
6004
6874
|
},
|
|
6005
|
-
|
|
6006
|
-
|
|
6007
|
-
|
|
6008
|
-
|
|
6009
|
-
|
|
6010
|
-
|
|
6011
|
-
|
|
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',
|
|
6012
6885
|
},
|
|
6013
|
-
"type": "step-result",
|
|
6014
6886
|
},
|
|
6015
|
-
|
|
6016
|
-
|
|
6017
|
-
|
|
6018
|
-
|
|
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',
|
|
6019
6901
|
},
|
|
6020
|
-
|
|
6902
|
+
startedAt: expect.any(Number),
|
|
6903
|
+
status: 'running',
|
|
6021
6904
|
},
|
|
6022
|
-
|
|
6023
|
-
|
|
6024
|
-
|
|
6905
|
+
type: 'step-start',
|
|
6906
|
+
},
|
|
6907
|
+
{
|
|
6908
|
+
payload: {
|
|
6909
|
+
id: 'step2',
|
|
6910
|
+
output: {
|
|
6911
|
+
result: 'success2',
|
|
6025
6912
|
},
|
|
6026
|
-
|
|
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',
|
|
6027
6928
|
},
|
|
6028
|
-
|
|
6029
|
-
|
|
6929
|
+
type: 'finish',
|
|
6930
|
+
},
|
|
6931
|
+
]);
|
|
6932
|
+
|
|
6030
6933
|
// Verify execution completed successfully
|
|
6031
6934
|
expect(executionResult.steps.step1).toMatchObject({
|
|
6032
6935
|
status: 'success',
|
|
@@ -6046,7 +6949,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6046
6949
|
});
|
|
6047
6950
|
});
|
|
6048
6951
|
|
|
6049
|
-
it('should handle basic sleep waiting flow', async ctx => {
|
|
6952
|
+
it('should handle basic sleep waiting flow with fn parameter', async ctx => {
|
|
6050
6953
|
const inngest = new Inngest({
|
|
6051
6954
|
id: 'mastra',
|
|
6052
6955
|
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
@@ -6055,19 +6958,19 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6055
6958
|
|
|
6056
6959
|
const { createWorkflow, createStep } = init(inngest);
|
|
6057
6960
|
|
|
6058
|
-
const step1Action = vi.fn<any>().mockResolvedValue({
|
|
6059
|
-
const step2Action = vi.fn<any>().mockResolvedValue({
|
|
6961
|
+
const step1Action = vi.fn<any>().mockResolvedValue({ value: 1000 });
|
|
6962
|
+
const step2Action = vi.fn<any>().mockResolvedValue({ value: 2000 });
|
|
6060
6963
|
|
|
6061
6964
|
const step1 = createStep({
|
|
6062
6965
|
id: 'step1',
|
|
6063
6966
|
execute: step1Action,
|
|
6064
6967
|
inputSchema: z.object({}),
|
|
6065
|
-
outputSchema: z.object({ value: z.
|
|
6968
|
+
outputSchema: z.object({ value: z.number() }),
|
|
6066
6969
|
});
|
|
6067
6970
|
const step2 = createStep({
|
|
6068
6971
|
id: 'step2',
|
|
6069
6972
|
execute: step2Action,
|
|
6070
|
-
inputSchema: z.object({ value: z.
|
|
6973
|
+
inputSchema: z.object({ value: z.number() }),
|
|
6071
6974
|
outputSchema: z.object({}),
|
|
6072
6975
|
});
|
|
6073
6976
|
|
|
@@ -6077,7 +6980,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6077
6980
|
outputSchema: z.object({}),
|
|
6078
6981
|
steps: [step1, step2],
|
|
6079
6982
|
});
|
|
6080
|
-
workflow
|
|
6983
|
+
workflow
|
|
6984
|
+
.then(step1)
|
|
6985
|
+
.sleep(async ({ inputData }) => {
|
|
6986
|
+
return inputData.value;
|
|
6987
|
+
})
|
|
6988
|
+
.then(step2)
|
|
6989
|
+
.commit();
|
|
6081
6990
|
|
|
6082
6991
|
const mastra = new Mastra({
|
|
6083
6992
|
storage: new DefaultStorage({
|
|
@@ -6099,10 +7008,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6099
7008
|
|
|
6100
7009
|
const app = await createHonoServer(mastra);
|
|
6101
7010
|
|
|
6102
|
-
const srv = serve({
|
|
7011
|
+
const srv = (globServer = serve({
|
|
6103
7012
|
fetch: app.fetch,
|
|
6104
7013
|
port: (ctx as any).handlerPort,
|
|
6105
|
-
});
|
|
7014
|
+
}));
|
|
7015
|
+
await resetInngest();
|
|
6106
7016
|
|
|
6107
7017
|
const runId = 'test-run-id';
|
|
6108
7018
|
let watchData: StreamEvent[] = [];
|
|
@@ -6110,7 +7020,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6110
7020
|
runId,
|
|
6111
7021
|
});
|
|
6112
7022
|
|
|
6113
|
-
await
|
|
7023
|
+
await resetInngest();
|
|
6114
7024
|
|
|
6115
7025
|
const { stream, getWorkflowState } = run.stream({ inputData: {} });
|
|
6116
7026
|
|
|
@@ -6123,11 +7033,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6123
7033
|
|
|
6124
7034
|
const executionResult = await getWorkflowState();
|
|
6125
7035
|
|
|
6126
|
-
await
|
|
7036
|
+
await resetInngest();
|
|
6127
7037
|
|
|
6128
7038
|
srv.close();
|
|
6129
7039
|
|
|
6130
|
-
expect(watchData.length).toBe(
|
|
7040
|
+
expect(watchData.length).toBe(11);
|
|
6131
7041
|
expect(watchData).toMatchObject([
|
|
6132
7042
|
{
|
|
6133
7043
|
payload: {
|
|
@@ -6138,6 +7048,9 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6138
7048
|
{
|
|
6139
7049
|
payload: {
|
|
6140
7050
|
id: 'step1',
|
|
7051
|
+
startedAt: expect.any(Number),
|
|
7052
|
+
status: 'running',
|
|
7053
|
+
payload: {},
|
|
6141
7054
|
},
|
|
6142
7055
|
type: 'step-start',
|
|
6143
7056
|
},
|
|
@@ -6145,8 +7058,9 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6145
7058
|
payload: {
|
|
6146
7059
|
id: 'step1',
|
|
6147
7060
|
output: {
|
|
6148
|
-
|
|
7061
|
+
value: 1000,
|
|
6149
7062
|
},
|
|
7063
|
+
endedAt: expect.any(Number),
|
|
6150
7064
|
status: 'success',
|
|
6151
7065
|
},
|
|
6152
7066
|
type: 'step-result',
|
|
@@ -6159,12 +7073,43 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6159
7073
|
type: 'step-finish',
|
|
6160
7074
|
},
|
|
6161
7075
|
{
|
|
6162
|
-
payload: {
|
|
7076
|
+
payload: {
|
|
7077
|
+
id: expect.any(String),
|
|
7078
|
+
startedAt: expect.any(Number),
|
|
7079
|
+
status: 'waiting',
|
|
7080
|
+
payload: {
|
|
7081
|
+
value: 1000,
|
|
7082
|
+
},
|
|
7083
|
+
},
|
|
6163
7084
|
type: 'step-waiting',
|
|
6164
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
|
+
},
|
|
6165
7105
|
{
|
|
6166
7106
|
payload: {
|
|
6167
7107
|
id: 'step2',
|
|
7108
|
+
payload: {
|
|
7109
|
+
value: 1000,
|
|
7110
|
+
},
|
|
7111
|
+
startedAt: expect.any(Number),
|
|
7112
|
+
status: 'running',
|
|
6168
7113
|
},
|
|
6169
7114
|
type: 'step-start',
|
|
6170
7115
|
},
|
|
@@ -6172,8 +7117,9 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6172
7117
|
payload: {
|
|
6173
7118
|
id: 'step2',
|
|
6174
7119
|
output: {
|
|
6175
|
-
|
|
7120
|
+
value: 2000,
|
|
6176
7121
|
},
|
|
7122
|
+
endedAt: expect.any(Number),
|
|
6177
7123
|
status: 'success',
|
|
6178
7124
|
},
|
|
6179
7125
|
type: 'step-result',
|
|
@@ -6192,19 +7138,20 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6192
7138
|
type: 'finish',
|
|
6193
7139
|
},
|
|
6194
7140
|
]);
|
|
7141
|
+
|
|
6195
7142
|
// Verify execution completed successfully
|
|
6196
7143
|
expect(executionResult.steps.step1).toMatchObject({
|
|
6197
7144
|
status: 'success',
|
|
6198
|
-
output: {
|
|
7145
|
+
output: { value: 1000 },
|
|
6199
7146
|
payload: {},
|
|
6200
7147
|
startedAt: expect.any(Number),
|
|
6201
7148
|
endedAt: expect.any(Number),
|
|
6202
7149
|
});
|
|
6203
7150
|
expect(executionResult.steps.step2).toMatchObject({
|
|
6204
7151
|
status: 'success',
|
|
6205
|
-
output: {
|
|
7152
|
+
output: { value: 2000 },
|
|
6206
7153
|
payload: {
|
|
6207
|
-
|
|
7154
|
+
value: 1000,
|
|
6208
7155
|
},
|
|
6209
7156
|
startedAt: expect.any(Number),
|
|
6210
7157
|
endedAt: expect.any(Number),
|
|
@@ -6264,10 +7211,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6264
7211
|
|
|
6265
7212
|
const app = await createHonoServer(mastra);
|
|
6266
7213
|
|
|
6267
|
-
const srv = serve({
|
|
7214
|
+
const srv = (globServer = serve({
|
|
6268
7215
|
fetch: app.fetch,
|
|
6269
7216
|
port: (ctx as any).handlerPort,
|
|
6270
|
-
});
|
|
7217
|
+
}));
|
|
7218
|
+
await resetInngest();
|
|
6271
7219
|
|
|
6272
7220
|
const runId = 'test-run-id';
|
|
6273
7221
|
let watchData: StreamEvent[] = [];
|
|
@@ -6275,7 +7223,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6275
7223
|
runId,
|
|
6276
7224
|
});
|
|
6277
7225
|
|
|
6278
|
-
await
|
|
7226
|
+
await resetInngest();
|
|
6279
7227
|
|
|
6280
7228
|
const { stream, getWorkflowState } = run.stream({ inputData: {} });
|
|
6281
7229
|
|
|
@@ -6295,7 +7243,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6295
7243
|
|
|
6296
7244
|
const executionResult = await getWorkflowState();
|
|
6297
7245
|
|
|
6298
|
-
await
|
|
7246
|
+
await resetInngest();
|
|
6299
7247
|
|
|
6300
7248
|
srv.close();
|
|
6301
7249
|
|
|
@@ -6489,12 +7437,12 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6489
7437
|
|
|
6490
7438
|
const app = await createHonoServer(mastra);
|
|
6491
7439
|
|
|
6492
|
-
const srv = serve({
|
|
7440
|
+
const srv = (globServer = serve({
|
|
6493
7441
|
fetch: app.fetch,
|
|
6494
7442
|
port: (ctx as any).handlerPort,
|
|
6495
|
-
});
|
|
7443
|
+
}));
|
|
6496
7444
|
|
|
6497
|
-
await
|
|
7445
|
+
await resetInngest();
|
|
6498
7446
|
|
|
6499
7447
|
const run = await promptEvalWorkflow.createRunAsync();
|
|
6500
7448
|
|
|
@@ -6678,12 +7626,12 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6678
7626
|
|
|
6679
7627
|
const app = await createHonoServer(mastra);
|
|
6680
7628
|
|
|
6681
|
-
const srv = serve({
|
|
7629
|
+
const srv = (globServer = serve({
|
|
6682
7630
|
fetch: app.fetch,
|
|
6683
7631
|
port: (ctx as any).handlerPort,
|
|
6684
|
-
});
|
|
7632
|
+
}));
|
|
6685
7633
|
|
|
6686
|
-
await
|
|
7634
|
+
await resetInngest();
|
|
6687
7635
|
|
|
6688
7636
|
const run = await workflow.createRunAsync({
|
|
6689
7637
|
runId: 'test-run-id',
|