@mastra/inngest 0.0.0-custom-instrumentation-20250626084921 → 0.0.0-fix-generate-title-20250616171351

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
@@ -5,12 +5,10 @@ import { openai } from '@ai-sdk/openai';
5
5
  import { serve } from '@hono/node-server';
6
6
  import { realtimeMiddleware } from '@inngest/realtime';
7
7
  import { createTool, Mastra, Telemetry } from '@mastra/core';
8
- import type { StreamEvent } from '@mastra/core';
9
8
  import { Agent } from '@mastra/core/agent';
10
9
  import { RuntimeContext } from '@mastra/core/runtime-context';
11
10
  import { createHonoServer } from '@mastra/deployer/server';
12
11
  import { DefaultStorage } from '@mastra/libsql';
13
- import { MockLanguageModelV1, simulateReadableStream } from 'ai/test';
14
12
  import { $ } from 'execa';
15
13
  import getPort from 'get-port';
16
14
  import { Inngest } from 'inngest';
@@ -35,118 +33,13 @@ describe('MastraInngestWorkflow', () => {
35
33
  ctx.inngestPort = inngestPort;
36
34
  ctx.handlerPort = handlerPort;
37
35
  ctx.containerName = containerName;
38
-
39
- vi.restoreAllMocks();
40
36
  });
41
37
 
42
38
  afterEach<LocalTestContext>(async ctx => {
43
39
  await $`docker stop ${ctx.containerName}`;
44
40
  });
45
41
 
