@mastra/inngest 0.0.0-custom-instrumentation-20250626084921 → 0.0.0-custom-instrumentation-20250708222033

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,27 +20,27 @@ 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', () => {
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 new Promise(resolve => setTimeout(resolve, 2000));
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 new Promise(resolve => setTimeout(resolve, 2000));
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 new Promise(resolve => setTimeout(resolve, 2000));
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 a sleep step', async ctx => {
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 new Promise(resolve => setTimeout(resolve, 2000));
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 a sleep until step', async ctx => {
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({ result: 'success' });
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({ result: z.string() }),
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 { result: 'slept successfully: ' + inputData.result };
476
+ return { value: inputData.value + 1000 };
477
477
  },
478
- inputSchema: z.object({ result: z.string() }),
479
- outputSchema: z.object({ result: z.string() }),
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
- result: z.string(),
486
+ value: z.number(),
487
487
  }),
488
488
  steps: [step1],
489
489
  });
490
490
 
491
491
  workflow
492
492
  .then(step1)
493
- .sleepUntil(new Date(Date.now() + 1000))
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 new Promise(resolve => setTimeout(resolve, 2000));
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: { result: 'success' },
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: { result: 'slept successfully: success' },
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 waitForEvent step', async ctx => {
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, resumeData }) => {
568
- return { result: inputData.result, resumed: resumeData };
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(), resumed: z.any() }),
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.then(step1).waitForEvent('hello-event', step2).commit();
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 new Promise(resolve => setTimeout(resolve, 2000));
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: 'success', resumed: { data: 'hello' } },
633
- payload: { result: 'success' },
634
- // resumePayload: { data: 'hello' },
635
- startedAt: expect.any(Number),
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 a waitForEvent step after timeout', async ctx => {
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({ result: 'success' });
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({ result: z.string() }),
657
+ outputSchema: z.object({ value: z.number() }),
658
658
  });
659
659
  const step2 = createStep({
660
660
  id: 'step2',
661
- execute: async ({ inputData, resumeData }) => {
662
- return { result: inputData.result, resumed: resumeData };
661
+ execute: async ({ inputData }) => {
662
+ return { value: inputData.value + 1000 };
663
663
  },
664
- inputSchema: z.object({ result: z.string() }),
665
- outputSchema: z.object({ result: z.string(), resumed: z.any() }),
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
- result: z.string(),
674
- resumed: z.any(),
672
+ value: z.number(),
675
673
  }),
676
674
  steps: [step1],
677
675
  });
678
676
 
