@mastra/inngest 0.0.0-ai-v5-20250626003446 → 0.0.0-ai-v5-20250710191716

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/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, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
15
+ import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest';
18
16
 
19
17
  import { z } from 'zod';
20
18
  import { init, serve as inngestServe } from './index';
@@ -22,28 +20,133 @@ import { init, serve as inngestServe } from './index';
22
20
  interface LocalTestContext {
23
21
  inngestPort: number;
24
22
  handlerPort: number;
25
- containerName: string;
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
- const inngestPort = await getPort();
31
- const handlerPort = await getPort();
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
- ctx.inngestPort = inngestPort;
36
- ctx.handlerPort = handlerPort;
37
- ctx.containerName = containerName;
39
+ globServer?.close();
38
40
 
39
41
  vi.restoreAllMocks();
40
42
  });
41
43
 
42
- afterEach<LocalTestContext>(async ctx => {
43
- await $`docker stop ${ctx.containerName}`;
44
- });
45
-
46
44
  describe.sequential('Basic Workflow Execution', () => {
45
+ it('should be able to bail workflow execution', async ctx => {
46
+ const inngest = new Inngest({
47
+ id: 'mastra',
48
+ baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
49
+ middleware: [realtimeMiddleware()],
50
+ });
51
+
52
+ const { createWorkflow, createStep } = init(inngest);
53
+
54
+ const step1 = createStep({
55
+ id: 'step1',
56
+ execute: async ({ bail, inputData }) => {
57
+ if (inputData.value === 'bail') {
58
+ return bail({ result: 'bailed' });
59
+ }
60
+
61
+ return { result: 'step1: ' + inputData.value };
62
+ },
63
+ inputSchema: z.object({ value: z.string() }),
64
+ outputSchema: z.object({ result: z.string() }),
65
+ });
66
+ const step2 = createStep({
67
+ id: 'step2',
68
+ execute: async ({ inputData }) => {
69
+ return { result: 'step2: ' + inputData.result };
70
+ },
71
+ inputSchema: z.object({ result: z.string() }),
72
+ outputSchema: z.object({ result: z.string() }),
73
+ });
74
+
75
+ const workflow = createWorkflow({
76
+ id: 'test-workflow',
77
+ inputSchema: z.object({ value: z.string() }),
78
+ outputSchema: z.object({
79
+ result: z.string(),
80
+ }),
81
+ steps: [step1, step2],
82
+ });
83
+
84
+ workflow.then(step1).then(step2).commit();
85
+
86
+ const mastra = new Mastra({
87
+ storage: new DefaultStorage({
88
+ url: ':memory:',
89
+ }),
90
+ workflows: {
91
+ 'test-workflow': workflow,
92
+ },
93
+ server: {
94
+ apiRoutes: [
95
+ {
96
+ path: '/inngest/api',
97
+ method: 'ALL',
98
+ createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
99
+ },
100
+ ],
101
+ },
102
+ });
103
+
104
+ const app = await createHonoServer(mastra);
105
+
106
+ const srv = (globServer = serve({
107
+ fetch: app.fetch,
108
+ port: (ctx as any).handlerPort,
109
+ }));
110
+
111
+ await resetInngest();
112
+
113
+ const run = await workflow.createRunAsync();
114
+ console.log('running');
115
+ const result = await run.start({ inputData: { value: 'bail' } });
116
+ console.log('result', result);
117
+
118
+ expect(result.steps['step1']).toEqual({
119
+ status: 'success',
120
+ output: { result: 'bailed' },
121
+ payload: { value: 'bail' },
122
+ startedAt: expect.any(Number),
123
+ endedAt: expect.any(Number),
124
+ });
125
+
126
+ expect(result.steps['step2']).toBeUndefined();
127
+
128
+ const run2 = await workflow.createRunAsync();
129
+ const result2 = await run2.start({ inputData: { value: 'no-bail' } });
130
+
131
+ srv.close();
132
+
133
+ expect(result2.steps['step1']).toEqual({
134
+ status: 'success',
135
+ output: { result: 'step1: no-bail' },
136
+ payload: { value: 'no-bail' },
137
+ startedAt: expect.any(Number),
138
+ endedAt: expect.any(Number),
139
+ });
140
+
141
+ expect(result2.steps['step2']).toEqual({
142
+ status: 'success',
143
+ output: { result: 'step2: step1: no-bail' },
144
+ payload: { result: 'step1: no-bail' },
145
+ startedAt: expect.any(Number),
146
+ endedAt: expect.any(Number),
147
+ });
148
+ });
149
+
47
150
  it('should execute a single step workflow successfully', async ctx => {
48
151
  const inngest = new Inngest({
49
152
  id: 'mastra',
@@ -89,13 +192,13 @@ describe('MastraInngestWorkflow', () => {
89
192
 
90
193
  const app = await createHonoServer(mastra);
91
194
 
92
- const srv = serve({
195
+ const srv = (globServer = serve({
93
196
  fetch: app.fetch,
94
197
  port: (ctx as any).handlerPort,
95
- });
96
- await new Promise(resolve => setTimeout(resolve, 2000));
198
+ }));
199
+ await resetInngest();
97
200
 
98
- const run = workflow.createRun();
201
+ const run = await workflow.createRunAsync();
99
202
  const result = await run.start({ inputData: {} });
100
203
 
101
204
  expect(execute).toHaveBeenCalled();
@@ -164,13 +267,13 @@ describe('MastraInngestWorkflow', () => {
164
267
 
165
268
  const app = await createHonoServer(mastra);
166
269
 
167
- const srv = serve({
270
+ const srv = (globServer = serve({
168
271
  fetch: app.fetch,
169
272
  port: (ctx as any).handlerPort,
170
- });
171
- await new Promise(resolve => setTimeout(resolve, 2000));
273
+ }));
274
+ await resetInngest();
172
275
 
173
- const run = workflow.createRun();
276
+ const run = await workflow.createRunAsync();
174
277
  const result = await run.start({ inputData: {} });
175
278
 
176
279
  expect(step1Action).toHaveBeenCalled();
@@ -245,13 +348,13 @@ describe('MastraInngestWorkflow', () => {
245
348
 
246
349
  const app = await createHonoServer(mastra);
247
350
 
248
- const srv = serve({
351
+ const srv = (globServer = serve({
249
352
  fetch: app.fetch,
250
353
  port: (ctx as any).handlerPort,
251
- });
252
- await new Promise(resolve => setTimeout(resolve, 2000));
354
+ }));
355
+ await resetInngest();
253
356
 
254
- const run = workflow.createRun();
357
+ const run = await workflow.createRunAsync();
255
358
  const result = await run.start({ inputData: {} });
256
359
 
257
360
  expect(executionOrder).toMatchObject(['step1', 'step2']);
@@ -264,7 +367,7 @@ describe('MastraInngestWorkflow', () => {
264
367
  srv.close();
265
368
  });
266
369
 
267
- it('should execute a a sleep step', async ctx => {
370
+ it('should execute a sleep step', async ctx => {
268
371
  const inngest = new Inngest({
269
372
  id: 'mastra',
270
373
  baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
@@ -319,13 +422,199 @@ describe('MastraInngestWorkflow', () => {
319
422
 
320
423
  const app = await createHonoServer(mastra);
321
424
 
322
- const srv = serve({
425
+ const srv = (globServer = serve({
323
426
  fetch: app.fetch,
324
427
  port: (ctx as any).handlerPort,
428
+ }));
429
+ await resetInngest();
430
+
431
+ const run = await workflow.createRunAsync();
432
+ const startTime = Date.now();
433
+ const result = await run.start({ inputData: {} });
434
+ const endTime = Date.now();
435
+
436
+ expect(execute).toHaveBeenCalled();
437
+ expect(result.steps['step1']).toMatchObject({
438
+ status: 'success',
439
+ output: { result: 'success' },
440
+ // payload: {},
441
+ // startedAt: expect.any(Number),
442
+ // endedAt: expect.any(Number),
443
+ });
444
+
445
+ expect(result.steps['step2']).toMatchObject({
446
+ status: 'success',
447
+ output: { result: 'slept successfully: success' },
448
+ // payload: { result: 'success' },
449
+ // startedAt: expect.any(Number),
450
+ // endedAt: expect.any(Number),
451
+ });
452
+
453
+ expect(endTime - startTime).toBeGreaterThan(1000);
454
+
455
+ srv.close();
456
+ });
457
+
458
+ it('should execute a sleep step with fn parameter', async ctx => {
459
+ const inngest = new Inngest({
460
+ id: 'mastra',
461
+ baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
462
+ });
463
+
464
+ const { createWorkflow, createStep } = init(inngest);
465
+
466
+ const execute = vi.fn<any>().mockResolvedValue({ value: 1000 });
467
+ const step1 = createStep({
468
+ id: 'step1',
469
+ execute,
470
+ inputSchema: z.object({}),
471
+ outputSchema: z.object({ value: z.number() }),
472
+ });
473
+ const step2 = createStep({
474
+ id: 'step2',
475
+ execute: async ({ inputData }) => {
476
+ return { value: inputData.value + 1000 };
477
+ },
478
+ inputSchema: z.object({ value: z.number() }),
479
+ outputSchema: z.object({ value: z.number() }),
480
+ });
481
+
482
+ const workflow = createWorkflow({
483
+ id: 'test-workflow',
484
+ inputSchema: z.object({}),
485
+ outputSchema: z.object({
486
+ value: z.number(),
487
+ }),
488
+ steps: [step1],
489
+ });
490
+
491
+ workflow
492
+ .then(step1)
493
+ .sleep(async ({ inputData }) => {
494
+ return inputData.value;
495
+ })
496
+ .then(step2)
497
+ .commit();
498
+
499
+ const mastra = new Mastra({
500
+ storage: new DefaultStorage({
501
+ url: ':memory:',
502
+ }),
503
+ workflows: {
504
+ 'test-workflow': workflow,
505
+ },
506
+ server: {
507
+ apiRoutes: [
508
+ {
509
+ path: '/inngest/api',
510
+ method: 'ALL',
511
+ createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
512
+ },
513
+ ],
514
+ },
515
+ });
516
+
517
+ const app = await createHonoServer(mastra);
518
+
519
+ const srv = (globServer = serve({
520
+ fetch: app.fetch,
521
+ port: (ctx as any).handlerPort,
522
+ }));
523
+ await resetInngest();
524
+
525
+ const run = await workflow.createRunAsync();
526
+ const startTime = Date.now();
527
+ const result = await run.start({ inputData: {} });
528
+ const endTime = Date.now();
529
+
530
+ expect(execute).toHaveBeenCalled();
531
+ expect(result.steps['step1']).toMatchObject({
532
+ status: 'success',
533
+ output: { value: 1000 },
534
+ // payload: {},
535
+ // startedAt: expect.any(Number),
536
+ // endedAt: expect.any(Number),
537
+ });
538
+
539
+ expect(result.steps['step2']).toMatchObject({
540
+ status: 'success',
541
+ output: { value: 2000 },
542
+ // payload: { result: 'success' },
543
+ // startedAt: expect.any(Number),
544
+ // endedAt: expect.any(Number),
545
+ });
546
+
547
+ expect(endTime - startTime).toBeGreaterThan(1000);
548
+
549
+ srv.close();
550
+ });
551
+
552
+ it('should execute a a sleep until step', async ctx => {
553
+ const inngest = new Inngest({
554
+ id: 'mastra',
555
+ baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
556
+ });
557
+
558
+ const { createWorkflow, createStep } = init(inngest);
559
+
560
+ const execute = vi.fn<any>().mockResolvedValue({ result: 'success' });
561
+ const step1 = createStep({
562
+ id: 'step1',
563
+ execute,
564
+ inputSchema: z.object({}),
565
+ outputSchema: z.object({ result: z.string() }),
566
+ });
567
+ const step2 = createStep({
568
+ id: 'step2',
569
+ execute: async ({ inputData }) => {
570
+ return { result: 'slept successfully: ' + inputData.result };
571
+ },
572
+ inputSchema: z.object({ result: z.string() }),
573
+ outputSchema: z.object({ result: z.string() }),
325
574
  });
326
- await new Promise(resolve => setTimeout(resolve, 2000));
327
575
 
328
- const run = workflow.createRun();
576
+ const workflow = createWorkflow({
577
+ id: 'test-workflow',
578
+ inputSchema: z.object({}),
579
+ outputSchema: z.object({
580
+ result: z.string(),
581
+ }),
582
+ steps: [step1],
583
+ });
584
+
585
+ workflow
586
+ .then(step1)
587
+ .sleepUntil(new Date(Date.now() + 1000))
588
+ .then(step2)
589
+ .commit();
590
+
591
+ const mastra = new Mastra({
592
+ storage: new DefaultStorage({
593
+ url: ':memory:',
594
+ }),
595
+ workflows: {
596
+ 'test-workflow': workflow,
597
+ },
598
+ server: {
599
+ apiRoutes: [
600
+ {
601
+ path: '/inngest/api',
602
+ method: 'ALL',
603
+ createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
604
+ },
605
+ ],
606
+ },
607
+ });
608
+
609
+ const app = await createHonoServer(mastra);
610
+
611
+ const srv = (globServer = serve({
612
+ fetch: app.fetch,
613
+ port: (ctx as any).handlerPort,
614
+ }));
615
+ await resetInngest();
616
+
617
+ const run = await workflow.createRunAsync();
329
618
  const startTime = Date.now();
330
619
  const result = await run.start({ inputData: {} });
331
620
  const endTime = Date.now();
@@ -352,7 +641,195 @@ describe('MastraInngestWorkflow', () => {
352
641
  srv.close();
353
642
  });
354
643
 
355
- it('should execute a a sleep until step', async ctx => {
644
+ it('should execute a sleep until step with fn parameter', async ctx => {
645
+ const inngest = new Inngest({
646
+ id: 'mastra',
647
+ baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
648
+ });
649
+
650
+ const { createWorkflow, createStep } = init(inngest);
651
+
652
+ const execute = vi.fn<any>().mockResolvedValue({ value: 1000 });
653
+ const step1 = createStep({
654
+ id: 'step1',
655
+ execute,
656
+ inputSchema: z.object({}),
657
+ outputSchema: z.object({ value: z.number() }),
658
+ });
659
+ const step2 = createStep({
660
+ id: 'step2',
661
+ execute: async ({ inputData }) => {
662
+ return { value: inputData.value + 1000 };
663
+ },
664
+ inputSchema: z.object({ value: z.number() }),
665
+ outputSchema: z.object({ value: z.number() }),
666
+ });
667
+
668
+ const workflow = createWorkflow({
669
+ id: 'test-workflow',
670
+ inputSchema: z.object({}),
671
+ outputSchema: z.object({
672
+ value: z.number(),
673
+ }),
674
+ steps: [step1],
675
+ });
676
+
677
+ workflow
678
+ .then(step1)
679
+ .sleepUntil(async ({ inputData }) => {
680
+ return new Date(Date.now() + inputData.value);
681
+ })
682
+ .then(step2)
683
+ .commit();
684
+
685
+ const mastra = new Mastra({
686
+ storage: new DefaultStorage({
687
+ url: ':memory:',
688
+ }),
689
+ workflows: {
690
+ 'test-workflow': workflow,
691
+ },
692
+ server: {
693
+ apiRoutes: [
694
+ {
695
+ path: '/inngest/api',
696
+ method: 'ALL',
697
+ createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
698
+ },
699
+ ],
700
+ },
701
+ });
702
+
703
+ const app = await createHonoServer(mastra);
704
+
705
+ const srv = (globServer = serve({
706
+ fetch: app.fetch,
707
+ port: (ctx as any).handlerPort,
708
+ }));
709
+ await resetInngest();
710
+
711
+ const run = await workflow.createRunAsync();
712
+ const startTime = Date.now();
713
+ const result = await run.start({ inputData: {} });
714
+ const endTime = Date.now();
715
+
716
+ expect(execute).toHaveBeenCalled();
717
+ expect(result.steps['step1']).toMatchObject({
718
+ status: 'success',
719
+ output: { value: 1000 },
720
+ // payload: {},
721
+ // startedAt: expect.any(Number),
722
+ // endedAt: expect.any(Number),
723
+ });
724
+
725
+ expect(result.steps['step2']).toMatchObject({
726
+ status: 'success',
727
+ output: { value: 2000 },
728
+ // payload: { result: 'success' },
729
+ // startedAt: expect.any(Number),
730
+ // endedAt: expect.any(Number),
731
+ });
732
+
733
+ expect(endTime - startTime).toBeGreaterThan(1000);
734
+
735
+ srv.close();
736
+ });
737
+
738
+ it('should execute a a waitForEvent step', async ctx => {
739
+ const inngest = new Inngest({
740
+ id: 'mastra',
741
+ baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
742
+ });
743
+
744
+ const { createWorkflow, createStep } = init(inngest);
745
+
746
+ const execute = vi.fn<any>().mockResolvedValue({ result: 'success' });
747
+ const step1 = createStep({
748
+ id: 'step1',
749
+ execute,
750
+ inputSchema: z.object({}),
751
+ outputSchema: z.object({ result: z.string() }),
752
+ });
753
+ const step2 = createStep({
754
+ id: 'step2',
755
+ execute: async ({ inputData, resumeData }) => {
756
+ return { result: inputData.result, resumed: resumeData };
757
+ },
758
+ inputSchema: z.object({ result: z.string() }),
759
+ outputSchema: z.object({ result: z.string(), resumed: z.any() }),
760
+ resumeSchema: z.any(),
761
+ });
762
+
763
+ const workflow = createWorkflow({
764
+ id: 'test-workflow',
765
+ inputSchema: z.object({}),
766
+ outputSchema: z.object({
767
+ result: z.string(),
768
+ resumed: z.any(),
769
+ }),
770
+ steps: [step1],
771
+ });
772
+
773
+ workflow.then(step1).waitForEvent('hello-event', step2).commit();
774
+
775
+ const mastra = new Mastra({
776
+ storage: new DefaultStorage({
777
+ url: ':memory:',
778
+ }),
779
+ workflows: {
780
+ 'test-workflow': workflow,
781
+ },
782
+ server: {
783
+ apiRoutes: [
784
+ {
785
+ path: '/inngest/api',
786
+ method: 'ALL',
787
+ createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
788
+ },
789
+ ],
790
+ },
791
+ });
792
+
793
+ const app = await createHonoServer(mastra);
794
+
795
+ const srv = (globServer = serve({
796
+ fetch: app.fetch,
797
+ port: (ctx as any).handlerPort,
798
+ }));
799
+ await resetInngest();
800
+
801
+ const run = await workflow.createRunAsync();
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();
808
+
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);
828
+
829
+ srv.close();
830
+ });
831
+
832
+ it('should execute a a waitForEvent step after timeout', async ctx => {
356
833
  const inngest = new Inngest({
357
834
  id: 'mastra',
358
835
  baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
@@ -369,11 +846,12 @@ describe('MastraInngestWorkflow', () => {
369
846
  });
370
847
  const step2 = createStep({
371
848
  id: 'step2',
372
- execute: async ({ inputData }) => {
373
- return { result: 'slept successfully: ' + inputData.result };
849
+ execute: async ({ inputData, resumeData }) => {
850
+ return { result: inputData.result, resumed: resumeData };
374
851
  },
375
852
  inputSchema: z.object({ result: z.string() }),
376
- outputSchema: z.object({ result: z.string() }),
853
+ outputSchema: z.object({ result: z.string(), resumed: z.any() }),
854
+ resumeSchema: z.any(),
377
855
  });
378
856
 
379
857
  const workflow = createWorkflow({
@@ -381,15 +859,12 @@ describe('MastraInngestWorkflow', () => {
381
859
  inputSchema: z.object({}),
382
860
  outputSchema: z.object({
383
861
  result: z.string(),
862
+ resumed: z.any(),
384
863
  }),
385
864
  steps: [step1],
386
865
  });
387
866
 
388
- workflow
389
- .then(step1)
390
- .sleepUntil(new Date(Date.now() + 1000))
391
- .then(step2)
392
- .commit();
867
+ workflow.then(step1).waitForEvent('hello-event', step2, { timeout: 1000 }).commit();
393
868
 
394
869
  const mastra = new Mastra({
395
870
  storage: new DefaultStorage({
@@ -411,13 +886,13 @@ describe('MastraInngestWorkflow', () => {
411
886
 
412
887
  const app = await createHonoServer(mastra);
413
888
 
414
- const srv = serve({
889
+ const srv = (globServer = serve({
415
890
  fetch: app.fetch,
416
891
  port: (ctx as any).handlerPort,
417
- });
418
- await new Promise(resolve => setTimeout(resolve, 2000));
892
+ }));
893
+ await resetInngest();
419
894
 
420
- const run = workflow.createRun();
895
+ const run = await workflow.createRunAsync();
421
896
  const startTime = Date.now();
422
897
  const result = await run.start({ inputData: {} });
423
898
  const endTime = Date.now();
@@ -432,41 +907,44 @@ describe('MastraInngestWorkflow', () => {
432
907
  });
433
908
 
434
909
  expect(result.steps['step2']).toMatchObject({
435
- status: 'success',
436
- output: { result: 'slept successfully: success' },
437
- // payload: { result: 'success' },
438
- // startedAt: expect.any(Number),
439
- // endedAt: expect.any(Number),
910
+ status: 'failed',
911
+ error: expect.any(String),
912
+ payload: { result: 'success' },
913
+ startedAt: expect.any(Number),
914
+ endedAt: expect.any(Number),
440
915
  });
441
916
 
442
917
  expect(endTime - startTime).toBeGreaterThan(1000);
443
918
 
444
919
  srv.close();
445
920
  });
921
+ });
446
922
 
447
- it('should execute a a waitForEvent step', async ctx => {
923
+ describe('abort', () => {
924
+ it('should be able to abort workflow execution in between steps', async ctx => {
448
925
  const inngest = new Inngest({
449
926
  id: 'mastra',
450
927
  baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
928
+ middleware: [realtimeMiddleware()],
451
929
  });
452
930
 
453
931
  const { createWorkflow, createStep } = init(inngest);
454
932
 
455
- const execute = vi.fn<any>().mockResolvedValue({ result: 'success' });
456
933
  const step1 = createStep({
457
934
  id: 'step1',
458
- execute,
459
- inputSchema: z.object({}),
935
+ execute: async ({ inputData }) => {
936
+ return { result: 'step1: ' + inputData.value };
937
+ },
938
+ inputSchema: z.object({ value: z.string() }),
460
939
  outputSchema: z.object({ result: z.string() }),
461
940
  });
462
941
  const step2 = createStep({
463
942
  id: 'step2',
464
- execute: async ({ inputData, resumeData }) => {
465
- return { result: inputData.result, resumed: resumeData };
943
+ execute: async ({ inputData }) => {
944
+ return { result: 'step2: ' + inputData.result };
466
945
  },
467
946
  inputSchema: z.object({ result: z.string() }),
468
- outputSchema: z.object({ result: z.string(), resumed: z.any() }),
469
- resumeSchema: z.any(),
947
+ outputSchema: z.object({ result: z.string() }),
470
948
  });
471
949
 
472
950
  const workflow = createWorkflow({
@@ -474,12 +952,11 @@ describe('MastraInngestWorkflow', () => {
474
952
  inputSchema: z.object({}),
475
953
  outputSchema: z.object({
476
954
  result: z.string(),
477
- resumed: z.any(),
478
955
  }),
479
- steps: [step1],
956
+ steps: [step1, step2],
480
957
  });
481
958
 
482
- workflow.then(step1).waitForEvent('hello-event', step2).commit();
959
+ workflow.then(step1).sleep(2000).then(step2).commit();
483
960
 
484
961
  const mastra = new Mastra({
485
962
  storage: new DefaultStorage({
@@ -501,66 +978,75 @@ describe('MastraInngestWorkflow', () => {
501
978
 
502
979
  const app = await createHonoServer(mastra);
503
980
 
504
- const srv = serve({
981
+ const srv = (globServer = serve({
505
982
  fetch: app.fetch,
506
983
  port: (ctx as any).handlerPort,
507
- });
508
- await new Promise(resolve => setTimeout(resolve, 2000));
984
+ }));
985
+ await resetInngest();
986
+
987
+ const run = await workflow.createRunAsync();
988
+ const p = run.start({ inputData: { value: 'test' } });
509
989
 
510
- const run = workflow.createRun();
511
- const startTime = Date.now();
512
990
  setTimeout(() => {
513
- run.sendEvent('hello-event', { data: 'hello' });
991
+ run.cancel();
514
992
  }, 1000);
515
- const result = await run.start({ inputData: {} });
516
- const endTime = Date.now();
517
993
 
518
- expect(execute).toHaveBeenCalled();
519
- expect(result.steps['step1']).toMatchObject({
520
- status: 'success',
521
- output: { result: 'success' },
522
- // payload: {},
523
- // startedAt: expect.any(Number),
524
- // endedAt: expect.any(Number),
525
- });
994
+ const result = await p;
526
995
 
527
- expect(result.steps['step2']).toMatchObject({
996
+ srv.close();
997
+
998
+ expect(result.status).toBe('canceled');
999
+ expect(result.steps['step1']).toEqual({
528
1000
  status: 'success',
529
- output: { result: 'success', resumed: { data: 'hello' } },
530
- payload: { result: 'success' },
531
- // resumePayload: { data: 'hello' },
1001
+ output: { result: 'step1: test' },
1002
+ payload: { value: 'test' },
532
1003
  startedAt: expect.any(Number),
533
1004
  endedAt: expect.any(Number),
534
1005
  });
535
1006
 
536
- expect(endTime - startTime).toBeGreaterThan(1000);
537
-
538
- srv.close();
1007
+ expect(result.steps['step2']).toBeUndefined();
539
1008
  });
540
1009
 
541
- it('should execute a a waitForEvent step after timeout', async ctx => {
1010
+ it('should be able to abort workflow execution during a step', async ctx => {
542
1011
  const inngest = new Inngest({
543
1012
  id: 'mastra',
544
1013
  baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
1014
+ middleware: [realtimeMiddleware()],
545
1015
  });
546
1016
 
547
1017
  const { createWorkflow, createStep } = init(inngest);
548
1018
 
549
- const execute = vi.fn<any>().mockResolvedValue({ result: 'success' });
550
1019
  const step1 = createStep({
551
1020
  id: 'step1',
552
- execute,
553
- inputSchema: z.object({}),
1021
+ execute: async ({ inputData }) => {
1022
+ return { result: 'step1: ' + inputData.value };
1023
+ },
1024
+ inputSchema: z.object({ value: z.string() }),
554
1025
  outputSchema: z.object({ result: z.string() }),
555
1026
  });
556
1027
  const step2 = createStep({
557
1028
  id: 'step2',
558
- execute: async ({ inputData, resumeData }) => {
559
- return { result: inputData.result, resumed: resumeData };
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 };
560
1047
  },
561
1048
  inputSchema: z.object({ result: z.string() }),
562
- outputSchema: z.object({ result: z.string(), resumed: z.any() }),
563
- resumeSchema: z.any(),
1049
+ outputSchema: z.object({ result: z.string() }),
564
1050
  });
565
1051
 
566
1052
  const workflow = createWorkflow({
@@ -568,12 +1054,11 @@ describe('MastraInngestWorkflow', () => {
568
1054
  inputSchema: z.object({}),
569
1055
  outputSchema: z.object({
570
1056
  result: z.string(),
571
- resumed: z.any(),
572
1057
  }),
573
- steps: [step1],
1058
+ steps: [step1, step2],
574
1059
  });
575
1060
 
576
- workflow.then(step1).waitForEvent('hello-event', step2, { timeout: 1000 }).commit();
1061
+ workflow.then(step1).then(step2).commit();
577
1062
 
578
1063
  const mastra = new Mastra({
579
1064
  storage: new DefaultStorage({
@@ -595,37 +1080,40 @@ describe('MastraInngestWorkflow', () => {
595
1080
 
596
1081
  const app = await createHonoServer(mastra);
597
1082
 
598
- const srv = serve({
1083
+ const srv = (globServer = serve({
599
1084
  fetch: app.fetch,
600
1085
  port: (ctx as any).handlerPort,
601
- });
602
- await new Promise(resolve => setTimeout(resolve, 2000));
1086
+ }));
1087
+ await resetInngest();
603
1088
 
604
- const run = workflow.createRun();
605
- const startTime = Date.now();
606
- const result = await run.start({ inputData: {} });
607
- const endTime = Date.now();
1089
+ const run = await workflow.createRunAsync();
1090
+ const p = run.start({ inputData: { value: 'test' } });
608
1091
 
609
- expect(execute).toHaveBeenCalled();
610
- expect(result.steps['step1']).toMatchObject({
611
- status: 'success',
612
- output: { result: 'success' },
613
- // payload: {},
614
- // startedAt: expect.any(Number),
615
- // endedAt: expect.any(Number),
616
- });
1092
+ setTimeout(() => {
1093
+ run.cancel();
1094
+ }, 1000);
617
1095
 
618
- expect(result.steps['step2']).toMatchObject({
619
- status: 'failed',
620
- error: expect.any(String),
621
- payload: { result: 'success' },
1096
+ const result = await p;
1097
+ console.log('result', result);
1098
+
1099
+ srv.close();
1100
+
1101
+ expect(result.status).toBe('canceled');
1102
+ expect(result.steps['step1']).toEqual({
1103
+ status: 'success',
1104
+ output: { result: 'step1: test' },
1105
+ payload: { value: 'test' },
622
1106
  startedAt: expect.any(Number),
623
1107
  endedAt: expect.any(Number),
624
1108
  });
625
1109
 
626
- expect(endTime - startTime).toBeGreaterThan(1000);
627
-
628
- srv.close();
1110
+ // expect(result.steps['step2']).toEqual({
1111
+ // status: 'canceled',
1112
+ // payload: { result: 'step1: test' },
1113
+ // output: undefined,
1114
+ // startedAt: expect.any(Number),
1115
+ // endedAt: expect.any(Number),
1116
+ // });
629
1117
  });
630
1118
  });
631
1119
 
@@ -681,12 +1169,14 @@ describe('MastraInngestWorkflow', () => {
681
1169
 
682
1170
  const app = await createHonoServer(mastra);
683
1171
 
684
- const srv = serve({
1172
+ const srv = (globServer = serve({
685
1173
  fetch: app.fetch,
686
1174
  port: (ctx as any).handlerPort,
687
- });
1175
+ }));
1176
+
1177
+ await resetInngest();
688
1178
 
689
- const run = workflow.createRun();
1179
+ const run = await workflow.createRunAsync();
690
1180
  const result = await run.start({ inputData: { inputData: 'test-input' } });
691
1181
 
692
1182
  expect(result.steps.step1).toMatchObject({ status: 'success', output: { result: 'success' } });
@@ -768,12 +1258,13 @@ describe('MastraInngestWorkflow', () => {
768
1258
 
769
1259
  const app = await createHonoServer(mastra);
770
1260
 
771
- const srv = serve({
1261
+ const srv = (globServer = serve({
772
1262
  fetch: app.fetch,
773
1263
  port: (ctx as any).handlerPort,
774
- });
1264
+ }));
1265
+ await resetInngest();
775
1266
 
776
- const run = workflow.createRun();
1267
+ const run = await workflow.createRunAsync();
777
1268
  const result = await run.start({ inputData: { inputValue: 'test-input' } });
778
1269
 
779
1270
  expect(step1Action).toHaveBeenCalled();
@@ -835,12 +1326,13 @@ describe('MastraInngestWorkflow', () => {
835
1326
 
836
1327
  const app = await createHonoServer(mastra);
837
1328
 
838
- const srv = serve({
1329
+ const srv = (globServer = serve({
839
1330
  fetch: app.fetch,
840
1331
  port: (ctx as any).handlerPort,
841
- });
1332
+ }));
1333
+ await resetInngest();
842
1334
 
843
- const run = workflow.createRun();
1335
+ const run = await workflow.createRunAsync();
844
1336
  await run.start({ inputData: { inputData: 'test-input' } });
845
1337
 
846
1338
  expect(execute).toHaveBeenCalledWith(
@@ -910,12 +1402,13 @@ describe('MastraInngestWorkflow', () => {
910
1402
 
911
1403
  const app = await createHonoServer(mastra);
912
1404
 
913
- const srv = serve({
1405
+ const srv = (globServer = serve({
914
1406
  fetch: app.fetch,
915
1407
  port: (ctx as any).handlerPort,
916
- });
1408
+ }));
1409
+ await resetInngest();
917
1410
 
918
- const run = workflow.createRun();
1411
+ const run = await workflow.createRunAsync();
919
1412
  const result = await run.start({ inputData: { cool: 'test-input' } });
920
1413
 
921
1414
  expect(execute).toHaveBeenCalledWith(
@@ -992,12 +1485,13 @@ describe('MastraInngestWorkflow', () => {
992
1485
 
993
1486
  const app = await createHonoServer(mastra);
994
1487
 
995
- const srv = serve({
1488
+ const srv = (globServer = serve({
996
1489
  fetch: app.fetch,
997
1490
  port: (ctx as any).handlerPort,
998
- });
1491
+ }));
1492
+ await resetInngest();
999
1493
 
1000
- const run = workflow.createRun();
1494
+ const run = await workflow.createRunAsync();
1001
1495
  await run.start({ inputData: {} });
1002
1496
 
1003
1497
  expect(step2Action).toHaveBeenCalledWith(
@@ -1095,12 +1589,13 @@ describe('MastraInngestWorkflow', () => {
1095
1589
 
1096
1590
  const app = await createHonoServer(mastra);
1097
1591
 
1098
- const srv = serve({
1592
+ const srv = (globServer = serve({
1099
1593
  fetch: app.fetch,
1100
1594
  port: (ctx as any).handlerPort,
1101
- });
1595
+ }));
1596
+ await resetInngest();
1102
1597
 
1103
- const run = workflow.createRun();
1598
+ const run = await workflow.createRunAsync();
1104
1599
  const result = await run.start({ inputData: { status: 'success' } });
1105
1600
  srv.close();
1106
1601
 
@@ -1171,12 +1666,13 @@ describe('MastraInngestWorkflow', () => {
1171
1666
 
1172
1667
  const app = await createHonoServer(mastra);
1173
1668
 
1174
- const srv = serve({
1669
+ const srv = (globServer = serve({
1175
1670
  fetch: app.fetch,
1176
1671
  port: (ctx as any).handlerPort,
1177
- });
1672
+ }));
1673
+ await resetInngest();
1178
1674
 
1179
- const run = workflow.createRun();
1675
+ const run = await workflow.createRunAsync();
1180
1676
  let result: Awaited<ReturnType<typeof run.start>> | undefined = undefined;
1181
1677
  try {
1182
1678
  result = await run.start({ inputData: {} });
@@ -1276,12 +1772,13 @@ describe('MastraInngestWorkflow', () => {
1276
1772
 
1277
1773
  const app = await createHonoServer(mastra);
1278
1774
 
1279
- const srv = serve({
1775
+ const srv = (globServer = serve({
1280
1776
  fetch: app.fetch,
1281
1777
  port: (ctx as any).handlerPort,
1282
- });
1778
+ }));
1779
+ await resetInngest();
1283
1780
 
1284
- const run = workflow.createRun();
1781
+ const run = await workflow.createRunAsync();
1285
1782
  const result = await run.start({ inputData: { status: 'success' } });
1286
1783
  srv.close();
1287
1784
 
@@ -1359,12 +1856,13 @@ describe('MastraInngestWorkflow', () => {
1359
1856
 
1360
1857
  const app = await createHonoServer(mastra);
1361
1858
 
1362
- const srv = serve({
1859
+ const srv = (globServer = serve({
1363
1860
  fetch: app.fetch,
1364
1861
  port: (ctx as any).handlerPort,
1365
- });
1862
+ }));
1863
+ await resetInngest();
1366
1864
 
1367
- const run = workflow.createRun();
1865
+ const run = await workflow.createRunAsync();
1368
1866
  const result = await run.start({ inputData: { count: 5 } });
1369
1867
  srv.close();
1370
1868
 
@@ -1426,13 +1924,13 @@ describe('MastraInngestWorkflow', () => {
1426
1924
 
1427
1925
  const app = await createHonoServer(mastra);
1428
1926
 
1429
- const srv = serve({
1927
+ const srv = (globServer = serve({
1430
1928
  fetch: app.fetch,
1431
1929
  port: (ctx as any).handlerPort,
1432
- });
1433
- await new Promise(resolve => setTimeout(resolve, 2000));
1930
+ }));
1931
+ await resetInngest();
1434
1932
 
1435
- const run = workflow.createRun();
1933
+ const run = await workflow.createRunAsync();
1436
1934
 
1437
1935
  await expect(run.start({ inputData: {} })).resolves.toMatchObject({
1438
1936
  steps: {
@@ -1510,13 +2008,13 @@ describe('MastraInngestWorkflow', () => {
1510
2008
 
1511
2009
  const app = await createHonoServer(mastra);
1512
2010
 
1513
- const srv = serve({
2011
+ const srv = (globServer = serve({
1514
2012
  fetch: app.fetch,
1515
2013
  port: (ctx as any).handlerPort,
1516
- });
1517
- await new Promise(resolve => setTimeout(resolve, 2000));
2014
+ }));
2015
+ await resetInngest();
1518
2016
 
1519
- const run = workflow.createRun();
2017
+ const run = await workflow.createRunAsync();
1520
2018
  const result = await run.start({ inputData: {} });
1521
2019
 
1522
2020
  expect(result.steps).toMatchObject({
@@ -1604,13 +2102,13 @@ describe('MastraInngestWorkflow', () => {
1604
2102
 
1605
2103
  const app = await createHonoServer(mastra);
1606
2104
 
1607
- const srv = serve({
2105
+ const srv = (globServer = serve({
1608
2106
  fetch: app.fetch,
1609
2107
  port: (ctx as any).handlerPort,
1610
- });
1611
- await new Promise(resolve => setTimeout(resolve, 2000));
2108
+ }));
2109
+ await resetInngest();
1612
2110
 
1613
- const run = mainWorkflow.createRun();
2111
+ const run = await mainWorkflow.createRunAsync();
1614
2112
  const result = await run.start({ inputData: {} });
1615
2113
 
1616
2114
  expect(result.steps).toMatchObject({
@@ -1732,13 +2230,13 @@ describe('MastraInngestWorkflow', () => {
1732
2230
 
1733
2231
  const app = await createHonoServer(mastra);
1734
2232
 
1735
- const srv = serve({
2233
+ const srv = (globServer = serve({
1736
2234
  fetch: app.fetch,
1737
2235
  port: (ctx as any).handlerPort,
1738
- });
1739
- await new Promise(resolve => setTimeout(resolve, 2000));
2236
+ }));
2237
+ await resetInngest();
1740
2238
 
1741
- const run = workflow.createRun();
2239
+ const run = await workflow.createRunAsync();
1742
2240
  const result = await run.start({ inputData: {} });
1743
2241
 
1744
2242
  expect(step2Action).toHaveBeenCalled();
@@ -1834,13 +2332,13 @@ describe('MastraInngestWorkflow', () => {
1834
2332
 
1835
2333
  const app = await createHonoServer(mastra);
1836
2334
 
1837
- const srv = serve({
2335
+ const srv = (globServer = serve({
1838
2336
  fetch: app.fetch,
1839
2337
  port: (ctx as any).handlerPort,
1840
- });
1841
- await new Promise(resolve => setTimeout(resolve, 2000));
2338
+ }));
2339
+ await resetInngest();
1842
2340
 
1843
- const run = counterWorkflow.createRun();
2341
+ const run = await counterWorkflow.createRunAsync();
1844
2342
  const result = await run.start({ inputData: { target: 10, value: 0 } });
1845
2343
 
1846
2344
  expect(increment).toHaveBeenCalledTimes(12);
@@ -1937,13 +2435,13 @@ describe('MastraInngestWorkflow', () => {
1937
2435
 
1938
2436
  const app = await createHonoServer(mastra);
1939
2437
 
1940
- const srv = serve({
2438
+ const srv = (globServer = serve({
1941
2439
  fetch: app.fetch,
1942
2440
  port: (ctx as any).handlerPort,
1943
- });
1944
- await new Promise(resolve => setTimeout(resolve, 2000));
2441
+ }));
2442
+ await resetInngest();
1945
2443
 
1946
- const run = counterWorkflow.createRun();
2444
+ const run = await counterWorkflow.createRunAsync();
1947
2445
  const result = await run.start({ inputData: { target: 10, value: 0 } });
1948
2446
 
1949
2447
  expect(increment).toHaveBeenCalledTimes(12);
@@ -2026,13 +2524,13 @@ describe('MastraInngestWorkflow', () => {
2026
2524
 
2027
2525
  const app = await createHonoServer(mastra);
2028
2526
 
2029
- const srv = serve({
2527
+ const srv = (globServer = serve({
2030
2528
  fetch: app.fetch,
2031
2529
  port: (ctx as any).handlerPort,
2032
- });
2033
- await new Promise(resolve => setTimeout(resolve, 2000));
2530
+ }));
2531
+ await resetInngest();
2034
2532
 
2035
- const run = counterWorkflow.createRun();
2533
+ const run = await counterWorkflow.createRunAsync();
2036
2534
  const result = await run.start({ inputData: [{ value: 1 }, { value: 22 }, { value: 333 }] });
2037
2535
 
2038
2536
  const endTime = Date.now();
@@ -2179,13 +2677,13 @@ describe('MastraInngestWorkflow', () => {
2179
2677
 
2180
2678
  const app = await createHonoServer(mastra);
2181
2679
 
2182
- const srv = serve({
2680
+ const srv = (globServer = serve({
2183
2681
  fetch: app.fetch,
2184
2682
  port: (ctx as any).handlerPort,
2185
- });
2186
- await new Promise(resolve => setTimeout(resolve, 2000));
2683
+ }));
2684
+ await resetInngest();
2187
2685
 
2188
- const run = counterWorkflow.createRun();
2686
+ const run = await counterWorkflow.createRunAsync();
2189
2687
  const result = await run.start({ inputData: { startValue: 1 } });
2190
2688
 
2191
2689
  expect(start).toHaveBeenCalledTimes(1);
@@ -2328,15 +2826,17 @@ describe('MastraInngestWorkflow', () => {
2328
2826
 
2329
2827
  const app = await createHonoServer(mastra);
2330
2828
 
2331
- const srv = serve({
2829
+ const srv = (globServer = serve({
2332
2830
  fetch: app.fetch,
2333
2831
  port: (ctx as any).handlerPort,
2334
- });
2335
- await new Promise(resolve => setTimeout(resolve, 2000));
2832
+ }));
2833
+ await resetInngest();
2336
2834
 
2337
- const run = counterWorkflow.createRun();
2835
+ const run = await counterWorkflow.createRunAsync();
2338
2836
  const result = await run.start({ inputData: { startValue: 6 } });
2339
2837
 
2838
+ srv.close();
2839
+
2340
2840
  expect(start).toHaveBeenCalledTimes(1);
2341
2841
  expect(other).toHaveBeenCalledTimes(1);
2342
2842
  expect(final).toHaveBeenCalledTimes(1);
@@ -2344,8 +2844,6 @@ describe('MastraInngestWorkflow', () => {
2344
2844
  expect(result.steps['else-branch'].output).toMatchObject({ finalValue: 26 + 6 + 1 });
2345
2845
  // @ts-ignore
2346
2846
  expect(result.steps.start.output).toMatchObject({ newValue: 7 });
2347
-
2348
- srv.close();
2349
2847
  });
2350
2848
  });
2351
2849
 
@@ -2400,7 +2898,7 @@ describe('MastraInngestWorkflow', () => {
2400
2898
  ).rejects.toThrow();
2401
2899
 
2402
2900
  // Should pass validation
2403
- const run = workflow.createRun();
2901
+ const run = await workflow.createRunAsync();
2404
2902
  await run.start({
2405
2903
  inputData: {
2406
2904
  required: 'test',
@@ -2500,19 +2998,19 @@ describe('MastraInngestWorkflow', () => {
2500
2998
 
2501
2999
  const app = await createHonoServer(mastra);
2502
3000
 
2503
- const srv = serve({
3001
+ const srv = (globServer = serve({
2504
3002
  fetch: app.fetch,
2505
3003
  port: (ctx as any).handlerPort,
2506
- });
2507
- await new Promise(resolve => setTimeout(resolve, 2000));
3004
+ }));
3005
+ await resetInngest();
2508
3006
 
2509
- const run = workflow.createRun();
3007
+ const run = await workflow.createRunAsync();
2510
3008
  const result = await run.start({ inputData: {} });
2511
3009
 
3010
+ srv.close();
3011
+
2512
3012
  expect(result.steps['nested-a']).toMatchObject({ status: 'success', output: { result: 'success3' } });
2513
3013
  expect(result.steps['nested-b']).toMatchObject({ status: 'success', output: { result: 'success5' } });
2514
-
2515
- srv.close();
2516
3014
  });
2517
3015
  });
2518
3016
 
@@ -2566,21 +3064,21 @@ describe('MastraInngestWorkflow', () => {
2566
3064
 
2567
3065
  const app = await createHonoServer(mastra);
2568
3066
 
2569
- const srv = serve({
3067
+ const srv = (globServer = serve({
2570
3068
  fetch: app.fetch,
2571
3069
  port: (ctx as any).handlerPort,
2572
- });
2573
- await new Promise(resolve => setTimeout(resolve, 2000));
3070
+ }));
3071
+ await resetInngest();
2574
3072
 
2575
- const run = workflow.createRun();
3073
+ const run = await workflow.createRunAsync();
2576
3074
  const result = await run.start({ inputData: {} });
2577
3075
 
3076
+ srv.close();
3077
+
2578
3078
  expect(result.steps.step1).toMatchObject({ status: 'success', output: { result: 'success' } });
2579
3079
  expect(result.steps.step2).toMatchObject({ status: 'failed', error: 'Step failed' });
2580
3080
  expect(step1.execute).toHaveBeenCalledTimes(1);
2581
3081
  expect(step2.execute).toHaveBeenCalledTimes(1); // 0 retries + 1 initial call
2582
-
2583
- srv.close();
2584
3082
  });
2585
3083
 
2586
3084
  // Need to fix so we can throw for inngest to recognize retries
@@ -2629,7 +3127,7 @@ describe('MastraInngestWorkflow', () => {
2629
3127
 
2630
3128
  workflow.then(step1).then(step2).commit();
2631
3129
 
2632
- const run = workflow.createRun();
3130
+ const run = await workflow.createRunAsync();
2633
3131
  const result = await run.start({ inputData: {} });
2634
3132
 
2635
3133
  expect(result.steps.step1).toMatchObject({ status: 'success', output: { result: 'success' } });
@@ -2698,13 +3196,14 @@ describe('MastraInngestWorkflow', () => {
2698
3196
 
2699
3197
  const app = await createHonoServer(mastra);
2700
3198
 
2701
- const srv = serve({
3199
+ const srv = (globServer = serve({
2702
3200
  fetch: app.fetch,
2703
3201
  port: (ctx as any).handlerPort,
2704
- });
2705
- await new Promise(resolve => setTimeout(resolve, 2000));
3202
+ }));
3203
+ await resetInngest();
2706
3204
 
2707
- const result = await workflow.createRun().start({ inputData: {} });
3205
+ const run = await workflow.createRunAsync();
3206
+ const result = await run.start({ inputData: {} });
2708
3207
 
2709
3208
  srv.close();
2710
3209
 
@@ -2769,13 +3268,13 @@ describe('MastraInngestWorkflow', () => {
2769
3268
 
2770
3269
  const app = await createHonoServer(mastra);
2771
3270
 
2772
- const srv = serve({
3271
+ const srv = (globServer = serve({
2773
3272
  fetch: app.fetch,
2774
3273
  port: (ctx as any).handlerPort,
2775
- });
2776
- await new Promise(resolve => setTimeout(resolve, 2000));
3274
+ }));
3275
+ await resetInngest();
2777
3276
 
2778
- const run = workflow.createRun();
3277
+ const run = await workflow.createRunAsync();
2779
3278
 
2780
3279
  // Start watching the workflow
2781
3280
  let cnt = 0;
@@ -2786,7 +3285,9 @@ describe('MastraInngestWorkflow', () => {
2786
3285
  });
2787
3286
 
2788
3287
  const executionResult = await run.start({ inputData: {} });
2789
- await new Promise(resolve => setTimeout(resolve, 2000));
3288
+ await new Promise(resolve => setTimeout(resolve, 1000));
3289
+
3290
+ srv.close();
2790
3291
 
2791
3292
  expect(cnt).toBe(5);
2792
3293
  expect(resps.length).toBe(5);
@@ -2898,8 +3399,6 @@ describe('MastraInngestWorkflow', () => {
2898
3399
  status: 'success',
2899
3400
  output: { result: 'success2' },
2900
3401
  });
2901
-
2902
- srv.close();
2903
3402
  });
2904
3403
 
2905
3404
  it('should unsubscribe from transitions when unwatch is called', async ctx => {
@@ -2955,16 +3454,16 @@ describe('MastraInngestWorkflow', () => {
2955
3454
 
2956
3455
  const app = await createHonoServer(mastra);
2957
3456
 
2958
- const srv = serve({
3457
+ const srv = (globServer = serve({
2959
3458
  fetch: app.fetch,
2960
3459
  port: (ctx as any).handlerPort,
2961
- });
2962
- await new Promise(resolve => setTimeout(resolve, 2000));
3460
+ }));
3461
+ await resetInngest();
2963
3462
 
2964
3463
  const onTransition = vi.fn();
2965
3464
  const onTransition2 = vi.fn();
2966
3465
 
2967
- const run = workflow.createRun();
3466
+ const run = await workflow.createRunAsync();
2968
3467
 
2969
3468
  run.watch(onTransition);
2970
3469
  run.watch(onTransition2);
@@ -2974,7 +3473,7 @@ describe('MastraInngestWorkflow', () => {
2974
3473
  expect(onTransition).toHaveBeenCalledTimes(5);
2975
3474
  expect(onTransition2).toHaveBeenCalledTimes(5);
2976
3475
 
2977
- const run2 = workflow.createRun();
3476
+ const run2 = await workflow.createRunAsync();
2978
3477
 
2979
3478
  run2.watch(onTransition2);
2980
3479
 
@@ -2983,7 +3482,7 @@ describe('MastraInngestWorkflow', () => {
2983
3482
  expect(onTransition).toHaveBeenCalledTimes(5);
2984
3483
  expect(onTransition2).toHaveBeenCalledTimes(10);
2985
3484
 
2986
- const run3 = workflow.createRun();
3485
+ const run3 = await workflow.createRunAsync();
2987
3486
 
2988
3487
  run3.watch(onTransition);
2989
3488
 
@@ -3018,8 +3517,8 @@ describe('MastraInngestWorkflow', () => {
3018
3517
  outputSchema: z.object({}),
3019
3518
  steps: [],
3020
3519
  });
3021
- const run = workflow.createRun();
3022
- const run2 = workflow.createRun({ runId: run.runId });
3520
+ const run = await workflow.createRunAsync();
3521
+ const run2 = await workflow.createRunAsync({ runId: run.runId });
3023
3522
 
3024
3523
  expect(run.runId).toBeDefined();
3025
3524
  expect(run2.runId).toBeDefined();
@@ -3127,13 +3626,13 @@ describe('MastraInngestWorkflow', () => {
3127
3626
 
3128
3627
  const app = await createHonoServer(mastra);
3129
3628
 
3130
- const srv = serve({
3629
+ const srv = (globServer = serve({
3131
3630
  fetch: app.fetch,
3132
3631
  port: (ctx as any).handlerPort,
3133
- });
3134
- await new Promise(resolve => setTimeout(resolve, 2000));
3632
+ }));
3633
+ await resetInngest();
3135
3634
 
3136
- const run = promptEvalWorkflow.createRun();
3635
+ const run = await promptEvalWorkflow.createRunAsync();
3137
3636
 
3138
3637
  // Create a promise to track when the workflow is ready to resume
3139
3638
  let resolveWorkflowSuspended: (value: unknown) => void;
@@ -3277,13 +3776,13 @@ describe('MastraInngestWorkflow', () => {
3277
3776
 
3278
3777
  const app = await createHonoServer(mastra);
3279
3778
 
3280
- const srv = serve({
3779
+ const srv = (globServer = serve({
3281
3780
  fetch: app.fetch,
3282
3781
  port: (ctx as any).handlerPort,
3283
- });
3284
- await new Promise(resolve => setTimeout(resolve, 2000));
3782
+ }));
3783
+ await resetInngest();
3285
3784
 
3286
- const run = workflow.createRun();
3785
+ const run = await workflow.createRunAsync();
3287
3786
 
3288
3787
  const started = run.start({ inputData: { input: 'test' } });
3289
3788
 
@@ -3315,13 +3814,13 @@ describe('MastraInngestWorkflow', () => {
3315
3814
 
3316
3815
  const initialResult = await started;
3317
3816
 
3817
+ srv.close();
3818
+
3318
3819
  expect(initialResult.steps.humanIntervention.status).toBe('suspended');
3319
3820
  expect(initialResult.steps.explainResponse).toBeUndefined();
3320
3821
  expect(humanInterventionAction).toHaveBeenCalledTimes(2);
3321
3822
  expect(explainResponseAction).not.toHaveBeenCalled();
3322
3823
 
3323
- srv.close();
3324
-
3325
3824
  if (!result) {
3326
3825
  throw new Error('Resume failed to return a result');
3327
3826
  }
@@ -3479,13 +3978,13 @@ describe('MastraInngestWorkflow', () => {
3479
3978
 
3480
3979
  const app = await createHonoServer(mastra);
3481
3980
 
3482
- const srv = serve({
3981
+ const srv = (globServer = serve({
3483
3982
  fetch: app.fetch,
3484
3983
  port: (ctx as any).handlerPort,
3485
- });
3486
- await new Promise(resolve => setTimeout(resolve, 2000));
3984
+ }));
3985
+ await resetInngest();
3487
3986
 
3488
- const run = workflow.createRun();
3987
+ const run = await workflow.createRunAsync();
3489
3988
  const started = run.start({ inputData: { input: 'test' } });
3490
3989
  let improvedResponseResultPromise: Promise<any | undefined>;
3491
3990
 
@@ -3536,11 +4035,12 @@ describe('MastraInngestWorkflow', () => {
3536
4035
  // @ts-ignore
3537
4036
  const improvedResponseResult = await improvedResponseResultPromise;
3538
4037
 
4038
+ srv.close();
4039
+
3539
4040
  expect(improvedResponseResult?.steps.humanIntervention.status).toBe('suspended');
3540
4041
  expect(improvedResponseResult?.steps.improveResponse.status).toBe('success');
3541
4042
  expect(improvedResponseResult?.steps.evaluateImprovedResponse.status).toBe('success');
3542
4043
 
3543
- srv.close();
3544
4044
  if (!result) {
3545
4045
  throw new Error('Resume failed to return a result');
3546
4046
  }
@@ -3673,13 +4173,13 @@ describe('MastraInngestWorkflow', () => {
3673
4173
 
3674
4174
  const app = await createHonoServer(mastra);
3675
4175
 
3676
- const srv = serve({
4176
+ const srv = (globServer = serve({
3677
4177
  fetch: app.fetch,
3678
4178
  port: (ctx as any).handlerPort,
3679
- });
3680
- await new Promise(resolve => setTimeout(resolve, 2000));
4179
+ }));
4180
+ await resetInngest();
3681
4181
 
3682
- const run = promptEvalWorkflow.createRun();
4182
+ const run = await promptEvalWorkflow.createRunAsync();
3683
4183
 
3684
4184
  const initialResult = await run.start({ inputData: { input: 'test' } });
3685
4185
  expect(initialResult.steps.promptAgent.status).toBe('suspended');
@@ -3690,7 +4190,11 @@ describe('MastraInngestWorkflow', () => {
3690
4190
  expect(initialResult.steps).toMatchObject({
3691
4191
  input: { input: 'test' },
3692
4192
  getUserInput: { status: 'success', output: { userInput: 'test input' } },
3693
- promptAgent: { status: 'suspended', payload: { testPayload: 'hello' } },
4193
+ promptAgent: {
4194
+ status: 'suspended',
4195
+ suspendedPayload: { testPayload: 'hello' },
4196
+ payload: { userInput: 'test input' },
4197
+ },
3694
4198
  });
3695
4199
 
3696
4200
  const newCtx = {
@@ -3728,6 +4232,9 @@ describe('MastraInngestWorkflow', () => {
3728
4232
  completenessScore: { score: 0.7 },
3729
4233
  },
3730
4234
  });
4235
+
4236
+ srv.close();
4237
+
3731
4238
  if (!secondResumeResult) {
3732
4239
  throw new Error('Resume failed to return a result');
3733
4240
  }
@@ -3750,8 +4257,6 @@ describe('MastraInngestWorkflow', () => {
3750
4257
  });
3751
4258
 
3752
4259
  expect(promptAgentAction).toHaveBeenCalledTimes(2);
3753
-
3754
- srv.close();
3755
4260
  });
3756
4261
  });
3757
4262
 
@@ -3797,14 +4302,14 @@ describe('MastraInngestWorkflow', () => {
3797
4302
 
3798
4303
  const app = await createHonoServer(mastra);
3799
4304
 
3800
- const srv = serve({
4305
+ const srv = (globServer = serve({
3801
4306
  fetch: app.fetch,
3802
4307
  port: (ctx as any).handlerPort,
3803
- });
3804
- await new Promise(resolve => setTimeout(resolve, 2000));
4308
+ }));
4309
+ await resetInngest();
3805
4310
 
3806
4311
  // Access new instance properties directly - should work without warning
3807
- const run = workflow.createRun();
4312
+ const run = await workflow.createRunAsync();
3808
4313
  await run.start({ inputData: {} });
3809
4314
 
3810
4315
  expect(telemetry).toBeDefined();
@@ -3901,13 +4406,13 @@ describe('MastraInngestWorkflow', () => {
3901
4406
 
3902
4407
  const app = await createHonoServer(mastra);
3903
4408
 
3904
- const srv = serve({
4409
+ const srv = (globServer = serve({
3905
4410
  fetch: app.fetch,
3906
4411
  port: (ctx as any).handlerPort,
3907
- });
3908
- await new Promise(resolve => setTimeout(resolve, 2000));
4412
+ }));
4413
+ await resetInngest();
3909
4414
 
3910
- const run = workflow.createRun();
4415
+ const run = await workflow.createRunAsync();
3911
4416
  const result = await run.start({
3912
4417
  inputData: { prompt1: 'Capital of France, just the name', prompt2: 'Capital of UK, just the name' },
3913
4418
  });
@@ -4038,13 +4543,13 @@ describe('MastraInngestWorkflow', () => {
4038
4543
 
4039
4544
  const app = await createHonoServer(mastra);
4040
4545
 
4041
- const srv = serve({
4546
+ const srv = (globServer = serve({
4042
4547
  fetch: app.fetch,
4043
4548
  port: (ctx as any).handlerPort,
4044
- });
4045
- await new Promise(resolve => setTimeout(resolve, 2000));
4549
+ }));
4550
+ await resetInngest();
4046
4551
 
4047
- const run = workflow.createRun();
4552
+ const run = await workflow.createRunAsync();
4048
4553
  const result = await run.start({
4049
4554
  inputData: { prompt1: 'Capital of France, just the name', prompt2: 'Capital of UK, just the name' },
4050
4555
  });
@@ -4181,13 +4686,13 @@ describe('MastraInngestWorkflow', () => {
4181
4686
 
4182
4687
  const app = await createHonoServer(mastra);
4183
4688
 
4184
- const srv = serve({
4689
+ const srv = (globServer = serve({
4185
4690
  fetch: app.fetch,
4186
4691
  port: (ctx as any).handlerPort,
4187
- });
4188
- await new Promise(resolve => setTimeout(resolve, 2000));
4692
+ }));
4693
+ await resetInngest();
4189
4694
 
4190
- const run = counterWorkflow.createRun();
4695
+ const run = await counterWorkflow.createRunAsync();
4191
4696
  const result = await run.start({ inputData: { startValue: 0 } });
4192
4697
 
4193
4698
  srv.close();
@@ -4333,13 +4838,13 @@ describe('MastraInngestWorkflow', () => {
4333
4838
 
4334
4839
  const app = await createHonoServer(mastra);
4335
4840
 
4336
- const srv = serve({
4841
+ const srv = (globServer = serve({
4337
4842
  fetch: app.fetch,
4338
4843
  port: (ctx as any).handlerPort,
4339
- });
4340
- await new Promise(resolve => setTimeout(resolve, 2000));
4844
+ }));
4845
+ await resetInngest();
4341
4846
 
4342
- const run = counterWorkflow.createRun();
4847
+ const run = await counterWorkflow.createRunAsync();
4343
4848
  const result = await run.start({ inputData: { startValue: 0 } });
4344
4849
 
4345
4850
  srv.close();
@@ -4493,12 +4998,13 @@ describe('MastraInngestWorkflow', () => {
4493
4998
  await next();
4494
4999
  });
4495
5000
 
4496
- const srv = serve({
5001
+ const srv = (globServer = serve({
4497
5002
  fetch: app.fetch,
4498
5003
  port: (ctx as any).handlerPort,
4499
- });
5004
+ }));
5005
+ await resetInngest();
4500
5006
 
4501
- const run = counterWorkflow.createRun();
5007
+ const run = await counterWorkflow.createRunAsync();
4502
5008
  const result = await run.start({ inputData: { startValue: 0 } });
4503
5009
 
4504
5010
  srv.close();
@@ -4652,12 +5158,13 @@ describe('MastraInngestWorkflow', () => {
4652
5158
  await next();
4653
5159
  });
4654
5160
 
4655
- const srv = serve({
5161
+ const srv = (globServer = serve({
4656
5162
  fetch: app.fetch,
4657
5163
  port: (ctx as any).handlerPort,
4658
- });
5164
+ }));
5165
+ await resetInngest();
4659
5166
 
4660
- const run = counterWorkflow.createRun();
5167
+ const run = await counterWorkflow.createRunAsync();
4661
5168
  const result = await run.start({ inputData: { startValue: 0 } });
4662
5169
 
4663
5170
  srv.close();
@@ -4849,12 +5356,13 @@ describe('MastraInngestWorkflow', () => {
4849
5356
  await next();
4850
5357
  });
4851
5358
 
4852
- const srv = serve({
5359
+ const srv = (globServer = serve({
4853
5360
  fetch: app.fetch,
4854
5361
  port: (ctx as any).handlerPort,
4855
- });
5362
+ }));
5363
+ await resetInngest();
4856
5364
 
4857
- const run = counterWorkflow.createRun();
5365
+ const run = await counterWorkflow.createRunAsync();
4858
5366
  const result = await run.start({ inputData: { startValue: 1 } });
4859
5367
 
4860
5368
  srv.close();
@@ -5002,13 +5510,13 @@ describe('MastraInngestWorkflow', () => {
5002
5510
 
5003
5511
  const app = await createHonoServer(mastra);
5004
5512
 
5005
- const srv = serve({
5513
+ const srv = (globServer = serve({
5006
5514
  fetch: app.fetch,
5007
5515
  port: (ctx as any).handlerPort,
5008
- });
5009
- await new Promise(resolve => setTimeout(resolve, 2000));
5516
+ }));
5517
+ await resetInngest();
5010
5518
 
5011
- const run = counterWorkflow.createRun();
5519
+ const run = await counterWorkflow.createRunAsync();
5012
5520
  const result = await run.start({ inputData: { startValue: 0 } });
5013
5521
 
5014
5522
  expect(begin).toHaveBeenCalledTimes(1);
@@ -5153,12 +5661,13 @@ describe('MastraInngestWorkflow', () => {
5153
5661
  await next();
5154
5662
  });
5155
5663
 
5156
- const srv = serve({
5664
+ const srv = (globServer = serve({
5157
5665
  fetch: app.fetch,
5158
5666
  port: (ctx as any).handlerPort,
5159
- });
5667
+ }));
5668
+ await resetInngest();
5160
5669
 
5161
- const run = counterWorkflow.createRun();
5670
+ const run = await counterWorkflow.createRunAsync();
5162
5671
  const result = await run.start({ inputData: { startValue: 0 } });
5163
5672
  const results = result.steps;
5164
5673
 
@@ -5334,13 +5843,13 @@ describe('MastraInngestWorkflow', () => {
5334
5843
 
5335
5844
  const app = await createHonoServer(mastra);
5336
5845
 
5337
- const srv = serve({
5846
+ const srv = (globServer = serve({
5338
5847
  fetch: app.fetch,
5339
5848
  port: (ctx as any).handlerPort,
5340
- });
5341
- await new Promise(resolve => setTimeout(resolve, 2000));
5849
+ }));
5850
+ await resetInngest();
5342
5851
 
5343
- const run = counterWorkflow.createRun();
5852
+ const run = await counterWorkflow.createRunAsync();
5344
5853
  const result = await run.start({ inputData: { startValue: 0 } });
5345
5854
 
5346
5855
  expect(passthroughStep.execute).toHaveBeenCalledTimes(2);
@@ -5496,13 +6005,13 @@ describe('MastraInngestWorkflow', () => {
5496
6005
 
5497
6006
  const app = await createHonoServer(mastra);
5498
6007
 
5499
- const srv = serve({
6008
+ const srv = (globServer = serve({
5500
6009
  fetch: app.fetch,
5501
6010
  port: (ctx as any).handlerPort,
5502
- });
5503
- await new Promise(resolve => setTimeout(resolve, 2000));
6011
+ }));
6012
+ await resetInngest();
5504
6013
 
5505
- const run = counterWorkflow.createRun();
6014
+ const run = await counterWorkflow.createRunAsync();
5506
6015
  const result = await run.start({ inputData: { startValue: 0 } });
5507
6016
 
5508
6017
  srv.close();
@@ -5571,14 +6080,14 @@ describe('MastraInngestWorkflow', () => {
5571
6080
 
5572
6081
  const app = await createHonoServer(mastra);
5573
6082
 
5574
- const srv = serve({
6083
+ const srv = (globServer = serve({
5575
6084
  fetch: app.fetch,
5576
6085
  port: (ctx as any).handlerPort,
5577
- });
5578
- await new Promise(resolve => setTimeout(resolve, 2000));
6086
+ }));
6087
+ await resetInngest();
5579
6088
 
5580
6089
  // Access new instance properties directly - should work without warning
5581
- const run = workflow.createRun();
6090
+ const run = await workflow.createRunAsync();
5582
6091
  await run.start({ inputData: {} });
5583
6092
 
5584
6093
  srv.close();
@@ -5634,12 +6143,13 @@ describe('MastraInngestWorkflow', () => {
5634
6143
 
5635
6144
  const app = await createHonoServer(mastra);
5636
6145
 
5637
- const srv = serve({
6146
+ const srv = (globServer = serve({
5638
6147
  fetch: app.fetch,
5639
6148
  port: (ctx as any).handlerPort,
5640
- });
6149
+ }));
6150
+ await resetInngest();
5641
6151
 
5642
- const run = workflow.createRun();
6152
+ const run = await workflow.createRunAsync();
5643
6153
  const result = await run.start({ runtimeContext });
5644
6154
 
5645
6155
  srv.close();
@@ -5648,7 +6158,7 @@ describe('MastraInngestWorkflow', () => {
5648
6158
  expect(result.steps.step1.output.injectedValue).toBe(testValue);
5649
6159
  });
5650
6160
 
5651
- it('should inject runtimeContext dependencies into steps during resume', async ctx => {
6161
+ it.skip('should inject runtimeContext dependencies into steps during resume', async ctx => {
5652
6162
  const inngest = new Inngest({
5653
6163
  id: 'mastra',
5654
6164
  baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
@@ -5692,7 +6202,7 @@ describe('MastraInngestWorkflow', () => {
5692
6202
  });
5693
6203
  workflow.then(step).commit();
5694
6204
 
5695
- const run = workflow.createRun();
6205
+ const run = await workflow.createRunAsync();
5696
6206
  await run.start({ runtimeContext });
5697
6207
 
5698
6208
  const resumeruntimeContext = new RuntimeContext();
@@ -5733,11 +6243,81 @@ describe('MastraInngestWorkflow', () => {
5733
6243
  const workflow = createWorkflow({
5734
6244
  id: 'test-workflow',
5735
6245
  inputSchema: z.object({}),
5736
- outputSchema: z.object({
5737
- hasEngine: z.boolean(),
5738
- }),
6246
+ outputSchema: z.object({
6247
+ hasEngine: z.boolean(),
6248
+ }),
6249
+ });
6250
+ workflow.then(step).commit();
6251
+
6252
+ const mastra = new Mastra({
6253
+ storage: new DefaultStorage({
6254
+ url: ':memory:',
6255
+ }),
6256
+ workflows: {
6257
+ 'test-workflow': workflow,
6258
+ },
6259
+ server: {
6260
+ apiRoutes: [
6261
+ {
6262
+ path: '/inngest/api',
6263
+ method: 'ALL',
6264
+ createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
6265
+ },
6266
+ ],
6267
+ },
6268
+ });
6269
+
6270
+ const app = await createHonoServer(mastra);
6271
+
6272
+ const srv = (globServer = serve({
6273
+ fetch: app.fetch,
6274
+ port: (ctx as any).handlerPort,
6275
+ }));
6276
+ await resetInngest();
6277
+
6278
+ const run = await workflow.createRunAsync();
6279
+ const result = await run.start({});
6280
+
6281
+ srv.close();
6282
+
6283
+ // @ts-ignore
6284
+ expect(result?.steps.step1.output.hasEngine).toBe(true);
6285
+ });
6286
+ });
6287
+
6288
+ describe('Streaming', () => {
6289
+ it('should generate a stream', async ctx => {
6290
+ const inngest = new Inngest({
6291
+ id: 'mastra',
6292
+ baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
6293
+ middleware: [realtimeMiddleware()],
6294
+ });
6295
+
6296
+ const { createWorkflow, createStep } = init(inngest);
6297
+
6298
+ const step1Action = vi.fn<any>().mockResolvedValue({ result: 'success1' });
6299
+ const step2Action = vi.fn<any>().mockResolvedValue({ result: 'success2' });
6300
+
6301
+ const step1 = createStep({
6302
+ id: 'step1',
6303
+ execute: step1Action,
6304
+ inputSchema: z.object({}),
6305
+ outputSchema: z.object({ value: z.string() }),
6306
+ });
6307
+ const step2 = createStep({
6308
+ id: 'step2',
6309
+ execute: step2Action,
6310
+ inputSchema: z.object({ value: z.string() }),
6311
+ outputSchema: z.object({}),
6312
+ });
6313
+
6314
+ const workflow = createWorkflow({
6315
+ id: 'test-workflow',
6316
+ inputSchema: z.object({}),
6317
+ outputSchema: z.object({}),
6318
+ steps: [step1, step2],
5739
6319
  });
5740
- workflow.then(step).commit();
6320
+ workflow.then(step1).then(step2).commit();
5741
6321
 
5742
6322
  const mastra = new Mastra({
5743
6323
  storage: new DefaultStorage({
@@ -5759,23 +6339,126 @@ describe('MastraInngestWorkflow', () => {
5759
6339
 
5760
6340
  const app = await createHonoServer(mastra);
5761
6341
 
5762
- const srv = serve({
6342
+ const srv = (globServer = serve({
5763
6343
  fetch: app.fetch,
5764
6344
  port: (ctx as any).handlerPort,
6345
+ }));
6346
+ await resetInngest();
6347
+
6348
+ const runId = 'test-run-id';
6349
+ let watchData: StreamEvent[] = [];
6350
+ const run = await workflow.createRunAsync({
6351
+ runId,
5765
6352
  });
5766
6353
 
5767
- const run = workflow.createRun();
5768
- const result = await run.start({});
6354
+ await resetInngest();
6355
+
6356
+ const { stream, getWorkflowState } = run.stream({ inputData: {} });
6357
+
6358
+ // Start watching the workflow
6359
+ const collectedStreamData: StreamEvent[] = [];
6360
+ for await (const data of stream) {
6361
+ collectedStreamData.push(JSON.parse(JSON.stringify(data)));
6362
+ }
6363
+ watchData = collectedStreamData;
6364
+
6365
+ const executionResult = await getWorkflowState();
6366
+
6367
+ await resetInngest();
5769
6368
 
5770
6369
  srv.close();
5771
6370
 
5772
- // @ts-ignore
5773
- expect(result?.steps.step1.output.hasEngine).toBe(true);
6371
+ expect(watchData.length).toBe(8);
6372
+ expect(watchData).toMatchObject([
6373
+ {
6374
+ payload: {
6375
+ runId: 'test-run-id',
6376
+ },
6377
+ type: 'start',
6378
+ },
6379
+ {
6380
+ payload: {
6381
+ id: 'step1',
6382
+ status: 'running',
6383
+ },
6384
+ type: 'step-start',
6385
+ },
6386
+ {
6387
+ payload: {
6388
+ id: 'step1',
6389
+ endedAt: expect.any(Number),
6390
+ startedAt: expect.any(Number),
6391
+ payload: {},
6392
+ output: {
6393
+ result: 'success1',
6394
+ },
6395
+ status: 'success',
6396
+ },
6397
+ type: 'step-result',
6398
+ },
6399
+ {
6400
+ payload: {
6401
+ id: 'step1',
6402
+ metadata: {},
6403
+ },
6404
+ type: 'step-finish',
6405
+ },
6406
+ {
6407
+ payload: {
6408
+ id: 'step2',
6409
+ status: 'running',
6410
+ },
6411
+ type: 'step-start',
6412
+ },
6413
+ {
6414
+ payload: {
6415
+ id: 'step2',
6416
+ endedAt: expect.any(Number),
6417
+ startedAt: expect.any(Number),
6418
+ payload: {
6419
+ result: 'success1',
6420
+ },
6421
+ output: {
6422
+ result: 'success2',
6423
+ },
6424
+ status: 'success',
6425
+ },
6426
+ type: 'step-result',
6427
+ },
6428
+ {
6429
+ payload: {
6430
+ id: 'step2',
6431
+ metadata: {},
6432
+ },
6433
+ type: 'step-finish',
6434
+ },
6435
+ {
6436
+ payload: {
6437
+ runId: 'test-run-id',
6438
+ },
6439
+ type: 'finish',
6440
+ },
6441
+ ]);
6442
+ // Verify execution completed successfully
6443
+ expect(executionResult.steps.step1).toMatchObject({
6444
+ status: 'success',
6445
+ output: { result: 'success1' },
6446
+ payload: {},
6447
+ startedAt: expect.any(Number),
6448
+ endedAt: expect.any(Number),
6449
+ });
6450
+ expect(executionResult.steps.step2).toMatchObject({
6451
+ status: 'success',
6452
+ output: { result: 'success2' },
6453
+ payload: {
6454
+ result: 'success1',
6455
+ },
6456
+ startedAt: expect.any(Number),
6457
+ endedAt: expect.any(Number),
6458
+ });
5774
6459
  });
5775
- });
5776
6460
 
5777
- describe('Streaming', () => {
5778
- it('should generate a stream', async ctx => {
6461
+ it('should handle basic sleep waiting flow', async ctx => {
5779
6462
  const inngest = new Inngest({
5780
6463
  id: 'mastra',
5781
6464
  baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
@@ -5806,7 +6489,7 @@ describe('MastraInngestWorkflow', () => {
5806
6489
  outputSchema: z.object({}),
5807
6490
  steps: [step1, step2],
5808
6491
  });
5809
- workflow.then(step1).then(step2).commit();
6492
+ workflow.then(step1).sleep(1000).then(step2).commit();
5810
6493
 
5811
6494
  const mastra = new Mastra({
5812
6495
  storage: new DefaultStorage({
@@ -5828,18 +6511,19 @@ describe('MastraInngestWorkflow', () => {
5828
6511
 
5829
6512
  const app = await createHonoServer(mastra);
5830
6513
 
5831
- const srv = serve({
6514
+ const srv = (globServer = serve({
5832
6515
  fetch: app.fetch,
5833
6516
  port: (ctx as any).handlerPort,
5834
- });
6517
+ }));
6518
+ await resetInngest();
5835
6519
 
5836
6520
  const runId = 'test-run-id';
5837
6521
  let watchData: StreamEvent[] = [];
5838
- const run = workflow.createRun({
6522
+ const run = await workflow.createRunAsync({
5839
6523
  runId,
5840
6524
  });
5841
6525
 
5842
- await new Promise(resolve => setTimeout(resolve, 1000));
6526
+ await resetInngest();
5843
6527
 
5844
6528
  const { stream, getWorkflowState } = run.stream({ inputData: {} });
5845
6529
 
@@ -5852,73 +6536,112 @@ describe('MastraInngestWorkflow', () => {
5852
6536
 
5853
6537
  const executionResult = await getWorkflowState();
5854
6538
 
5855
- await new Promise(resolve => setTimeout(resolve, 1000));
6539
+ await resetInngest();
5856
6540
 
5857
6541
  srv.close();
5858
6542
 
5859
- expect(watchData.length).toBe(8);
5860
- expect(watchData).toMatchInlineSnapshot(`
5861
- [
5862
- {
5863
- "payload": {
5864
- "runId": "test-run-id",
5865
- },
5866
- "type": "start",
6543
+ expect(watchData.length).toBe(11);
6544
+ expect(watchData).toMatchObject([
6545
+ {
6546
+ payload: {
6547
+ runId: 'test-run-id',
5867
6548
  },
5868
- {
5869
- "payload": {
5870
- "id": "step1",
5871
- },
5872
- "type": "step-start",
6549
+ type: 'start',
6550
+ },
6551
+ {
6552
+ payload: {
6553
+ id: 'step1',
6554
+ startedAt: expect.any(Number),
6555
+ status: 'running',
6556
+ payload: {},
5873
6557
  },
5874
- {
5875
- "payload": {
5876
- "id": "step1",
5877
- "output": {
5878
- "result": "success1",
5879
- },
5880
- "status": "success",
6558
+ type: 'step-start',
6559
+ },
6560
+ {
6561
+ payload: {
6562
+ id: 'step1',
6563
+ output: {
6564
+ result: 'success1',
5881
6565
  },
5882
- "type": "step-result",
6566
+ endedAt: expect.any(Number),
6567
+ status: 'success',
5883
6568
  },
5884
- {
5885
- "payload": {
5886
- "id": "step1",
5887
- "metadata": {},
5888
- },
5889
- "type": "step-finish",
6569
+ type: 'step-result',
6570
+ },
6571
+ {
6572
+ payload: {
6573
+ id: 'step1',
6574
+ metadata: {},
5890
6575
  },
5891
- {
5892
- "payload": {
5893
- "id": "step2",
6576
+ type: 'step-finish',
6577
+ },
6578
+ {
6579
+ payload: {
6580
+ id: expect.any(String),
6581
+ startedAt: expect.any(Number),
6582
+ status: 'waiting',
6583
+ payload: {
6584
+ result: 'success1',
5894
6585
  },
5895
- "type": "step-start",
5896
6586
  },
5897
- {
5898
- "payload": {
5899
- "id": "step2",
5900
- "output": {
5901
- "result": "success2",
5902
- },
5903
- "status": "success",
6587
+ type: 'step-waiting',
6588
+ },
6589
+ {
6590
+ payload: {
6591
+ id: expect.any(String),
6592
+ endedAt: expect.any(Number),
6593
+ startedAt: expect.any(Number),
6594
+ status: 'success',
6595
+ output: {
6596
+ result: 'success1',
5904
6597
  },
5905
- "type": "step-result",
5906
6598
  },
5907
- {
5908
- "payload": {
5909
- "id": "step2",
5910
- "metadata": {},
6599
+ type: 'step-result',
6600
+ },
6601
+ {
6602
+ type: 'step-finish',
6603
+ payload: {
6604
+ id: expect.any(String),
6605
+ metadata: {},
6606
+ },
6607
+ },
6608
+ {
6609
+ payload: {
6610
+ id: 'step2',
6611
+ payload: {
6612
+ result: 'success1',
5911
6613
  },
5912
- "type": "step-finish",
6614
+ startedAt: expect.any(Number),
6615
+ status: 'running',
5913
6616
  },
5914
- {
5915
- "payload": {
5916
- "runId": "test-run-id",
6617
+ type: 'step-start',
6618
+ },
6619
+ {
6620
+ payload: {
6621
+ id: 'step2',
6622
+ output: {
6623
+ result: 'success2',
5917
6624
  },
5918
- "type": "finish",
6625
+ endedAt: expect.any(Number),
6626
+ status: 'success',
6627
+ },
6628
+ type: 'step-result',
6629
+ },
6630
+ {
6631
+ payload: {
6632
+ id: 'step2',
6633
+ metadata: {},
6634
+ },
6635
+ type: 'step-finish',
6636
+ },
6637
+ {
6638
+ payload: {
6639
+ runId: 'test-run-id',
5919
6640
  },
5920
- ]
5921
- `);
6641
+ type: 'finish',
6642
+ },
6643
+ ]);
6644
+
5922
6645
  // Verify execution completed successfully
5923
6646
  expect(executionResult.steps.step1).toMatchObject({
5924
6647
  status: 'success',
@@ -5938,7 +6661,7 @@ describe('MastraInngestWorkflow', () => {
5938
6661
  });
5939
6662
  });
5940
6663
 
5941
- it('should handle basic sleep waiting flow', async ctx => {
6664
+ it('should handle basic sleep waiting flow with fn parameter', async ctx => {
5942
6665
  const inngest = new Inngest({
5943
6666
  id: 'mastra',
5944
6667
  baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
@@ -5947,19 +6670,19 @@ describe('MastraInngestWorkflow', () => {
5947
6670
 
5948
6671
  const { createWorkflow, createStep } = init(inngest);
5949
6672
 
5950
- const step1Action = vi.fn<any>().mockResolvedValue({ result: 'success1' });
5951
- const step2Action = vi.fn<any>().mockResolvedValue({ result: 'success2' });
6673
+ const step1Action = vi.fn<any>().mockResolvedValue({ value: 1000 });
6674
+ const step2Action = vi.fn<any>().mockResolvedValue({ value: 2000 });
5952
6675
 
5953
6676
  const step1 = createStep({
5954
6677
  id: 'step1',
5955
6678
  execute: step1Action,
5956
6679
  inputSchema: z.object({}),
5957
- outputSchema: z.object({ value: z.string() }),
6680
+ outputSchema: z.object({ value: z.number() }),
5958
6681
  });
5959
6682
  const step2 = createStep({
5960
6683
  id: 'step2',
5961
6684
  execute: step2Action,
5962
- inputSchema: z.object({ value: z.string() }),
6685
+ inputSchema: z.object({ value: z.number() }),
5963
6686
  outputSchema: z.object({}),
5964
6687
  });
5965
6688
 
@@ -5969,7 +6692,13 @@ describe('MastraInngestWorkflow', () => {
5969
6692
  outputSchema: z.object({}),
5970
6693
  steps: [step1, step2],
5971
6694
  });
5972
- workflow.then(step1).sleep(1000).then(step2).commit();
6695
+ workflow
6696
+ .then(step1)
6697
+ .sleep(async ({ inputData }) => {
6698
+ return inputData.value;
6699
+ })
6700
+ .then(step2)
6701
+ .commit();
5973
6702
 
5974
6703
  const mastra = new Mastra({
5975
6704
  storage: new DefaultStorage({
@@ -5991,18 +6720,19 @@ describe('MastraInngestWorkflow', () => {
5991
6720
 
5992
6721
  const app = await createHonoServer(mastra);
5993
6722
 
5994
- const srv = serve({
6723
+ const srv = (globServer = serve({
5995
6724
  fetch: app.fetch,
5996
6725
  port: (ctx as any).handlerPort,
5997
- });
6726
+ }));
6727
+ await resetInngest();
5998
6728
 
5999
6729
  const runId = 'test-run-id';
6000
6730
  let watchData: StreamEvent[] = [];
6001
- const run = workflow.createRun({
6731
+ const run = await workflow.createRunAsync({
6002
6732
  runId,
6003
6733
  });
6004
6734
 
6005
- await new Promise(resolve => setTimeout(resolve, 1000));
6735
+ await resetInngest();
6006
6736
 
6007
6737
  const { stream, getWorkflowState } = run.stream({ inputData: {} });
6008
6738
 
@@ -6015,11 +6745,11 @@ describe('MastraInngestWorkflow', () => {
6015
6745
 
6016
6746
  const executionResult = await getWorkflowState();
6017
6747
 
6018
- await new Promise(resolve => setTimeout(resolve, 1000));
6748
+ await resetInngest();
6019
6749
 
6020
6750
  srv.close();
6021
6751
 
6022
- expect(watchData.length).toBe(9);
6752
+ expect(watchData.length).toBe(11);
6023
6753
  expect(watchData).toMatchObject([
6024
6754
  {
6025
6755
  payload: {
@@ -6030,6 +6760,9 @@ describe('MastraInngestWorkflow', () => {
6030
6760
  {
6031
6761
  payload: {
6032
6762
  id: 'step1',
6763
+ startedAt: expect.any(Number),
6764
+ status: 'running',
6765
+ payload: {},
6033
6766
  },
6034
6767
  type: 'step-start',
6035
6768
  },
@@ -6037,8 +6770,9 @@ describe('MastraInngestWorkflow', () => {
6037
6770
  payload: {
6038
6771
  id: 'step1',
6039
6772
  output: {
6040
- result: 'success1',
6773
+ value: 1000,
6041
6774
  },
6775
+ endedAt: expect.any(Number),
6042
6776
  status: 'success',
6043
6777
  },
6044
6778
  type: 'step-result',
@@ -6051,12 +6785,43 @@ describe('MastraInngestWorkflow', () => {
6051
6785
  type: 'step-finish',
6052
6786
  },
6053
6787
  {
6054
- payload: {},
6788
+ payload: {
6789
+ id: expect.any(String),
6790
+ startedAt: expect.any(Number),
6791
+ status: 'waiting',
6792
+ payload: {
6793
+ value: 1000,
6794
+ },
6795
+ },
6055
6796
  type: 'step-waiting',
6056
6797
  },
6798
+ {
6799
+ payload: {
6800
+ id: expect.any(String),
6801
+ endedAt: expect.any(Number),
6802
+ startedAt: expect.any(Number),
6803
+ status: 'success',
6804
+ output: {
6805
+ value: 1000,
6806
+ },
6807
+ },
6808
+ type: 'step-result',
6809
+ },
6810
+ {
6811
+ type: 'step-finish',
6812
+ payload: {
6813
+ id: expect.any(String),
6814
+ metadata: {},
6815
+ },
6816
+ },
6057
6817
  {
6058
6818
  payload: {
6059
6819
  id: 'step2',
6820
+ payload: {
6821
+ value: 1000,
6822
+ },
6823
+ startedAt: expect.any(Number),
6824
+ status: 'running',
6060
6825
  },
6061
6826
  type: 'step-start',
6062
6827
  },
@@ -6064,8 +6829,9 @@ describe('MastraInngestWorkflow', () => {
6064
6829
  payload: {
6065
6830
  id: 'step2',
6066
6831
  output: {
6067
- result: 'success2',
6832
+ value: 2000,
6068
6833
  },
6834
+ endedAt: expect.any(Number),
6069
6835
  status: 'success',
6070
6836
  },
6071
6837
  type: 'step-result',
@@ -6084,19 +6850,20 @@ describe('MastraInngestWorkflow', () => {
6084
6850
  type: 'finish',
6085
6851
  },
6086
6852
  ]);
6853
+
6087
6854
  // Verify execution completed successfully
6088
6855
  expect(executionResult.steps.step1).toMatchObject({
6089
6856
  status: 'success',
6090
- output: { result: 'success1' },
6857
+ output: { value: 1000 },
6091
6858
  payload: {},
6092
6859
  startedAt: expect.any(Number),
6093
6860
  endedAt: expect.any(Number),
6094
6861
  });
6095
6862
  expect(executionResult.steps.step2).toMatchObject({
6096
6863
  status: 'success',
6097
- output: { result: 'success2' },
6864
+ output: { value: 2000 },
6098
6865
  payload: {
6099
- result: 'success1',
6866
+ value: 1000,
6100
6867
  },
6101
6868
  startedAt: expect.any(Number),
6102
6869
  endedAt: expect.any(Number),
@@ -6156,18 +6923,19 @@ describe('MastraInngestWorkflow', () => {
6156
6923
 
6157
6924
  const app = await createHonoServer(mastra);
6158
6925
 
6159
- const srv = serve({
6926
+ const srv = (globServer = serve({
6160
6927
  fetch: app.fetch,
6161
6928
  port: (ctx as any).handlerPort,
6162
- });
6929
+ }));
6930
+ await resetInngest();
6163
6931
 
6164
6932
  const runId = 'test-run-id';
6165
6933
  let watchData: StreamEvent[] = [];
6166
- const run = workflow.createRun({
6934
+ const run = await workflow.createRunAsync({
6167
6935
  runId,
6168
6936
  });
6169
6937
 
6170
- await new Promise(resolve => setTimeout(resolve, 1000));
6938
+ await resetInngest();
6171
6939
 
6172
6940
  const { stream, getWorkflowState } = run.stream({ inputData: {} });
6173
6941
 
@@ -6187,7 +6955,7 @@ describe('MastraInngestWorkflow', () => {
6187
6955
 
6188
6956
  const executionResult = await getWorkflowState();
6189
6957
 
6190
- await new Promise(resolve => setTimeout(resolve, 1000));
6958
+ await resetInngest();
6191
6959
 
6192
6960
  srv.close();
6193
6961
 
@@ -6381,14 +7149,14 @@ describe('MastraInngestWorkflow', () => {
6381
7149
 
6382
7150
  const app = await createHonoServer(mastra);
6383
7151
 
6384
- const srv = serve({
7152
+ const srv = (globServer = serve({
6385
7153
  fetch: app.fetch,
6386
7154
  port: (ctx as any).handlerPort,
6387
- });
7155
+ }));
6388
7156
 
6389
- await new Promise(resolve => setTimeout(resolve, 1000));
7157
+ await resetInngest();
6390
7158
 
6391
- const run = promptEvalWorkflow.createRun();
7159
+ const run = await promptEvalWorkflow.createRunAsync();
6392
7160
 
6393
7161
  const { stream, getWorkflowState } = run.stream({ inputData: { input: 'test' } });
6394
7162
 
@@ -6570,17 +7338,17 @@ describe('MastraInngestWorkflow', () => {
6570
7338
 
6571
7339
  const app = await createHonoServer(mastra);
6572
7340
 
6573
- const srv = serve({
7341
+ const srv = (globServer = serve({
6574
7342
  fetch: app.fetch,
6575
7343
  port: (ctx as any).handlerPort,
6576
- });
7344
+ }));
6577
7345
 
6578
- await new Promise(resolve => setTimeout(resolve, 1000));
7346
+ await resetInngest();
6579
7347
 
6580
- const run = workflow.createRun({
7348
+ const run = await workflow.createRunAsync({
6581
7349
  runId: 'test-run-id',
6582
7350
  });
6583
- const { stream } = await run.stream({
7351
+ const { stream } = run.stream({
6584
7352
  inputData: {
6585
7353
  prompt1: 'Capital of France, just the name',
6586
7354
  prompt2: 'Capital of UK, just the name',