@mastra/inngest 0.0.0-tool-call-parts-20250630193309 → 0.0.0-tsconfig-compile-20250703214351

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,6 +455,100 @@ describe('MastraInngestWorkflow', () => {
455
455
  srv.close();
456
456
  });
457
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
+
458
552
  it('should execute a a sleep until step', async ctx => {
459
553
  const inngest = new Inngest({
460
554
  id: 'mastra',
@@ -514,11 +608,11 @@ describe('MastraInngestWorkflow', () => {
514
608
 
515
609
  const app = await createHonoServer(mastra);
516
610
 
517
- const srv = serve({
611
+ const srv = (globServer = serve({
518
612
  fetch: app.fetch,
519
613
  port: (ctx as any).handlerPort,
520
- });
521
- await new Promise(resolve => setTimeout(resolve, 2000));
614
+ }));
615
+ await resetInngest();
522
616
 
523
617
  const run = await workflow.createRunAsync();
524
618
  const startTime = Date.now();
@@ -547,6 +641,100 @@ describe('MastraInngestWorkflow', () => {
547
641
  srv.close();
548
642
  });
549
643
 
644
+ it('should execute a sleep until step with fn parameter', async ctx => {
645
+ const inngest = new Inngest({
646
+ id: 'mastra',
647
+ baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
648
+ });
649
+
650
+ const { createWorkflow, createStep } = init(inngest);
651
+
652
+ const execute = vi.fn<any>().mockResolvedValue({ value: 1000 });
653
+ const step1 = createStep({
654
+ id: 'step1',
655
+ execute,
656
+ inputSchema: z.object({}),
657
+ outputSchema: z.object({ value: z.number() }),
658
+ });
659
+ const step2 = createStep({
660
+ id: 'step2',
661
+ execute: async ({ inputData }) => {
662
+ return { value: inputData.value + 1000 };
663
+ },
664
+ inputSchema: z.object({ value: z.number() }),
665
+ outputSchema: z.object({ value: z.number() }),
666
+ });
667
+
668
+ const workflow = createWorkflow({
669
+ id: 'test-workflow',
670
+ inputSchema: z.object({}),
671
+ outputSchema: z.object({
672
+ value: z.number(),
673
+ }),
674
+ steps: [step1],
675
+ });
676
+
677
+ workflow
678
+ .then(step1)
679
+ .sleepUntil(async ({ inputData }) => {
680
+ return new Date(Date.now() + inputData.value);
681
+ })
682
+ .then(step2)
683
+ .commit();
684
+
685
+ const mastra = new Mastra({
686
+ storage: new DefaultStorage({
687
+ url: ':memory:',
688
+ }),
689
+ workflows: {
690
+ 'test-workflow': workflow,
691
+ },
692
+ server: {
693
+ apiRoutes: [
694
+ {
695
+ path: '/inngest/api',
696
+ method: 'ALL',
697
+ createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
698
+ },
699
+ ],
700
+ },
701
+ });
702
+
703
+ const app = await createHonoServer(mastra);
704
+
705
+ const srv = (globServer = serve({
706
+ fetch: app.fetch,
707
+ port: (ctx as any).handlerPort,
708
+ }));
709
+ await resetInngest();
710
+
711
+ const run = await workflow.createRunAsync();
712
+ const startTime = Date.now();
713
+ const result = await run.start({ inputData: {} });
714
+ const endTime = Date.now();
715
+
716
+ expect(execute).toHaveBeenCalled();
717
+ expect(result.steps['step1']).toMatchObject({
718
+ status: 'success',
719
+ output: { value: 1000 },
720
+ // payload: {},
721
+ // startedAt: expect.any(Number),
722
+ // endedAt: expect.any(Number),
723
+ });
724
+
725
+ expect(result.steps['step2']).toMatchObject({
726
+ status: 'success',
727
+ output: { value: 2000 },
728
+ // payload: { result: 'success' },
729
+ // startedAt: expect.any(Number),
730
+ // endedAt: expect.any(Number),
731
+ });
732
+
733
+ expect(endTime - startTime).toBeGreaterThan(1000);
734
+
735
+ srv.close();
736
+ });
737
+
550
738
  it('should execute a a waitForEvent step', async ctx => {
551
739
  const inngest = new Inngest({
552
740
  id: 'mastra',
@@ -604,11 +792,11 @@ describe('MastraInngestWorkflow', () => {
604
792
 
605
793
  const app = await createHonoServer(mastra);
606
794
 
607
- const srv = serve({
795
+ const srv = (globServer = serve({
608
796
  fetch: app.fetch,
609
797
  port: (ctx as any).handlerPort,
610
- });
611
- await new Promise(resolve => setTimeout(resolve, 2000));
798
+ }));
799
+ await resetInngest();
612
800
 
613
801
  const run = await workflow.createRunAsync();
614
802
  const startTime = Date.now();
@@ -698,11 +886,11 @@ describe('MastraInngestWorkflow', () => {
698
886
 
699
887
  const app = await createHonoServer(mastra);
700
888
 
701
- const srv = serve({
889
+ const srv = (globServer = serve({
702
890
  fetch: app.fetch,
703
891
  port: (ctx as any).handlerPort,
704
- });
705
- await new Promise(resolve => setTimeout(resolve, 2000));
892
+ }));
893
+ await resetInngest();
706
894
 
707
895
  const run = await workflow.createRunAsync();
708
896
  const startTime = Date.now();
@@ -732,6 +920,203 @@ describe('MastraInngestWorkflow', () => {
732
920
  });
733
921
  });
734
922
 
923
+ describe('abort', () => {
924
+ it('should be able to abort workflow execution in between steps', async ctx => {
925
+ const inngest = new Inngest({
926
+ id: 'mastra',
927
+ baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
928
+ middleware: [realtimeMiddleware()],
929
+ });
930
+
931
+ const { createWorkflow, createStep } = init(inngest);
932
+
933
+ const step1 = createStep({
934
+ id: 'step1',
935
+ execute: async ({ inputData }) => {
936
+ return { result: 'step1: ' + inputData.value };
937
+ },
938
+ inputSchema: z.object({ value: z.string() }),
939
+ outputSchema: z.object({ result: z.string() }),
940
+ });
941
+ const step2 = createStep({
942
+ id: 'step2',
943
+ execute: async ({ inputData }) => {
944
+ return { result: 'step2: ' + inputData.result };
945
+ },
946
+ inputSchema: z.object({ result: z.string() }),
947
+ outputSchema: z.object({ result: z.string() }),
948
+ });
949
+
950
+ const workflow = createWorkflow({
951
+ id: 'test-workflow',
952
+ inputSchema: z.object({}),
953
+ outputSchema: z.object({
954
+ result: z.string(),
955
+ }),
956
+ steps: [step1, step2],
957
+ });
958
+
959
+ workflow.then(step1).sleep(2000).then(step2).commit();
960
+
961
+ const mastra = new Mastra({
962
+ storage: new DefaultStorage({
963
+ url: ':memory:',
964
+ }),
965
+ workflows: {
966
+ 'test-workflow': workflow,
967
+ },
968
+ server: {
969
+ apiRoutes: [
970
+ {
971
+ path: '/inngest/api',
972
+ method: 'ALL',
973
+ createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
974
+ },
975
+ ],
976
+ },
977
+ });
978
+
979
+ const app = await createHonoServer(mastra);
980
+
981
+ const srv = (globServer = serve({
982
+ fetch: app.fetch,
983
+ port: (ctx as any).handlerPort,
984
+ }));
985
+ await resetInngest();
986
+
987
+ const run = await workflow.createRunAsync();
988
+ const p = run.start({ inputData: { value: 'test' } });
989
+
990
+ setTimeout(() => {
991
+ run.cancel();
992
+ }, 1000);
993
+
994
+ const result = await p;
995
+
996
+ srv.close();
997
+
998
+ expect(result.status).toBe('canceled');
999
+ expect(result.steps['step1']).toEqual({
1000
+ status: 'success',
1001
+ output: { result: 'step1: test' },
1002
+ payload: { value: 'test' },
1003
+ startedAt: expect.any(Number),
1004
+ endedAt: expect.any(Number),
1005
+ });
1006
+
1007
+ expect(result.steps['step2']).toBeUndefined();
1008
+ });
1009
+
1010
+ it('should be able to abort workflow execution during a step', async ctx => {
1011
+ const inngest = new Inngest({
1012
+ id: 'mastra',
1013
+ baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
1014
+ middleware: [realtimeMiddleware()],
1015
+ });
1016
+
1017
+ const { createWorkflow, createStep } = init(inngest);
1018
+
1019
+ const step1 = createStep({
1020
+ id: 'step1',
1021
+ execute: async ({ inputData }) => {
1022
+ return { result: 'step1: ' + inputData.value };
1023
+ },
1024
+ inputSchema: z.object({ value: z.string() }),
1025
+ outputSchema: z.object({ result: z.string() }),
1026
+ });
1027
+ const step2 = createStep({
1028
+ id: 'step2',
1029
+ execute: async ({ inputData, abortSignal, abort }) => {
1030
+ console.log('abort signal', abortSignal);
1031
+ const timeout: Promise<string> = new Promise((resolve, _reject) => {
1032
+ const ref = setTimeout(() => {
1033
+ resolve('step2: ' + inputData.result);
1034
+ }, 5000);
1035
+
1036
+ abortSignal.addEventListener('abort', () => {
1037
+ resolve('');
1038
+ clearTimeout(ref);
1039
+ });
1040
+ });
1041
+
1042
+ const result = await timeout;
1043
+ if (abortSignal.aborted) {
1044
+ return abort();
1045
+ }
1046
+ return { result };
1047
+ },
1048
+ inputSchema: z.object({ result: z.string() }),
1049
+ outputSchema: z.object({ result: z.string() }),
1050
+ });
1051
+
1052
+ const workflow = createWorkflow({
1053
+ id: 'test-workflow',
1054
+ inputSchema: z.object({}),
1055
+ outputSchema: z.object({
1056
+ result: z.string(),
1057
+ }),
1058
+ steps: [step1, step2],
1059
+ });
1060
+
1061
+ workflow.then(step1).then(step2).commit();
1062
+
1063
+ const mastra = new Mastra({
1064
+ storage: new DefaultStorage({
1065
+ url: ':memory:',
1066
+ }),
1067
+ workflows: {
1068
+ 'test-workflow': workflow,
1069
+ },
1070
+ server: {
1071
+ apiRoutes: [
1072
+ {
1073
+ path: '/inngest/api',
1074
+ method: 'ALL',
1075
+ createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
1076
+ },
1077
+ ],
1078
+ },
1079
+ });
1080
+
1081
+ const app = await createHonoServer(mastra);
1082
+
1083
+ const srv = (globServer = serve({
1084
+ fetch: app.fetch,
1085
+ port: (ctx as any).handlerPort,
1086
+ }));
1087
+ await resetInngest();
1088
+
1089
+ const run = await workflow.createRunAsync();
1090
+ const p = run.start({ inputData: { value: 'test' } });
1091
+
1092
+ setTimeout(() => {
1093
+ run.cancel();
1094
+ }, 1000);
1095
+
1096
+ const result = await p;
1097
+ console.log('result', result);
1098
+
1099
+ srv.close();
1100
+
1101
+ expect(result.status).toBe('canceled');
1102
+ expect(result.steps['step1']).toEqual({
1103
+ status: 'success',
1104
+ output: { result: 'step1: test' },
1105
+ payload: { value: 'test' },
1106
+ startedAt: expect.any(Number),
1107
+ endedAt: expect.any(Number),
1108
+ });
1109
+
1110
+ // expect(result.steps['step2']).toEqual({
1111
+ // status: 'canceled',
1112
+ // payload: { result: 'step1: test' },
1113
+ // output: undefined,
1114
+ // startedAt: expect.any(Number),
1115
+ // endedAt: expect.any(Number),
1116
+ // });
1117
+ });
1118
+ });
1119
+
735
1120
  describe('Variable Resolution', () => {
736
1121
  it('should resolve trigger data', async ctx => {
737
1122
  const inngest = new Inngest({
@@ -784,10 +1169,12 @@ describe('MastraInngestWorkflow', () => {
784
1169
 
785
1170
  const app = await createHonoServer(mastra);
786
1171
 
787
- const srv = serve({
1172
+ const srv = (globServer = serve({
788
1173
  fetch: app.fetch,
789
1174
  port: (ctx as any).handlerPort,
790
- });
1175
+ }));
1176
+
1177
+ await resetInngest();
791
1178
 
792
1179
  const run = await workflow.createRunAsync();
793
1180
  const result = await run.start({ inputData: { inputData: 'test-input' } });
@@ -871,10 +1258,11 @@ describe('MastraInngestWorkflow', () => {
871
1258
 
872
1259
  const app = await createHonoServer(mastra);
873
1260
 
874
- const srv = serve({
1261
+ const srv = (globServer = serve({
875
1262
  fetch: app.fetch,
876
1263
  port: (ctx as any).handlerPort,
877
- });
1264
+ }));
1265
+ await resetInngest();
878
1266
 
879
1267
  const run = await workflow.createRunAsync();
880
1268
  const result = await run.start({ inputData: { inputValue: 'test-input' } });
@@ -938,10 +1326,11 @@ describe('MastraInngestWorkflow', () => {
938
1326
 
939
1327
  const app = await createHonoServer(mastra);
940
1328
 
941
- const srv = serve({
1329
+ const srv = (globServer = serve({
942
1330
  fetch: app.fetch,
943
1331
  port: (ctx as any).handlerPort,
944
- });
1332
+ }));
1333
+ await resetInngest();
945
1334
 
946
1335
  const run = await workflow.createRunAsync();
947
1336
  await run.start({ inputData: { inputData: 'test-input' } });
@@ -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}`,
@@ -5867,10 +6269,11 @@ describe('MastraInngestWorkflow', () => {
5867
6269
 
5868
6270
  const app = await createHonoServer(mastra);
5869
6271
 
5870
- const srv = serve({
6272
+ const srv = (globServer = serve({
5871
6273
  fetch: app.fetch,
5872
6274
  port: (ctx as any).handlerPort,
5873
- });
6275
+ }));
6276
+ await resetInngest();
5874
6277
 
5875
6278
  const run = await workflow.createRunAsync();
5876
6279
  const result = await run.start({});
@@ -5936,10 +6339,11 @@ describe('MastraInngestWorkflow', () => {
5936
6339
 
5937
6340
  const app = await createHonoServer(mastra);
5938
6341
 
5939
- const srv = serve({
6342
+ const srv = (globServer = serve({
5940
6343
  fetch: app.fetch,
5941
6344
  port: (ctx as any).handlerPort,
5942
- });
6345
+ }));
6346
+ await resetInngest();
5943
6347
 
5944
6348
  const runId = 'test-run-id';
5945
6349
  let watchData: StreamEvent[] = [];
@@ -5947,7 +6351,7 @@ describe('MastraInngestWorkflow', () => {
5947
6351
  runId,
5948
6352
  });
5949
6353
 
5950
- await new Promise(resolve => setTimeout(resolve, 1000));
6354
+ await resetInngest();
5951
6355
 
5952
6356
  const { stream, getWorkflowState } = run.stream({ inputData: {} });
5953
6357
 
@@ -5960,7 +6364,7 @@ describe('MastraInngestWorkflow', () => {
5960
6364
 
5961
6365
  const executionResult = await getWorkflowState();
5962
6366
 
5963
- await new Promise(resolve => setTimeout(resolve, 1000));
6367
+ await resetInngest();
5964
6368
 
5965
6369
  srv.close();
5966
6370
 
@@ -6107,10 +6511,11 @@ describe('MastraInngestWorkflow', () => {
6107
6511
 
6108
6512
  const app = await createHonoServer(mastra);
6109
6513
 
6110
- const srv = serve({
6514
+ const srv = (globServer = serve({
6111
6515
  fetch: app.fetch,
6112
6516
  port: (ctx as any).handlerPort,
6113
- });
6517
+ }));
6518
+ await resetInngest();
6114
6519
 
6115
6520
  const runId = 'test-run-id';
6116
6521
  let watchData: StreamEvent[] = [];
@@ -6118,7 +6523,7 @@ describe('MastraInngestWorkflow', () => {
6118
6523
  runId,
6119
6524
  });
6120
6525
 
6121
- await new Promise(resolve => setTimeout(resolve, 1000));
6526
+ await resetInngest();
6122
6527
 
6123
6528
  const { stream, getWorkflowState } = run.stream({ inputData: {} });
6124
6529
 
@@ -6131,11 +6536,11 @@ describe('MastraInngestWorkflow', () => {
6131
6536
 
6132
6537
  const executionResult = await getWorkflowState();
6133
6538
 
6134
- await new Promise(resolve => setTimeout(resolve, 1000));
6539
+ await resetInngest();
6135
6540
 
6136
6541
  srv.close();
6137
6542
 
6138
- expect(watchData.length).toBe(9);
6543
+ expect(watchData.length).toBe(11);
6139
6544
  expect(watchData).toMatchObject([
6140
6545
  {
6141
6546
  payload: {
@@ -6146,6 +6551,9 @@ describe('MastraInngestWorkflow', () => {
6146
6551
  {
6147
6552
  payload: {
6148
6553
  id: 'step1',
6554
+ startedAt: expect.any(Number),
6555
+ status: 'running',
6556
+ payload: {},
6149
6557
  },
6150
6558
  type: 'step-start',
6151
6559
  },
@@ -6155,6 +6563,7 @@ describe('MastraInngestWorkflow', () => {
6155
6563
  output: {
6156
6564
  result: 'success1',
6157
6565
  },
6566
+ endedAt: expect.any(Number),
6158
6567
  status: 'success',
6159
6568
  },
6160
6569
  type: 'step-result',
@@ -6167,12 +6576,43 @@ describe('MastraInngestWorkflow', () => {
6167
6576
  type: 'step-finish',
6168
6577
  },
6169
6578
  {
6170
- payload: {},
6579
+ payload: {
6580
+ id: expect.any(String),
6581
+ startedAt: expect.any(Number),
6582
+ status: 'waiting',
6583
+ payload: {
6584
+ result: 'success1',
6585
+ },
6586
+ },
6171
6587
  type: 'step-waiting',
6172
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',
6597
+ },
6598
+ },
6599
+ type: 'step-result',
6600
+ },
6601
+ {
6602
+ type: 'step-finish',
6603
+ payload: {
6604
+ id: expect.any(String),
6605
+ metadata: {},
6606
+ },
6607
+ },
6173
6608
  {
6174
6609
  payload: {
6175
6610
  id: 'step2',
6611
+ payload: {
6612
+ result: 'success1',
6613
+ },
6614
+ startedAt: expect.any(Number),
6615
+ status: 'running',
6176
6616
  },
6177
6617
  type: 'step-start',
6178
6618
  },
@@ -6182,6 +6622,7 @@ describe('MastraInngestWorkflow', () => {
6182
6622
  output: {
6183
6623
  result: 'success2',
6184
6624
  },
6625
+ endedAt: expect.any(Number),
6185
6626
  status: 'success',
6186
6627
  },
6187
6628
  type: 'step-result',
@@ -6200,6 +6641,7 @@ describe('MastraInngestWorkflow', () => {
6200
6641
  type: 'finish',
6201
6642
  },
6202
6643
  ]);
6644
+
6203
6645
  // Verify execution completed successfully
6204
6646
  expect(executionResult.steps.step1).toMatchObject({
6205
6647
  status: 'success',
@@ -6219,6 +6661,215 @@ describe('MastraInngestWorkflow', () => {
6219
6661
  });
6220
6662
  });
6221
6663
 
6664
+ it('should handle basic sleep waiting flow with fn parameter', async ctx => {
6665
+ const inngest = new Inngest({
6666
+ id: 'mastra',
6667
+ baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
6668
+ middleware: [realtimeMiddleware()],
6669
+ });
6670
+
6671
+ const { createWorkflow, createStep } = init(inngest);
6672
+
6673
+ const step1Action = vi.fn<any>().mockResolvedValue({ value: 1000 });
6674
+ const step2Action = vi.fn<any>().mockResolvedValue({ value: 2000 });
6675
+
6676
+ const step1 = createStep({
6677
+ id: 'step1',
6678
+ execute: step1Action,
6679
+ inputSchema: z.object({}),
6680
+ outputSchema: z.object({ value: z.number() }),
6681
+ });
6682
+ const step2 = createStep({
6683
+ id: 'step2',
6684
+ execute: step2Action,
6685
+ inputSchema: z.object({ value: z.number() }),
6686
+ outputSchema: z.object({}),
6687
+ });
6688
+
6689
+ const workflow = createWorkflow({
6690
+ id: 'test-workflow',
6691
+ inputSchema: z.object({}),
6692
+ outputSchema: z.object({}),
6693
+ steps: [step1, step2],
6694
+ });
6695
+ workflow
6696
+ .then(step1)
6697
+ .sleep(async ({ inputData }) => {
6698
+ return inputData.value;
6699
+ })
6700
+ .then(step2)
6701
+ .commit();
6702
+
6703
+ const mastra = new Mastra({
6704
+ storage: new DefaultStorage({
6705
+ url: ':memory:',
6706
+ }),
6707
+ workflows: {
6708
+ 'test-workflow': workflow,
6709
+ },
6710
+ server: {
6711
+ apiRoutes: [
6712
+ {
6713
+ path: '/inngest/api',
6714
+ method: 'ALL',
6715
+ createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
6716
+ },
6717
+ ],
6718
+ },
6719
+ });
6720
+
6721
+ const app = await createHonoServer(mastra);
6722
+
6723
+ const srv = (globServer = serve({
6724
+ fetch: app.fetch,
6725
+ port: (ctx as any).handlerPort,
6726
+ }));
6727
+ await resetInngest();
6728
+
6729
+ const runId = 'test-run-id';
6730
+ let watchData: StreamEvent[] = [];
6731
+ const run = await workflow.createRunAsync({
6732
+ runId,
6733
+ });
6734
+
6735
+ await resetInngest();
6736
+
6737
+ const { stream, getWorkflowState } = run.stream({ inputData: {} });
6738
+
6739
+ // Start watching the workflow
6740
+ const collectedStreamData: StreamEvent[] = [];
6741
+ for await (const data of stream) {
6742
+ collectedStreamData.push(JSON.parse(JSON.stringify(data)));
6743
+ }
6744
+ watchData = collectedStreamData;
6745
+
6746
+ const executionResult = await getWorkflowState();
6747
+
6748
+ await resetInngest();
6749
+
6750
+ srv.close();
6751
+
6752
+ expect(watchData.length).toBe(11);
6753
+ expect(watchData).toMatchObject([
6754
+ {
6755
+ payload: {
6756
+ runId: 'test-run-id',
6757
+ },
6758
+ type: 'start',
6759
+ },
6760
+ {
6761
+ payload: {
6762
+ id: 'step1',
6763
+ startedAt: expect.any(Number),
6764
+ status: 'running',
6765
+ payload: {},
6766
+ },
6767
+ type: 'step-start',
6768
+ },
6769
+ {
6770
+ payload: {
6771
+ id: 'step1',
6772
+ output: {
6773
+ value: 1000,
6774
+ },
6775
+ endedAt: expect.any(Number),
6776
+ status: 'success',
6777
+ },
6778
+ type: 'step-result',
6779
+ },
6780
+ {
6781
+ payload: {
6782
+ id: 'step1',
6783
+ metadata: {},
6784
+ },
6785
+ type: 'step-finish',
6786
+ },
6787
+ {
6788
+ payload: {
6789
+ id: expect.any(String),
6790
+ startedAt: expect.any(Number),
6791
+ status: 'waiting',
6792
+ payload: {
6793
+ value: 1000,
6794
+ },
6795
+ },
6796
+ type: 'step-waiting',
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
+ },
6817
+ {
6818
+ payload: {
6819
+ id: 'step2',
6820
+ payload: {
6821
+ value: 1000,
6822
+ },
6823
+ startedAt: expect.any(Number),
6824
+ status: 'running',
6825
+ },
6826
+ type: 'step-start',
6827
+ },
6828
+ {
6829
+ payload: {
6830
+ id: 'step2',
6831
+ output: {
6832
+ value: 2000,
6833
+ },
6834
+ endedAt: expect.any(Number),
6835
+ status: 'success',
6836
+ },
6837
+ type: 'step-result',
6838
+ },
6839
+ {
6840
+ payload: {
6841
+ id: 'step2',
6842
+ metadata: {},
6843
+ },
6844
+ type: 'step-finish',
6845
+ },
6846
+ {
6847
+ payload: {
6848
+ runId: 'test-run-id',
6849
+ },
6850
+ type: 'finish',
6851
+ },
6852
+ ]);
6853
+
6854
+ // Verify execution completed successfully
6855
+ expect(executionResult.steps.step1).toMatchObject({
6856
+ status: 'success',
6857
+ output: { value: 1000 },
6858
+ payload: {},
6859
+ startedAt: expect.any(Number),
6860
+ endedAt: expect.any(Number),
6861
+ });
6862
+ expect(executionResult.steps.step2).toMatchObject({
6863
+ status: 'success',
6864
+ output: { value: 2000 },
6865
+ payload: {
6866
+ value: 1000,
6867
+ },
6868
+ startedAt: expect.any(Number),
6869
+ endedAt: expect.any(Number),
6870
+ });
6871
+ });
6872
+
6222
6873
  it('should handle waitForEvent waiting flow', async ctx => {
6223
6874
  const inngest = new Inngest({
6224
6875
  id: 'mastra',
@@ -6272,10 +6923,11 @@ describe('MastraInngestWorkflow', () => {
6272
6923
 
6273
6924
  const app = await createHonoServer(mastra);
6274
6925
 
6275
- const srv = serve({
6926
+ const srv = (globServer = serve({
6276
6927
  fetch: app.fetch,
6277
6928
  port: (ctx as any).handlerPort,
6278
- });
6929
+ }));
6930
+ await resetInngest();
6279
6931
 
6280
6932
  const runId = 'test-run-id';
6281
6933
  let watchData: StreamEvent[] = [];
@@ -6283,7 +6935,7 @@ describe('MastraInngestWorkflow', () => {
6283
6935
  runId,
6284
6936
  });
6285
6937
 
6286
- await new Promise(resolve => setTimeout(resolve, 1000));
6938
+ await resetInngest();
6287
6939
 
6288
6940
  const { stream, getWorkflowState } = run.stream({ inputData: {} });
6289
6941
 
@@ -6303,7 +6955,7 @@ describe('MastraInngestWorkflow', () => {
6303
6955
 
6304
6956
  const executionResult = await getWorkflowState();
6305
6957
 
6306
- await new Promise(resolve => setTimeout(resolve, 1000));
6958
+ await resetInngest();
6307
6959
 
6308
6960
  srv.close();
6309
6961
 
@@ -6497,12 +7149,12 @@ describe('MastraInngestWorkflow', () => {
6497
7149
 
6498
7150
  const app = await createHonoServer(mastra);
6499
7151
 
6500
- const srv = serve({
7152
+ const srv = (globServer = serve({
6501
7153
  fetch: app.fetch,
6502
7154
  port: (ctx as any).handlerPort,
6503
- });
7155
+ }));
6504
7156
 
6505
- await new Promise(resolve => setTimeout(resolve, 1000));
7157
+ await resetInngest();
6506
7158
 
6507
7159
  const run = await promptEvalWorkflow.createRunAsync();
6508
7160
 
@@ -6686,12 +7338,12 @@ describe('MastraInngestWorkflow', () => {
6686
7338
 
6687
7339
  const app = await createHonoServer(mastra);
6688
7340
 
6689
- const srv = serve({
7341
+ const srv = (globServer = serve({
6690
7342
  fetch: app.fetch,
6691
7343
  port: (ctx as any).handlerPort,
6692
- });
7344
+ }));
6693
7345
 
6694
- await new Promise(resolve => setTimeout(resolve, 1000));
7346
+ await resetInngest();
6695
7347
 
6696
7348
  const run = await workflow.createRunAsync({
6697
7349
  runId: 'test-run-id',