679
- workflow.then(step1).waitForEvent('hello-event', step2, { timeout: 1000 }).commit();
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 new Promise(resolve => setTimeout(resolve, 2000));
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: { result: 'success' },
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: 'failed',
723
- error: expect.any(String),
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
- describe('Variable Resolution', () => {
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({ inputData: z.string() }),
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({ inputData: z.string() }),
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).then(step2).commit();
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 result = await run.start({ inputData: { inputData: 'test-input' } });
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(result.steps.step1).toMatchObject({ status: 'success', output: { result: 'success' } });
796
- expect(result.steps.step2).toMatchObject({ status: 'success', output: { result: 'success' } });
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 provide access to step results and trigger data via getStepResult helper', async ctx => {
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 step1Action = vi.fn().mockImplementation(async ({ inputData }) => {
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: step1Action,
829
- inputSchema: z.object({ inputValue: z.string() }),
830
- outputSchema: z.object({ value: z.string() }),
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: step2Action,
835
- inputSchema: z.object({ value: z.string() }),
836
- outputSchema: z.object({ value: z.string() }),
837
- });
838
-
839
- const nonExecutedStep = createStep({
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({ inputValue: z.string() }),
849
- outputSchema: z.object({ value: z.string() }),
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).then(step2).commit();
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 result = await run.start({ inputData: { inputValue: 'test-input' } });
896
+ const startTime = Date.now();
897
+ const result = await run.start({ inputData: {} });
898
+ const endTime = Date.now();
881
899
 
882
- expect(step1Action).toHaveBeenCalled();
883
- expect(step2Action).toHaveBeenCalled();
884
- expect(result.steps).toMatchObject({
885
- input: { inputValue: 'test-input' },
886
- step1: { status: 'success', output: { value: 'step1-result' } },
887
- step2: { status: 'success', output: { value: 'step2-result' } },
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
- it('should resolve trigger data from context', async ctx => {
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
- inputSchema: triggerSchema,
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: triggerSchema,
916
- outputSchema: z.object({ result: z.string() }),
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
- await run.start({ inputData: { inputData: 'test-input' } });
988
+ const p = run.start({ inputData: { value: 'test' } });
948
989
 
949
- expect(execute).toHaveBeenCalledWith(
950
- expect.objectContaining({
951
- inputData: { inputData: 'test-input' },
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 new Promise(resolve => setTimeout(resolve, 2000));
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 new Promise(resolve => setTimeout(resolve, 2000));
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 new Promise(resolve => setTimeout(resolve, 2000));
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 new Promise(resolve => setTimeout(resolve, 2000));
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 new Promise(resolve => setTimeout(resolve, 2000));
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 new Promise(resolve => setTimeout(resolve, 2000));
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 new Promise(resolve => setTimeout(resolve, 2000));
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 new Promise(resolve => setTimeout(resolve, 2000));
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 new Promise(resolve => setTimeout(resolve, 2000));
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 new Promise(resolve => setTimeout(resolve, 2000));
3004
+ }));
3005
+ await resetInngest();
2611
3006
 
2612
3007
  const run = await workflow.createRunAsync();
2613
3008
  const result = await run.start({ inputData: {} });
2614
3009
 
3010
+ srv.close();
3011
+
2615
3012
  expect(result.steps['nested-a']).toMatchObject({ status: 'success', output: { result: 'success3' } });
2616
3013
  expect(result.steps['nested-b']).toMatchObject({ status: 'success', output: { result: 'success5' } });
2617
-
2618
- srv.close();
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 new Promise(resolve => setTimeout(resolve, 2000));
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 new Promise(resolve => setTimeout(resolve, 2000));
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 new Promise(resolve => setTimeout(resolve, 2000));
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, 2000));
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 new Promise(resolve => setTimeout(resolve, 2000));
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 new Promise(resolve => setTimeout(resolve, 2000));
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 new Promise(resolve => setTimeout(resolve, 2000));
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 new Promise(resolve => setTimeout(resolve, 2000));
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 new Promise(resolve => setTimeout(resolve, 2000));
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,8 +4257,6 @@ describe('MastraInngestWorkflow', () => {
3858
4257
  });
3859
4258
 
3860
4259
  expect(promptAgentAction).toHaveBeenCalledTimes(2);
3861
-
3862
- srv.close();
3863
4260
  });
3864
4261
  });
3865
4262
 