46
- describe.sequential('Basic Workflow Execution', () => {
47
- it('should be able to bail workflow execution', async ctx => {
48
- const inngest = new Inngest({
49
- id: 'mastra',
50
- baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
51
- middleware: [realtimeMiddleware()],
52
- });
53
-
54
- const { createWorkflow, createStep } = init(inngest);
55
-
56
- const step1 = createStep({
57
- id: 'step1',
58
- execute: async ({ bail, inputData }) => {
59
- if (inputData.value === 'bail') {
60
- return bail({ result: 'bailed' });
61
- }
62
-
63
- return { result: 'step1: ' + inputData.value };
64
- },
65
- inputSchema: z.object({ value: z.string() }),
66
- outputSchema: z.object({ result: z.string() }),
67
- });
68
- const step2 = createStep({
69
- id: 'step2',
70
- execute: async ({ inputData }) => {
71
- return { result: 'step2: ' + inputData.result };
72
- },
73
- inputSchema: z.object({ result: z.string() }),
74
- outputSchema: z.object({ result: z.string() }),
75
- });
76
-
77
- const workflow = createWorkflow({
78
- id: 'test-workflow',
79
- inputSchema: z.object({ value: z.string() }),
80
- outputSchema: z.object({
81
- result: z.string(),
82
- }),
83
- steps: [step1, step2],
84
- });
85
-
86
- workflow.then(step1).then(step2).commit();
87
-
88
- const mastra = new Mastra({
89
- storage: new DefaultStorage({
90
- url: ':memory:',
91
- }),
92
- workflows: {
93
- 'test-workflow': workflow,
94
- },
95
- server: {
96
- apiRoutes: [
97
- {
98
- path: '/inngest/api',
99
- method: 'ALL',
100
- createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
101
- },
102
- ],
103
- },
104
- });
105
-
106
- const app = await createHonoServer(mastra);
107
-
108
- const srv = serve({
109
- fetch: app.fetch,
110
- port: (ctx as any).handlerPort,
111
- });
112
-
113
- const run = await workflow.createRunAsync();
114
- const result = await run.start({ inputData: { value: 'bail' } });
115
-
116
- await new Promise(resolve => setTimeout(resolve, 2000));
117
-
118
- expect(result.steps['step1']).toEqual({
119
- status: 'success',
120
- output: { result: 'bailed' },
121
- payload: { value: 'bail' },
122
- startedAt: expect.any(Number),
123
- endedAt: expect.any(Number),
124
- });
125
-
126
- expect(result.steps['step2']).toBeUndefined();
127
-
128
- const run2 = await workflow.createRunAsync();
129
- const result2 = await run2.start({ inputData: { value: 'no-bail' } });
130
-
131
- srv.close();
132
-
133
- expect(result2.steps['step1']).toEqual({
134
- status: 'success',
135
- output: { result: 'step1: no-bail' },
136
- payload: { value: 'no-bail' },
137
- startedAt: expect.any(Number),
138
- endedAt: expect.any(Number),
139
- });
140
-
141
- expect(result2.steps['step2']).toEqual({
142
- status: 'success',
143
- output: { result: 'step2: step1: no-bail' },
144
- payload: { result: 'step1: no-bail' },
145
- startedAt: expect.any(Number),
146
- endedAt: expect.any(Number),
147
- });
148
- });
149
-
42
+ describe('Basic Workflow Execution', () => {
150
43
  it('should execute a single step workflow successfully', async ctx => {
151
44
  const inngest = new Inngest({
152
45
  id: 'mastra',
@@ -198,11 +91,11 @@ describe('MastraInngestWorkflow', () => {
198
91
  });
199
92
  await new Promise(resolve => setTimeout(resolve, 2000));
200
93
 
201
- const run = await workflow.createRunAsync();
94
+ const run = workflow.createRun();
202
95
  const result = await run.start({ inputData: {} });
203
96
 
204
97
  expect(execute).toHaveBeenCalled();
205
- expect(result.steps['step1']).toMatchObject({
98
+ expect(result.steps['step1']).toEqual({
206
99
  status: 'success',
207
100
  output: { result: 'success' },
208
101
  });
@@ -273,12 +166,12 @@ describe('MastraInngestWorkflow', () => {
273
166
  });
274
167
  await new Promise(resolve => setTimeout(resolve, 2000));
275
168
 
276
- const run = await workflow.createRunAsync();
169
+ const run = workflow.createRun();
277
170
  const result = await run.start({ inputData: {} });
278
171
 
279
172
  expect(step1Action).toHaveBeenCalled();
280
173
  expect(step2Action).toHaveBeenCalled();
281
- expect(result.steps).toMatchObject({
174
+ expect(result.steps).toEqual({
282
175
  input: {},
283
176
  step1: { status: 'success', output: { value: 'step1' } },
284
177
  step2: { status: 'success', output: { value: 'step2' } },
@@ -354,11 +247,11 @@ describe('MastraInngestWorkflow', () => {
354
247
  });
355
248
  await new Promise(resolve => setTimeout(resolve, 2000));
356
249
 
357
- const run = await workflow.createRunAsync();
250
+ const run = workflow.createRun();
358
251
  const result = await run.start({ inputData: {} });
359
252
 
360
- expect(executionOrder).toMatchObject(['step1', 'step2']);
361
- expect(result.steps).toMatchObject({
253
+ expect(executionOrder).toEqual(['step1', 'step2']);
254
+ expect(result.steps).toEqual({
362
255
  input: {},
363
256
  step1: { status: 'success', output: { value: 'step1' } },
364
257
  step2: { status: 'success', output: { value: 'step2' } },
@@ -428,13 +321,13 @@ describe('MastraInngestWorkflow', () => {
428
321
  });
429
322
  await new Promise(resolve => setTimeout(resolve, 2000));
430
323
 
431
- const run = await workflow.createRunAsync();
324
+ const run = workflow.createRun();
432
325
  const startTime = Date.now();
433
326
  const result = await run.start({ inputData: {} });
434
327
  const endTime = Date.now();
435
328
 
436
329
  expect(execute).toHaveBeenCalled();
437
- expect(result.steps['step1']).toMatchObject({
330
+ expect(result.steps['step1']).toEqual({
438
331
  status: 'success',
439
332
  output: { result: 'success' },
440
333
  // payload: {},
@@ -442,7 +335,7 @@ describe('MastraInngestWorkflow', () => {
442
335
  // endedAt: expect.any(Number),
443
336
  });
444
337
 
445
- expect(result.steps['step2']).toMatchObject({
338
+ expect(result.steps['step2']).toEqual({
446
339
  status: 'success',
447
340
  output: { result: 'slept successfully: success' },
448
341
  // payload: { result: 'success' },
@@ -520,13 +413,13 @@ describe('MastraInngestWorkflow', () => {
520
413
  });
521
414
  await new Promise(resolve => setTimeout(resolve, 2000));
522
415
 
523
- const run = await workflow.createRunAsync();
416
+ const run = workflow.createRun();
524
417
  const startTime = Date.now();
525
418
  const result = await run.start({ inputData: {} });
526
419
  const endTime = Date.now();
527
420
 
528
421
  expect(execute).toHaveBeenCalled();
529
- expect(result.steps['step1']).toMatchObject({
422
+ expect(result.steps['step1']).toEqual({
530
423
  status: 'success',
531
424
  output: { result: 'success' },
532
425
  // payload: {},
@@ -534,7 +427,7 @@ describe('MastraInngestWorkflow', () => {
534
427
  // endedAt: expect.any(Number),
535
428
  });
536
429
 
537
- expect(result.steps['step2']).toMatchObject({
430
+ expect(result.steps['step2']).toEqual({
538
431
  status: 'success',
539
432
  output: { result: 'slept successfully: success' },
540
433
  // payload: { result: 'success' },
@@ -546,190 +439,6 @@ describe('MastraInngestWorkflow', () => {
546
439
 
547
440
  srv.close();
548
441
  });
549
-
550
- it('should execute a a waitForEvent step', async ctx => {
551
- const inngest = new Inngest({
552
- id: 'mastra',
553
- baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
554
- });
555
-
556
- const { createWorkflow, createStep } = init(inngest);
557
-
558
- const execute = vi.fn<any>().mockResolvedValue({ result: 'success' });
559
- const step1 = createStep({
560
- id: 'step1',
561
- execute,
562
- inputSchema: z.object({}),
563
- outputSchema: z.object({ result: z.string() }),
564
- });
565
- const step2 = createStep({
566
- id: 'step2',
567
- execute: async ({ inputData, resumeData }) => {
568
- return { result: inputData.result, resumed: resumeData };
569
- },
570
- inputSchema: z.object({ result: z.string() }),
571
- outputSchema: z.object({ result: z.string(), resumed: z.any() }),
572
- resumeSchema: z.any(),
573
- });
574
-
575
- const workflow = createWorkflow({
576
- id: 'test-workflow',
577
- inputSchema: z.object({}),
578
- outputSchema: z.object({
579
- result: z.string(),
580
- resumed: z.any(),
581
- }),
582
- steps: [step1],
583
- });
584
-
585
- workflow.then(step1).waitForEvent('hello-event', step2).commit();
586
-
587
- const mastra = new Mastra({
588
- storage: new DefaultStorage({
589
- url: ':memory:',
590
- }),
591
- workflows: {
592
- 'test-workflow': workflow,
593
- },
594
- server: {
595
- apiRoutes: [
596
- {
597
- path: '/inngest/api',
598
- method: 'ALL',
599
- createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
600
- },
601
- ],
602
- },
603
- });
604
-
605
- const app = await createHonoServer(mastra);
606
-
607
- const srv = serve({
608
- fetch: app.fetch,
609
- port: (ctx as any).handlerPort,
610
- });
611
- await new Promise(resolve => setTimeout(resolve, 2000));
612
-
613
- const run = await workflow.createRunAsync();
614
- const startTime = Date.now();
615
- setTimeout(() => {
616
- run.sendEvent('hello-event', { data: 'hello' });
617
- }, 1000);
618
- const result = await run.start({ inputData: {} });
619
- const endTime = Date.now();
620
-
621
- expect(execute).toHaveBeenCalled();
622
- expect(result.steps['step1']).toMatchObject({
623
- status: 'success',
624
- output: { result: 'success' },
625
- // payload: {},
626
- // startedAt: expect.any(Number),
627
- // endedAt: expect.any(Number),
628
- });
629
-
630
- expect(result.steps['step2']).toMatchObject({
631
- status: 'success',
632
- output: { result: 'success', resumed: { data: 'hello' } },
633
- payload: { result: 'success' },
634
- // resumePayload: { data: 'hello' },
635
- startedAt: expect.any(Number),
636
- endedAt: expect.any(Number),
637
- });
638
-
639
- expect(endTime - startTime).toBeGreaterThan(1000);
640
-
641
- srv.close();
642
- });
643
-
644
- it('should execute a a waitForEvent step after timeout', 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({ result: 'success' });
653
- const step1 = createStep({
654
- id: 'step1',
655
- execute,
656
- inputSchema: z.object({}),
657
- outputSchema: z.object({ result: z.string() }),
658
- });
659
- const step2 = createStep({
660
- id: 'step2',
661
- execute: async ({ inputData, resumeData }) => {
662
- return { result: inputData.result, resumed: resumeData };
663
- },
664
- inputSchema: z.object({ result: z.string() }),
665
- outputSchema: z.object({ result: z.string(), resumed: z.any() }),
666
- resumeSchema: z.any(),
667
- });
668
-
669
- const workflow = createWorkflow({
670
- id: 'test-workflow',
671
- inputSchema: z.object({}),
672
- outputSchema: z.object({
673
- result: z.string(),
674
- resumed: z.any(),
675
- }),
676
- steps: [step1],
677
- });
678
-
679
- workflow.then(step1).waitForEvent('hello-event', step2, { timeout: 1000 }).commit();
680
-
681
- const mastra = new Mastra({
682
- storage: new DefaultStorage({
683
- url: ':memory:',
684
- }),
685
- workflows: {
686
- 'test-workflow': workflow,
687
- },
688
- server: {
689
- apiRoutes: [
690
- {
691
- path: '/inngest/api',
692
- method: 'ALL',
693
- createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
694
- },
695
- ],
696
- },
697
- });
698
-
699
- const app = await createHonoServer(mastra);
700
-
701
- const srv = serve({
702
- fetch: app.fetch,
703
- port: (ctx as any).handlerPort,
704
- });
705
- await new Promise(resolve => setTimeout(resolve, 2000));
706
-
707
- const run = await workflow.createRunAsync();
708
- const startTime = Date.now();
709
- const result = await run.start({ inputData: {} });
710
- const endTime = Date.now();
711
-
712
- expect(execute).toHaveBeenCalled();
713
- expect(result.steps['step1']).toMatchObject({
714
- status: 'success',
715
- output: { result: 'success' },
716
- // payload: {},
717
- // startedAt: expect.any(Number),
718
- // endedAt: expect.any(Number),
719
- });
720
-
721
- expect(result.steps['step2']).toMatchObject({
722
- status: 'failed',
723
- error: expect.any(String),
724
- payload: { result: 'success' },
725
- startedAt: expect.any(Number),
726
- endedAt: expect.any(Number),
727
- });
728
-
729
- expect(endTime - startTime).toBeGreaterThan(1000);
730
-
731
- srv.close();
732
- });
733
442
  });
734
443
 
735
444
  describe('Variable Resolution', () => {
@@ -789,11 +498,11 @@ describe('MastraInngestWorkflow', () => {
789
498
  port: (ctx as any).handlerPort,
790
499
  });
791
500
 
792
- const run = await workflow.createRunAsync();
501
+ const run = workflow.createRun();
793
502
  const result = await run.start({ inputData: { inputData: 'test-input' } });
794
503
 
795
- expect(result.steps.step1).toMatchObject({ status: 'success', output: { result: 'success' } });
796
- expect(result.steps.step2).toMatchObject({ status: 'success', output: { result: 'success' } });
504
+ expect(result.steps.step1).toEqual({ status: 'success', output: { result: 'success' } });
505
+ expect(result.steps.step2).toEqual({ status: 'success', output: { result: 'success' } });
797
506
 
798
507
  srv.close();
799
508
  });
@@ -808,14 +517,14 @@ describe('MastraInngestWorkflow', () => {
808
517
 
809
518
  const step1Action = vi.fn().mockImplementation(async ({ inputData }) => {
810
519
  // Test accessing trigger data with correct type
811
- expect(inputData).toMatchObject({ inputValue: 'test-input' });
520
+ expect(inputData).toEqual({ inputValue: 'test-input' });
812
521
  return { value: 'step1-result' };
813
522
  });
814
523
 
815
524
  const step2Action = vi.fn().mockImplementation(async ({ getStepResult }) => {
816
525
  // Test accessing previous step result with type
817
526
  const step1Result = getStepResult(step1);
818
- expect(step1Result).toMatchObject({ value: 'step1-result' });
527
+ expect(step1Result).toEqual({ value: 'step1-result' });
819
528
 
820
529
  const failedStep = getStepResult(nonExecutedStep);
821
530
  expect(failedStep).toBe(null);
@@ -876,12 +585,12 @@ describe('MastraInngestWorkflow', () => {
876
585
  port: (ctx as any).handlerPort,
877
586
  });
878
587
 
879
- const run = await workflow.createRunAsync();
588
+ const run = workflow.createRun();
880
589
  const result = await run.start({ inputData: { inputValue: 'test-input' } });
881
590
 
882
591
  expect(step1Action).toHaveBeenCalled();
883
592
  expect(step2Action).toHaveBeenCalled();
884
- expect(result.steps).toMatchObject({
593
+ expect(result.steps).toEqual({
885
594
  input: { inputValue: 'test-input' },
886
595
  step1: { status: 'success', output: { value: 'step1-result' } },
887
596
  step2: { status: 'success', output: { value: 'step2-result' } },
@@ -943,7 +652,7 @@ describe('MastraInngestWorkflow', () => {
943
652
  port: (ctx as any).handlerPort,
944
653
  });
945
654
 
946
- const run = await workflow.createRunAsync();
655
+ const run = workflow.createRun();
947
656
  await run.start({ inputData: { inputData: 'test-input' } });
948
657
 
949
658
  expect(execute).toHaveBeenCalledWith(
@@ -1018,7 +727,7 @@ describe('MastraInngestWorkflow', () => {
1018
727
  port: (ctx as any).handlerPort,
1019
728
  });
1020
729
 
1021
- const run = await workflow.createRunAsync();
730
+ const run = workflow.createRun();
1022
731
  const result = await run.start({ inputData: { cool: 'test-input' } });
1023
732
 
1024
733
  expect(execute).toHaveBeenCalledWith(
@@ -1027,7 +736,7 @@ describe('MastraInngestWorkflow', () => {
1027
736
  }),
1028
737
  );
1029
738
 
1030
- expect(result.steps.step2).toMatchObject({ status: 'success', output: { result: { cool: 'test-input' } } });
739
+ expect(result.steps.step2).toEqual({ status: 'success', output: { result: { cool: 'test-input' } } });
1031
740
 
1032
741
  srv.close();
1033
742
  });
@@ -1100,7 +809,7 @@ describe('MastraInngestWorkflow', () => {
1100
809
  port: (ctx as any).handlerPort,
1101
810
  });
1102
811
 
1103
- const run = await workflow.createRunAsync();
812
+ const run = workflow.createRun();
1104
813
  await run.start({ inputData: {} });
1105
814
 
1106
815
  expect(step2Action).toHaveBeenCalledWith(
@@ -1203,14 +912,14 @@ describe('MastraInngestWorkflow', () => {
1203
912
  port: (ctx as any).handlerPort,
1204
913
  });
1205
914
 
1206
- const run = await workflow.createRunAsync();
915
+ const run = workflow.createRun();
1207
916
  const result = await run.start({ inputData: { status: 'success' } });
1208
917
  srv.close();
1209
918
 
1210
919
  expect(step1Action).toHaveBeenCalled();
1211
920
  expect(step2Action).toHaveBeenCalled();
1212
921
  expect(step3Action).not.toHaveBeenCalled();
1213
- expect(result.steps).toMatchObject({
922
+ expect(result.steps).toEqual({
1214
923
  input: { status: 'success' },
1215
924
  step1: { status: 'success', output: { status: 'success' } },
1216
925
  step2: { status: 'success', output: { result: 'step2' } },
@@ -1279,7 +988,7 @@ describe('MastraInngestWorkflow', () => {
1279
988
  port: (ctx as any).handlerPort,
1280
989
  });
1281
990
 
1282
- const run = await workflow.createRunAsync();
991
+ const run = workflow.createRun();
1283
992
  let result: Awaited<ReturnType<typeof run.start>> | undefined = undefined;
1284
993
  try {
1285
994
  result = await run.start({ inputData: {} });
@@ -1291,7 +1000,7 @@ describe('MastraInngestWorkflow', () => {
1291
1000
 
1292
1001
  expect(step1Action).toHaveBeenCalled();
1293
1002
  expect(step2Action).not.toHaveBeenCalled();
1294
- expect(result?.steps).toMatchObject({
1003
+ expect(result?.steps).toEqual({
1295
1004
  input: {},
1296
1005
  step1: { status: 'failed', error: 'Failed' },
1297
1006
  });
@@ -1384,7 +1093,7 @@ describe('MastraInngestWorkflow', () => {
1384
1093
  port: (ctx as any).handlerPort,
1385
1094
  });
1386
1095
 
1387
- const run = await workflow.createRunAsync();
1096
+ const run = workflow.createRun();
1388
1097
  const result = await run.start({ inputData: { status: 'success' } });
1389
1098
  srv.close();
1390
1099
 
@@ -1467,17 +1176,18 @@ describe('MastraInngestWorkflow', () => {
1467
1176
  port: (ctx as any).handlerPort,
1468
1177
  });
1469
1178
 
1470
- const run = await workflow.createRunAsync();
1179
+ const run = workflow.createRun();
1471
1180
  const result = await run.start({ inputData: { count: 5 } });
1472
1181
  srv.close();
1473
1182
 
1474
1183
  expect(step2Action).toHaveBeenCalled();
1475
- expect(result.steps.step1).toMatchObject({
1184
+ expect(result.steps.step1).toEqual({
1476
1185
  status: 'success',
1477
1186
  output: { count: 5 },
1478
1187
  });
1479
- expect(result.steps.step2).toMatchObject({
1188
+ expect(result.steps.step2).toEqual({
1480
1189
  status: 'success',
1190
+ output: undefined,
1481
1191
  });
1482
1192
  });
1483
1193
  });
@@ -1535,7 +1245,7 @@ describe('MastraInngestWorkflow', () => {
1535
1245
  });
1536
1246
  await new Promise(resolve => setTimeout(resolve, 2000));
1537
1247
 
1538
- const run = await workflow.createRunAsync();
1248
+ const run = workflow.createRun();
1539
1249
 
1540
1250
  await expect(run.start({ inputData: {} })).resolves.toMatchObject({
1541
1251
  steps: {
@@ -1619,7 +1329,7 @@ describe('MastraInngestWorkflow', () => {
1619
1329
  });
1620
1330
  await new Promise(resolve => setTimeout(resolve, 2000));
1621
1331
 
1622
- const run = await workflow.createRunAsync();
1332
+ const run = workflow.createRun();
1623
1333
  const result = await run.start({ inputData: {} });
1624
1334
 
1625
1335
  expect(result.steps).toMatchObject({
@@ -1713,7 +1423,7 @@ describe('MastraInngestWorkflow', () => {
1713
1423
  });
1714
1424
  await new Promise(resolve => setTimeout(resolve, 2000));
1715
1425
 
1716
- const run = await mainWorkflow.createRunAsync();
1426
+ const run = mainWorkflow.createRun();
1717
1427
  const result = await run.start({ inputData: {} });
1718
1428
 
1719
1429
  expect(result.steps).toMatchObject({
@@ -1841,12 +1551,12 @@ describe('MastraInngestWorkflow', () => {
1841
1551
  });
1842
1552
  await new Promise(resolve => setTimeout(resolve, 2000));
1843
1553
 
1844
- const run = await workflow.createRunAsync();
1554
+ const run = workflow.createRun();
1845
1555
  const result = await run.start({ inputData: {} });
1846
1556
 
1847
1557
  expect(step2Action).toHaveBeenCalled();
1848
1558
  expect(step3Action).not.toHaveBeenCalled();
1849
- expect(result.steps.step2).toMatchObject({ status: 'success', output: { result: 'step2' } });
1559
+ expect(result.steps.step2).toEqual({ status: 'success', output: { result: 'step2' } });
1850
1560
 
1851
1561
  srv.close();
1852
1562
  });
@@ -1943,15 +1653,15 @@ describe('MastraInngestWorkflow', () => {
1943
1653
  });
1944
1654
  await new Promise(resolve => setTimeout(resolve, 2000));
1945
1655
 
1946
- const run = await counterWorkflow.createRunAsync();
1656
+ const run = counterWorkflow.createRun();
1947
1657
  const result = await run.start({ inputData: { target: 10, value: 0 } });
1948
1658
 
1949
1659
  expect(increment).toHaveBeenCalledTimes(12);
1950
1660
  expect(final).toHaveBeenCalledTimes(1);
1951
1661
  // @ts-ignore
1952
- expect(result.result).toMatchObject({ finalValue: 12 });
1662
+ expect(result.result).toEqual({ finalValue: 12 });
1953
1663
  // @ts-ignore
1954
- expect(result.steps.increment.output).toMatchObject({ value: 12 });
1664
+ expect(result.steps.increment.output).toEqual({ value: 12 });
1955
1665
 
1956
1666
  srv.close();
1957
1667
  });
@@ -2046,15 +1756,15 @@ describe('MastraInngestWorkflow', () => {
2046
1756
  });
2047
1757
  await new Promise(resolve => setTimeout(resolve, 2000));
2048
1758
 
2049
- const run = await counterWorkflow.createRunAsync();
1759
+ const run = counterWorkflow.createRun();
2050
1760
  const result = await run.start({ inputData: { target: 10, value: 0 } });
2051
1761
 
2052
1762
  expect(increment).toHaveBeenCalledTimes(12);
2053
1763
  expect(final).toHaveBeenCalledTimes(1);
2054
1764
  // @ts-ignore
2055
- expect(result.result).toMatchObject({ finalValue: 12 });
1765
+ expect(result.result).toEqual({ finalValue: 12 });
2056
1766
  // @ts-ignore
2057
- expect(result.steps.increment.output).toMatchObject({ value: 12 });
1767
+ expect(result.steps.increment.output).toEqual({ value: 12 });
2058
1768
 
2059
1769
  srv.close();
2060
1770
  });
@@ -2135,7 +1845,7 @@ describe('MastraInngestWorkflow', () => {
2135
1845
  });
2136
1846
  await new Promise(resolve => setTimeout(resolve, 2000));
2137
1847
 
2138
- const run = await counterWorkflow.createRunAsync();
1848
+ const run = counterWorkflow.createRun();
2139
1849
  const result = await run.start({ inputData: [{ value: 1 }, { value: 22 }, { value: 333 }] });
2140
1850
 
2141
1851
  const endTime = Date.now();
@@ -2143,7 +1853,7 @@ describe('MastraInngestWorkflow', () => {
2143
1853
  expect(duration).toBeGreaterThan(1e3 * 3);
2144
1854
 
2145
1855
  expect(map).toHaveBeenCalledTimes(3);
2146
- expect(result.steps).toMatchObject({
1856
+ expect(result.steps).toEqual({
2147
1857
  input: [{ value: 1 }, { value: 22 }, { value: 333 }],
2148
1858
  map: { status: 'success', output: [{ value: 12 }, { value: 33 }, { value: 344 }] },
2149
1859
  final: { status: 'success', output: { finalValue: 1 + 11 + (22 + 11) + (333 + 11) } },
@@ -2288,16 +1998,16 @@ describe('MastraInngestWorkflow', () => {
2288
1998
  });
2289
1999
  await new Promise(resolve => setTimeout(resolve, 2000));
2290
2000
 
2291
- const run = await counterWorkflow.createRunAsync();
2001
+ const run = counterWorkflow.createRun();
2292
2002
  const result = await run.start({ inputData: { startValue: 1 } });
2293
2003
 
2294
2004
  expect(start).toHaveBeenCalledTimes(1);
2295
2005
  expect(other).toHaveBeenCalledTimes(0);
2296
2006
  expect(final).toHaveBeenCalledTimes(1);
2297
2007
  // @ts-ignore
2298
- expect(result.steps.finalIf.output).toMatchObject({ finalValue: 2 });
2008
+ expect(result.steps.finalIf.output).toEqual({ finalValue: 2 });
2299
2009
  // @ts-ignore
2300
- expect(result.steps.start.output).toMatchObject({ newValue: 2 });
2010
+ expect(result.steps.start.output).toEqual({ newValue: 2 });
2301
2011
 
2302
2012
  srv.close();
2303
2013
  });
@@ -2437,16 +2147,16 @@ describe('MastraInngestWorkflow', () => {
2437
2147
  });
2438
2148
  await new Promise(resolve => setTimeout(resolve, 2000));
2439
2149
 
2440
- const run = await counterWorkflow.createRunAsync();
2150
+ const run = counterWorkflow.createRun();
2441
2151
  const result = await run.start({ inputData: { startValue: 6 } });
2442
2152
 
2443
2153
  expect(start).toHaveBeenCalledTimes(1);
2444
2154
  expect(other).toHaveBeenCalledTimes(1);
2445
2155
  expect(final).toHaveBeenCalledTimes(1);
2446
2156
  // @ts-ignore
2447
- expect(result.steps['else-branch'].output).toMatchObject({ finalValue: 26 + 6 + 1 });
2157
+ expect(result.steps['else-branch'].output).toEqual({ finalValue: 26 + 6 + 1 });
2448
2158
  // @ts-ignore
2449
- expect(result.steps.start.output).toMatchObject({ newValue: 7 });
2159
+ expect(result.steps.start.output).toEqual({ newValue: 7 });
2450
2160
 
2451
2161
  srv.close();
2452
2162
  });
@@ -2503,7 +2213,7 @@ describe('MastraInngestWorkflow', () => {
2503
2213
  ).rejects.toThrow();
2504
2214
 
2505
2215
  // Should pass validation
2506
- const run = await workflow.createRunAsync();
2216
+ const run = workflow.createRun();
2507
2217
  await run.start({
2508
2218
  inputData: {
2509
2219
  required: 'test',
@@ -2609,11 +2319,11 @@ describe('MastraInngestWorkflow', () => {
2609
2319
  });
2610
2320
  await new Promise(resolve => setTimeout(resolve, 2000));
2611
2321
 
2612
- const run = await workflow.createRunAsync();
2322
+ const run = workflow.createRun();
2613
2323
  const result = await run.start({ inputData: {} });
2614
2324
 
2615
- expect(result.steps['nested-a']).toMatchObject({ status: 'success', output: { result: 'success3' } });
2616
- expect(result.steps['nested-b']).toMatchObject({ status: 'success', output: { result: 'success5' } });
2325
+ expect(result.steps['nested-a']).toEqual({ status: 'success', output: { result: 'success3' } });
2326
+ expect(result.steps['nested-b']).toEqual({ status: 'success', output: { result: 'success5' } });
2617
2327
 
2618
2328
  srv.close();
2619
2329
  });
@@ -2675,11 +2385,11 @@ describe('MastraInngestWorkflow', () => {
2675
2385
  });
2676
2386
  await new Promise(resolve => setTimeout(resolve, 2000));
2677
2387
 
2678
- const run = await workflow.createRunAsync();
2388
+ const run = workflow.createRun();
2679
2389
  const result = await run.start({ inputData: {} });
2680
2390
 
2681
- expect(result.steps.step1).toMatchObject({ status: 'success', output: { result: 'success' } });
2682
- expect(result.steps.step2).toMatchObject({ status: 'failed', error: 'Step failed' });
2391
+ expect(result.steps.step1).toEqual({ status: 'success', output: { result: 'success' } });
2392
+ expect(result.steps.step2).toEqual({ status: 'failed', error: 'Step failed' });
2683
2393
  expect(step1.execute).toHaveBeenCalledTimes(1);
2684
2394
  expect(step2.execute).toHaveBeenCalledTimes(1); // 0 retries + 1 initial call
2685
2395
 
@@ -2732,11 +2442,11 @@ describe('MastraInngestWorkflow', () => {
2732
2442
 
2733
2443
  workflow.then(step1).then(step2).commit();
2734
2444
 
2735
- const run = await workflow.createRunAsync();
2445
+ const run = workflow.createRun();
2736
2446
  const result = await run.start({ inputData: {} });
2737
2447
 
2738
- expect(result.steps.step1).toMatchObject({ status: 'success', output: { result: 'success' } });
2739
- expect(result.steps.step2).toMatchObject({ status: 'failed', error: 'Step failed' });
2448
+ expect(result.steps.step1).toEqual({ status: 'success', output: { result: 'success' } });
2449
+ expect(result.steps.step2).toEqual({ status: 'failed', error: 'Step failed' });
2740
2450
  expect(step1.execute).toHaveBeenCalledTimes(1);
2741
2451
  expect(step2.execute).toHaveBeenCalledTimes(6); // 5 retries + 1 initial call
2742
2452
  });
@@ -2807,15 +2517,14 @@ describe('MastraInngestWorkflow', () => {
2807
2517
  });
2808
2518
  await new Promise(resolve => setTimeout(resolve, 2000));
2809
2519
 
2810
- const run = await workflow.createRunAsync();
2811
- const result = await run.start({ inputData: {} });
2520
+ const result = await workflow.createRun().start({ inputData: {} });
2812
2521
 
2813
2522
  srv.close();
2814
2523
 
2815
2524
  expect(step1Action).toHaveBeenCalled();
2816
2525
  expect(toolAction).toHaveBeenCalled();
2817
- expect(result.steps.step1).toMatchObject({ status: 'success', output: { name: 'step1' } });
2818
- expect(result.steps['random-tool']).toMatchObject({ status: 'success', output: { name: 'step1' } });
2526
+ expect(result.steps.step1).toEqual({ status: 'success', output: { name: 'step1' } });
2527
+ expect(result.steps['random-tool']).toEqual({ status: 'success', output: { name: 'step1' } });
2819
2528
  }, 10000);
2820
2529
  });
2821
2530
 
@@ -2879,7 +2588,7 @@ describe('MastraInngestWorkflow', () => {
2879
2588
  });
2880
2589
  await new Promise(resolve => setTimeout(resolve, 2000));
2881
2590
 
2882
- const run = await workflow.createRunAsync();
2591
+ const run = workflow.createRun();
2883
2592
 
2884
2593
  // Start watching the workflow
2885
2594
  let cnt = 0;
@@ -2994,11 +2703,11 @@ describe('MastraInngestWorkflow', () => {
2994
2703
  });
2995
2704
 
2996
2705
  // Verify execution completed successfully
2997
- expect(executionResult.steps.step1).toMatchObject({
2706
+ expect(executionResult.steps.step1).toEqual({
2998
2707
  status: 'success',
2999
2708
  output: { result: 'success1' },
3000
2709
  });
3001
- expect(executionResult.steps.step2).toMatchObject({
2710
+ expect(executionResult.steps.step2).toEqual({
3002
2711
  status: 'success',
3003
2712
  output: { result: 'success2' },
3004
2713
  });
@@ -3068,7 +2777,7 @@ describe('MastraInngestWorkflow', () => {
3068
2777
  const onTransition = vi.fn();
3069
2778
  const onTransition2 = vi.fn();
3070
2779
 
3071
- const run = await workflow.createRunAsync();
2780
+ const run = workflow.createRun();
3072
2781
 
3073
2782
  run.watch(onTransition);
3074
2783
  run.watch(onTransition2);
@@ -3078,7 +2787,7 @@ describe('MastraInngestWorkflow', () => {
3078
2787
  expect(onTransition).toHaveBeenCalledTimes(5);
3079
2788
  expect(onTransition2).toHaveBeenCalledTimes(5);
3080
2789
 
3081
- const run2 = await workflow.createRunAsync();
2790
+ const run2 = workflow.createRun();
3082
2791
 
3083
2792
  run2.watch(onTransition2);
3084
2793
 
@@ -3087,7 +2796,7 @@ describe('MastraInngestWorkflow', () => {
3087
2796
  expect(onTransition).toHaveBeenCalledTimes(5);
3088
2797
  expect(onTransition2).toHaveBeenCalledTimes(10);
3089
2798
 
3090
- const run3 = await workflow.createRunAsync();
2799
+ const run3 = workflow.createRun();
3091
2800
 
3092
2801
  run3.watch(onTransition);
3093
2802
 
@@ -3122,8 +2831,8 @@ describe('MastraInngestWorkflow', () => {
3122
2831
  outputSchema: z.object({}),
3123
2832
  steps: [],
3124
2833
  });
3125
- const run = await workflow.createRunAsync();
3126
- const run2 = await workflow.createRunAsync({ runId: run.runId });
2834
+ const run = workflow.createRun();
2835
+ const run2 = workflow.createRun({ runId: run.runId });
3127
2836
 
3128
2837
  expect(run.runId).toBeDefined();
3129
2838
  expect(run2.runId).toBeDefined();
@@ -3237,7 +2946,7 @@ describe('MastraInngestWorkflow', () => {
3237
2946
  });
3238
2947
  await new Promise(resolve => setTimeout(resolve, 2000));
3239
2948
 
3240
- const run = await promptEvalWorkflow.createRunAsync();
2949
+ const run = promptEvalWorkflow.createRun();
3241
2950
 
3242
2951
  // Create a promise to track when the workflow is ready to resume
3243
2952
  let resolveWorkflowSuspended: (value: unknown) => void;
@@ -3267,7 +2976,7 @@ describe('MastraInngestWorkflow', () => {
3267
2976
  throw new Error('Resume failed to return a result');
3268
2977
  }
3269
2978
 
3270
- expect(resumeResult.steps).toMatchObject({
2979
+ expect(resumeResult.steps).toEqual({
3271
2980
  input: { input: 'test' },
3272
2981
  getUserInput: { status: 'success', output: { userInput: 'test input' } },
3273
2982
  promptAgent: { status: 'success', output: { modelOutput: 'test output' } },
@@ -3387,7 +3096,7 @@ describe('MastraInngestWorkflow', () => {
3387
3096
  });
3388
3097
  await new Promise(resolve => setTimeout(resolve, 2000));
3389
3098
 
3390
- const run = await workflow.createRunAsync();
3099
+ const run = workflow.createRun();
3391
3100
 
3392
3101
  const started = run.start({ inputData: { input: 'test' } });
3393
3102
 
@@ -3430,7 +3139,7 @@ describe('MastraInngestWorkflow', () => {
3430
3139
  throw new Error('Resume failed to return a result');
3431
3140
  }
3432
3141
 
3433
- expect(result.steps).toMatchObject({
3142
+ expect(result.steps).toEqual({
3434
3143
  input: { input: 'test' },
3435
3144
  getUserInput: { status: 'success', output: { userInput: 'test input' } },
3436
3145
  promptAgent: { status: 'success', output: { modelOutput: 'test output' } },
@@ -3589,7 +3298,7 @@ describe('MastraInngestWorkflow', () => {
3589
3298
  });
3590
3299
  await new Promise(resolve => setTimeout(resolve, 2000));
3591
3300
 
3592
- const run = await workflow.createRunAsync();
3301
+ const run = workflow.createRun();
3593
3302
  const started = run.start({ inputData: { input: 'test' } });
3594
3303
  let improvedResponseResultPromise: Promise<any | undefined>;
3595
3304
 
@@ -3783,22 +3492,18 @@ describe('MastraInngestWorkflow', () => {
3783
3492
  });
3784
3493
  await new Promise(resolve => setTimeout(resolve, 2000));
3785
3494
 
3786
- const run = await promptEvalWorkflow.createRunAsync();
3495
+ const run = promptEvalWorkflow.createRun();
3787
3496
 
3788
3497
  const initialResult = await run.start({ inputData: { input: 'test' } });
3789
3498
  expect(initialResult.steps.promptAgent.status).toBe('suspended');
3790
3499
  expect(promptAgentAction).toHaveBeenCalledTimes(1);
3791
3500
  // expect(initialResult.activePaths.size).toBe(1);
3792
3501
  // expect(initialResult.activePaths.get('promptAgent')?.status).toBe('suspended');
3793
- // expect(initialResult.activePaths.get('promptAgent')?.suspendPayload).toMatchObject({ testPayload: 'hello' });
3794
- expect(initialResult.steps).toMatchObject({
3502
+ // expect(initialResult.activePaths.get('promptAgent')?.suspendPayload).toEqual({ testPayload: 'hello' });
3503
+ expect(initialResult.steps).toEqual({
3795
3504
  input: { input: 'test' },
3796
3505
  getUserInput: { status: 'success', output: { userInput: 'test input' } },
3797
- promptAgent: {
3798
- status: 'suspended',
3799
- suspendedPayload: { testPayload: 'hello' },
3800
- payload: { userInput: 'test input' },
3801
- },
3506
+ promptAgent: { status: 'suspended', payload: { testPayload: 'hello' } },
3802
3507
  });
3803
3508
 
3804
3509
  const newCtx = {
@@ -3815,7 +3520,7 @@ describe('MastraInngestWorkflow', () => {
3815
3520
 
3816
3521
  // expect(firstResumeResult.activePaths.size).toBe(1);
3817
3522
  // expect(firstResumeResult.activePaths.get('improveResponse')?.status).toBe('suspended');
3818
- expect(firstResumeResult.steps).toMatchObject({
3523
+ expect(firstResumeResult.steps).toEqual({
3819
3524
  input: { input: 'test' },
3820
3525
  getUserInput: { status: 'success', output: { userInput: 'test input' } },
3821
3526
  promptAgent: { status: 'success', output: { modelOutput: 'test output' } },
@@ -3842,7 +3547,7 @@ describe('MastraInngestWorkflow', () => {
3842
3547
 
3843
3548
  expect(promptAgentAction).toHaveBeenCalledTimes(2);
3844
3549
 
3845
- expect(secondResumeResult.steps).toMatchObject({
3550
+ expect(secondResumeResult.steps).toEqual({
3846
3551
  input: { input: 'test' },
3847
3552
  getUserInput: { status: 'success', output: { userInput: 'test input' } },
3848
3553
  promptAgent: { status: 'success', output: { modelOutput: 'test output' } },
@@ -3912,7 +3617,7 @@ describe('MastraInngestWorkflow', () => {
3912
3617
  await new Promise(resolve => setTimeout(resolve, 2000));
3913
3618
 
3914
3619
  // Access new instance properties directly - should work without warning
3915
- const run = await workflow.createRunAsync();
3620
+ const run = workflow.createRun();
3916
3621
  await run.start({ inputData: {} });
3917
3622
 
3918
3623
  expect(telemetry).toBeDefined();
@@ -3927,7 +3632,6 @@ describe('MastraInngestWorkflow', () => {
3927
3632
  const inngest = new Inngest({
3928
3633
  id: 'mastra',
3929
3634
  baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
3930
- middleware: [realtimeMiddleware()],
3931
3635
  });
3932
3636
 
3933
3637
  const { createWorkflow, createStep } = init(inngest);
@@ -4015,29 +3719,28 @@ describe('MastraInngestWorkflow', () => {
4015
3719
  });
4016
3720
  await new Promise(resolve => setTimeout(resolve, 2000));
4017
3721
 
4018
- const run = await workflow.createRunAsync();
3722
+ const run = workflow.createRun();
4019
3723
  const result = await run.start({
4020
3724
  inputData: { prompt1: 'Capital of France, just the name', prompt2: 'Capital of UK, just the name' },
4021
3725
  });
4022
3726
 
4023
- srv.close();
4024
-
4025
- expect(result.steps['test-agent-1']).toMatchObject({
3727
+ expect(result.steps['test-agent-1']).toEqual({
4026
3728
  status: 'success',
4027
3729
  output: { text: 'Paris' },
4028
3730
  });
4029
3731
 
4030
- expect(result.steps['test-agent-2']).toMatchObject({
3732
+ expect(result.steps['test-agent-2']).toEqual({
4031
3733
  status: 'success',
4032
3734
  output: { text: 'London' },
4033
3735
  });
3736
+
3737
+ srv.close();
4034
3738
  });
4035
3739
 
4036
3740
  it('should be able to use an agent in parallel', async ctx => {
4037
3741
  const inngest = new Inngest({
4038
3742
  id: 'mastra',
4039
3743
  baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
4040
- middleware: [realtimeMiddleware()],
4041
3744
  });
4042
3745
 
4043
3746
  const { createWorkflow, createStep } = init(inngest);
@@ -4152,23 +3855,23 @@ describe('MastraInngestWorkflow', () => {
4152
3855
  });
4153
3856
  await new Promise(resolve => setTimeout(resolve, 2000));
4154
3857
 
4155
- const run = await workflow.createRunAsync();
3858
+ const run = workflow.createRun();
4156
3859
  const result = await run.start({
4157
3860
  inputData: { prompt1: 'Capital of France, just the name', prompt2: 'Capital of UK, just the name' },
4158
3861
  });
4159
3862
 
4160
3863
  expect(execute).toHaveBeenCalledTimes(1);
4161
- expect(result.steps['finalStep']).toMatchObject({
3864
+ expect(result.steps['finalStep']).toEqual({
4162
3865
  status: 'success',
4163
3866
  output: { result: 'success' },
4164
3867
  });
4165
3868
 
4166
- expect(result.steps['nested-workflow']).toMatchObject({
3869
+ expect(result.steps['nested-workflow']).toEqual({
4167
3870
  status: 'success',
4168
3871
  output: { text: 'Paris' },
4169
3872
  });
4170
3873
 
4171
- expect(result.steps['nested-workflow-2']).toMatchObject({
3874
+ expect(result.steps['nested-workflow-2']).toEqual({
4172
3875
  status: 'success',
4173
3876
  output: { text: 'London' },
4174
3877
  });
@@ -4295,7 +3998,7 @@ describe('MastraInngestWorkflow', () => {
4295
3998
  });
4296
3999
  await new Promise(resolve => setTimeout(resolve, 2000));
4297
4000
 
4298
- const run = await counterWorkflow.createRunAsync();
4001
+ const run = counterWorkflow.createRun();
4299
4002
  const result = await run.start({ inputData: { startValue: 0 } });
4300
4003
 
4301
4004
  srv.close();
@@ -4305,16 +4008,16 @@ describe('MastraInngestWorkflow', () => {
4305
4008
  expect(final).toHaveBeenCalledTimes(2);
4306
4009
  expect(last).toHaveBeenCalledTimes(1);
4307
4010
  // @ts-ignore
4308
- expect(result.steps['nested-workflow-a'].output).toMatchObject({
4011
+ expect(result.steps['nested-workflow-a'].output).toEqual({
4309
4012
  finalValue: 26 + 1,
4310
4013
  });
4311
4014
 
4312
4015
  // @ts-ignore
4313
- expect(result.steps['nested-workflow-b'].output).toMatchObject({
4016
+ expect(result.steps['nested-workflow-b'].output).toEqual({
4314
4017
  finalValue: 1,
4315
4018
  });
4316
4019
 
4317
- expect(result.steps['last-step']).toMatchObject({
4020
+ expect(result.steps['last-step']).toEqual({
4318
4021
  output: { success: true },
4319
4022
  status: 'success',
4320
4023
  });
@@ -4447,7 +4150,7 @@ describe('MastraInngestWorkflow', () => {
4447
4150
  });
4448
4151
  await new Promise(resolve => setTimeout(resolve, 2000));
4449
4152
 
4450
- const run = await counterWorkflow.createRunAsync();
4153
+ const run = counterWorkflow.createRun();
4451
4154
  const result = await run.start({ inputData: { startValue: 0 } });
4452
4155
 
4453
4156
  srv.close();
@@ -4457,16 +4160,16 @@ describe('MastraInngestWorkflow', () => {
4457
4160
  expect(final).toHaveBeenCalledTimes(2);
4458
4161
  expect(last).toHaveBeenCalledTimes(1);
4459
4162
  // @ts-ignore
4460
- expect(result.steps['nested-workflow-a'].output).toMatchObject({
4163
+ expect(result.steps['nested-workflow-a'].output).toEqual({
4461
4164
  finalValue: 26 + 1,
4462
4165
  });
4463
4166
 
4464
4167
  // @ts-ignore
4465
- expect(result.steps['nested-workflow-b'].output).toMatchObject({
4168
+ expect(result.steps['nested-workflow-b'].output).toEqual({
4466
4169
  finalValue: 1,
4467
4170
  });
4468
4171
 
4469
- expect(result.steps['last-step']).toMatchObject({
4172
+ expect(result.steps['last-step']).toEqual({
4470
4173
  output: { success: true },
4471
4174
  status: 'success',
4472
4175
  });
@@ -4606,7 +4309,7 @@ describe('MastraInngestWorkflow', () => {
4606
4309
  port: (ctx as any).handlerPort,
4607
4310
  });
4608
4311
 
4609
- const run = await counterWorkflow.createRunAsync();
4312
+ const run = counterWorkflow.createRun();
4610
4313
  const result = await run.start({ inputData: { startValue: 0 } });
4611
4314
 
4612
4315
  srv.close();
@@ -4617,16 +4320,16 @@ describe('MastraInngestWorkflow', () => {
4617
4320
  expect(first).toHaveBeenCalledTimes(1);
4618
4321
  expect(last).toHaveBeenCalledTimes(1);
4619
4322
  // @ts-ignore
4620
- expect(result.steps['nested-workflow-a'].output).toMatchObject({
4323
+ expect(result.steps['nested-workflow-a'].output).toEqual({
4621
4324
  finalValue: 26 + 1,
4622
4325
  });
4623
4326
 
4624
- expect(result.steps['first-step']).toMatchObject({
4327
+ expect(result.steps['first-step']).toEqual({
4625
4328
  output: { success: true },
4626
4329
  status: 'success',
4627
4330
  });
4628
4331
 
4629
- expect(result.steps['last-step']).toMatchObject({
4332
+ expect(result.steps['last-step']).toEqual({
4630
4333
  output: { success: true },
4631
4334
  status: 'success',
4632
4335
  });
@@ -4765,7 +4468,7 @@ describe('MastraInngestWorkflow', () => {
4765
4468
  port: (ctx as any).handlerPort,
4766
4469
  });
4767
4470
 
4768
- const run = await counterWorkflow.createRunAsync();
4471
+ const run = counterWorkflow.createRun();
4769
4472
  const result = await run.start({ inputData: { startValue: 0 } });
4770
4473
 
4771
4474
  srv.close();
@@ -4777,16 +4480,16 @@ describe('MastraInngestWorkflow', () => {
4777
4480
  expect(last).toHaveBeenCalledTimes(1);
4778
4481
 
4779
4482
  // @ts-ignore
4780
- expect(result.steps['nested-workflow-b'].output).toMatchObject({
4483
+ expect(result.steps['nested-workflow-b'].output).toEqual({
4781
4484
  finalValue: 1,
4782
4485
  });
4783
4486
 
4784
- expect(result.steps['first-step']).toMatchObject({
4487
+ expect(result.steps['first-step']).toEqual({
4785
4488
  output: { success: true },
4786
4489
  status: 'success',
4787
4490
  });
4788
4491
 
4789
- expect(result.steps['last-step']).toMatchObject({
4492
+ expect(result.steps['last-step']).toEqual({
4790
4493
  output: { success: true },
4791
4494
  status: 'success',
4792
4495
  });
@@ -4962,7 +4665,7 @@ describe('MastraInngestWorkflow', () => {
4962
4665
  port: (ctx as any).handlerPort,
4963
4666
  });
4964
4667
 
4965
- const run = await counterWorkflow.createRunAsync();
4668
+ const run = counterWorkflow.createRun();
4966
4669
  const result = await run.start({ inputData: { startValue: 1 } });
4967
4670
 
4968
4671
  srv.close();
@@ -4974,16 +4677,16 @@ describe('MastraInngestWorkflow', () => {
4974
4677
  // expect(last).toHaveBeenCalledTimes(1);
4975
4678
 
4976
4679
  // @ts-ignore
4977
- expect(result.steps['nested-workflow-b'].output).toMatchObject({
4680
+ expect(result.steps['nested-workflow-b'].output).toEqual({
4978
4681
  finalValue: 1,
4979
4682
  });
4980
4683
 
4981
- expect(result.steps['first-step']).toMatchObject({
4684
+ expect(result.steps['first-step']).toEqual({
4982
4685
  output: { success: true },
4983
4686
  status: 'success',
4984
4687
  });
4985
4688
 
4986
- expect(result.steps['last-step']).toMatchObject({
4689
+ expect(result.steps['last-step']).toEqual({
4987
4690
  output: { success: true },
4988
4691
  status: 'success',
4989
4692
  });
@@ -5116,7 +4819,7 @@ describe('MastraInngestWorkflow', () => {
5116
4819
  });
5117
4820
  await new Promise(resolve => setTimeout(resolve, 2000));
5118
4821
 
5119
- const run = await counterWorkflow.createRunAsync();
4822
+ const run = counterWorkflow.createRun();
5120
4823
  const result = await run.start({ inputData: { startValue: 0 } });
5121
4824
 
5122
4825
  expect(begin).toHaveBeenCalledTimes(1);
@@ -5129,12 +4832,12 @@ describe('MastraInngestWorkflow', () => {
5129
4832
  });
5130
4833
 
5131
4834
  // @ts-ignore
5132
- expect(result.steps['last-step']).toMatchObject(undefined);
4835
+ expect(result.steps['last-step']).toEqual(undefined);
5133
4836
 
5134
4837
  const resumedResults = await run.resume({ step: [wfA, otherStep], resumeData: { newValue: 0 } });
5135
4838
 
5136
4839
  // @ts-ignore
5137
- expect(resumedResults.steps['nested-workflow-a'].output).toMatchObject({
4840
+ expect(resumedResults.steps['nested-workflow-a'].output).toEqual({
5138
4841
  finalValue: 26 + 1,
5139
4842
  });
5140
4843
 
@@ -5266,7 +4969,7 @@ describe('MastraInngestWorkflow', () => {
5266
4969
  port: (ctx as any).handlerPort,
5267
4970
  });
5268
4971
 
5269
- const run = await counterWorkflow.createRunAsync();
4972
+ const run = counterWorkflow.createRun();
5270
4973
  const result = await run.start({ inputData: { startValue: 0 } });
5271
4974
  const results = result.steps;
5272
4975
 
@@ -5285,7 +4988,7 @@ describe('MastraInngestWorkflow', () => {
5285
4988
  },
5286
4989
  });
5287
4990
 
5288
- expect(result.steps['last-step']).toMatchObject({
4991
+ expect(result.steps['last-step']).toEqual({
5289
4992
  status: 'success',
5290
4993
  output: { success: true },
5291
4994
  });
@@ -5448,7 +5151,7 @@ describe('MastraInngestWorkflow', () => {
5448
5151
  });
5449
5152
  await new Promise(resolve => setTimeout(resolve, 2000));
5450
5153
 
5451
- const run = await counterWorkflow.createRunAsync();
5154
+ const run = counterWorkflow.createRun();
5452
5155
  const result = await run.start({ inputData: { startValue: 0 } });
5453
5156
 
5454
5157
  expect(passthroughStep.execute).toHaveBeenCalledTimes(2);
@@ -5462,23 +5165,18 @@ describe('MastraInngestWorkflow', () => {
5462
5165
  });
5463
5166
 
5464
5167
  // @ts-ignore
5465
- expect(result.steps['last-step']).toMatchObject(undefined);
5168
+ expect(result.steps['last-step']).toEqual(undefined);
5466
5169
 
5467
5170
  if (result.status !== 'suspended') {
5468
5171
  expect.fail('Workflow should be suspended');
5469
5172
  }
5470
- expect(result.suspended[0]).toMatchObject([
5471
- 'nested-workflow-c',
5472
- 'nested-workflow-b',
5473
- 'nested-workflow-a',
5474
- 'other',
5475
- ]);
5173
+ expect(result.suspended[0]).toEqual(['nested-workflow-c', 'nested-workflow-b', 'nested-workflow-a', 'other']);
5476
5174
  const resumedResults = await run.resume({ step: result.suspended[0], resumeData: { newValue: 0 } });
5477
5175
 
5478
5176
  srv.close();
5479
5177
 
5480
5178
  // @ts-ignore
5481
- expect(resumedResults.steps['nested-workflow-c'].output).toMatchObject({
5179
+ expect(resumedResults.steps['nested-workflow-c'].output).toEqual({
5482
5180
  finalValue: 26 + 1,
5483
5181
  });
5484
5182
 
@@ -5610,7 +5308,7 @@ describe('MastraInngestWorkflow', () => {
5610
5308
  });
5611
5309
  await new Promise(resolve => setTimeout(resolve, 2000));
5612
5310
 
5613
- const run = await counterWorkflow.createRunAsync();
5311
+ const run = counterWorkflow.createRun();
5614
5312
  const result = await run.start({ inputData: { startValue: 0 } });
5615
5313
 
5616
5314
  srv.close();
@@ -5620,16 +5318,16 @@ describe('MastraInngestWorkflow', () => {
5620
5318
  expect(final).toHaveBeenCalledTimes(2);
5621
5319
  expect(last).toHaveBeenCalledTimes(1);
5622
5320
  // @ts-ignore
5623
- expect(result.steps['nested-workflow-a-clone'].output).toMatchObject({
5321
+ expect(result.steps['nested-workflow-a-clone'].output).toEqual({
5624
5322
  finalValue: 26 + 1,
5625
5323
  });
5626
5324
 
5627
5325
  // @ts-ignore
5628
- expect(result.steps['nested-workflow-b'].output).toMatchObject({
5326
+ expect(result.steps['nested-workflow-b'].output).toEqual({
5629
5327
  finalValue: 1,
5630
5328
  });
5631
5329
 
5632
- expect(result.steps['last-step']).toMatchObject({
5330
+ expect(result.steps['last-step']).toEqual({
5633
5331
  output: { success: true },
5634
5332
  status: 'success',
5635
5333
  });
@@ -5686,7 +5384,7 @@ describe('MastraInngestWorkflow', () => {
5686
5384
  await new Promise(resolve => setTimeout(resolve, 2000));
5687
5385
 
5688
5386
  // Access new instance properties directly - should work without warning
5689
- const run = await workflow.createRunAsync();
5387
+ const run = workflow.createRun();
5690
5388
  await run.start({ inputData: {} });
5691
5389
 
5692
5390
  srv.close();
@@ -5747,7 +5445,7 @@ describe('MastraInngestWorkflow', () => {
5747
5445
  port: (ctx as any).handlerPort,
5748
5446
  });
5749
5447
 
5750
- const run = await workflow.createRunAsync();
5448
+ const run = workflow.createRun();
5751
5449
  const result = await run.start({ runtimeContext });
5752
5450
 
5753
5451
  srv.close();
@@ -5800,7 +5498,7 @@ describe('MastraInngestWorkflow', () => {
5800
5498
  });
5801
5499
  workflow.then(step).commit();
5802
5500
 
5803
- const run = await workflow.createRunAsync();
5501
+ const run = workflow.createRun();
5804
5502
  await run.start({ runtimeContext });
5805
5503
 
5806
5504
  const resumeruntimeContext = new RuntimeContext();
@@ -5819,1049 +5517,5 @@ describe('MastraInngestWorkflow', () => {
5819
5517
  });
5820
5518
  });
5821
5519
 
5822
- describe('Access to inngest step primitives', () => {
5823
- it('should inject inngest step primitives into steps during run', async ctx => {
5824
- const inngest = new Inngest({
5825
- id: 'mastra',
5826
- baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
5827
- });
5828
-
5829
- const { createWorkflow, createStep } = init(inngest);
5830
-
5831
- const step = createStep({
5832
- id: 'step1',
5833
- execute: async ({ engine }) => {
5834
- return {
5835
- hasEngine: !!engine.step,
5836
- };
5837
- },
5838
- inputSchema: z.object({}),
5839
- outputSchema: z.object({}),
5840
- });
5841
- const workflow = createWorkflow({
5842
- id: 'test-workflow',
5843
- inputSchema: z.object({}),
5844
- outputSchema: z.object({
5845
- hasEngine: z.boolean(),
5846
- }),
5847
- });
5848
- workflow.then(step).commit();
5849
-
5850
- const mastra = new Mastra({
5851
- storage: new DefaultStorage({
5852
- url: ':memory:',
5853
- }),
5854
- workflows: {
5855
- 'test-workflow': workflow,
5856
- },
5857
- server: {
5858
- apiRoutes: [
5859
- {
5860
- path: '/inngest/api',
5861
- method: 'ALL',
5862
- createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
5863
- },
5864
- ],
5865
- },
5866
- });
5867
-
5868
- const app = await createHonoServer(mastra);
5869
-
5870
- const srv = serve({
5871
- fetch: app.fetch,
5872
- port: (ctx as any).handlerPort,
5873
- });
5874
-
5875
- const run = await workflow.createRunAsync();
5876
- const result = await run.start({});
5877
-
5878
- srv.close();
5879
-
5880
- // @ts-ignore
5881
- expect(result?.steps.step1.output.hasEngine).toBe(true);
5882
- });
5883
- });
5884
-
5885
- describe('Streaming', () => {
5886
- it('should generate a stream', async ctx => {
5887
- const inngest = new Inngest({
5888
- id: 'mastra',
5889
- baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
5890
- middleware: [realtimeMiddleware()],
5891
- });
5892
-
5893
- const { createWorkflow, createStep } = init(inngest);
5894
-
5895
- const step1Action = vi.fn<any>().mockResolvedValue({ result: 'success1' });
5896
- const step2Action = vi.fn<any>().mockResolvedValue({ result: 'success2' });
5897
-
5898
- const step1 = createStep({
5899
- id: 'step1',
5900
- execute: step1Action,
5901
- inputSchema: z.object({}),
5902
- outputSchema: z.object({ value: z.string() }),
5903
- });
5904
- const step2 = createStep({
5905
- id: 'step2',
5906
- execute: step2Action,
5907
- inputSchema: z.object({ value: z.string() }),
5908
- outputSchema: z.object({}),
5909
- });
5910
-
5911
- const workflow = createWorkflow({
5912
- id: 'test-workflow',
5913
- inputSchema: z.object({}),
5914
- outputSchema: z.object({}),
5915
- steps: [step1, step2],
5916
- });
5917
- workflow.then(step1).then(step2).commit();
5918
-
5919
- const mastra = new Mastra({
5920
- storage: new DefaultStorage({
5921
- url: ':memory:',
5922
- }),
5923
- workflows: {
5924
- 'test-workflow': workflow,
5925
- },
5926
- server: {
5927
- apiRoutes: [
5928
- {
5929
- path: '/inngest/api',
5930
- method: 'ALL',
5931
- createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
5932
- },
5933
- ],
5934
- },
5935
- });
5936
-
5937
- const app = await createHonoServer(mastra);
5938
-
5939
- const srv = serve({
5940
- fetch: app.fetch,
5941
- port: (ctx as any).handlerPort,
5942
- });
5943
-
5944
- const runId = 'test-run-id';
5945
- let watchData: StreamEvent[] = [];
5946
- const run = await workflow.createRunAsync({
5947
- runId,
5948
- });
5949
-
5950
- await new Promise(resolve => setTimeout(resolve, 1000));
5951
-
5952
- const { stream, getWorkflowState } = run.stream({ inputData: {} });
5953
-
5954
- // Start watching the workflow
5955
- const collectedStreamData: StreamEvent[] = [];
5956
- for await (const data of stream) {
5957
- collectedStreamData.push(JSON.parse(JSON.stringify(data)));
5958
- }
5959
- watchData = collectedStreamData;
5960
-
5961
- const executionResult = await getWorkflowState();
5962
-
5963
- await new Promise(resolve => setTimeout(resolve, 1000));
5964
-
5965
- srv.close();
5966
-
5967
- expect(watchData.length).toBe(8);
5968
- expect(watchData).toMatchInlineSnapshot(`
5969
- [
5970
- {
5971
- "payload": {
5972
- "runId": "test-run-id",
5973
- },
5974
- "type": "start",
5975
- },
5976
- {
5977
- "payload": {
5978
- "id": "step1",
5979
- },
5980
- "type": "step-start",
5981
- },
5982
- {
5983
- "payload": {
5984
- "id": "step1",
5985
- "output": {
5986
- "result": "success1",
5987
- },
5988
- "status": "success",
5989
- },
5990
- "type": "step-result",
5991
- },
5992
- {
5993
- "payload": {
5994
- "id": "step1",
5995
- "metadata": {},
5996
- },
5997
- "type": "step-finish",
5998
- },
5999
- {
6000
- "payload": {
6001
- "id": "step2",
6002
- },
6003
- "type": "step-start",
6004
- },
6005
- {
6006
- "payload": {
6007
- "id": "step2",
6008
- "output": {
6009
- "result": "success2",
6010
- },
6011
- "status": "success",
6012
- },
6013
- "type": "step-result",
6014
- },
6015
- {
6016
- "payload": {
6017
- "id": "step2",
6018
- "metadata": {},
6019
- },
6020
- "type": "step-finish",
6021
- },
6022
- {
6023
- "payload": {
6024
- "runId": "test-run-id",
6025
- },
6026
- "type": "finish",
6027
- },
6028
- ]
6029
- `);
6030
- // Verify execution completed successfully
6031
- expect(executionResult.steps.step1).toMatchObject({
6032
- status: 'success',
6033
- output: { result: 'success1' },
6034
- payload: {},
6035
- startedAt: expect.any(Number),
6036
- endedAt: expect.any(Number),
6037
- });
6038
- expect(executionResult.steps.step2).toMatchObject({
6039
- status: 'success',
6040
- output: { result: 'success2' },
6041
- payload: {
6042
- result: 'success1',
6043
- },
6044
- startedAt: expect.any(Number),
6045
- endedAt: expect.any(Number),
6046
- });
6047
- });
6048
-
6049
- it('should handle basic sleep waiting flow', async ctx => {
6050
- const inngest = new Inngest({
6051
- id: 'mastra',
6052
- baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
6053
- middleware: [realtimeMiddleware()],
6054
- });
6055
-
6056
- const { createWorkflow, createStep } = init(inngest);
6057
-
6058
- const step1Action = vi.fn<any>().mockResolvedValue({ result: 'success1' });
6059
- const step2Action = vi.fn<any>().mockResolvedValue({ result: 'success2' });
6060
-
6061
- const step1 = createStep({
6062
- id: 'step1',
6063
- execute: step1Action,
6064
- inputSchema: z.object({}),
6065
- outputSchema: z.object({ value: z.string() }),
6066
- });
6067
- const step2 = createStep({
6068
- id: 'step2',
6069
- execute: step2Action,
6070
- inputSchema: z.object({ value: z.string() }),
6071
- outputSchema: z.object({}),
6072
- });
6073
-
6074
- const workflow = createWorkflow({
6075
- id: 'test-workflow',
6076
- inputSchema: z.object({}),
6077
- outputSchema: z.object({}),
6078
- steps: [step1, step2],
6079
- });
6080
- workflow.then(step1).sleep(1000).then(step2).commit();
6081
-
6082
- const mastra = new Mastra({
6083
- storage: new DefaultStorage({
6084
- url: ':memory:',
6085
- }),
6086
- workflows: {
6087
- 'test-workflow': workflow,
6088
- },
6089
- server: {
6090
- apiRoutes: [
6091
- {
6092
- path: '/inngest/api',
6093
- method: 'ALL',
6094
- createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
6095
- },
6096
- ],
6097
- },
6098
- });
6099
-
6100
- const app = await createHonoServer(mastra);
6101
-
6102
- const srv = serve({
6103
- fetch: app.fetch,
6104
- port: (ctx as any).handlerPort,
6105
- });
6106
-
6107
- const runId = 'test-run-id';
6108
- let watchData: StreamEvent[] = [];
6109
- const run = await workflow.createRunAsync({
6110
- runId,
6111
- });
6112
-
6113
- await new Promise(resolve => setTimeout(resolve, 1000));
6114
-
6115
- const { stream, getWorkflowState } = run.stream({ inputData: {} });
6116
-
6117
- // Start watching the workflow
6118
- const collectedStreamData: StreamEvent[] = [];
6119
- for await (const data of stream) {
6120
- collectedStreamData.push(JSON.parse(JSON.stringify(data)));
6121
- }
6122
- watchData = collectedStreamData;
6123
-
6124
- const executionResult = await getWorkflowState();
6125
-
6126
- await new Promise(resolve => setTimeout(resolve, 1000));
6127
-
6128
- srv.close();
6129
-
6130
- expect(watchData.length).toBe(9);
6131
- expect(watchData).toMatchObject([
6132
- {
6133
- payload: {
6134
- runId: 'test-run-id',
6135
- },
6136
- type: 'start',
6137
- },
6138
- {
6139
- payload: {
6140
- id: 'step1',
6141
- },
6142
- type: 'step-start',
6143
- },
6144
- {
6145
- payload: {
6146
- id: 'step1',
6147
- output: {
6148
- result: 'success1',
6149
- },
6150
- status: 'success',
6151
- },
6152
- type: 'step-result',
6153
- },
6154
- {
6155
- payload: {
6156
- id: 'step1',
6157
- metadata: {},
6158
- },
6159
- type: 'step-finish',
6160
- },
6161
- {
6162
- payload: {},
6163
- type: 'step-waiting',
6164
- },
6165
- {
6166
- payload: {
6167
- id: 'step2',
6168
- },
6169
- type: 'step-start',
6170
- },
6171
- {
6172
- payload: {
6173
- id: 'step2',
6174
- output: {
6175
- result: 'success2',
6176
- },
6177
- status: 'success',
6178
- },
6179
- type: 'step-result',
6180
- },
6181
- {
6182
- payload: {
6183
- id: 'step2',
6184
- metadata: {},
6185
- },
6186
- type: 'step-finish',
6187
- },
6188
- {
6189
- payload: {
6190
- runId: 'test-run-id',
6191
- },
6192
- type: 'finish',
6193
- },
6194
- ]);
6195
- // Verify execution completed successfully
6196
- expect(executionResult.steps.step1).toMatchObject({
6197
- status: 'success',
6198
- output: { result: 'success1' },
6199
- payload: {},
6200
- startedAt: expect.any(Number),
6201
- endedAt: expect.any(Number),
6202
- });
6203
- expect(executionResult.steps.step2).toMatchObject({
6204
- status: 'success',
6205
- output: { result: 'success2' },
6206
- payload: {
6207
- result: 'success1',
6208
- },
6209
- startedAt: expect.any(Number),
6210
- endedAt: expect.any(Number),
6211
- });
6212
- });
6213
-
6214
- it('should handle waitForEvent waiting flow', async ctx => {
6215
- const inngest = new Inngest({
6216
- id: 'mastra',
6217
- baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
6218
- middleware: [realtimeMiddleware()],
6219
- });
6220
-
6221
- const { createWorkflow, createStep } = init(inngest);
6222
-
6223
- const step1Action = vi.fn<any>().mockResolvedValue({ result: 'success1' });
6224
- const step2Action = vi.fn<any>().mockResolvedValue({ result: 'success2' });
6225
-
6226
- const step1 = createStep({
6227
- id: 'step1',
6228
- execute: step1Action,
6229
- inputSchema: z.object({}),
6230
- outputSchema: z.object({ value: z.string() }),
6231
- });
6232
- const step2 = createStep({
6233
- id: 'step2',
6234
- execute: step2Action,
6235
- inputSchema: z.object({ value: z.string() }),
6236
- outputSchema: z.object({}),
6237
- });
6238
-
6239
- const workflow = createWorkflow({
6240
- id: 'test-workflow',
6241
- inputSchema: z.object({}),
6242
- outputSchema: z.object({}),
6243
- steps: [step1, step2],
6244
- });
6245
- workflow.then(step1).waitForEvent('user-event-test', step2).commit();
6246
-
6247
- const mastra = new Mastra({
6248
- storage: new DefaultStorage({
6249
- url: ':memory:',
6250
- }),
6251
- workflows: {
6252
- 'test-workflow': workflow,
6253
- },
6254
- server: {
6255
- apiRoutes: [
6256
- {
6257
- path: '/inngest/api',
6258
- method: 'ALL',
6259
- createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
6260
- },
6261
- ],
6262
- },
6263
- });
6264
-
6265
- const app = await createHonoServer(mastra);
6266
-
6267
- const srv = serve({
6268
- fetch: app.fetch,
6269
- port: (ctx as any).handlerPort,
6270
- });
6271
-
6272
- const runId = 'test-run-id';
6273
- let watchData: StreamEvent[] = [];
6274
- const run = await workflow.createRunAsync({
6275
- runId,
6276
- });
6277
-
6278
- await new Promise(resolve => setTimeout(resolve, 1000));
6279
-
6280
- const { stream, getWorkflowState } = run.stream({ inputData: {} });
6281
-
6282
- setTimeout(() => {
6283
- run.sendEvent('user-event-test', {
6284
- value: 'eventdata',
6285
- });
6286
- }, 3000);
6287
-
6288
- // Start watching the workflow
6289
- const collectedStreamData: StreamEvent[] = [];
6290
- for await (const data of stream) {
6291
- collectedStreamData.push(JSON.parse(JSON.stringify(data)));
6292
- }
6293
- watchData = collectedStreamData;
6294
- console.dir({ watchData }, { depth: null });
6295
-
6296
- const executionResult = await getWorkflowState();
6297
-
6298
- await new Promise(resolve => setTimeout(resolve, 1000));
6299
-
6300
- srv.close();
6301
-
6302
- expect(watchData.length).toBe(9);
6303
- expect(watchData).toMatchObject([
6304
- {
6305
- payload: {
6306
- runId: 'test-run-id',
6307
- },
6308
- type: 'start',
6309
- },
6310
- {
6311
- payload: {
6312
- id: 'step1',
6313
- },
6314
- type: 'step-start',
6315
- },
6316
- {
6317
- payload: {
6318
- id: 'step1',
6319
- output: {
6320
- result: 'success1',
6321
- },
6322
- status: 'success',
6323
- },
6324
- type: 'step-result',
6325
- },
6326
- {
6327
- payload: {
6328
- id: 'step1',
6329
- metadata: {},
6330
- },
6331
- type: 'step-finish',
6332
- },
6333
- {
6334
- payload: {
6335
- id: 'step2',
6336
- },
6337
- type: 'step-waiting',
6338
- },
6339
- {
6340
- payload: {
6341
- id: 'step2',
6342
- },
6343
- type: 'step-start',
6344
- },
6345
- {
6346
- payload: {
6347
- id: 'step2',
6348
- output: {
6349
- result: 'success2',
6350
- },
6351
- status: 'success',
6352
- },
6353
- type: 'step-result',
6354
- },
6355
- {
6356
- payload: {
6357
- id: 'step2',
6358
- metadata: {},
6359
- },
6360
- type: 'step-finish',
6361
- },
6362
- {
6363
- payload: {
6364
- runId: 'test-run-id',
6365
- },
6366
- type: 'finish',
6367
- },
6368
- ]);
6369
- // Verify execution completed successfully
6370
- expect(executionResult.steps.step1).toMatchObject({
6371
- status: 'success',
6372
- output: { result: 'success1' },
6373
- payload: {},
6374
- startedAt: expect.any(Number),
6375
- endedAt: expect.any(Number),
6376
- });
6377
- expect(executionResult.steps.step2).toMatchObject({
6378
- status: 'success',
6379
- output: { result: 'success2' },
6380
- payload: {
6381
- result: 'success1',
6382
- },
6383
- resumePayload: {
6384
- value: 'eventdata',
6385
- },
6386
- startedAt: expect.any(Number),
6387
- resumedAt: expect.any(Number),
6388
- endedAt: expect.any(Number),
6389
- });
6390
- });
6391
-
6392
- it('should handle basic suspend and resume flow', async ctx => {
6393
- const inngest = new Inngest({
6394
- id: 'mastra',
6395
- baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
6396
- middleware: [realtimeMiddleware()],
6397
- });
6398
-
6399
- const { createWorkflow, createStep } = init(inngest);
6400
-
6401
- const getUserInputAction = vi.fn().mockResolvedValue({ userInput: 'test input' });
6402
- const promptAgentAction = vi
6403
- .fn()
6404
- .mockImplementationOnce(async ({ suspend }) => {
6405
- console.log('suspend');
6406
- await suspend();
6407
- return undefined;
6408
- })
6409
- .mockImplementationOnce(() => ({ modelOutput: 'test output' }));
6410
- const evaluateToneAction = vi.fn().mockResolvedValue({
6411
- toneScore: { score: 0.8 },
6412
- completenessScore: { score: 0.7 },
6413
- });
6414
- const improveResponseAction = vi.fn().mockResolvedValue({ improvedOutput: 'improved output' });
6415
- const evaluateImprovedAction = vi.fn().mockResolvedValue({
6416
- toneScore: { score: 0.9 },
6417
- completenessScore: { score: 0.8 },
6418
- });
6419
-
6420
- const getUserInput = createStep({
6421
- id: 'getUserInput',
6422
- execute: getUserInputAction,
6423
- inputSchema: z.object({ input: z.string() }),
6424
- outputSchema: z.object({ userInput: z.string() }),
6425
- });
6426
- const promptAgent = createStep({
6427
- id: 'promptAgent',
6428
- execute: promptAgentAction,
6429
- inputSchema: z.object({ userInput: z.string() }),
6430
- outputSchema: z.object({ modelOutput: z.string() }),
6431
- });
6432
- const evaluateTone = createStep({
6433
- id: 'evaluateToneConsistency',
6434
- execute: evaluateToneAction,
6435
- inputSchema: z.object({ modelOutput: z.string() }),
6436
- outputSchema: z.object({
6437
- toneScore: z.any(),
6438
- completenessScore: z.any(),
6439
- }),
6440
- });
6441
- const improveResponse = createStep({
6442
- id: 'improveResponse',
6443
- execute: improveResponseAction,
6444
- inputSchema: z.object({ toneScore: z.any(), completenessScore: z.any() }),
6445
- outputSchema: z.object({ improvedOutput: z.string() }),
6446
- });
6447
- const evaluateImproved = createStep({
6448
- id: 'evaluateImprovedResponse',
6449
- execute: evaluateImprovedAction,
6450
- inputSchema: z.object({ improvedOutput: z.string() }),
6451
- outputSchema: z.object({
6452
- toneScore: z.any(),
6453
- completenessScore: z.any(),
6454
- }),
6455
- });
6456
-
6457
- const promptEvalWorkflow = createWorkflow({
6458
- id: 'test-workflow',
6459
- inputSchema: z.object({ input: z.string() }),
6460
- outputSchema: z.object({}),
6461
- steps: [getUserInput, promptAgent, evaluateTone, improveResponse, evaluateImproved],
6462
- });
6463
-
6464
- promptEvalWorkflow
6465
- .then(getUserInput)
6466
- .then(promptAgent)
6467
- .then(evaluateTone)
6468
- .then(improveResponse)
6469
- .then(evaluateImproved)
6470
- .commit();
6471
-
6472
- const mastra = new Mastra({
6473
- storage: new DefaultStorage({
6474
- url: ':memory:',
6475
- }),
6476
- workflows: {
6477
- 'test-workflow': promptEvalWorkflow,
6478
- },
6479
- server: {
6480
- apiRoutes: [
6481
- {
6482
- path: '/inngest/api',
6483
- method: 'ALL',
6484
- createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
6485
- },
6486
- ],
6487
- },
6488
- });
6489
-
6490
- const app = await createHonoServer(mastra);
6491
-
6492
- const srv = serve({
6493
- fetch: app.fetch,
6494
- port: (ctx as any).handlerPort,
6495
- });
6496
-
6497
- await new Promise(resolve => setTimeout(resolve, 1000));
6498
-
6499
- const run = await promptEvalWorkflow.createRunAsync();
6500
-
6501
- const { stream, getWorkflowState } = run.stream({ inputData: { input: 'test' } });
6502
-
6503
- for await (const data of stream) {
6504
- if (data.type === 'step-suspended') {
6505
- expect(promptAgentAction).toHaveBeenCalledTimes(1);
6506
-
6507
- // make it async to show that execution is not blocked
6508
- setImmediate(() => {
6509
- const resumeData = { stepId: 'promptAgent', context: { userInput: 'test input for resumption' } };
6510
- run.resume({ resumeData: resumeData as any, step: promptAgent });
6511
- });
6512
- expect(evaluateToneAction).not.toHaveBeenCalledTimes(1);
6513
- }
6514
- }
6515
-
6516
- await new Promise(resolve => setTimeout(resolve, 5000));
6517
- const resumeResult = await getWorkflowState();
6518
-
6519
- srv.close();
6520
-
6521
- expect(evaluateToneAction).toHaveBeenCalledTimes(1);
6522
- expect(resumeResult.steps).toMatchObject({
6523
- input: { input: 'test' },
6524
- getUserInput: {
6525
- status: 'success',
6526
- output: { userInput: 'test input' },
6527
- payload: { input: 'test' },
6528
- startedAt: expect.any(Number),
6529
- endedAt: expect.any(Number),
6530
- },
6531
- promptAgent: {
6532
- status: 'success',
6533
- output: { modelOutput: 'test output' },
6534
- payload: { userInput: 'test input' },
6535
- startedAt: expect.any(Number),
6536
- endedAt: expect.any(Number),
6537
- resumePayload: { stepId: 'promptAgent', context: { userInput: 'test input for resumption' } },
6538
- resumedAt: expect.any(Number),
6539
- // suspendedAt: expect.any(Number),
6540
- },
6541
- evaluateToneConsistency: {
6542
- status: 'success',
6543
- output: { toneScore: { score: 0.8 }, completenessScore: { score: 0.7 } },
6544
- payload: { modelOutput: 'test output' },
6545
- startedAt: expect.any(Number),
6546
- endedAt: expect.any(Number),
6547
- },
6548
- improveResponse: {
6549
- status: 'success',
6550
- output: { improvedOutput: 'improved output' },
6551
- payload: { toneScore: { score: 0.8 }, completenessScore: { score: 0.7 } },
6552
- startedAt: expect.any(Number),
6553
- endedAt: expect.any(Number),
6554
- },
6555
- evaluateImprovedResponse: {
6556
- status: 'success',
6557
- output: { toneScore: { score: 0.9 }, completenessScore: { score: 0.8 } },
6558
- payload: { improvedOutput: 'improved output' },
6559
- startedAt: expect.any(Number),
6560
- endedAt: expect.any(Number),
6561
- },
6562
- });
6563
- });
6564
-
6565
- it('should be able to use an agent as a step', async ctx => {
6566
- const inngest = new Inngest({
6567
- id: 'mastra',
6568
- baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
6569
- middleware: [realtimeMiddleware()],
6570
- });
6571
-
6572
- const { createWorkflow, createStep } = init(inngest);
6573
-
6574
- const workflow = createWorkflow({
6575
- id: 'test-workflow',
6576
- inputSchema: z.object({
6577
- prompt1: z.string(),
6578
- prompt2: z.string(),
6579
- }),
6580
- outputSchema: z.object({}),
6581
- });
6582
-
6583
- const agent = new Agent({
6584
- name: 'test-agent-1',
6585
- instructions: 'test agent instructions"',
6586
- model: new MockLanguageModelV1({
6587
- doStream: async () => ({
6588
- stream: simulateReadableStream({
6589
- chunks: [
6590
- { type: 'text-delta', textDelta: 'Paris' },
6591
- {
6592
- type: 'finish',
6593
- finishReason: 'stop',
6594
- logprobs: undefined,
6595
- usage: { completionTokens: 10, promptTokens: 3 },
6596
- },
6597
- ],
6598
- }),
6599
- rawCall: { rawPrompt: null, rawSettings: {} },
6600
- }),
6601
- }),
6602
- });
6603
-
6604
- const agent2 = new Agent({
6605
- name: 'test-agent-2',
6606
- instructions: 'test agent instructions',
6607
- model: new MockLanguageModelV1({
6608
- doStream: async () => ({
6609
- stream: simulateReadableStream({
6610
- chunks: [
6611
- { type: 'text-delta', textDelta: 'London' },
6612
- {
6613
- type: 'finish',
6614
- finishReason: 'stop',
6615
- logprobs: undefined,
6616
- usage: { completionTokens: 10, promptTokens: 3 },
6617
- },
6618
- ],
6619
- }),
6620
- rawCall: { rawPrompt: null, rawSettings: {} },
6621
- }),
6622
- }),
6623
- });
6624
-
6625
- const startStep = createStep({
6626
- id: 'start',
6627
- inputSchema: z.object({
6628
- prompt1: z.string(),
6629
- prompt2: z.string(),
6630
- }),
6631
- outputSchema: z.object({ prompt1: z.string(), prompt2: z.string() }),
6632
- execute: async ({ inputData }) => {
6633
- return {
6634
- prompt1: inputData.prompt1,
6635
- prompt2: inputData.prompt2,
6636
- };
6637
- },
6638
- });
6639
-
6640
- const agentStep1 = createStep(agent);
6641
- const agentStep2 = createStep(agent2);
6642
-
6643
- workflow
6644
- .then(startStep)
6645
- .map({
6646
- prompt: {
6647
- step: startStep,
6648
- path: 'prompt1',
6649
- },
6650
- })
6651
- .then(agentStep1)
6652
- .map({
6653
- prompt: {
6654
- step: startStep,
6655
- path: 'prompt2',
6656
- },
6657
- })
6658
- .then(agentStep2)
6659
- .commit();
6660
-
6661
- const mastra = new Mastra({
6662
- storage: new DefaultStorage({
6663
- url: ':memory:',
6664
- }),
6665
- workflows: {
6666
- 'test-workflow': workflow,
6667
- },
6668
- server: {
6669
- apiRoutes: [
6670
- {
6671
- path: '/inngest/api',
6672
- method: 'ALL',
6673
- createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
6674
- },
6675
- ],
6676
- },
6677
- });
6678
-
6679
- const app = await createHonoServer(mastra);
6680
-
6681
- const srv = serve({
6682
- fetch: app.fetch,
6683
- port: (ctx as any).handlerPort,
6684
- });
6685
-
6686
- await new Promise(resolve => setTimeout(resolve, 1000));
6687
-
6688
- const run = await workflow.createRunAsync({
6689
- runId: 'test-run-id',
6690
- });
6691
- const { stream } = run.stream({
6692
- inputData: {
6693
- prompt1: 'Capital of France, just the name',
6694
- prompt2: 'Capital of UK, just the name',
6695
- },
6696
- });
6697
-
6698
- const values: StreamEvent[] = [];
6699
- for await (const value of stream.values()) {
6700
- values.push(value);
6701
- }
6702
-
6703
- srv.close();
6704
-
6705
- expect(values).toMatchObject([
6706
- {
6707
- payload: {
6708
- runId: 'test-run-id',
6709
- },
6710
- type: 'start',
6711
- },
6712
- {
6713
- payload: {
6714
- id: 'start',
6715
- },
6716
- type: 'step-start',
6717
- },
6718
- {
6719
- payload: {
6720
- id: 'start',
6721
- output: {
6722
- prompt1: 'Capital of France, just the name',
6723
- prompt2: 'Capital of UK, just the name',
6724
- },
6725
- status: 'success',
6726
- },
6727
- type: 'step-result',
6728
- },
6729
- {
6730
- payload: {
6731
- id: 'start',
6732
- metadata: {},
6733
- },
6734
- type: 'step-finish',
6735
- },
6736
- {
6737
- payload: {
6738
- id: expect.any(String),
6739
- },
6740
- type: 'step-start',
6741
- },
6742
- {
6743
- payload: {
6744
- id: expect.any(String),
6745
- output: {
6746
- prompt: 'Capital of France, just the name',
6747
- },
6748
- status: 'success',
6749
- },
6750
- type: 'step-result',
6751
- },
6752
- {
6753
- payload: {
6754
- id: expect.any(String),
6755
- metadata: {},
6756
- },
6757
- type: 'step-finish',
6758
- },
6759
- {
6760
- payload: {
6761
- id: 'test-agent-1',
6762
- },
6763
- type: 'step-start',
6764
- },
6765
- {
6766
- args: {
6767
- prompt: 'Capital of France, just the name',
6768
- },
6769
- name: 'test-agent-1',
6770
- type: 'tool-call-streaming-start',
6771
- },
6772
- {
6773
- args: {
6774
- prompt: 'Capital of France, just the name',
6775
- },
6776
- argsTextDelta: 'Paris',
6777
- name: 'test-agent-1',
6778
- type: 'tool-call-delta',
6779
- },
6780
- {
6781
- payload: {
6782
- id: 'test-agent-1',
6783
- output: {
6784
- text: 'Paris',
6785
- },
6786
- status: 'success',
6787
- },
6788
- type: 'step-result',
6789
- },
6790
- {
6791
- payload: {
6792
- id: expect.any(String),
6793
- metadata: {},
6794
- },
6795
- type: 'step-finish',
6796
- },
6797
- {
6798
- payload: {
6799
- id: expect.any(String),
6800
- },
6801
- type: 'step-start',
6802
- },
6803
- {
6804
- payload: {
6805
- id: expect.any(String),
6806
- output: {
6807
- prompt: 'Capital of UK, just the name',
6808
- },
6809
- status: 'success',
6810
- },
6811
- type: 'step-result',
6812
- },
6813
- {
6814
- payload: {
6815
- id: expect.any(String),
6816
- metadata: {},
6817
- },
6818
- type: 'step-finish',
6819
- },
6820
- {
6821
- payload: {
6822
- id: expect.any(String),
6823
- },
6824
- type: 'step-start',
6825
- },
6826
- {
6827
- args: {
6828
- prompt: 'Capital of UK, just the name',
6829
- },
6830
- name: 'test-agent-2',
6831
- type: 'tool-call-streaming-start',
6832
- },
6833
- {
6834
- args: {
6835
- prompt: 'Capital of UK, just the name',
6836
- },
6837
- argsTextDelta: 'London',
6838
- name: 'test-agent-2',
6839
- type: 'tool-call-delta',
6840
- },
6841
- {
6842
- payload: {
6843
- id: expect.any(String),
6844
- output: {
6845
- text: 'London',
6846
- },
6847
- status: 'success',
6848
- },
6849
- type: 'step-result',
6850
- },
6851
- {
6852
- payload: {
6853
- id: expect.any(String),
6854
- metadata: {},
6855
- },
6856
- type: 'step-finish',
6857
- },
6858
- {
6859
- payload: {
6860
- runId: 'test-run-id',
6861
- },
6862
- type: 'finish',
6863
- },
6864
- ]);
6865
- });
6866
- });
5520
+ describe('Access to inngest step primitives', () => {});
6867
5521
  }, 40e3);