@mastra/inngest 0.0.0-support-d1-client-20250701191943 → 0.0.0-taofeeq-fix-tool-call-showing-after-message-20250806184630

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();
@@ -790,11 +978,11 @@ describe('MastraInngestWorkflow', () => {
790
978
 
791
979
  const app = await createHonoServer(mastra);
792
980
 
793
- const srv = serve({
981
+ const srv = (globServer = serve({
794
982
  fetch: app.fetch,
795
983
  port: (ctx as any).handlerPort,
796
- });
797
- await new Promise(resolve => setTimeout(resolve, 2000));
984
+ }));
985
+ await resetInngest();
798
986
 
799
987
  const run = await workflow.createRunAsync();
800
988
  const p = run.start({ inputData: { value: 'test' } });
@@ -892,11 +1080,11 @@ describe('MastraInngestWorkflow', () => {
892
1080
 
893
1081
  const app = await createHonoServer(mastra);
894
1082
 
895
- const srv = serve({
1083
+ const srv = (globServer = serve({
896
1084
  fetch: app.fetch,
897
1085
  port: (ctx as any).handlerPort,
898
- });
899
- await new Promise(resolve => setTimeout(resolve, 2000));
1086
+ }));
1087
+ await resetInngest();
900
1088
 
901
1089
  const run = await workflow.createRunAsync();
902
1090
  const p = run.start({ inputData: { value: 'test' } });
@@ -981,10 +1169,12 @@ describe('MastraInngestWorkflow', () => {
981
1169
 
982
1170
  const app = await createHonoServer(mastra);
983
1171
 
984
- const srv = serve({
1172
+ const srv = (globServer = serve({
985
1173
  fetch: app.fetch,
986
1174
  port: (ctx as any).handlerPort,
987
- });
1175
+ }));
1176
+
1177
+ await resetInngest();
988
1178
 
989
1179
  const run = await workflow.createRunAsync();
990
1180
  const result = await run.start({ inputData: { inputData: 'test-input' } });
@@ -1068,10 +1258,11 @@ describe('MastraInngestWorkflow', () => {
1068
1258
 
1069
1259
  const app = await createHonoServer(mastra);
1070
1260
 
1071
- const srv = serve({
1261
+ const srv = (globServer = serve({
1072
1262
  fetch: app.fetch,
1073
1263
  port: (ctx as any).handlerPort,
1074
- });
1264
+ }));
1265
+ await resetInngest();
1075
1266
 
1076
1267
  const run = await workflow.createRunAsync();
1077
1268
  const result = await run.start({ inputData: { inputValue: 'test-input' } });
@@ -1135,10 +1326,11 @@ describe('MastraInngestWorkflow', () => {
1135
1326
 
1136
1327
  const app = await createHonoServer(mastra);
1137
1328
 
1138
- const srv = serve({
1329
+ const srv = (globServer = serve({
1139
1330
  fetch: app.fetch,
1140
1331
  port: (ctx as any).handlerPort,
1141
- });
1332
+ }));
1333
+ await resetInngest();
1142
1334
 
1143
1335
  const run = await workflow.createRunAsync();
1144
1336
  await run.start({ inputData: { inputData: 'test-input' } });
@@ -1210,10 +1402,11 @@ describe('MastraInngestWorkflow', () => {
1210
1402
 
1211
1403
  const app = await createHonoServer(mastra);
1212
1404
 
1213
- const srv = serve({
1405
+ const srv = (globServer = serve({
1214
1406
  fetch: app.fetch,
1215
1407
  port: (ctx as any).handlerPort,
1216
- });
1408
+ }));
1409
+ await resetInngest();
1217
1410
 
1218
1411
  const run = await workflow.createRunAsync();
1219
1412
  const result = await run.start({ inputData: { cool: 'test-input' } });
@@ -1292,10 +1485,11 @@ describe('MastraInngestWorkflow', () => {
1292
1485
 
1293
1486
  const app = await createHonoServer(mastra);
1294
1487
 
1295
- const srv = serve({
1488
+ const srv = (globServer = serve({
1296
1489
  fetch: app.fetch,
1297
1490
  port: (ctx as any).handlerPort,
1298
- });
1491
+ }));
1492
+ await resetInngest();
1299
1493
 
1300
1494
  const run = await workflow.createRunAsync();
1301
1495
  await run.start({ inputData: {} });
@@ -1395,10 +1589,11 @@ describe('MastraInngestWorkflow', () => {
1395
1589
 
1396
1590
  const app = await createHonoServer(mastra);
1397
1591
 
1398
- const srv = serve({
1592
+ const srv = (globServer = serve({
1399
1593
  fetch: app.fetch,
1400
1594
  port: (ctx as any).handlerPort,
1401
- });
1595
+ }));
1596
+ await resetInngest();
1402
1597
 
1403
1598
  const run = await workflow.createRunAsync();
1404
1599
  const result = await run.start({ inputData: { status: 'success' } });
@@ -1471,10 +1666,11 @@ describe('MastraInngestWorkflow', () => {
1471
1666
 
1472
1667
  const app = await createHonoServer(mastra);
1473
1668
 
1474
- const srv = serve({
1669
+ const srv = (globServer = serve({
1475
1670
  fetch: app.fetch,
1476
1671
  port: (ctx as any).handlerPort,
1477
- });
1672
+ }));
1673
+ await resetInngest();
1478
1674
 
1479
1675
  const run = await workflow.createRunAsync();
1480
1676
  let result: Awaited<ReturnType<typeof run.start>> | undefined = undefined;
@@ -1576,10 +1772,11 @@ describe('MastraInngestWorkflow', () => {
1576
1772
 
1577
1773
  const app = await createHonoServer(mastra);
1578
1774
 
1579
- const srv = serve({
1775
+ const srv = (globServer = serve({
1580
1776
  fetch: app.fetch,
1581
1777
  port: (ctx as any).handlerPort,
1582
- });
1778
+ }));
1779
+ await resetInngest();
1583
1780
 
1584
1781
  const run = await workflow.createRunAsync();
1585
1782
  const result = await run.start({ inputData: { status: 'success' } });
@@ -1659,10 +1856,11 @@ describe('MastraInngestWorkflow', () => {
1659
1856
 
1660
1857
  const app = await createHonoServer(mastra);
1661
1858
 
1662
- const srv = serve({
1859
+ const srv = (globServer = serve({
1663
1860
  fetch: app.fetch,
1664
1861
  port: (ctx as any).handlerPort,
1665
- });
1862
+ }));
1863
+ await resetInngest();
1666
1864
 
1667
1865
  const run = await workflow.createRunAsync();
1668
1866
  const result = await run.start({ inputData: { count: 5 } });
@@ -1726,11 +1924,11 @@ describe('MastraInngestWorkflow', () => {
1726
1924
 
1727
1925
  const app = await createHonoServer(mastra);
1728
1926
 
1729
- const srv = serve({
1927
+ const srv = (globServer = serve({
1730
1928
  fetch: app.fetch,
1731
1929
  port: (ctx as any).handlerPort,
1732
- });
1733
- await new Promise(resolve => setTimeout(resolve, 2000));
1930
+ }));
1931
+ await resetInngest();
1734
1932
 
1735
1933
  const run = await workflow.createRunAsync();
1736
1934
 
@@ -1810,11 +2008,11 @@ describe('MastraInngestWorkflow', () => {
1810
2008
 
1811
2009
  const app = await createHonoServer(mastra);
1812
2010
 
1813
- const srv = serve({
2011
+ const srv = (globServer = serve({
1814
2012
  fetch: app.fetch,
1815
2013
  port: (ctx as any).handlerPort,
1816
- });
1817
- await new Promise(resolve => setTimeout(resolve, 2000));
2014
+ }));
2015
+ await resetInngest();
1818
2016
 
1819
2017
  const run = await workflow.createRunAsync();
1820
2018
  const result = await run.start({ inputData: {} });
@@ -1904,11 +2102,11 @@ describe('MastraInngestWorkflow', () => {
1904
2102
 
1905
2103
  const app = await createHonoServer(mastra);
1906
2104
 
1907
- const srv = serve({
2105
+ const srv = (globServer = serve({
1908
2106
  fetch: app.fetch,
1909
2107
  port: (ctx as any).handlerPort,
1910
- });
1911
- await new Promise(resolve => setTimeout(resolve, 2000));
2108
+ }));
2109
+ await resetInngest();
1912
2110
 
1913
2111
  const run = await mainWorkflow.createRunAsync();
1914
2112
  const result = await run.start({ inputData: {} });
@@ -2032,11 +2230,11 @@ describe('MastraInngestWorkflow', () => {
2032
2230
 
2033
2231
  const app = await createHonoServer(mastra);
2034
2232
 
2035
- const srv = serve({
2233
+ const srv = (globServer = serve({
2036
2234
  fetch: app.fetch,
2037
2235
  port: (ctx as any).handlerPort,
2038
- });
2039
- await new Promise(resolve => setTimeout(resolve, 2000));
2236
+ }));
2237
+ await resetInngest();
2040
2238
 
2041
2239
  const run = await workflow.createRunAsync();
2042
2240
  const result = await run.start({ inputData: {} });
@@ -2134,11 +2332,11 @@ describe('MastraInngestWorkflow', () => {
2134
2332
 
2135
2333
  const app = await createHonoServer(mastra);
2136
2334
 
2137
- const srv = serve({
2335
+ const srv = (globServer = serve({
2138
2336
  fetch: app.fetch,
2139
2337
  port: (ctx as any).handlerPort,
2140
- });
2141
- await new Promise(resolve => setTimeout(resolve, 2000));
2338
+ }));
2339
+ await resetInngest();
2142
2340
 
2143
2341
  const run = await counterWorkflow.createRunAsync();
2144
2342
  const result = await run.start({ inputData: { target: 10, value: 0 } });
@@ -2237,11 +2435,11 @@ describe('MastraInngestWorkflow', () => {
2237
2435
 
2238
2436
  const app = await createHonoServer(mastra);
2239
2437
 
2240
- const srv = serve({
2438
+ const srv = (globServer = serve({
2241
2439
  fetch: app.fetch,
2242
2440
  port: (ctx as any).handlerPort,
2243
- });
2244
- await new Promise(resolve => setTimeout(resolve, 2000));
2441
+ }));
2442
+ await resetInngest();
2245
2443
 
2246
2444
  const run = await counterWorkflow.createRunAsync();
2247
2445
  const result = await run.start({ inputData: { target: 10, value: 0 } });
@@ -2326,11 +2524,11 @@ describe('MastraInngestWorkflow', () => {
2326
2524
 
2327
2525
  const app = await createHonoServer(mastra);
2328
2526
 
2329
- const srv = serve({
2527
+ const srv = (globServer = serve({
2330
2528
  fetch: app.fetch,
2331
2529
  port: (ctx as any).handlerPort,
2332
- });
2333
- await new Promise(resolve => setTimeout(resolve, 2000));
2530
+ }));
2531
+ await resetInngest();
2334
2532
 
2335
2533
  const run = await counterWorkflow.createRunAsync();
2336
2534
  const result = await run.start({ inputData: [{ value: 1 }, { value: 22 }, { value: 333 }] });
@@ -2479,11 +2677,11 @@ describe('MastraInngestWorkflow', () => {
2479
2677
 
2480
2678
  const app = await createHonoServer(mastra);
2481
2679
 
2482
- const srv = serve({
2680
+ const srv = (globServer = serve({
2483
2681
  fetch: app.fetch,
2484
2682
  port: (ctx as any).handlerPort,
2485
- });
2486
- await new Promise(resolve => setTimeout(resolve, 2000));
2683
+ }));
2684
+ await resetInngest();
2487
2685
 
2488
2686
  const run = await counterWorkflow.createRunAsync();
2489
2687
  const result = await run.start({ inputData: { startValue: 1 } });
@@ -2628,15 +2826,17 @@ describe('MastraInngestWorkflow', () => {
2628
2826
 
2629
2827
  const app = await createHonoServer(mastra);
2630
2828
 
2631
- const srv = serve({
2829
+ const srv = (globServer = serve({
2632
2830
  fetch: app.fetch,
2633
2831
  port: (ctx as any).handlerPort,
2634
- });
2635
- await new Promise(resolve => setTimeout(resolve, 2000));
2832
+ }));
2833
+ await resetInngest();
2636
2834
 
2637
2835
  const run = await counterWorkflow.createRunAsync();
2638
2836
  const result = await run.start({ inputData: { startValue: 6 } });
2639
2837
 
2838
+ srv.close();
2839
+
2640
2840
  expect(start).toHaveBeenCalledTimes(1);
2641
2841
  expect(other).toHaveBeenCalledTimes(1);
2642
2842
  expect(final).toHaveBeenCalledTimes(1);
@@ -2644,8 +2844,6 @@ describe('MastraInngestWorkflow', () => {
2644
2844
  expect(result.steps['else-branch'].output).toMatchObject({ finalValue: 26 + 6 + 1 });
2645
2845
  // @ts-ignore
2646
2846
  expect(result.steps.start.output).toMatchObject({ newValue: 7 });
2647
-
2648
- srv.close();
2649
2847
  });
2650
2848
  });
2651
2849
 
@@ -2800,19 +2998,19 @@ describe('MastraInngestWorkflow', () => {
2800
2998
 
2801
2999
  const app = await createHonoServer(mastra);
2802
3000
 
2803
- const srv = serve({
3001
+ const srv = (globServer = serve({
2804
3002
  fetch: app.fetch,
2805
3003
  port: (ctx as any).handlerPort,
2806
- });
2807
- await new Promise(resolve => setTimeout(resolve, 2000));
3004
+ }));
3005
+ await resetInngest();
2808
3006
 
2809
3007
  const run = await workflow.createRunAsync();
2810
3008
  const result = await run.start({ inputData: {} });
2811
3009
 
3010
+ srv.close();
3011
+
2812
3012
  expect(result.steps['nested-a']).toMatchObject({ status: 'success', output: { result: 'success3' } });
2813
3013
  expect(result.steps['nested-b']).toMatchObject({ status: 'success', output: { result: 'success5' } });
2814
-
2815
- srv.close();
2816
3014
  });
2817
3015
  });
2818
3016
 
@@ -2866,21 +3064,21 @@ describe('MastraInngestWorkflow', () => {
2866
3064
 
2867
3065
  const app = await createHonoServer(mastra);
2868
3066
 
2869
- const srv = serve({
3067
+ const srv = (globServer = serve({
2870
3068
  fetch: app.fetch,
2871
3069
  port: (ctx as any).handlerPort,
2872
- });
2873
- await new Promise(resolve => setTimeout(resolve, 2000));
3070
+ }));
3071
+ await resetInngest();
2874
3072
 
2875
3073
  const run = await workflow.createRunAsync();
2876
3074
  const result = await run.start({ inputData: {} });
2877
3075
 
3076
+ srv.close();
3077
+
2878
3078
  expect(result.steps.step1).toMatchObject({ status: 'success', output: { result: 'success' } });
2879
3079
  expect(result.steps.step2).toMatchObject({ status: 'failed', error: 'Step failed' });
2880
3080
  expect(step1.execute).toHaveBeenCalledTimes(1);
2881
3081
  expect(step2.execute).toHaveBeenCalledTimes(1); // 0 retries + 1 initial call
2882
-
2883
- srv.close();
2884
3082
  });
2885
3083
 
2886
3084
  // Need to fix so we can throw for inngest to recognize retries
@@ -2998,11 +3196,11 @@ describe('MastraInngestWorkflow', () => {
2998
3196
 
2999
3197
  const app = await createHonoServer(mastra);
3000
3198
 
3001
- const srv = serve({
3199
+ const srv = (globServer = serve({
3002
3200
  fetch: app.fetch,
3003
3201
  port: (ctx as any).handlerPort,
3004
- });
3005
- await new Promise(resolve => setTimeout(resolve, 2000));
3202
+ }));
3203
+ await resetInngest();
3006
3204
 
3007
3205
  const run = await workflow.createRunAsync();
3008
3206
  const result = await run.start({ inputData: {} });
@@ -3070,11 +3268,11 @@ describe('MastraInngestWorkflow', () => {
3070
3268
 
3071
3269
  const app = await createHonoServer(mastra);
3072
3270
 
3073
- const srv = serve({
3271
+ const srv = (globServer = serve({
3074
3272
  fetch: app.fetch,
3075
3273
  port: (ctx as any).handlerPort,
3076
- });
3077
- await new Promise(resolve => setTimeout(resolve, 2000));
3274
+ }));
3275
+ await resetInngest();
3078
3276
 
3079
3277
  const run = await workflow.createRunAsync();
3080
3278
 
@@ -3087,7 +3285,9 @@ describe('MastraInngestWorkflow', () => {
3087
3285
  });
3088
3286
 
3089
3287
  const executionResult = await run.start({ inputData: {} });
3090
- await new Promise(resolve => setTimeout(resolve, 2000));
3288
+ await new Promise(resolve => setTimeout(resolve, 1000));
3289
+
3290
+ srv.close();
3091
3291
 
3092
3292
  expect(cnt).toBe(5);
3093
3293
  expect(resps.length).toBe(5);
@@ -3199,8 +3399,6 @@ describe('MastraInngestWorkflow', () => {
3199
3399
  status: 'success',
3200
3400
  output: { result: 'success2' },
3201
3401
  });
3202
-
3203
- srv.close();
3204
3402
  });
3205
3403
 
3206
3404
  it('should unsubscribe from transitions when unwatch is called', async ctx => {
@@ -3256,11 +3454,11 @@ describe('MastraInngestWorkflow', () => {
3256
3454
 
3257
3455
  const app = await createHonoServer(mastra);
3258
3456
 
3259
- const srv = serve({
3457
+ const srv = (globServer = serve({
3260
3458
  fetch: app.fetch,
3261
3459
  port: (ctx as any).handlerPort,
3262
- });
3263
- await new Promise(resolve => setTimeout(resolve, 2000));
3460
+ }));
3461
+ await resetInngest();
3264
3462
 
3265
3463
  const onTransition = vi.fn();
3266
3464
  const onTransition2 = vi.fn();
@@ -3428,11 +3626,11 @@ describe('MastraInngestWorkflow', () => {
3428
3626
 
3429
3627
  const app = await createHonoServer(mastra);
3430
3628
 
3431
- const srv = serve({
3629
+ const srv = (globServer = serve({
3432
3630
  fetch: app.fetch,
3433
3631
  port: (ctx as any).handlerPort,
3434
- });
3435
- await new Promise(resolve => setTimeout(resolve, 2000));
3632
+ }));
3633
+ await resetInngest();
3436
3634
 
3437
3635
  const run = await promptEvalWorkflow.createRunAsync();
3438
3636
 
@@ -3578,11 +3776,11 @@ describe('MastraInngestWorkflow', () => {
3578
3776
 
3579
3777
  const app = await createHonoServer(mastra);
3580
3778
 
3581
- const srv = serve({
3779
+ const srv = (globServer = serve({
3582
3780
  fetch: app.fetch,
3583
3781
  port: (ctx as any).handlerPort,
3584
- });
3585
- await new Promise(resolve => setTimeout(resolve, 2000));
3782
+ }));
3783
+ await resetInngest();
3586
3784
 
3587
3785
  const run = await workflow.createRunAsync();
3588
3786
 
@@ -3616,13 +3814,13 @@ describe('MastraInngestWorkflow', () => {
3616
3814
 
3617
3815
  const initialResult = await started;
3618
3816
 
3817
+ srv.close();
3818
+
3619
3819
  expect(initialResult.steps.humanIntervention.status).toBe('suspended');
3620
3820
  expect(initialResult.steps.explainResponse).toBeUndefined();
3621
3821
  expect(humanInterventionAction).toHaveBeenCalledTimes(2);
3622
3822
  expect(explainResponseAction).not.toHaveBeenCalled();
3623
3823
 
3624
- srv.close();
3625
-
3626
3824
  if (!result) {
3627
3825
  throw new Error('Resume failed to return a result');
3628
3826
  }
@@ -3780,11 +3978,11 @@ describe('MastraInngestWorkflow', () => {
3780
3978
 
3781
3979
  const app = await createHonoServer(mastra);
3782
3980
 
3783
- const srv = serve({
3981
+ const srv = (globServer = serve({
3784
3982
  fetch: app.fetch,
3785
3983
  port: (ctx as any).handlerPort,
3786
- });
3787
- await new Promise(resolve => setTimeout(resolve, 2000));
3984
+ }));
3985
+ await resetInngest();
3788
3986
 
3789
3987
  const run = await workflow.createRunAsync();
3790
3988
  const started = run.start({ inputData: { input: 'test' } });
@@ -3837,11 +4035,12 @@ describe('MastraInngestWorkflow', () => {
3837
4035
  // @ts-ignore
3838
4036
  const improvedResponseResult = await improvedResponseResultPromise;
3839
4037
 
4038
+ srv.close();
4039
+
3840
4040
  expect(improvedResponseResult?.steps.humanIntervention.status).toBe('suspended');
3841
4041
  expect(improvedResponseResult?.steps.improveResponse.status).toBe('success');
3842
4042
  expect(improvedResponseResult?.steps.evaluateImprovedResponse.status).toBe('success');
3843
4043
 
3844
- srv.close();
3845
4044
  if (!result) {
3846
4045
  throw new Error('Resume failed to return a result');
3847
4046
  }
@@ -3974,11 +4173,11 @@ describe('MastraInngestWorkflow', () => {
3974
4173
 
3975
4174
  const app = await createHonoServer(mastra);
3976
4175
 
3977
- const srv = serve({
4176
+ const srv = (globServer = serve({
3978
4177
  fetch: app.fetch,
3979
4178
  port: (ctx as any).handlerPort,
3980
- });
3981
- await new Promise(resolve => setTimeout(resolve, 2000));
4179
+ }));
4180
+ await resetInngest();
3982
4181
 
3983
4182
  const run = await promptEvalWorkflow.createRunAsync();
3984
4183
 
@@ -4033,6 +4232,9 @@ describe('MastraInngestWorkflow', () => {
4033
4232
  completenessScore: { score: 0.7 },
4034
4233
  },
4035
4234
  });
4235
+
4236
+ srv.close();
4237
+
4036
4238
  if (!secondResumeResult) {
4037
4239
  throw new Error('Resume failed to return a result');
4038
4240
  }
@@ -4055,32 +4257,148 @@ describe('MastraInngestWorkflow', () => {
4055
4257
  });
4056
4258
 
4057
4259
  expect(promptAgentAction).toHaveBeenCalledTimes(2);
4058
-
4059
- srv.close();
4060
4260
  });
4061
- });
4062
4261
 
4063
- describe('Accessing Mastra', () => {
4064
- it('should be able to access the deprecated mastra primitives', async ctx => {
4262
+ it('should handle consecutive nested workflows with suspend/resume', async ctx => {
4065
4263
  const inngest = new Inngest({
4066
4264
  id: 'mastra',
4067
4265
  baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
4266
+ middleware: [realtimeMiddleware()],
4068
4267
  });
4069
4268
 
4070
4269
  const { createWorkflow, createStep } = init(inngest);
4071
- let telemetry: Telemetry | undefined;
4072
- const step1 = createStep({
4073
- id: 'step1',
4074
- inputSchema: z.object({}),
4075
- outputSchema: z.object({}),
4076
- execute: async ({ mastra }) => {
4077
- telemetry = mastra?.getTelemetry();
4078
- return {};
4079
- },
4080
- });
4081
4270
 
4082
- const workflow = createWorkflow({ id: 'test-workflow', inputSchema: z.object({}), outputSchema: z.object({}) });
4083
- workflow.then(step1).commit();
4271
+ const step1 = vi.fn().mockImplementation(async ({ resumeData, suspend }) => {
4272
+ if (!resumeData?.suspect) {
4273
+ return await suspend({ message: 'What is the suspect?' });
4274
+ }
4275
+ return { suspect: resumeData.suspect };
4276
+ });
4277
+ const step1Definition = createStep({
4278
+ id: 'step-1',
4279
+ inputSchema: z.object({ suspect: z.string() }),
4280
+ outputSchema: z.object({ suspect: z.string() }),
4281
+ suspendSchema: z.object({ message: z.string() }),
4282
+ resumeSchema: z.object({ suspect: z.string() }),
4283
+ execute: step1,
4284
+ });
4285
+
4286
+ const step2 = vi.fn().mockImplementation(async ({ resumeData, suspend }) => {
4287
+ if (!resumeData?.suspect) {
4288
+ return await suspend({ message: 'What is the second suspect?' });
4289
+ }
4290
+ return { suspect: resumeData.suspect };
4291
+ });
4292
+ const step2Definition = createStep({
4293
+ id: 'step-2',
4294
+ inputSchema: z.object({ suspect: z.string() }),
4295
+ outputSchema: z.object({ suspect: z.string() }),
4296
+ suspendSchema: z.object({ message: z.string() }),
4297
+ resumeSchema: z.object({ suspect: z.string() }),
4298
+ execute: step2,
4299
+ });
4300
+
4301
+ const subWorkflow1 = createWorkflow({
4302
+ id: 'sub-workflow-1',
4303
+ inputSchema: z.object({ suspect: z.string() }),
4304
+ outputSchema: z.object({ suspect: z.string() }),
4305
+ })
4306
+ .then(step1Definition)
4307
+ .commit();
4308
+
4309
+ const subWorkflow2 = createWorkflow({
4310
+ id: 'sub-workflow-2',
4311
+ inputSchema: z.object({ suspect: z.string() }),
4312
+ outputSchema: z.object({ suspect: z.string() }),
4313
+ })
4314
+ .then(step2Definition)
4315
+ .commit();
4316
+
4317
+ const mainWorkflow = createWorkflow({
4318
+ id: 'main-workflow',
4319
+ inputSchema: z.object({ suspect: z.string() }),
4320
+ outputSchema: z.object({ suspect: z.string() }),
4321
+ })
4322
+ .then(subWorkflow1)
4323
+ .then(subWorkflow2)
4324
+ .commit();
4325
+
4326
+ const mastra = new Mastra({
4327
+ logger: false,
4328
+ storage: new DefaultStorage({
4329
+ url: ':memory:',
4330
+ }),
4331
+ workflows: { mainWorkflow },
4332
+ server: {
4333
+ apiRoutes: [
4334
+ {
4335
+ path: '/inngest/api',
4336
+ method: 'ALL',
4337
+ createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
4338
+ },
4339
+ ],
4340
+ },
4341
+ });
4342
+
4343
+ const app = await createHonoServer(mastra);
4344
+
4345
+ const srv = (globServer = serve({
4346
+ fetch: app.fetch,
4347
+ port: (ctx as any).handlerPort,
4348
+ }));
4349
+ await resetInngest();
4350
+
4351
+ const run = await mainWorkflow.createRunAsync();
4352
+
4353
+ const initialResult = await run.start({ inputData: { suspect: 'initial-suspect' } });
4354
+ expect(initialResult.status).toBe('suspended');
4355
+
4356
+ const firstResumeResult = await run.resume({
4357
+ step: ['sub-workflow-1', 'step-1'],
4358
+ resumeData: { suspect: 'first-suspect' },
4359
+ });
4360
+ expect(firstResumeResult.status).toBe('suspended');
4361
+
4362
+ const secondResumeResult = await run.resume({
4363
+ step: ['sub-workflow-2', 'step-2'],
4364
+ resumeData: { suspect: 'second-suspect' },
4365
+ });
4366
+
4367
+ expect(step1).toHaveBeenCalledTimes(2);
4368
+ expect(step2).toHaveBeenCalledTimes(2);
4369
+ expect(secondResumeResult.status).toBe('success');
4370
+ expect(secondResumeResult.steps['sub-workflow-1']).toMatchObject({
4371
+ status: 'success',
4372
+ });
4373
+ expect(secondResumeResult.steps['sub-workflow-2']).toMatchObject({
4374
+ status: 'success',
4375
+ });
4376
+
4377
+ srv.close();
4378
+ });
4379
+ });
4380
+
4381
+ describe('Accessing Mastra', () => {
4382
+ it('should be able to access the deprecated mastra primitives', async ctx => {
4383
+ const inngest = new Inngest({
4384
+ id: 'mastra',
4385
+ baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
4386
+ });
4387
+
4388
+ const { createWorkflow, createStep } = init(inngest);
4389
+ let telemetry: Telemetry | undefined;
4390
+ const step1 = createStep({
4391
+ id: 'step1',
4392
+ inputSchema: z.object({}),
4393
+ outputSchema: z.object({}),
4394
+ execute: async ({ mastra }) => {
4395
+ telemetry = mastra?.getTelemetry();
4396
+ return {};
4397
+ },
4398
+ });
4399
+
4400
+ const workflow = createWorkflow({ id: 'test-workflow', inputSchema: z.object({}), outputSchema: z.object({}) });
4401
+ workflow.then(step1).commit();
4084
4402
 
4085
4403
  const mastra = new Mastra({
4086
4404
  storage: new DefaultStorage({
@@ -4102,11 +4420,11 @@ describe('MastraInngestWorkflow', () => {
4102
4420
 
4103
4421
  const app = await createHonoServer(mastra);
4104
4422
 
4105
- const srv = serve({
4423
+ const srv = (globServer = serve({
4106
4424
  fetch: app.fetch,
4107
4425
  port: (ctx as any).handlerPort,
4108
- });
4109
- await new Promise(resolve => setTimeout(resolve, 2000));
4426
+ }));
4427
+ await resetInngest();
4110
4428
 
4111
4429
  // Access new instance properties directly - should work without warning
4112
4430
  const run = await workflow.createRunAsync();
@@ -4206,11 +4524,11 @@ describe('MastraInngestWorkflow', () => {
4206
4524
 
4207
4525
  const app = await createHonoServer(mastra);
4208
4526
 
4209
- const srv = serve({
4527
+ const srv = (globServer = serve({
4210
4528
  fetch: app.fetch,
4211
4529
  port: (ctx as any).handlerPort,
4212
- });
4213
- await new Promise(resolve => setTimeout(resolve, 2000));
4530
+ }));
4531
+ await resetInngest();
4214
4532
 
4215
4533
  const run = await workflow.createRunAsync();
4216
4534
  const result = await run.start({
@@ -4343,11 +4661,11 @@ describe('MastraInngestWorkflow', () => {
4343
4661
 
4344
4662
  const app = await createHonoServer(mastra);
4345
4663
 
4346
- const srv = serve({
4664
+ const srv = (globServer = serve({
4347
4665
  fetch: app.fetch,
4348
4666
  port: (ctx as any).handlerPort,
4349
- });
4350
- await new Promise(resolve => setTimeout(resolve, 2000));
4667
+ }));
4668
+ await resetInngest();
4351
4669
 
4352
4670
  const run = await workflow.createRunAsync();
4353
4671
  const result = await run.start({
@@ -4486,11 +4804,11 @@ describe('MastraInngestWorkflow', () => {
4486
4804
 
4487
4805
  const app = await createHonoServer(mastra);
4488
4806
 
4489
- const srv = serve({
4807
+ const srv = (globServer = serve({
4490
4808
  fetch: app.fetch,
4491
4809
  port: (ctx as any).handlerPort,
4492
- });
4493
- await new Promise(resolve => setTimeout(resolve, 2000));
4810
+ }));
4811
+ await resetInngest();
4494
4812
 
4495
4813
  const run = await counterWorkflow.createRunAsync();
4496
4814
  const result = await run.start({ inputData: { startValue: 0 } });
@@ -4638,11 +4956,11 @@ describe('MastraInngestWorkflow', () => {
4638
4956
 
4639
4957
  const app = await createHonoServer(mastra);
4640
4958
 
4641
- const srv = serve({
4959
+ const srv = (globServer = serve({
4642
4960
  fetch: app.fetch,
4643
4961
  port: (ctx as any).handlerPort,
4644
- });
4645
- await new Promise(resolve => setTimeout(resolve, 2000));
4962
+ }));
4963
+ await resetInngest();
4646
4964
 
4647
4965
  const run = await counterWorkflow.createRunAsync();
4648
4966
  const result = await run.start({ inputData: { startValue: 0 } });
@@ -4798,10 +5116,11 @@ describe('MastraInngestWorkflow', () => {
4798
5116
  await next();
4799
5117
  });
4800
5118
 
4801
- const srv = serve({
5119
+ const srv = (globServer = serve({
4802
5120
  fetch: app.fetch,
4803
5121
  port: (ctx as any).handlerPort,
4804
- });
5122
+ }));
5123
+ await resetInngest();
4805
5124
 
4806
5125
  const run = await counterWorkflow.createRunAsync();
4807
5126
  const result = await run.start({ inputData: { startValue: 0 } });
@@ -4957,10 +5276,11 @@ describe('MastraInngestWorkflow', () => {
4957
5276
  await next();
4958
5277
  });
4959
5278
 
4960
- const srv = serve({
5279
+ const srv = (globServer = serve({
4961
5280
  fetch: app.fetch,
4962
5281
  port: (ctx as any).handlerPort,
4963
- });
5282
+ }));
5283
+ await resetInngest();
4964
5284
 
4965
5285
  const run = await counterWorkflow.createRunAsync();
4966
5286
  const result = await run.start({ inputData: { startValue: 0 } });
@@ -5154,10 +5474,11 @@ describe('MastraInngestWorkflow', () => {
5154
5474
  await next();
5155
5475
  });
5156
5476
 
5157
- const srv = serve({
5477
+ const srv = (globServer = serve({
5158
5478
  fetch: app.fetch,
5159
5479
  port: (ctx as any).handlerPort,
5160
- });
5480
+ }));
5481
+ await resetInngest();
5161
5482
 
5162
5483
  const run = await counterWorkflow.createRunAsync();
5163
5484
  const result = await run.start({ inputData: { startValue: 1 } });
@@ -5307,11 +5628,11 @@ describe('MastraInngestWorkflow', () => {
5307
5628
 
5308
5629
  const app = await createHonoServer(mastra);
5309
5630
 
5310
- const srv = serve({
5631
+ const srv = (globServer = serve({
5311
5632
  fetch: app.fetch,
5312
5633
  port: (ctx as any).handlerPort,
5313
- });
5314
- await new Promise(resolve => setTimeout(resolve, 2000));
5634
+ }));
5635
+ await resetInngest();
5315
5636
 
5316
5637
  const run = await counterWorkflow.createRunAsync();
5317
5638
  const result = await run.start({ inputData: { startValue: 0 } });
@@ -5458,10 +5779,11 @@ describe('MastraInngestWorkflow', () => {
5458
5779
  await next();
5459
5780
  });
5460
5781
 
5461
- const srv = serve({
5782
+ const srv = (globServer = serve({
5462
5783
  fetch: app.fetch,
5463
5784
  port: (ctx as any).handlerPort,
5464
- });
5785
+ }));
5786
+ await resetInngest();
5465
5787
 
5466
5788
  const run = await counterWorkflow.createRunAsync();
5467
5789
  const result = await run.start({ inputData: { startValue: 0 } });
@@ -5639,11 +5961,11 @@ describe('MastraInngestWorkflow', () => {
5639
5961
 
5640
5962
  const app = await createHonoServer(mastra);
5641
5963
 
5642
- const srv = serve({
5964
+ const srv = (globServer = serve({
5643
5965
  fetch: app.fetch,
5644
5966
  port: (ctx as any).handlerPort,
5645
- });
5646
- await new Promise(resolve => setTimeout(resolve, 2000));
5967
+ }));
5968
+ await resetInngest();
5647
5969
 
5648
5970
  const run = await counterWorkflow.createRunAsync();
5649
5971
  const result = await run.start({ inputData: { startValue: 0 } });
@@ -5801,11 +6123,11 @@ describe('MastraInngestWorkflow', () => {
5801
6123
 
5802
6124
  const app = await createHonoServer(mastra);
5803
6125
 
5804
- const srv = serve({
6126
+ const srv = (globServer = serve({
5805
6127
  fetch: app.fetch,
5806
6128
  port: (ctx as any).handlerPort,
5807
- });
5808
- await new Promise(resolve => setTimeout(resolve, 2000));
6129
+ }));
6130
+ await resetInngest();
5809
6131
 
5810
6132
  const run = await counterWorkflow.createRunAsync();
5811
6133
  const result = await run.start({ inputData: { startValue: 0 } });
@@ -5876,11 +6198,11 @@ describe('MastraInngestWorkflow', () => {
5876
6198
 
5877
6199
  const app = await createHonoServer(mastra);
5878
6200
 
5879
- const srv = serve({
6201
+ const srv = (globServer = serve({
5880
6202
  fetch: app.fetch,
5881
6203
  port: (ctx as any).handlerPort,
5882
- });
5883
- await new Promise(resolve => setTimeout(resolve, 2000));
6204
+ }));
6205
+ await resetInngest();
5884
6206
 
5885
6207
  // Access new instance properties directly - should work without warning
5886
6208
  const run = await workflow.createRunAsync();
@@ -5939,10 +6261,11 @@ describe('MastraInngestWorkflow', () => {
5939
6261
 
5940
6262
  const app = await createHonoServer(mastra);
5941
6263
 
5942
- const srv = serve({
6264
+ const srv = (globServer = serve({
5943
6265
  fetch: app.fetch,
5944
6266
  port: (ctx as any).handlerPort,
5945
- });
6267
+ }));
6268
+ await resetInngest();
5946
6269
 
5947
6270
  const run = await workflow.createRunAsync();
5948
6271
  const result = await run.start({ runtimeContext });
@@ -5953,7 +6276,7 @@ describe('MastraInngestWorkflow', () => {
5953
6276
  expect(result.steps.step1.output.injectedValue).toBe(testValue);
5954
6277
  });
5955
6278
 
5956
- it('should inject runtimeContext dependencies into steps during resume', async ctx => {
6279
+ it.skip('should inject runtimeContext dependencies into steps during resume', async ctx => {
5957
6280
  const inngest = new Inngest({
5958
6281
  id: 'mastra',
5959
6282
  baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
@@ -6014,6 +6337,176 @@ describe('MastraInngestWorkflow', () => {
6014
6337
  // @ts-ignore
6015
6338
  expect(result?.steps.step1.output.injectedValue).toBe(testValue + '2');
6016
6339
  });
6340
+
6341
+ it('should have access to runtimeContext from before suspension during workflow resume', async ctx => {
6342
+ const inngest = new Inngest({
6343
+ id: 'mastra',
6344
+ baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
6345
+ });
6346
+
6347
+ const { createWorkflow, createStep } = init(inngest);
6348
+
6349
+ const testValue = 'test-dependency';
6350
+ const resumeStep = createStep({
6351
+ id: 'resume',
6352
+ inputSchema: z.object({ value: z.number() }),
6353
+ outputSchema: z.object({ value: z.number() }),
6354
+ resumeSchema: z.object({ value: z.number() }),
6355
+ suspendSchema: z.object({ message: z.string() }),
6356
+ execute: async ({ inputData, resumeData, suspend }) => {
6357
+ const finalValue = (resumeData?.value ?? 0) + inputData.value;
6358
+
6359
+ if (!resumeData?.value || finalValue < 10) {
6360
+ return await suspend({
6361
+ message: `Please provide additional information. now value is ${inputData.value}`,
6362
+ });
6363
+ }
6364
+
6365
+ return { value: finalValue };
6366
+ },
6367
+ });
6368
+
6369
+ const incrementStep = createStep({
6370
+ id: 'increment',
6371
+ inputSchema: z.object({
6372
+ value: z.number(),
6373
+ }),
6374
+ outputSchema: z.object({
6375
+ value: z.number(),
6376
+ }),
6377
+ execute: async ({ inputData, runtimeContext }) => {
6378
+ runtimeContext.set('testKey', testValue);
6379
+ return {
6380
+ value: inputData.value + 1,
6381
+ };
6382
+ },
6383
+ });
6384
+
6385
+ const incrementWorkflow = createWorkflow({
6386
+ id: 'increment-workflow',
6387
+ inputSchema: z.object({ value: z.number() }),
6388
+ outputSchema: z.object({ value: z.number() }),
6389
+ })
6390
+ .then(incrementStep)
6391
+ .then(resumeStep)
6392
+ .then(
6393
+ createStep({
6394
+ id: 'final',
6395
+ inputSchema: z.object({ value: z.number() }),
6396
+ outputSchema: z.object({ value: z.number() }),
6397
+ execute: async ({ inputData, runtimeContext }) => {
6398
+ const testKey = runtimeContext.get('testKey');
6399
+ expect(testKey).toBe(testValue);
6400
+ return { value: inputData.value };
6401
+ },
6402
+ }),
6403
+ )
6404
+ .commit();
6405
+
6406
+ new Mastra({
6407
+ logger: false,
6408
+ storage: testStorage,
6409
+ workflows: { incrementWorkflow },
6410
+ });
6411
+
6412
+ const run = await incrementWorkflow.createRunAsync();
6413
+ const result = await run.start({ inputData: { value: 0 } });
6414
+ expect(result.status).toBe('suspended');
6415
+
6416
+ const resumeResult = await run.resume({
6417
+ resumeData: { value: 21 },
6418
+ step: ['resume'],
6419
+ });
6420
+
6421
+ expect(resumeResult.status).toBe('success');
6422
+ });
6423
+
6424
+ it('should not show removed runtimeContext values in subsequent steps', async ctx => {
6425
+ const inngest = new Inngest({
6426
+ id: 'mastra',
6427
+ baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
6428
+ });
6429
+
6430
+ const { createWorkflow, createStep } = init(inngest);
6431
+ const testValue = 'test-dependency';
6432
+ const resumeStep = createStep({
6433
+ id: 'resume',
6434
+ inputSchema: z.object({ value: z.number() }),
6435
+ outputSchema: z.object({ value: z.number() }),
6436
+ resumeSchema: z.object({ value: z.number() }),
6437
+ suspendSchema: z.object({ message: z.string() }),
6438
+ execute: async ({ inputData, resumeData, suspend, runtimeContext }) => {
6439
+ const finalValue = (resumeData?.value ?? 0) + inputData.value;
6440
+
6441
+ if (!resumeData?.value || finalValue < 10) {
6442
+ return await suspend({
6443
+ message: `Please provide additional information. now value is ${inputData.value}`,
6444
+ });
6445
+ }
6446
+
6447
+ const testKey = runtimeContext.get('testKey');
6448
+ expect(testKey).toBe(testValue);
6449
+
6450
+ runtimeContext.delete('testKey');
6451
+
6452
+ return { value: finalValue };
6453
+ },
6454
+ });
6455
+
6456
+ const incrementStep = createStep({
6457
+ id: 'increment',
6458
+ inputSchema: z.object({
6459
+ value: z.number(),
6460
+ }),
6461
+ outputSchema: z.object({
6462
+ value: z.number(),
6463
+ }),
6464
+ execute: async ({ inputData, runtimeContext }) => {
6465
+ runtimeContext.set('testKey', testValue);
6466
+ return {
6467
+ value: inputData.value + 1,
6468
+ };
6469
+ },
6470
+ });
6471
+
6472
+ const incrementWorkflow = createWorkflow({
6473
+ id: 'increment-workflow',
6474
+ inputSchema: z.object({ value: z.number() }),
6475
+ outputSchema: z.object({ value: z.number() }),
6476
+ })
6477
+ .then(incrementStep)
6478
+ .then(resumeStep)
6479
+ .then(
6480
+ createStep({
6481
+ id: 'final',
6482
+ inputSchema: z.object({ value: z.number() }),
6483
+ outputSchema: z.object({ value: z.number() }),
6484
+ execute: async ({ inputData, runtimeContext }) => {
6485
+ const testKey = runtimeContext.get('testKey');
6486
+ expect(testKey).toBeUndefined();
6487
+ return { value: inputData.value };
6488
+ },
6489
+ }),
6490
+ )
6491
+ .commit();
6492
+
6493
+ new Mastra({
6494
+ logger: false,
6495
+ storage: testStorage,
6496
+ workflows: { incrementWorkflow },
6497
+ });
6498
+
6499
+ const run = await incrementWorkflow.createRunAsync();
6500
+ const result = await run.start({ inputData: { value: 0 } });
6501
+ expect(result.status).toBe('suspended');
6502
+
6503
+ const resumeResult = await run.resume({
6504
+ resumeData: { value: 21 },
6505
+ step: ['resume'],
6506
+ });
6507
+
6508
+ expect(resumeResult.status).toBe('success');
6509
+ });
6017
6510
  });
6018
6511
 
6019
6512
  describe('Access to inngest step primitives', () => {
@@ -6064,10 +6557,11 @@ describe('MastraInngestWorkflow', () => {
6064
6557
 
6065
6558
  const app = await createHonoServer(mastra);
6066
6559
 
6067
- const srv = serve({
6560
+ const srv = (globServer = serve({
6068
6561
  fetch: app.fetch,
6069
6562
  port: (ctx as any).handlerPort,
6070
- });
6563
+ }));
6564
+ await resetInngest();
6071
6565
 
6072
6566
  const run = await workflow.createRunAsync();
6073
6567
  const result = await run.start({});
@@ -6133,10 +6627,11 @@ describe('MastraInngestWorkflow', () => {
6133
6627
 
6134
6628
  const app = await createHonoServer(mastra);
6135
6629
 
6136
- const srv = serve({
6630
+ const srv = (globServer = serve({
6137
6631
  fetch: app.fetch,
6138
6632
  port: (ctx as any).handlerPort,
6139
- });
6633
+ }));
6634
+ await resetInngest();
6140
6635
 
6141
6636
  const runId = 'test-run-id';
6142
6637
  let watchData: StreamEvent[] = [];
@@ -6144,7 +6639,7 @@ describe('MastraInngestWorkflow', () => {
6144
6639
  runId,
6145
6640
  });
6146
6641
 
6147
- await new Promise(resolve => setTimeout(resolve, 1000));
6642
+ await resetInngest();
6148
6643
 
6149
6644
  const { stream, getWorkflowState } = run.stream({ inputData: {} });
6150
6645
 
@@ -6157,7 +6652,7 @@ describe('MastraInngestWorkflow', () => {
6157
6652
 
6158
6653
  const executionResult = await getWorkflowState();
6159
6654
 
6160
- await new Promise(resolve => setTimeout(resolve, 1000));
6655
+ await resetInngest();
6161
6656
 
6162
6657
  srv.close();
6163
6658
 
@@ -6304,10 +6799,11 @@ describe('MastraInngestWorkflow', () => {
6304
6799
 
6305
6800
  const app = await createHonoServer(mastra);
6306
6801
 
6307
- const srv = serve({
6802
+ const srv = (globServer = serve({
6308
6803
  fetch: app.fetch,
6309
6804
  port: (ctx as any).handlerPort,
6310
- });
6805
+ }));
6806
+ await resetInngest();
6311
6807
 
6312
6808
  const runId = 'test-run-id';
6313
6809
  let watchData: StreamEvent[] = [];
@@ -6315,7 +6811,7 @@ describe('MastraInngestWorkflow', () => {
6315
6811
  runId,
6316
6812
  });
6317
6813
 
6318
- await new Promise(resolve => setTimeout(resolve, 1000));
6814
+ await resetInngest();
6319
6815
 
6320
6816
  const { stream, getWorkflowState } = run.stream({ inputData: {} });
6321
6817
 
@@ -6328,11 +6824,11 @@ describe('MastraInngestWorkflow', () => {
6328
6824
 
6329
6825
  const executionResult = await getWorkflowState();
6330
6826
 
6331
- await new Promise(resolve => setTimeout(resolve, 1000));
6827
+ await resetInngest();
6332
6828
 
6333
6829
  srv.close();
6334
6830
 
6335
- expect(watchData.length).toBe(9);
6831
+ expect(watchData.length).toBe(11);
6336
6832
  expect(watchData).toMatchObject([
6337
6833
  {
6338
6834
  payload: {
@@ -6343,6 +6839,9 @@ describe('MastraInngestWorkflow', () => {
6343
6839
  {
6344
6840
  payload: {
6345
6841
  id: 'step1',
6842
+ startedAt: expect.any(Number),
6843
+ status: 'running',
6844
+ payload: {},
6346
6845
  },
6347
6846
  type: 'step-start',
6348
6847
  },
@@ -6352,6 +6851,7 @@ describe('MastraInngestWorkflow', () => {
6352
6851
  output: {
6353
6852
  result: 'success1',
6354
6853
  },
6854
+ endedAt: expect.any(Number),
6355
6855
  status: 'success',
6356
6856
  },
6357
6857
  type: 'step-result',
@@ -6364,12 +6864,43 @@ describe('MastraInngestWorkflow', () => {
6364
6864
  type: 'step-finish',
6365
6865
  },
6366
6866
  {
6367
- payload: {},
6867
+ payload: {
6868
+ id: expect.any(String),
6869
+ startedAt: expect.any(Number),
6870
+ status: 'waiting',
6871
+ payload: {
6872
+ result: 'success1',
6873
+ },
6874
+ },
6368
6875
  type: 'step-waiting',
6369
6876
  },
6877
+ {
6878
+ payload: {
6879
+ id: expect.any(String),
6880
+ endedAt: expect.any(Number),
6881
+ startedAt: expect.any(Number),
6882
+ status: 'success',
6883
+ output: {
6884
+ result: 'success1',
6885
+ },
6886
+ },
6887
+ type: 'step-result',
6888
+ },
6889
+ {
6890
+ type: 'step-finish',
6891
+ payload: {
6892
+ id: expect.any(String),
6893
+ metadata: {},
6894
+ },
6895
+ },
6370
6896
  {
6371
6897
  payload: {
6372
6898
  id: 'step2',
6899
+ payload: {
6900
+ result: 'success1',
6901
+ },
6902
+ startedAt: expect.any(Number),
6903
+ status: 'running',
6373
6904
  },
6374
6905
  type: 'step-start',
6375
6906
  },
@@ -6379,6 +6910,7 @@ describe('MastraInngestWorkflow', () => {
6379
6910
  output: {
6380
6911
  result: 'success2',
6381
6912
  },
6913
+ endedAt: expect.any(Number),
6382
6914
  status: 'success',
6383
6915
  },
6384
6916
  type: 'step-result',
@@ -6397,6 +6929,7 @@ describe('MastraInngestWorkflow', () => {
6397
6929
  type: 'finish',
6398
6930
  },
6399
6931
  ]);
6932
+
6400
6933
  // Verify execution completed successfully
6401
6934
  expect(executionResult.steps.step1).toMatchObject({
6402
6935
  status: 'success',
@@ -6416,6 +6949,215 @@ describe('MastraInngestWorkflow', () => {
6416
6949
  });
6417
6950
  });
6418
6951
 
6952
+ it('should handle basic sleep waiting flow with fn parameter', async ctx => {
6953
+ const inngest = new Inngest({
6954
+ id: 'mastra',
6955
+ baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
6956
+ middleware: [realtimeMiddleware()],
6957
+ });
6958
+
6959
+ const { createWorkflow, createStep } = init(inngest);
6960
+
6961
+ const step1Action = vi.fn<any>().mockResolvedValue({ value: 1000 });
6962
+ const step2Action = vi.fn<any>().mockResolvedValue({ value: 2000 });
6963
+
6964
+ const step1 = createStep({
6965
+ id: 'step1',
6966
+ execute: step1Action,
6967
+ inputSchema: z.object({}),
6968
+ outputSchema: z.object({ value: z.number() }),
6969
+ });
6970
+ const step2 = createStep({
6971
+ id: 'step2',
6972
+ execute: step2Action,
6973
+ inputSchema: z.object({ value: z.number() }),
6974
+ outputSchema: z.object({}),
6975
+ });
6976
+
6977
+ const workflow = createWorkflow({
6978
+ id: 'test-workflow',
6979
+ inputSchema: z.object({}),
6980
+ outputSchema: z.object({}),
6981
+ steps: [step1, step2],
6982
+ });
6983
+ workflow
6984
+ .then(step1)
6985
+ .sleep(async ({ inputData }) => {
6986
+ return inputData.value;
6987
+ })
6988
+ .then(step2)
6989
+ .commit();
6990
+
6991
+ const mastra = new Mastra({
6992
+ storage: new DefaultStorage({
6993
+ url: ':memory:',
6994
+ }),
6995
+ workflows: {
6996
+ 'test-workflow': workflow,
6997
+ },
6998
+ server: {
6999
+ apiRoutes: [
7000
+ {
7001
+ path: '/inngest/api',
7002
+ method: 'ALL',
7003
+ createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
7004
+ },
7005
+ ],
7006
+ },
7007
+ });
7008
+
7009
+ const app = await createHonoServer(mastra);
7010
+
7011
+ const srv = (globServer = serve({
7012
+ fetch: app.fetch,
7013
+ port: (ctx as any).handlerPort,
7014
+ }));
7015
+ await resetInngest();
7016
+
7017
+ const runId = 'test-run-id';
7018
+ let watchData: StreamEvent[] = [];
7019
+ const run = await workflow.createRunAsync({
7020
+ runId,
7021
+ });
7022
+
7023
+ await resetInngest();
7024
+
7025
+ const { stream, getWorkflowState } = run.stream({ inputData: {} });
7026
+
7027
+ // Start watching the workflow
7028
+ const collectedStreamData: StreamEvent[] = [];
7029
+ for await (const data of stream) {
7030
+ collectedStreamData.push(JSON.parse(JSON.stringify(data)));
7031
+ }
7032
+ watchData = collectedStreamData;
7033
+
7034
+ const executionResult = await getWorkflowState();
7035
+
7036
+ await resetInngest();
7037
+
7038
+ srv.close();
7039
+
7040
+ expect(watchData.length).toBe(11);
7041
+ expect(watchData).toMatchObject([
7042
+ {
7043
+ payload: {
7044
+ runId: 'test-run-id',
7045
+ },
7046
+ type: 'start',
7047
+ },
7048
+ {
7049
+ payload: {
7050
+ id: 'step1',
7051
+ startedAt: expect.any(Number),
7052
+ status: 'running',
7053
+ payload: {},
7054
+ },
7055
+ type: 'step-start',
7056
+ },
7057
+ {
7058
+ payload: {
7059
+ id: 'step1',
7060
+ output: {
7061
+ value: 1000,
7062
+ },
7063
+ endedAt: expect.any(Number),
7064
+ status: 'success',
7065
+ },
7066
+ type: 'step-result',
7067
+ },
7068
+ {
7069
+ payload: {
7070
+ id: 'step1',
7071
+ metadata: {},
7072
+ },
7073
+ type: 'step-finish',
7074
+ },
7075
+ {
7076
+ payload: {
7077
+ id: expect.any(String),
7078
+ startedAt: expect.any(Number),
7079
+ status: 'waiting',
7080
+ payload: {
7081
+ value: 1000,
7082
+ },
7083
+ },
7084
+ type: 'step-waiting',
7085
+ },
7086
+ {
7087
+ payload: {
7088
+ id: expect.any(String),
7089
+ endedAt: expect.any(Number),
7090
+ startedAt: expect.any(Number),
7091
+ status: 'success',
7092
+ output: {
7093
+ value: 1000,
7094
+ },
7095
+ },
7096
+ type: 'step-result',
7097
+ },
7098
+ {
7099
+ type: 'step-finish',
7100
+ payload: {
7101
+ id: expect.any(String),
7102
+ metadata: {},
7103
+ },
7104
+ },
7105
+ {
7106
+ payload: {
7107
+ id: 'step2',
7108
+ payload: {
7109
+ value: 1000,
7110
+ },
7111
+ startedAt: expect.any(Number),
7112
+ status: 'running',
7113
+ },
7114
+ type: 'step-start',
7115
+ },
7116
+ {
7117
+ payload: {
7118
+ id: 'step2',
7119
+ output: {
7120
+ value: 2000,
7121
+ },
7122
+ endedAt: expect.any(Number),
7123
+ status: 'success',
7124
+ },
7125
+ type: 'step-result',
7126
+ },
7127
+ {
7128
+ payload: {
7129
+ id: 'step2',
7130
+ metadata: {},
7131
+ },
7132
+ type: 'step-finish',
7133
+ },
7134
+ {
7135
+ payload: {
7136
+ runId: 'test-run-id',
7137
+ },
7138
+ type: 'finish',
7139
+ },
7140
+ ]);
7141
+
7142
+ // Verify execution completed successfully
7143
+ expect(executionResult.steps.step1).toMatchObject({
7144
+ status: 'success',
7145
+ output: { value: 1000 },
7146
+ payload: {},
7147
+ startedAt: expect.any(Number),
7148
+ endedAt: expect.any(Number),
7149
+ });
7150
+ expect(executionResult.steps.step2).toMatchObject({
7151
+ status: 'success',
7152
+ output: { value: 2000 },
7153
+ payload: {
7154
+ value: 1000,
7155
+ },
7156
+ startedAt: expect.any(Number),
7157
+ endedAt: expect.any(Number),
7158
+ });
7159
+ });
7160
+
6419
7161
  it('should handle waitForEvent waiting flow', async ctx => {
6420
7162
  const inngest = new Inngest({
6421
7163
  id: 'mastra',
@@ -6469,10 +7211,11 @@ describe('MastraInngestWorkflow', () => {
6469
7211
 
6470
7212
  const app = await createHonoServer(mastra);
6471
7213
 
6472
- const srv = serve({
7214
+ const srv = (globServer = serve({
6473
7215
  fetch: app.fetch,
6474
7216
  port: (ctx as any).handlerPort,
6475
- });
7217
+ }));
7218
+ await resetInngest();
6476
7219
 
6477
7220
  const runId = 'test-run-id';
6478
7221
  let watchData: StreamEvent[] = [];
@@ -6480,7 +7223,7 @@ describe('MastraInngestWorkflow', () => {
6480
7223
  runId,
6481
7224
  });
6482
7225
 
6483
- await new Promise(resolve => setTimeout(resolve, 1000));
7226
+ await resetInngest();
6484
7227
 
6485
7228
  const { stream, getWorkflowState } = run.stream({ inputData: {} });
6486
7229
 
@@ -6500,7 +7243,7 @@ describe('MastraInngestWorkflow', () => {
6500
7243
 
6501
7244
  const executionResult = await getWorkflowState();
6502
7245
 
6503
- await new Promise(resolve => setTimeout(resolve, 1000));
7246
+ await resetInngest();
6504
7247
 
6505
7248
  srv.close();
6506
7249
 
@@ -6694,12 +7437,12 @@ describe('MastraInngestWorkflow', () => {
6694
7437
 
6695
7438
  const app = await createHonoServer(mastra);
6696
7439
 
6697
- const srv = serve({
7440
+ const srv = (globServer = serve({
6698
7441
  fetch: app.fetch,
6699
7442
  port: (ctx as any).handlerPort,
6700
- });
7443
+ }));
6701
7444
 
6702
- await new Promise(resolve => setTimeout(resolve, 1000));
7445
+ await resetInngest();
6703
7446
 
6704
7447
  const run = await promptEvalWorkflow.createRunAsync();
6705
7448
 
@@ -6883,12 +7626,12 @@ describe('MastraInngestWorkflow', () => {
6883
7626
 
6884
7627
  const app = await createHonoServer(mastra);
6885
7628
 
6886
- const srv = serve({
7629
+ const srv = (globServer = serve({
6887
7630
  fetch: app.fetch,
6888
7631
  port: (ctx as any).handlerPort,
6889
- });
7632
+ }));
6890
7633
 
6891
- await new Promise(resolve => setTimeout(resolve, 1000));
7634
+ await resetInngest();
6892
7635
 
6893
7636
  const run = await workflow.createRunAsync({
6894
7637
  runId: 'test-run-id',