@@ -3905,11 +4302,11 @@ describe('MastraInngestWorkflow', () => {
3905
4302
 
3906
4303
  const app = await createHonoServer(mastra);
3907
4304
 
3908
- const srv = serve({
4305
+ const srv = (globServer = serve({
3909
4306
  fetch: app.fetch,
3910
4307
  port: (ctx as any).handlerPort,
3911
- });
3912
- await new Promise(resolve => setTimeout(resolve, 2000));
4308
+ }));
4309
+ await resetInngest();
3913
4310
 
3914
4311
  // Access new instance properties directly - should work without warning
3915
4312
  const run = await workflow.createRunAsync();
@@ -4009,11 +4406,11 @@ describe('MastraInngestWorkflow', () => {
4009
4406
 
4010
4407
  const app = await createHonoServer(mastra);
4011
4408
 
4012
- const srv = serve({
4409
+ const srv = (globServer = serve({
4013
4410
  fetch: app.fetch,
4014
4411
  port: (ctx as any).handlerPort,
4015
- });
4016
- await new Promise(resolve => setTimeout(resolve, 2000));
4412
+ }));
4413
+ await resetInngest();
4017
4414
 
4018
4415
  const run = await workflow.createRunAsync();
4019
4416
  const result = await run.start({
@@ -4146,11 +4543,11 @@ describe('MastraInngestWorkflow', () => {
4146
4543
 
4147
4544
  const app = await createHonoServer(mastra);
4148
4545
 
4149
- const srv = serve({
4546
+ const srv = (globServer = serve({
4150
4547
  fetch: app.fetch,
4151
4548
  port: (ctx as any).handlerPort,
4152
- });
4153
- await new Promise(resolve => setTimeout(resolve, 2000));
4549
+ }));
4550
+ await resetInngest();
4154
4551
 
4155
4552
  const run = await workflow.createRunAsync();
4156
4553
  const result = await run.start({
@@ -4289,11 +4686,11 @@ describe('MastraInngestWorkflow', () => {
4289
4686
 
4290
4687
  const app = await createHonoServer(mastra);
4291
4688
 
4292
- const srv = serve({
4689
+ const srv = (globServer = serve({
4293
4690
  fetch: app.fetch,
4294
4691
  port: (ctx as any).handlerPort,
4295
- });
4296
- await new Promise(resolve => setTimeout(resolve, 2000));
4692
+ }));
4693
+ await resetInngest();
4297
4694
 
4298
4695
  const run = await counterWorkflow.createRunAsync();
4299
4696
  const result = await run.start({ inputData: { startValue: 0 } });
@@ -4441,11 +4838,11 @@ describe('MastraInngestWorkflow', () => {
4441
4838
 
4442
4839
  const app = await createHonoServer(mastra);
4443
4840
 
4444
- const srv = serve({
4841
+ const srv = (globServer = serve({
4445
4842
  fetch: app.fetch,
4446
4843
  port: (ctx as any).handlerPort,
4447
- });
4448
- await new Promise(resolve => setTimeout(resolve, 2000));
4844
+ }));
4845
+ await resetInngest();
4449
4846
 
4450
4847
  const run = await counterWorkflow.createRunAsync();
4451
4848
  const result = await run.start({ inputData: { startValue: 0 } });
@@ -4601,10 +4998,11 @@ describe('MastraInngestWorkflow', () => {
4601
4998
  await next();
4602
4999
  });
4603
5000
 
4604
- const srv = serve({
5001
+ const srv = (globServer = serve({
4605
5002
  fetch: app.fetch,
4606
5003
  port: (ctx as any).handlerPort,
4607
- });
5004
+ }));
5005
+ await resetInngest();
4608
5006
 
4609
5007
  const run = await counterWorkflow.createRunAsync();
4610
5008
  const result = await run.start({ inputData: { startValue: 0 } });
@@ -4760,10 +5158,11 @@ describe('MastraInngestWorkflow', () => {
4760
5158
  await next();
4761
5159
  });
4762
5160
 
4763
- const srv = serve({
5161
+ const srv = (globServer = serve({
4764
5162
  fetch: app.fetch,
4765
5163
  port: (ctx as any).handlerPort,
4766
- });
5164
+ }));
5165
+ await resetInngest();
4767
5166
 
4768
5167
  const run = await counterWorkflow.createRunAsync();
4769
5168
  const result = await run.start({ inputData: { startValue: 0 } });
@@ -4957,10 +5356,11 @@ describe('MastraInngestWorkflow', () => {
4957
5356
  await next();
4958
5357
  });
4959
5358
 
4960
- const srv = serve({
5359
+ const srv = (globServer = serve({
4961
5360
  fetch: app.fetch,
4962
5361
  port: (ctx as any).handlerPort,
4963
- });
5362
+ }));
5363
+ await resetInngest();
4964
5364
 
4965
5365
  const run = await counterWorkflow.createRunAsync();
4966
5366
  const result = await run.start({ inputData: { startValue: 1 } });
@@ -5110,11 +5510,11 @@ describe('MastraInngestWorkflow', () => {
5110
5510
 
5111
5511
  const app = await createHonoServer(mastra);
5112
5512
 
5113
- const srv = serve({
5513
+ const srv = (globServer = serve({
5114
5514
  fetch: app.fetch,
5115
5515
  port: (ctx as any).handlerPort,
5116
- });
5117
- await new Promise(resolve => setTimeout(resolve, 2000));
5516
+ }));
5517
+ await resetInngest();
5118
5518
 
5119
5519
  const run = await counterWorkflow.createRunAsync();
5120
5520
  const result = await run.start({ inputData: { startValue: 0 } });
@@ -5261,10 +5661,11 @@ describe('MastraInngestWorkflow', () => {
5261
5661
  await next();
5262
5662
  });
5263
5663
 
5264
- const srv = serve({
5664
+ const srv = (globServer = serve({
5265
5665
  fetch: app.fetch,
5266
5666
  port: (ctx as any).handlerPort,
5267
- });
5667
+ }));
5668
+ await resetInngest();
5268
5669
 
5269
5670
  const run = await counterWorkflow.createRunAsync();
5270
5671
  const result = await run.start({ inputData: { startValue: 0 } });
@@ -5442,11 +5843,11 @@ describe('MastraInngestWorkflow', () => {
5442
5843
 
5443
5844
  const app = await createHonoServer(mastra);
5444
5845
 
5445
- const srv = serve({
5846
+ const srv = (globServer = serve({
5446
5847
  fetch: app.fetch,
5447
5848
  port: (ctx as any).handlerPort,
5448
- });
5449
- await new Promise(resolve => setTimeout(resolve, 2000));
5849
+ }));
5850
+ await resetInngest();
5450
5851
 
5451
5852
  const run = await counterWorkflow.createRunAsync();
5452
5853
  const result = await run.start({ inputData: { startValue: 0 } });
@@ -5604,11 +6005,11 @@ describe('MastraInngestWorkflow', () => {
5604
6005
 
5605
6006
  const app = await createHonoServer(mastra);
5606
6007
 
5607
- const srv = serve({
6008
+ const srv = (globServer = serve({
5608
6009
  fetch: app.fetch,
5609
6010
  port: (ctx as any).handlerPort,
5610
- });
5611
- await new Promise(resolve => setTimeout(resolve, 2000));
6011
+ }));
6012
+ await resetInngest();
5612
6013
 
5613
6014
  const run = await counterWorkflow.createRunAsync();
5614
6015
  const result = await run.start({ inputData: { startValue: 0 } });
@@ -5679,11 +6080,11 @@ describe('MastraInngestWorkflow', () => {
5679
6080
 
5680
6081
  const app = await createHonoServer(mastra);
5681
6082
 
5682
- const srv = serve({
6083
+ const srv = (globServer = serve({
5683
6084
  fetch: app.fetch,
5684
6085
  port: (ctx as any).handlerPort,
5685
- });
5686
- await new Promise(resolve => setTimeout(resolve, 2000));
6086
+ }));
6087
+ await resetInngest();
5687
6088
 
5688
6089
  // Access new instance properties directly - should work without warning
5689
6090
  const run = await workflow.createRunAsync();
@@ -5742,10 +6143,11 @@ describe('MastraInngestWorkflow', () => {
5742
6143
 
5743
6144
  const app = await createHonoServer(mastra);
5744
6145
 
5745
- const srv = serve({
6146
+ const srv = (globServer = serve({
5746
6147
  fetch: app.fetch,
5747
6148
  port: (ctx as any).handlerPort,
5748
- });
6149
+ }));
6150
+ await resetInngest();
5749
6151
 
5750
6152
  const run = await workflow.createRunAsync();
5751
6153
  const result = await run.start({ runtimeContext });
@@ -5756,7 +6158,7 @@ describe('MastraInngestWorkflow', () => {
5756
6158
  expect(result.steps.step1.output.injectedValue).toBe(testValue);
5757
6159
  });
5758
6160
 
5759
- it('should inject runtimeContext dependencies into steps during resume', async ctx => {
6161
+ it.skip('should inject runtimeContext dependencies into steps during resume', async ctx => {
5760
6162
  const inngest = new Inngest({
5761
6163
  id: 'mastra',
5762
6164
  baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
@@ -5841,11 +6243,81 @@ describe('MastraInngestWorkflow', () => {
5841
6243
  const workflow = createWorkflow({
5842
6244
  id: 'test-workflow',
5843
6245
  inputSchema: z.object({}),
5844
- outputSchema: z.object({
5845
- hasEngine: z.boolean(),
5846
- }),
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],
5847
6319
  });
5848
- workflow.then(step).commit();
6320
+ workflow.then(step1).then(step2).commit();
5849
6321
 
5850
6322
  const mastra = new Mastra({
5851
6323
  storage: new DefaultStorage({
@@ -5867,23 +6339,126 @@ describe('MastraInngestWorkflow', () => {
5867
6339
 
5868
6340
  const app = await createHonoServer(mastra);
5869
6341
 
5870
- const srv = serve({
6342
+ const srv = (globServer = serve({
5871
6343
  fetch: app.fetch,
5872
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,
5873
6352
  });
5874
6353
 
5875
- const run = await workflow.createRunAsync();
5876
- 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();
5877
6368
 
5878
6369
  srv.close();
5879
6370
 
5880
- // @ts-ignore
5881
- 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
+ });
5882
6459
  });
5883
- });
5884
6460
 
5885
- describe('Streaming', () => {
5886
- it('should generate a stream', async ctx => {
6461
+ it('should handle basic sleep waiting flow', async ctx => {
5887
6462
  const inngest = new Inngest({
5888
6463
  id: 'mastra',
5889
6464
  baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
@@ -5914,7 +6489,7 @@ describe('MastraInngestWorkflow', () => {
5914
6489
  outputSchema: z.object({}),
5915
6490
  steps: [step1, step2],
5916
6491
  });
5917
- workflow.then(step1).then(step2).commit();
6492
+ workflow.then(step1).sleep(1000).then(step2).commit();
5918
6493
 
5919
6494
  const mastra = new Mastra({
5920
6495
  storage: new DefaultStorage({
@@ -5936,10 +6511,11 @@ describe('MastraInngestWorkflow', () => {
5936
6511
 
5937
6512
  const app = await createHonoServer(mastra);
5938
6513
 
5939
- const srv = serve({
6514
+ const srv = (globServer = serve({
5940
6515
  fetch: app.fetch,
5941
6516
  port: (ctx as any).handlerPort,
5942
- });
6517
+ }));
6518
+ await resetInngest();
5943
6519
 
5944
6520
  const runId = 'test-run-id';
5945
6521
  let watchData: StreamEvent[] = [];
@@ -5947,7 +6523,7 @@ describe('MastraInngestWorkflow', () => {
5947
6523
  runId,
5948
6524
  });
5949
6525
 
5950
- await new Promise(resolve => setTimeout(resolve, 1000));
6526
+ await resetInngest();
5951
6527
 
5952
6528
  const { stream, getWorkflowState } = run.stream({ inputData: {} });
5953
6529
 
@@ -5960,73 +6536,112 @@ describe('MastraInngestWorkflow', () => {
5960
6536
 
5961
6537
  const executionResult = await getWorkflowState();
5962
6538
 
5963
- await new Promise(resolve => setTimeout(resolve, 1000));
6539
+ await resetInngest();
5964
6540
 
5965
6541
  srv.close();
5966
6542
 
5967
- expect(watchData.length).toBe(8);
5968
- expect(watchData).toMatchInlineSnapshot(`
5969
- [
5970
- {
5971
- "payload": {
5972
- "runId": "test-run-id",
5973
- },
5974
- "type": "start",
6543
+ expect(watchData.length).toBe(11);
6544
+ expect(watchData).toMatchObject([
6545
+ {
6546
+ payload: {
6547
+ runId: 'test-run-id',
5975
6548
  },
5976
- {
5977
- "payload": {
5978
- "id": "step1",
5979
- },
5980
- "type": "step-start",
6549
+ type: 'start',
6550
+ },
6551
+ {
6552
+ payload: {
6553
+ id: 'step1',
6554
+ startedAt: expect.any(Number),
6555
+ status: 'running',
6556
+ payload: {},
5981
6557
  },
5982
- {
5983
- "payload": {
5984
- "id": "step1",
5985
- "output": {
5986
- "result": "success1",
5987
- },
5988
- "status": "success",
6558
+ type: 'step-start',
6559
+ },
6560
+ {
6561
+ payload: {
6562
+ id: 'step1',
6563
+ output: {
6564
+ result: 'success1',
5989
6565
  },
5990
- "type": "step-result",
6566
+ endedAt: expect.any(Number),
6567
+ status: 'success',
5991
6568
  },
5992
- {
5993
- "payload": {
5994
- "id": "step1",
5995
- "metadata": {},
5996
- },
5997
- "type": "step-finish",
6569
+ type: 'step-result',
6570
+ },
6571
+ {
6572
+ payload: {
6573
+ id: 'step1',
6574
+ metadata: {},
5998
6575
  },
5999
- {
6000
- "payload": {
6001
- "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',
6002
6585
  },
6003
- "type": "step-start",
6004
6586
  },
6005
- {
6006
- "payload": {
6007
- "id": "step2",
6008
- "output": {
6009
- "result": "success2",
6010
- },
6011
- "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',
6012
6597
  },
6013
- "type": "step-result",
6014
6598
  },
6015
- {
6016
- "payload": {
6017
- "id": "step2",
6018
- "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',
6019
6613
  },
6020
- "type": "step-finish",
6614
+ startedAt: expect.any(Number),
6615
+ status: 'running',
6021
6616
  },
6022
- {
6023
- "payload": {
6024
- "runId": "test-run-id",
6617
+ type: 'step-start',
6618
+ },
6619
+ {
6620
+ payload: {
6621
+ id: 'step2',
6622
+ output: {
6623
+ result: 'success2',
6025
6624
  },
6026
- "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',
6027
6640
  },
6028
- ]
6029
- `);
6641
+ type: 'finish',
6642
+ },
6643
+ ]);
6644
+
6030
6645
  // Verify execution completed successfully
6031
6646
  expect(executionResult.steps.step1).toMatchObject({
6032
6647
  status: 'success',
@@ -6046,7 +6661,7 @@ describe('MastraInngestWorkflow', () => {
6046
6661
  });
6047
6662
  });
6048
6663
 
6049
- it('should handle basic sleep waiting flow', async ctx => {
6664
+ it('should handle basic sleep waiting flow with fn parameter', async ctx => {
6050
6665
  const inngest = new Inngest({
6051
6666
  id: 'mastra',
6052
6667
  baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
@@ -6055,19 +6670,19 @@ describe('MastraInngestWorkflow', () => {
6055
6670
 
6056
6671
  const { createWorkflow, createStep } = init(inngest);
6057
6672
 
6058
- const step1Action = vi.fn<any>().mockResolvedValue({ result: 'success1' });
6059
- 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 });
6060
6675
 
6061
6676
  const step1 = createStep({
6062
6677
  id: 'step1',
6063
6678
  execute: step1Action,
6064
6679
  inputSchema: z.object({}),
6065
- outputSchema: z.object({ value: z.string() }),
6680
+ outputSchema: z.object({ value: z.number() }),
6066
6681
  });
6067
6682
  const step2 = createStep({
6068
6683
  id: 'step2',
6069
6684
  execute: step2Action,
6070
- inputSchema: z.object({ value: z.string() }),
6685
+ inputSchema: z.object({ value: z.number() }),
6071
6686
  outputSchema: z.object({}),
6072
6687
  });
6073
6688
 
@@ -6077,7 +6692,13 @@ describe('MastraInngestWorkflow', () => {
6077
6692
  outputSchema: z.object({}),
6078
6693
  steps: [step1, step2],
6079
6694
  });
6080
- 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();
6081
6702
 
6082
6703
  const mastra = new Mastra({
6083
6704
  storage: new DefaultStorage({
@@ -6099,10 +6720,11 @@ describe('MastraInngestWorkflow', () => {
6099
6720
 
6100
6721
  const app = await createHonoServer(mastra);
6101
6722
 
6102
- const srv = serve({
6723
+ const srv = (globServer = serve({
6103
6724
  fetch: app.fetch,
6104
6725
  port: (ctx as any).handlerPort,
6105
- });
6726
+ }));
6727
+ await resetInngest();
6106
6728
 
6107
6729
  const runId = 'test-run-id';
6108
6730
  let watchData: StreamEvent[] = [];
@@ -6110,7 +6732,7 @@ describe('MastraInngestWorkflow', () => {
6110
6732
  runId,
6111
6733
  });
6112
6734
 
6113
- await new Promise(resolve => setTimeout(resolve, 1000));
6735
+ await resetInngest();
6114
6736
 
6115
6737
  const { stream, getWorkflowState } = run.stream({ inputData: {} });
6116
6738
 
@@ -6123,11 +6745,11 @@ describe('MastraInngestWorkflow', () => {
6123
6745
 
6124
6746
  const executionResult = await getWorkflowState();
6125
6747
 
6126
- await new Promise(resolve => setTimeout(resolve, 1000));
6748
+ await resetInngest();
6127
6749
 
6128
6750
  srv.close();
6129
6751
 
6130
- expect(watchData.length).toBe(9);
6752
+ expect(watchData.length).toBe(11);
6131
6753
  expect(watchData).toMatchObject([
6132
6754
  {
6133
6755
  payload: {
@@ -6138,6 +6760,9 @@ describe('MastraInngestWorkflow', () => {
6138
6760
  {
6139
6761
  payload: {
6140
6762
  id: 'step1',
6763
+ startedAt: expect.any(Number),
6764
+ status: 'running',
6765
+ payload: {},
6141
6766
  },
6142
6767
  type: 'step-start',
6143
6768
  },
@@ -6145,8 +6770,9 @@ describe('MastraInngestWorkflow', () => {
6145
6770
  payload: {
6146
6771
  id: 'step1',
6147
6772
  output: {
6148
- result: 'success1',
6773
+ value: 1000,
6149
6774
  },
6775
+ endedAt: expect.any(Number),
6150
6776
  status: 'success',
6151
6777
  },
6152
6778
  type: 'step-result',
@@ -6159,12 +6785,43 @@ describe('MastraInngestWorkflow', () => {
6159
6785
  type: 'step-finish',
6160
6786
  },
6161
6787
  {
6162
- payload: {},
6788
+ payload: {
6789
+ id: expect.any(String),
6790
+ startedAt: expect.any(Number),
6791
+ status: 'waiting',
6792
+ payload: {
6793
+ value: 1000,
6794
+ },
6795
+ },
6163
6796
  type: 'step-waiting',
6164
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
+ },
6165
6817
  {
6166
6818
  payload: {
6167
6819
  id: 'step2',
6820
+ payload: {
6821
+ value: 1000,
6822
+ },
6823
+ startedAt: expect.any(Number),
6824
+ status: 'running',
6168
6825
  },
6169
6826
  type: 'step-start',
6170
6827
  },
@@ -6172,8 +6829,9 @@ describe('MastraInngestWorkflow', () => {
6172
6829
  payload: {
6173
6830
  id: 'step2',
6174
6831
  output: {
6175
- result: 'success2',
6832
+ value: 2000,
6176
6833
  },
6834
+ endedAt: expect.any(Number),
6177
6835
  status: 'success',
6178
6836
  },
6179
6837
  type: 'step-result',
@@ -6192,19 +6850,20 @@ describe('MastraInngestWorkflow', () => {
6192
6850
  type: 'finish',
6193
6851
  },
6194
6852
  ]);
6853
+
6195
6854
  // Verify execution completed successfully
6196
6855
  expect(executionResult.steps.step1).toMatchObject({
6197
6856
  status: 'success',
6198
- output: { result: 'success1' },
6857
+ output: { value: 1000 },
6199
6858
  payload: {},
6200
6859
  startedAt: expect.any(Number),
6201
6860
  endedAt: expect.any(Number),
6202
6861
  });
6203
6862
  expect(executionResult.steps.step2).toMatchObject({
6204
6863
  status: 'success',
6205
- output: { result: 'success2' },
6864
+ output: { value: 2000 },
6206
6865
  payload: {
6207
- result: 'success1',
6866
+ value: 1000,
6208
6867
  },
6209
6868
  startedAt: expect.any(Number),
6210
6869
  endedAt: expect.any(Number),
@@ -6264,10 +6923,11 @@ describe('MastraInngestWorkflow', () => {
6264
6923
 
6265
6924
  const app = await createHonoServer(mastra);
6266
6925
 
6267
- const srv = serve({
6926
+ const srv = (globServer = serve({
6268
6927
  fetch: app.fetch,
6269
6928
  port: (ctx as any).handlerPort,
6270
- });
6929
+ }));
6930
+ await resetInngest();
6271
6931
 
6272
6932
  const runId = 'test-run-id';
6273
6933
  let watchData: StreamEvent[] = [];
@@ -6275,7 +6935,7 @@ describe('MastraInngestWorkflow', () => {
6275
6935
  runId,
6276
6936
  });
6277
6937
 
6278
- await new Promise(resolve => setTimeout(resolve, 1000));
6938
+ await resetInngest();
6279
6939
 
6280
6940
  const { stream, getWorkflowState } = run.stream({ inputData: {} });
6281
6941
 
@@ -6295,7 +6955,7 @@ describe('MastraInngestWorkflow', () => {
6295
6955
 
6296
6956
  const executionResult = await getWorkflowState();
6297
6957
 
6298
- await new Promise(resolve => setTimeout(resolve, 1000));
6958
+ await resetInngest();
6299
6959
 
6300
6960
  srv.close();
6301
6961
 
@@ -6489,12 +7149,12 @@ describe('MastraInngestWorkflow', () => {
6489
7149
 
6490
7150
  const app = await createHonoServer(mastra);
6491
7151
 
6492
- const srv = serve({
7152
+ const srv = (globServer = serve({
6493
7153
  fetch: app.fetch,
6494
7154
  port: (ctx as any).handlerPort,
6495
- });
7155
+ }));
6496
7156
 
6497
- await new Promise(resolve => setTimeout(resolve, 1000));
7157
+ await resetInngest();
6498
7158
 
6499
7159
  const run = await promptEvalWorkflow.createRunAsync();
6500
7160
 
@@ -6678,12 +7338,12 @@ describe('MastraInngestWorkflow', () => {
6678
7338
 
6679
7339
  const app = await createHonoServer(mastra);
6680
7340
 
6681
- const srv = serve({
7341
+ const srv = (globServer = serve({
6682
7342
  fetch: app.fetch,
6683
7343
  port: (ctx as any).handlerPort,
6684
- });
7344
+ }));
6685
7345
 
6686
- await new Promise(resolve => setTimeout(resolve, 1000));
7346
+ await resetInngest();
6687
7347
 
6688
7348
  const run = await workflow.createRunAsync({
6689
7349
  runId: 'test-run-id',