@mastra/inngest 0.0.0-tool-call-parts-20250630193309 → 0.0.0-transpile-packages-20250730132657
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/CHANGELOG.md +225 -3
- package/LICENSE.md +11 -42
- package/dist/_tsup-dts-rollup.d.cts +63 -16
- package/dist/_tsup-dts-rollup.d.ts +63 -16
- package/dist/index.cjs +213 -23
- package/dist/index.js +214 -24
- package/docker-compose.yaml +3 -3
- package/package.json +12 -11
- package/src/index.test.ts +1158 -218
- package/src/index.ts +274 -21
- package/vitest.config.ts +6 -0
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,
|
|
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
|
-
|
|
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
|
-
|
|
31
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
798
|
+
}));
|
|
799
|
+
await resetInngest();
|
|
612
800
|
|
|
613
801
|
const run = await workflow.createRunAsync();
|
|
614
802
|
const startTime = Date.now();
|
|
@@ -671,12 +859,206 @@ describe('MastraInngestWorkflow', () => {
|
|
|
671
859
|
inputSchema: z.object({}),
|
|
672
860
|
outputSchema: z.object({
|
|
673
861
|
result: z.string(),
|
|
674
|
-
resumed: z.any(),
|
|
862
|
+
resumed: z.any(),
|
|
863
|
+
}),
|
|
864
|
+
steps: [step1],
|
|
865
|
+
});
|
|
866
|
+
|
|
867
|
+
workflow.then(step1).waitForEvent('hello-event', step2, { timeout: 1000 }).commit();
|
|
868
|
+
|
|
869
|
+
const mastra = new Mastra({
|
|
870
|
+
storage: new DefaultStorage({
|
|
871
|
+
url: ':memory:',
|
|
872
|
+
}),
|
|
873
|
+
workflows: {
|
|
874
|
+
'test-workflow': workflow,
|
|
875
|
+
},
|
|
876
|
+
server: {
|
|
877
|
+
apiRoutes: [
|
|
878
|
+
{
|
|
879
|
+
path: '/inngest/api',
|
|
880
|
+
method: 'ALL',
|
|
881
|
+
createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
|
|
882
|
+
},
|
|
883
|
+
],
|
|
884
|
+
},
|
|
885
|
+
});
|
|
886
|
+
|
|
887
|
+
const app = await createHonoServer(mastra);
|
|
888
|
+
|
|
889
|
+
const srv = (globServer = serve({
|
|
890
|
+
fetch: app.fetch,
|
|
891
|
+
port: (ctx as any).handlerPort,
|
|
892
|
+
}));
|
|
893
|
+
await resetInngest();
|
|
894
|
+
|
|
895
|
+
const run = await workflow.createRunAsync();
|
|
896
|
+
const startTime = Date.now();
|
|
897
|
+
const result = await run.start({ inputData: {} });
|
|
898
|
+
const endTime = Date.now();
|
|
899
|
+
|
|
900
|
+
expect(execute).toHaveBeenCalled();
|
|
901
|
+
expect(result.steps['step1']).toMatchObject({
|
|
902
|
+
status: 'success',
|
|
903
|
+
output: { result: 'success' },
|
|
904
|
+
// payload: {},
|
|
905
|
+
// startedAt: expect.any(Number),
|
|
906
|
+
// endedAt: expect.any(Number),
|
|
907
|
+
});
|
|
908
|
+
|
|
909
|
+
expect(result.steps['step2']).toMatchObject({
|
|
910
|
+
status: 'failed',
|
|
911
|
+
error: expect.any(String),
|
|
912
|
+
payload: { result: 'success' },
|
|
913
|
+
startedAt: expect.any(Number),
|
|
914
|
+
endedAt: expect.any(Number),
|
|
915
|
+
});
|
|
916
|
+
|
|
917
|
+
expect(endTime - startTime).toBeGreaterThan(1000);
|
|
918
|
+
|
|
919
|
+
srv.close();
|
|
920
|
+
});
|
|
921
|
+
});
|
|
922
|
+
|
|
923
|
+
describe('abort', () => {
|
|
924
|
+
it('should be able to abort workflow execution in between steps', async ctx => {
|
|
925
|
+
const inngest = new Inngest({
|
|
926
|
+
id: 'mastra',
|
|
927
|
+
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
928
|
+
middleware: [realtimeMiddleware()],
|
|
929
|
+
});
|
|
930
|
+
|
|
931
|
+
const { createWorkflow, createStep } = init(inngest);
|
|
932
|
+
|
|
933
|
+
const step1 = createStep({
|
|
934
|
+
id: 'step1',
|
|
935
|
+
execute: async ({ inputData }) => {
|
|
936
|
+
return { result: 'step1: ' + inputData.value };
|
|
937
|
+
},
|
|
938
|
+
inputSchema: z.object({ value: z.string() }),
|
|
939
|
+
outputSchema: z.object({ result: z.string() }),
|
|
940
|
+
});
|
|
941
|
+
const step2 = createStep({
|
|
942
|
+
id: 'step2',
|
|
943
|
+
execute: async ({ inputData }) => {
|
|
944
|
+
return { result: 'step2: ' + inputData.result };
|
|
945
|
+
},
|
|
946
|
+
inputSchema: z.object({ result: z.string() }),
|
|
947
|
+
outputSchema: z.object({ result: z.string() }),
|
|
948
|
+
});
|
|
949
|
+
|
|
950
|
+
const workflow = createWorkflow({
|
|
951
|
+
id: 'test-workflow',
|
|
952
|
+
inputSchema: z.object({}),
|
|
953
|
+
outputSchema: z.object({
|
|
954
|
+
result: z.string(),
|
|
955
|
+
}),
|
|
956
|
+
steps: [step1, step2],
|
|
957
|
+
});
|
|
958
|
+
|
|
959
|
+
workflow.then(step1).sleep(2000).then(step2).commit();
|
|
960
|
+
|
|
961
|
+
const mastra = new Mastra({
|
|
962
|
+
storage: new DefaultStorage({
|
|
963
|
+
url: ':memory:',
|
|
964
|
+
}),
|
|
965
|
+
workflows: {
|
|
966
|
+
'test-workflow': workflow,
|
|
967
|
+
},
|
|
968
|
+
server: {
|
|
969
|
+
apiRoutes: [
|
|
970
|
+
{
|
|
971
|
+
path: '/inngest/api',
|
|
972
|
+
method: 'ALL',
|
|
973
|
+
createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
|
|
974
|
+
},
|
|
975
|
+
],
|
|
976
|
+
},
|
|
977
|
+
});
|
|
978
|
+
|
|
979
|
+
const app = await createHonoServer(mastra);
|
|
980
|
+
|
|
981
|
+
const srv = (globServer = serve({
|
|
982
|
+
fetch: app.fetch,
|
|
983
|
+
port: (ctx as any).handlerPort,
|
|
984
|
+
}));
|
|
985
|
+
await resetInngest();
|
|
986
|
+
|
|
987
|
+
const run = await workflow.createRunAsync();
|
|
988
|
+
const p = run.start({ inputData: { value: 'test' } });
|
|
989
|
+
|
|
990
|
+
setTimeout(() => {
|
|
991
|
+
run.cancel();
|
|
992
|
+
}, 1000);
|
|
993
|
+
|
|
994
|
+
const result = await p;
|
|
995
|
+
|
|
996
|
+
srv.close();
|
|
997
|
+
|
|
998
|
+
expect(result.status).toBe('canceled');
|
|
999
|
+
expect(result.steps['step1']).toEqual({
|
|
1000
|
+
status: 'success',
|
|
1001
|
+
output: { result: 'step1: test' },
|
|
1002
|
+
payload: { value: 'test' },
|
|
1003
|
+
startedAt: expect.any(Number),
|
|
1004
|
+
endedAt: expect.any(Number),
|
|
1005
|
+
});
|
|
1006
|
+
|
|
1007
|
+
expect(result.steps['step2']).toBeUndefined();
|
|
1008
|
+
});
|
|
1009
|
+
|
|
1010
|
+
it('should be able to abort workflow execution during a step', async ctx => {
|
|
1011
|
+
const inngest = new Inngest({
|
|
1012
|
+
id: 'mastra',
|
|
1013
|
+
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
1014
|
+
middleware: [realtimeMiddleware()],
|
|
1015
|
+
});
|
|
1016
|
+
|
|
1017
|
+
const { createWorkflow, createStep } = init(inngest);
|
|
1018
|
+
|
|
1019
|
+
const step1 = createStep({
|
|
1020
|
+
id: 'step1',
|
|
1021
|
+
execute: async ({ inputData }) => {
|
|
1022
|
+
return { result: 'step1: ' + inputData.value };
|
|
1023
|
+
},
|
|
1024
|
+
inputSchema: z.object({ value: z.string() }),
|
|
1025
|
+
outputSchema: z.object({ result: z.string() }),
|
|
1026
|
+
});
|
|
1027
|
+
const step2 = createStep({
|
|
1028
|
+
id: 'step2',
|
|
1029
|
+
execute: async ({ inputData, abortSignal, abort }) => {
|
|
1030
|
+
console.log('abort signal', abortSignal);
|
|
1031
|
+
const timeout: Promise<string> = new Promise((resolve, _reject) => {
|
|
1032
|
+
const ref = setTimeout(() => {
|
|
1033
|
+
resolve('step2: ' + inputData.result);
|
|
1034
|
+
}, 5000);
|
|
1035
|
+
|
|
1036
|
+
abortSignal.addEventListener('abort', () => {
|
|
1037
|
+
resolve('');
|
|
1038
|
+
clearTimeout(ref);
|
|
1039
|
+
});
|
|
1040
|
+
});
|
|
1041
|
+
|
|
1042
|
+
const result = await timeout;
|
|
1043
|
+
if (abortSignal.aborted) {
|
|
1044
|
+
return abort();
|
|
1045
|
+
}
|
|
1046
|
+
return { result };
|
|
1047
|
+
},
|
|
1048
|
+
inputSchema: z.object({ result: z.string() }),
|
|
1049
|
+
outputSchema: z.object({ result: z.string() }),
|
|
1050
|
+
});
|
|
1051
|
+
|
|
1052
|
+
const workflow = createWorkflow({
|
|
1053
|
+
id: 'test-workflow',
|
|
1054
|
+
inputSchema: z.object({}),
|
|
1055
|
+
outputSchema: z.object({
|
|
1056
|
+
result: z.string(),
|
|
675
1057
|
}),
|
|
676
|
-
steps: [step1],
|
|
1058
|
+
steps: [step1, step2],
|
|
677
1059
|
});
|
|
678
1060
|
|
|
679
|
-
workflow.then(step1).
|
|
1061
|
+
workflow.then(step1).then(step2).commit();
|
|
680
1062
|
|
|
681
1063
|
const mastra = new Mastra({
|
|
682
1064
|
storage: new DefaultStorage({
|
|
@@ -698,37 +1080,40 @@ describe('MastraInngestWorkflow', () => {
|
|
|
698
1080
|
|
|
699
1081
|
const app = await createHonoServer(mastra);
|
|
700
1082
|
|
|
701
|
-
const srv = serve({
|
|
1083
|
+
const srv = (globServer = serve({
|
|
702
1084
|
fetch: app.fetch,
|
|
703
1085
|
port: (ctx as any).handlerPort,
|
|
704
|
-
});
|
|
705
|
-
await
|
|
1086
|
+
}));
|
|
1087
|
+
await resetInngest();
|
|
706
1088
|
|
|
707
1089
|
const run = await workflow.createRunAsync();
|
|
708
|
-
const
|
|
709
|
-
const result = await run.start({ inputData: {} });
|
|
710
|
-
const endTime = Date.now();
|
|
1090
|
+
const p = run.start({ inputData: { value: 'test' } });
|
|
711
1091
|
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
output: { result: 'success' },
|
|
716
|
-
// payload: {},
|
|
717
|
-
// startedAt: expect.any(Number),
|
|
718
|
-
// endedAt: expect.any(Number),
|
|
719
|
-
});
|
|
1092
|
+
setTimeout(() => {
|
|
1093
|
+
run.cancel();
|
|
1094
|
+
}, 1000);
|
|
720
1095
|
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
1096
|
+
const result = await p;
|
|
1097
|
+
console.log('result', result);
|
|
1098
|
+
|
|
1099
|
+
srv.close();
|
|
1100
|
+
|
|
1101
|
+
expect(result.status).toBe('canceled');
|
|
1102
|
+
expect(result.steps['step1']).toEqual({
|
|
1103
|
+
status: 'success',
|
|
1104
|
+
output: { result: 'step1: test' },
|
|
1105
|
+
payload: { value: 'test' },
|
|
725
1106
|
startedAt: expect.any(Number),
|
|
726
1107
|
endedAt: expect.any(Number),
|
|
727
1108
|
});
|
|
728
1109
|
|
|
729
|
-
expect(
|
|
730
|
-
|
|
731
|
-
|
|
1110
|
+
// expect(result.steps['step2']).toEqual({
|
|
1111
|
+
// status: 'canceled',
|
|
1112
|
+
// payload: { result: 'step1: test' },
|
|
1113
|
+
// output: undefined,
|
|
1114
|
+
// startedAt: expect.any(Number),
|
|
1115
|
+
// endedAt: expect.any(Number),
|
|
1116
|
+
// });
|
|
732
1117
|
});
|
|
733
1118
|
});
|
|
734
1119
|
|
|
@@ -784,10 +1169,12 @@ describe('MastraInngestWorkflow', () => {
|
|
|
784
1169
|
|
|
785
1170
|
const app = await createHonoServer(mastra);
|
|
786
1171
|
|
|
787
|
-
const srv = serve({
|
|
1172
|
+
const srv = (globServer = serve({
|
|
788
1173
|
fetch: app.fetch,
|
|
789
1174
|
port: (ctx as any).handlerPort,
|
|
790
|
-
});
|
|
1175
|
+
}));
|
|
1176
|
+
|
|
1177
|
+
await resetInngest();
|
|
791
1178
|
|
|
792
1179
|
const run = await workflow.createRunAsync();
|
|
793
1180
|
const result = await run.start({ inputData: { inputData: 'test-input' } });
|
|
@@ -871,10 +1258,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
871
1258
|
|
|
872
1259
|
const app = await createHonoServer(mastra);
|
|
873
1260
|
|
|
874
|
-
const srv = serve({
|
|
1261
|
+
const srv = (globServer = serve({
|
|
875
1262
|
fetch: app.fetch,
|
|
876
1263
|
port: (ctx as any).handlerPort,
|
|
877
|
-
});
|
|
1264
|
+
}));
|
|
1265
|
+
await resetInngest();
|
|
878
1266
|
|
|
879
1267
|
const run = await workflow.createRunAsync();
|
|
880
1268
|
const result = await run.start({ inputData: { inputValue: 'test-input' } });
|
|
@@ -938,10 +1326,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
938
1326
|
|
|
939
1327
|
const app = await createHonoServer(mastra);
|
|
940
1328
|
|
|
941
|
-
const srv = serve({
|
|
1329
|
+
const srv = (globServer = serve({
|
|
942
1330
|
fetch: app.fetch,
|
|
943
1331
|
port: (ctx as any).handlerPort,
|
|
944
|
-
});
|
|
1332
|
+
}));
|
|
1333
|
+
await resetInngest();
|
|
945
1334
|
|
|
946
1335
|
const run = await workflow.createRunAsync();
|
|
947
1336
|
await run.start({ inputData: { inputData: 'test-input' } });
|
|
@@ -1013,10 +1402,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1013
1402
|
|
|
1014
1403
|
const app = await createHonoServer(mastra);
|
|
1015
1404
|
|
|
1016
|
-
const srv = serve({
|
|
1405
|
+
const srv = (globServer = serve({
|
|
1017
1406
|
fetch: app.fetch,
|
|
1018
1407
|
port: (ctx as any).handlerPort,
|
|
1019
|
-
});
|
|
1408
|
+
}));
|
|
1409
|
+
await resetInngest();
|
|
1020
1410
|
|
|
1021
1411
|
const run = await workflow.createRunAsync();
|
|
1022
1412
|
const result = await run.start({ inputData: { cool: 'test-input' } });
|
|
@@ -1095,10 +1485,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1095
1485
|
|
|
1096
1486
|
const app = await createHonoServer(mastra);
|
|
1097
1487
|
|
|
1098
|
-
const srv = serve({
|
|
1488
|
+
const srv = (globServer = serve({
|
|
1099
1489
|
fetch: app.fetch,
|
|
1100
1490
|
port: (ctx as any).handlerPort,
|
|
1101
|
-
});
|
|
1491
|
+
}));
|
|
1492
|
+
await resetInngest();
|
|
1102
1493
|
|
|
1103
1494
|
const run = await workflow.createRunAsync();
|
|
1104
1495
|
await run.start({ inputData: {} });
|
|
@@ -1198,10 +1589,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1198
1589
|
|
|
1199
1590
|
const app = await createHonoServer(mastra);
|
|
1200
1591
|
|
|
1201
|
-
const srv = serve({
|
|
1592
|
+
const srv = (globServer = serve({
|
|
1202
1593
|
fetch: app.fetch,
|
|
1203
1594
|
port: (ctx as any).handlerPort,
|
|
1204
|
-
});
|
|
1595
|
+
}));
|
|
1596
|
+
await resetInngest();
|
|
1205
1597
|
|
|
1206
1598
|
const run = await workflow.createRunAsync();
|
|
1207
1599
|
const result = await run.start({ inputData: { status: 'success' } });
|
|
@@ -1274,10 +1666,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1274
1666
|
|
|
1275
1667
|
const app = await createHonoServer(mastra);
|
|
1276
1668
|
|
|
1277
|
-
const srv = serve({
|
|
1669
|
+
const srv = (globServer = serve({
|
|
1278
1670
|
fetch: app.fetch,
|
|
1279
1671
|
port: (ctx as any).handlerPort,
|
|
1280
|
-
});
|
|
1672
|
+
}));
|
|
1673
|
+
await resetInngest();
|
|
1281
1674
|
|
|
1282
1675
|
const run = await workflow.createRunAsync();
|
|
1283
1676
|
let result: Awaited<ReturnType<typeof run.start>> | undefined = undefined;
|
|
@@ -1379,10 +1772,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1379
1772
|
|
|
1380
1773
|
const app = await createHonoServer(mastra);
|
|
1381
1774
|
|
|
1382
|
-
const srv = serve({
|
|
1775
|
+
const srv = (globServer = serve({
|
|
1383
1776
|
fetch: app.fetch,
|
|
1384
1777
|
port: (ctx as any).handlerPort,
|
|
1385
|
-
});
|
|
1778
|
+
}));
|
|
1779
|
+
await resetInngest();
|
|
1386
1780
|
|
|
1387
1781
|
const run = await workflow.createRunAsync();
|
|
1388
1782
|
const result = await run.start({ inputData: { status: 'success' } });
|
|
@@ -1462,10 +1856,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1462
1856
|
|
|
1463
1857
|
const app = await createHonoServer(mastra);
|
|
1464
1858
|
|
|
1465
|
-
const srv = serve({
|
|
1859
|
+
const srv = (globServer = serve({
|
|
1466
1860
|
fetch: app.fetch,
|
|
1467
1861
|
port: (ctx as any).handlerPort,
|
|
1468
|
-
});
|
|
1862
|
+
}));
|
|
1863
|
+
await resetInngest();
|
|
1469
1864
|
|
|
1470
1865
|
const run = await workflow.createRunAsync();
|
|
1471
1866
|
const result = await run.start({ inputData: { count: 5 } });
|
|
@@ -1529,11 +1924,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1529
1924
|
|
|
1530
1925
|
const app = await createHonoServer(mastra);
|
|
1531
1926
|
|
|
1532
|
-
const srv = serve({
|
|
1927
|
+
const srv = (globServer = serve({
|
|
1533
1928
|
fetch: app.fetch,
|
|
1534
1929
|
port: (ctx as any).handlerPort,
|
|
1535
|
-
});
|
|
1536
|
-
await
|
|
1930
|
+
}));
|
|
1931
|
+
await resetInngest();
|
|
1537
1932
|
|
|
1538
1933
|
const run = await workflow.createRunAsync();
|
|
1539
1934
|
|
|
@@ -1613,11 +2008,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1613
2008
|
|
|
1614
2009
|
const app = await createHonoServer(mastra);
|
|
1615
2010
|
|
|
1616
|
-
const srv = serve({
|
|
2011
|
+
const srv = (globServer = serve({
|
|
1617
2012
|
fetch: app.fetch,
|
|
1618
2013
|
port: (ctx as any).handlerPort,
|
|
1619
|
-
});
|
|
1620
|
-
await
|
|
2014
|
+
}));
|
|
2015
|
+
await resetInngest();
|
|
1621
2016
|
|
|
1622
2017
|
const run = await workflow.createRunAsync();
|
|
1623
2018
|
const result = await run.start({ inputData: {} });
|
|
@@ -1707,11 +2102,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1707
2102
|
|
|
1708
2103
|
const app = await createHonoServer(mastra);
|
|
1709
2104
|
|
|
1710
|
-
const srv = serve({
|
|
2105
|
+
const srv = (globServer = serve({
|
|
1711
2106
|
fetch: app.fetch,
|
|
1712
2107
|
port: (ctx as any).handlerPort,
|
|
1713
|
-
});
|
|
1714
|
-
await
|
|
2108
|
+
}));
|
|
2109
|
+
await resetInngest();
|
|
1715
2110
|
|
|
1716
2111
|
const run = await mainWorkflow.createRunAsync();
|
|
1717
2112
|
const result = await run.start({ inputData: {} });
|
|
@@ -1835,11 +2230,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1835
2230
|
|
|
1836
2231
|
const app = await createHonoServer(mastra);
|
|
1837
2232
|
|
|
1838
|
-
const srv = serve({
|
|
2233
|
+
const srv = (globServer = serve({
|
|
1839
2234
|
fetch: app.fetch,
|
|
1840
2235
|
port: (ctx as any).handlerPort,
|
|
1841
|
-
});
|
|
1842
|
-
await
|
|
2236
|
+
}));
|
|
2237
|
+
await resetInngest();
|
|
1843
2238
|
|
|
1844
2239
|
const run = await workflow.createRunAsync();
|
|
1845
2240
|
const result = await run.start({ inputData: {} });
|
|
@@ -1937,11 +2332,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
1937
2332
|
|
|
1938
2333
|
const app = await createHonoServer(mastra);
|
|
1939
2334
|
|
|
1940
|
-
const srv = serve({
|
|
2335
|
+
const srv = (globServer = serve({
|
|
1941
2336
|
fetch: app.fetch,
|
|
1942
2337
|
port: (ctx as any).handlerPort,
|
|
1943
|
-
});
|
|
1944
|
-
await
|
|
2338
|
+
}));
|
|
2339
|
+
await resetInngest();
|
|
1945
2340
|
|
|
1946
2341
|
const run = await counterWorkflow.createRunAsync();
|
|
1947
2342
|
const result = await run.start({ inputData: { target: 10, value: 0 } });
|
|
@@ -2040,11 +2435,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2040
2435
|
|
|
2041
2436
|
const app = await createHonoServer(mastra);
|
|
2042
2437
|
|
|
2043
|
-
const srv = serve({
|
|
2438
|
+
const srv = (globServer = serve({
|
|
2044
2439
|
fetch: app.fetch,
|
|
2045
2440
|
port: (ctx as any).handlerPort,
|
|
2046
|
-
});
|
|
2047
|
-
await
|
|
2441
|
+
}));
|
|
2442
|
+
await resetInngest();
|
|
2048
2443
|
|
|
2049
2444
|
const run = await counterWorkflow.createRunAsync();
|
|
2050
2445
|
const result = await run.start({ inputData: { target: 10, value: 0 } });
|
|
@@ -2129,11 +2524,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2129
2524
|
|
|
2130
2525
|
const app = await createHonoServer(mastra);
|
|
2131
2526
|
|
|
2132
|
-
const srv = serve({
|
|
2527
|
+
const srv = (globServer = serve({
|
|
2133
2528
|
fetch: app.fetch,
|
|
2134
2529
|
port: (ctx as any).handlerPort,
|
|
2135
|
-
});
|
|
2136
|
-
await
|
|
2530
|
+
}));
|
|
2531
|
+
await resetInngest();
|
|
2137
2532
|
|
|
2138
2533
|
const run = await counterWorkflow.createRunAsync();
|
|
2139
2534
|
const result = await run.start({ inputData: [{ value: 1 }, { value: 22 }, { value: 333 }] });
|
|
@@ -2282,11 +2677,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2282
2677
|
|
|
2283
2678
|
const app = await createHonoServer(mastra);
|
|
2284
2679
|
|
|
2285
|
-
const srv = serve({
|
|
2680
|
+
const srv = (globServer = serve({
|
|
2286
2681
|
fetch: app.fetch,
|
|
2287
2682
|
port: (ctx as any).handlerPort,
|
|
2288
|
-
});
|
|
2289
|
-
await
|
|
2683
|
+
}));
|
|
2684
|
+
await resetInngest();
|
|
2290
2685
|
|
|
2291
2686
|
const run = await counterWorkflow.createRunAsync();
|
|
2292
2687
|
const result = await run.start({ inputData: { startValue: 1 } });
|
|
@@ -2431,15 +2826,17 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2431
2826
|
|
|
2432
2827
|
const app = await createHonoServer(mastra);
|
|
2433
2828
|
|
|
2434
|
-
const srv = serve({
|
|
2829
|
+
const srv = (globServer = serve({
|
|
2435
2830
|
fetch: app.fetch,
|
|
2436
2831
|
port: (ctx as any).handlerPort,
|
|
2437
|
-
});
|
|
2438
|
-
await
|
|
2832
|
+
}));
|
|
2833
|
+
await resetInngest();
|
|
2439
2834
|
|
|
2440
2835
|
const run = await counterWorkflow.createRunAsync();
|
|
2441
2836
|
const result = await run.start({ inputData: { startValue: 6 } });
|
|
2442
2837
|
|
|
2838
|
+
srv.close();
|
|
2839
|
+
|
|
2443
2840
|
expect(start).toHaveBeenCalledTimes(1);
|
|
2444
2841
|
expect(other).toHaveBeenCalledTimes(1);
|
|
2445
2842
|
expect(final).toHaveBeenCalledTimes(1);
|
|
@@ -2447,8 +2844,6 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2447
2844
|
expect(result.steps['else-branch'].output).toMatchObject({ finalValue: 26 + 6 + 1 });
|
|
2448
2845
|
// @ts-ignore
|
|
2449
2846
|
expect(result.steps.start.output).toMatchObject({ newValue: 7 });
|
|
2450
|
-
|
|
2451
|
-
srv.close();
|
|
2452
2847
|
});
|
|
2453
2848
|
});
|
|
2454
2849
|
|
|
@@ -2603,19 +2998,19 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2603
2998
|
|
|
2604
2999
|
const app = await createHonoServer(mastra);
|
|
2605
3000
|
|
|
2606
|
-
const srv = serve({
|
|
3001
|
+
const srv = (globServer = serve({
|
|
2607
3002
|
fetch: app.fetch,
|
|
2608
3003
|
port: (ctx as any).handlerPort,
|
|
2609
|
-
});
|
|
2610
|
-
await
|
|
3004
|
+
}));
|
|
3005
|
+
await resetInngest();
|
|
2611
3006
|
|
|
2612
3007
|
const run = await workflow.createRunAsync();
|
|
2613
3008
|
const result = await run.start({ inputData: {} });
|
|
2614
3009
|
|
|
3010
|
+
srv.close();
|
|
3011
|
+
|
|
2615
3012
|
expect(result.steps['nested-a']).toMatchObject({ status: 'success', output: { result: 'success3' } });
|
|
2616
3013
|
expect(result.steps['nested-b']).toMatchObject({ status: 'success', output: { result: 'success5' } });
|
|
2617
|
-
|
|
2618
|
-
srv.close();
|
|
2619
3014
|
});
|
|
2620
3015
|
});
|
|
2621
3016
|
|
|
@@ -2669,21 +3064,21 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2669
3064
|
|
|
2670
3065
|
const app = await createHonoServer(mastra);
|
|
2671
3066
|
|
|
2672
|
-
const srv = serve({
|
|
3067
|
+
const srv = (globServer = serve({
|
|
2673
3068
|
fetch: app.fetch,
|
|
2674
3069
|
port: (ctx as any).handlerPort,
|
|
2675
|
-
});
|
|
2676
|
-
await
|
|
3070
|
+
}));
|
|
3071
|
+
await resetInngest();
|
|
2677
3072
|
|
|
2678
3073
|
const run = await workflow.createRunAsync();
|
|
2679
3074
|
const result = await run.start({ inputData: {} });
|
|
2680
3075
|
|
|
3076
|
+
srv.close();
|
|
3077
|
+
|
|
2681
3078
|
expect(result.steps.step1).toMatchObject({ status: 'success', output: { result: 'success' } });
|
|
2682
3079
|
expect(result.steps.step2).toMatchObject({ status: 'failed', error: 'Step failed' });
|
|
2683
3080
|
expect(step1.execute).toHaveBeenCalledTimes(1);
|
|
2684
3081
|
expect(step2.execute).toHaveBeenCalledTimes(1); // 0 retries + 1 initial call
|
|
2685
|
-
|
|
2686
|
-
srv.close();
|
|
2687
3082
|
});
|
|
2688
3083
|
|
|
2689
3084
|
// Need to fix so we can throw for inngest to recognize retries
|
|
@@ -2801,11 +3196,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2801
3196
|
|
|
2802
3197
|
const app = await createHonoServer(mastra);
|
|
2803
3198
|
|
|
2804
|
-
const srv = serve({
|
|
3199
|
+
const srv = (globServer = serve({
|
|
2805
3200
|
fetch: app.fetch,
|
|
2806
3201
|
port: (ctx as any).handlerPort,
|
|
2807
|
-
});
|
|
2808
|
-
await
|
|
3202
|
+
}));
|
|
3203
|
+
await resetInngest();
|
|
2809
3204
|
|
|
2810
3205
|
const run = await workflow.createRunAsync();
|
|
2811
3206
|
const result = await run.start({ inputData: {} });
|
|
@@ -2873,11 +3268,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2873
3268
|
|
|
2874
3269
|
const app = await createHonoServer(mastra);
|
|
2875
3270
|
|
|
2876
|
-
const srv = serve({
|
|
3271
|
+
const srv = (globServer = serve({
|
|
2877
3272
|
fetch: app.fetch,
|
|
2878
3273
|
port: (ctx as any).handlerPort,
|
|
2879
|
-
});
|
|
2880
|
-
await
|
|
3274
|
+
}));
|
|
3275
|
+
await resetInngest();
|
|
2881
3276
|
|
|
2882
3277
|
const run = await workflow.createRunAsync();
|
|
2883
3278
|
|
|
@@ -2890,7 +3285,9 @@ describe('MastraInngestWorkflow', () => {
|
|
|
2890
3285
|
});
|
|
2891
3286
|
|
|
2892
3287
|
const executionResult = await run.start({ inputData: {} });
|
|
2893
|
-
await new Promise(resolve => setTimeout(resolve,
|
|
3288
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
3289
|
+
|
|
3290
|
+
srv.close();
|
|
2894
3291
|
|
|
2895
3292
|
expect(cnt).toBe(5);
|
|
2896
3293
|
expect(resps.length).toBe(5);
|
|
@@ -3002,8 +3399,6 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3002
3399
|
status: 'success',
|
|
3003
3400
|
output: { result: 'success2' },
|
|
3004
3401
|
});
|
|
3005
|
-
|
|
3006
|
-
srv.close();
|
|
3007
3402
|
});
|
|
3008
3403
|
|
|
3009
3404
|
it('should unsubscribe from transitions when unwatch is called', async ctx => {
|
|
@@ -3059,11 +3454,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3059
3454
|
|
|
3060
3455
|
const app = await createHonoServer(mastra);
|
|
3061
3456
|
|
|
3062
|
-
const srv = serve({
|
|
3457
|
+
const srv = (globServer = serve({
|
|
3063
3458
|
fetch: app.fetch,
|
|
3064
3459
|
port: (ctx as any).handlerPort,
|
|
3065
|
-
});
|
|
3066
|
-
await
|
|
3460
|
+
}));
|
|
3461
|
+
await resetInngest();
|
|
3067
3462
|
|
|
3068
3463
|
const onTransition = vi.fn();
|
|
3069
3464
|
const onTransition2 = vi.fn();
|
|
@@ -3231,11 +3626,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3231
3626
|
|
|
3232
3627
|
const app = await createHonoServer(mastra);
|
|
3233
3628
|
|
|
3234
|
-
const srv = serve({
|
|
3629
|
+
const srv = (globServer = serve({
|
|
3235
3630
|
fetch: app.fetch,
|
|
3236
3631
|
port: (ctx as any).handlerPort,
|
|
3237
|
-
});
|
|
3238
|
-
await
|
|
3632
|
+
}));
|
|
3633
|
+
await resetInngest();
|
|
3239
3634
|
|
|
3240
3635
|
const run = await promptEvalWorkflow.createRunAsync();
|
|
3241
3636
|
|
|
@@ -3381,11 +3776,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3381
3776
|
|
|
3382
3777
|
const app = await createHonoServer(mastra);
|
|
3383
3778
|
|
|
3384
|
-
const srv = serve({
|
|
3779
|
+
const srv = (globServer = serve({
|
|
3385
3780
|
fetch: app.fetch,
|
|
3386
3781
|
port: (ctx as any).handlerPort,
|
|
3387
|
-
});
|
|
3388
|
-
await
|
|
3782
|
+
}));
|
|
3783
|
+
await resetInngest();
|
|
3389
3784
|
|
|
3390
3785
|
const run = await workflow.createRunAsync();
|
|
3391
3786
|
|
|
@@ -3419,13 +3814,13 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3419
3814
|
|
|
3420
3815
|
const initialResult = await started;
|
|
3421
3816
|
|
|
3817
|
+
srv.close();
|
|
3818
|
+
|
|
3422
3819
|
expect(initialResult.steps.humanIntervention.status).toBe('suspended');
|
|
3423
3820
|
expect(initialResult.steps.explainResponse).toBeUndefined();
|
|
3424
3821
|
expect(humanInterventionAction).toHaveBeenCalledTimes(2);
|
|
3425
3822
|
expect(explainResponseAction).not.toHaveBeenCalled();
|
|
3426
3823
|
|
|
3427
|
-
srv.close();
|
|
3428
|
-
|
|
3429
3824
|
if (!result) {
|
|
3430
3825
|
throw new Error('Resume failed to return a result');
|
|
3431
3826
|
}
|
|
@@ -3583,11 +3978,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3583
3978
|
|
|
3584
3979
|
const app = await createHonoServer(mastra);
|
|
3585
3980
|
|
|
3586
|
-
const srv = serve({
|
|
3981
|
+
const srv = (globServer = serve({
|
|
3587
3982
|
fetch: app.fetch,
|
|
3588
3983
|
port: (ctx as any).handlerPort,
|
|
3589
|
-
});
|
|
3590
|
-
await
|
|
3984
|
+
}));
|
|
3985
|
+
await resetInngest();
|
|
3591
3986
|
|
|
3592
3987
|
const run = await workflow.createRunAsync();
|
|
3593
3988
|
const started = run.start({ inputData: { input: 'test' } });
|
|
@@ -3640,11 +4035,12 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3640
4035
|
// @ts-ignore
|
|
3641
4036
|
const improvedResponseResult = await improvedResponseResultPromise;
|
|
3642
4037
|
|
|
4038
|
+
srv.close();
|
|
4039
|
+
|
|
3643
4040
|
expect(improvedResponseResult?.steps.humanIntervention.status).toBe('suspended');
|
|
3644
4041
|
expect(improvedResponseResult?.steps.improveResponse.status).toBe('success');
|
|
3645
4042
|
expect(improvedResponseResult?.steps.evaluateImprovedResponse.status).toBe('success');
|
|
3646
4043
|
|
|
3647
|
-
srv.close();
|
|
3648
4044
|
if (!result) {
|
|
3649
4045
|
throw new Error('Resume failed to return a result');
|
|
3650
4046
|
}
|
|
@@ -3777,11 +4173,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3777
4173
|
|
|
3778
4174
|
const app = await createHonoServer(mastra);
|
|
3779
4175
|
|
|
3780
|
-
const srv = serve({
|
|
4176
|
+
const srv = (globServer = serve({
|
|
3781
4177
|
fetch: app.fetch,
|
|
3782
4178
|
port: (ctx as any).handlerPort,
|
|
3783
|
-
});
|
|
3784
|
-
await
|
|
4179
|
+
}));
|
|
4180
|
+
await resetInngest();
|
|
3785
4181
|
|
|
3786
4182
|
const run = await promptEvalWorkflow.createRunAsync();
|
|
3787
4183
|
|
|
@@ -3836,6 +4232,9 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3836
4232
|
completenessScore: { score: 0.7 },
|
|
3837
4233
|
},
|
|
3838
4234
|
});
|
|
4235
|
+
|
|
4236
|
+
srv.close();
|
|
4237
|
+
|
|
3839
4238
|
if (!secondResumeResult) {
|
|
3840
4239
|
throw new Error('Resume failed to return a result');
|
|
3841
4240
|
}
|
|
@@ -3858,6 +4257,122 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3858
4257
|
});
|
|
3859
4258
|
|
|
3860
4259
|
expect(promptAgentAction).toHaveBeenCalledTimes(2);
|
|
4260
|
+
});
|
|
4261
|
+
|
|
4262
|
+
it('should handle consecutive nested workflows with suspend/resume', async ctx => {
|
|
4263
|
+
const inngest = new Inngest({
|
|
4264
|
+
id: 'mastra',
|
|
4265
|
+
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
4266
|
+
middleware: [realtimeMiddleware()],
|
|
4267
|
+
});
|
|
4268
|
+
|
|
4269
|
+
const { createWorkflow, createStep } = init(inngest);
|
|
4270
|
+
|
|
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
|
+
});
|
|
3861
4376
|
|
|
3862
4377
|
srv.close();
|
|
3863
4378
|
});
|
|
@@ -3905,11 +4420,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
3905
4420
|
|
|
3906
4421
|
const app = await createHonoServer(mastra);
|
|
3907
4422
|
|
|
3908
|
-
const srv = serve({
|
|
4423
|
+
const srv = (globServer = serve({
|
|
3909
4424
|
fetch: app.fetch,
|
|
3910
4425
|
port: (ctx as any).handlerPort,
|
|
3911
|
-
});
|
|
3912
|
-
await
|
|
4426
|
+
}));
|
|
4427
|
+
await resetInngest();
|
|
3913
4428
|
|
|
3914
4429
|
// Access new instance properties directly - should work without warning
|
|
3915
4430
|
const run = await workflow.createRunAsync();
|
|
@@ -4009,11 +4524,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
4009
4524
|
|
|
4010
4525
|
const app = await createHonoServer(mastra);
|
|
4011
4526
|
|
|
4012
|
-
const srv = serve({
|
|
4527
|
+
const srv = (globServer = serve({
|
|
4013
4528
|
fetch: app.fetch,
|
|
4014
4529
|
port: (ctx as any).handlerPort,
|
|
4015
|
-
});
|
|
4016
|
-
await
|
|
4530
|
+
}));
|
|
4531
|
+
await resetInngest();
|
|
4017
4532
|
|
|
4018
4533
|
const run = await workflow.createRunAsync();
|
|
4019
4534
|
const result = await run.start({
|
|
@@ -4146,11 +4661,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
4146
4661
|
|
|
4147
4662
|
const app = await createHonoServer(mastra);
|
|
4148
4663
|
|
|
4149
|
-
const srv = serve({
|
|
4664
|
+
const srv = (globServer = serve({
|
|
4150
4665
|
fetch: app.fetch,
|
|
4151
4666
|
port: (ctx as any).handlerPort,
|
|
4152
|
-
});
|
|
4153
|
-
await
|
|
4667
|
+
}));
|
|
4668
|
+
await resetInngest();
|
|
4154
4669
|
|
|
4155
4670
|
const run = await workflow.createRunAsync();
|
|
4156
4671
|
const result = await run.start({
|
|
@@ -4289,11 +4804,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
4289
4804
|
|
|
4290
4805
|
const app = await createHonoServer(mastra);
|
|
4291
4806
|
|
|
4292
|
-
const srv = serve({
|
|
4807
|
+
const srv = (globServer = serve({
|
|
4293
4808
|
fetch: app.fetch,
|
|
4294
4809
|
port: (ctx as any).handlerPort,
|
|
4295
|
-
});
|
|
4296
|
-
await
|
|
4810
|
+
}));
|
|
4811
|
+
await resetInngest();
|
|
4297
4812
|
|
|
4298
4813
|
const run = await counterWorkflow.createRunAsync();
|
|
4299
4814
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
@@ -4441,11 +4956,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
4441
4956
|
|
|
4442
4957
|
const app = await createHonoServer(mastra);
|
|
4443
4958
|
|
|
4444
|
-
const srv = serve({
|
|
4959
|
+
const srv = (globServer = serve({
|
|
4445
4960
|
fetch: app.fetch,
|
|
4446
4961
|
port: (ctx as any).handlerPort,
|
|
4447
|
-
});
|
|
4448
|
-
await
|
|
4962
|
+
}));
|
|
4963
|
+
await resetInngest();
|
|
4449
4964
|
|
|
4450
4965
|
const run = await counterWorkflow.createRunAsync();
|
|
4451
4966
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
@@ -4601,10 +5116,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
4601
5116
|
await next();
|
|
4602
5117
|
});
|
|
4603
5118
|
|
|
4604
|
-
const srv = serve({
|
|
5119
|
+
const srv = (globServer = serve({
|
|
4605
5120
|
fetch: app.fetch,
|
|
4606
5121
|
port: (ctx as any).handlerPort,
|
|
4607
|
-
});
|
|
5122
|
+
}));
|
|
5123
|
+
await resetInngest();
|
|
4608
5124
|
|
|
4609
5125
|
const run = await counterWorkflow.createRunAsync();
|
|
4610
5126
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
@@ -4760,10 +5276,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
4760
5276
|
await next();
|
|
4761
5277
|
});
|
|
4762
5278
|
|
|
4763
|
-
const srv = serve({
|
|
5279
|
+
const srv = (globServer = serve({
|
|
4764
5280
|
fetch: app.fetch,
|
|
4765
5281
|
port: (ctx as any).handlerPort,
|
|
4766
|
-
});
|
|
5282
|
+
}));
|
|
5283
|
+
await resetInngest();
|
|
4767
5284
|
|
|
4768
5285
|
const run = await counterWorkflow.createRunAsync();
|
|
4769
5286
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
@@ -4957,10 +5474,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
4957
5474
|
await next();
|
|
4958
5475
|
});
|
|
4959
5476
|
|
|
4960
|
-
const srv = serve({
|
|
5477
|
+
const srv = (globServer = serve({
|
|
4961
5478
|
fetch: app.fetch,
|
|
4962
5479
|
port: (ctx as any).handlerPort,
|
|
4963
|
-
});
|
|
5480
|
+
}));
|
|
5481
|
+
await resetInngest();
|
|
4964
5482
|
|
|
4965
5483
|
const run = await counterWorkflow.createRunAsync();
|
|
4966
5484
|
const result = await run.start({ inputData: { startValue: 1 } });
|
|
@@ -5110,11 +5628,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5110
5628
|
|
|
5111
5629
|
const app = await createHonoServer(mastra);
|
|
5112
5630
|
|
|
5113
|
-
const srv = serve({
|
|
5631
|
+
const srv = (globServer = serve({
|
|
5114
5632
|
fetch: app.fetch,
|
|
5115
5633
|
port: (ctx as any).handlerPort,
|
|
5116
|
-
});
|
|
5117
|
-
await
|
|
5634
|
+
}));
|
|
5635
|
+
await resetInngest();
|
|
5118
5636
|
|
|
5119
5637
|
const run = await counterWorkflow.createRunAsync();
|
|
5120
5638
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
@@ -5261,10 +5779,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5261
5779
|
await next();
|
|
5262
5780
|
});
|
|
5263
5781
|
|
|
5264
|
-
const srv = serve({
|
|
5782
|
+
const srv = (globServer = serve({
|
|
5265
5783
|
fetch: app.fetch,
|
|
5266
5784
|
port: (ctx as any).handlerPort,
|
|
5267
|
-
});
|
|
5785
|
+
}));
|
|
5786
|
+
await resetInngest();
|
|
5268
5787
|
|
|
5269
5788
|
const run = await counterWorkflow.createRunAsync();
|
|
5270
5789
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
@@ -5442,11 +5961,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5442
5961
|
|
|
5443
5962
|
const app = await createHonoServer(mastra);
|
|
5444
5963
|
|
|
5445
|
-
const srv = serve({
|
|
5964
|
+
const srv = (globServer = serve({
|
|
5446
5965
|
fetch: app.fetch,
|
|
5447
5966
|
port: (ctx as any).handlerPort,
|
|
5448
|
-
});
|
|
5449
|
-
await
|
|
5967
|
+
}));
|
|
5968
|
+
await resetInngest();
|
|
5450
5969
|
|
|
5451
5970
|
const run = await counterWorkflow.createRunAsync();
|
|
5452
5971
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
@@ -5604,11 +6123,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5604
6123
|
|
|
5605
6124
|
const app = await createHonoServer(mastra);
|
|
5606
6125
|
|
|
5607
|
-
const srv = serve({
|
|
6126
|
+
const srv = (globServer = serve({
|
|
5608
6127
|
fetch: app.fetch,
|
|
5609
6128
|
port: (ctx as any).handlerPort,
|
|
5610
|
-
});
|
|
5611
|
-
await
|
|
6129
|
+
}));
|
|
6130
|
+
await resetInngest();
|
|
5612
6131
|
|
|
5613
6132
|
const run = await counterWorkflow.createRunAsync();
|
|
5614
6133
|
const result = await run.start({ inputData: { startValue: 0 } });
|
|
@@ -5679,11 +6198,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5679
6198
|
|
|
5680
6199
|
const app = await createHonoServer(mastra);
|
|
5681
6200
|
|
|
5682
|
-
const srv = serve({
|
|
6201
|
+
const srv = (globServer = serve({
|
|
5683
6202
|
fetch: app.fetch,
|
|
5684
6203
|
port: (ctx as any).handlerPort,
|
|
5685
|
-
});
|
|
5686
|
-
await
|
|
6204
|
+
}));
|
|
6205
|
+
await resetInngest();
|
|
5687
6206
|
|
|
5688
6207
|
// Access new instance properties directly - should work without warning
|
|
5689
6208
|
const run = await workflow.createRunAsync();
|
|
@@ -5742,10 +6261,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5742
6261
|
|
|
5743
6262
|
const app = await createHonoServer(mastra);
|
|
5744
6263
|
|
|
5745
|
-
const srv = serve({
|
|
6264
|
+
const srv = (globServer = serve({
|
|
5746
6265
|
fetch: app.fetch,
|
|
5747
6266
|
port: (ctx as any).handlerPort,
|
|
5748
|
-
});
|
|
6267
|
+
}));
|
|
6268
|
+
await resetInngest();
|
|
5749
6269
|
|
|
5750
6270
|
const run = await workflow.createRunAsync();
|
|
5751
6271
|
const result = await run.start({ runtimeContext });
|
|
@@ -5756,7 +6276,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5756
6276
|
expect(result.steps.step1.output.injectedValue).toBe(testValue);
|
|
5757
6277
|
});
|
|
5758
6278
|
|
|
5759
|
-
it('should inject runtimeContext dependencies into steps during resume', async ctx => {
|
|
6279
|
+
it.skip('should inject runtimeContext dependencies into steps during resume', async ctx => {
|
|
5760
6280
|
const inngest = new Inngest({
|
|
5761
6281
|
id: 'mastra',
|
|
5762
6282
|
baseUrl: `http://localhost:${(ctx as any).inngestPort}`,
|
|
@@ -5800,22 +6320,192 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5800
6320
|
});
|
|
5801
6321
|
workflow.then(step).commit();
|
|
5802
6322
|
|
|
5803
|
-
const run = await workflow.createRunAsync();
|
|
5804
|
-
await run.start({ runtimeContext });
|
|
6323
|
+
const run = await workflow.createRunAsync();
|
|
6324
|
+
await run.start({ runtimeContext });
|
|
6325
|
+
|
|
6326
|
+
const resumeruntimeContext = new RuntimeContext();
|
|
6327
|
+
resumeruntimeContext.set('testKey', testValue + '2');
|
|
6328
|
+
|
|
6329
|
+
const result = await run.resume({
|
|
6330
|
+
step: step,
|
|
6331
|
+
resumeData: {
|
|
6332
|
+
human: true,
|
|
6333
|
+
},
|
|
6334
|
+
runtimeContext: resumeruntimeContext,
|
|
6335
|
+
});
|
|
6336
|
+
|
|
6337
|
+
// @ts-ignore
|
|
6338
|
+
expect(result?.steps.step1.output.injectedValue).toBe(testValue + '2');
|
|
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
|
+
});
|
|
5805
6498
|
|
|
5806
|
-
const
|
|
5807
|
-
|
|
6499
|
+
const run = await incrementWorkflow.createRunAsync();
|
|
6500
|
+
const result = await run.start({ inputData: { value: 0 } });
|
|
6501
|
+
expect(result.status).toBe('suspended');
|
|
5808
6502
|
|
|
5809
|
-
const
|
|
5810
|
-
|
|
5811
|
-
|
|
5812
|
-
human: true,
|
|
5813
|
-
},
|
|
5814
|
-
runtimeContext: resumeruntimeContext,
|
|
6503
|
+
const resumeResult = await run.resume({
|
|
6504
|
+
resumeData: { value: 21 },
|
|
6505
|
+
step: ['resume'],
|
|
5815
6506
|
});
|
|
5816
6507
|
|
|
5817
|
-
|
|
5818
|
-
expect(result?.steps.step1.output.injectedValue).toBe(testValue + '2');
|
|
6508
|
+
expect(resumeResult.status).toBe('success');
|
|
5819
6509
|
});
|
|
5820
6510
|
});
|
|
5821
6511
|
|
|
@@ -5867,10 +6557,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5867
6557
|
|
|
5868
6558
|
const app = await createHonoServer(mastra);
|
|
5869
6559
|
|
|
5870
|
-
const srv = serve({
|
|
6560
|
+
const srv = (globServer = serve({
|
|
5871
6561
|
fetch: app.fetch,
|
|
5872
6562
|
port: (ctx as any).handlerPort,
|
|
5873
|
-
});
|
|
6563
|
+
}));
|
|
6564
|
+
await resetInngest();
|
|
5874
6565
|
|
|
5875
6566
|
const run = await workflow.createRunAsync();
|
|
5876
6567
|
const result = await run.start({});
|
|
@@ -5936,10 +6627,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5936
6627
|
|
|
5937
6628
|
const app = await createHonoServer(mastra);
|
|
5938
6629
|
|
|
5939
|
-
const srv = serve({
|
|
6630
|
+
const srv = (globServer = serve({
|
|
5940
6631
|
fetch: app.fetch,
|
|
5941
6632
|
port: (ctx as any).handlerPort,
|
|
5942
|
-
});
|
|
6633
|
+
}));
|
|
6634
|
+
await resetInngest();
|
|
5943
6635
|
|
|
5944
6636
|
const runId = 'test-run-id';
|
|
5945
6637
|
let watchData: StreamEvent[] = [];
|
|
@@ -5947,7 +6639,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5947
6639
|
runId,
|
|
5948
6640
|
});
|
|
5949
6641
|
|
|
5950
|
-
await
|
|
6642
|
+
await resetInngest();
|
|
5951
6643
|
|
|
5952
6644
|
const { stream, getWorkflowState } = run.stream({ inputData: {} });
|
|
5953
6645
|
|
|
@@ -5960,7 +6652,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
5960
6652
|
|
|
5961
6653
|
const executionResult = await getWorkflowState();
|
|
5962
6654
|
|
|
5963
|
-
await
|
|
6655
|
+
await resetInngest();
|
|
5964
6656
|
|
|
5965
6657
|
srv.close();
|
|
5966
6658
|
|
|
@@ -6107,10 +6799,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6107
6799
|
|
|
6108
6800
|
const app = await createHonoServer(mastra);
|
|
6109
6801
|
|
|
6110
|
-
const srv = serve({
|
|
6802
|
+
const srv = (globServer = serve({
|
|
6111
6803
|
fetch: app.fetch,
|
|
6112
6804
|
port: (ctx as any).handlerPort,
|
|
6113
|
-
});
|
|
6805
|
+
}));
|
|
6806
|
+
await resetInngest();
|
|
6114
6807
|
|
|
6115
6808
|
const runId = 'test-run-id';
|
|
6116
6809
|
let watchData: StreamEvent[] = [];
|
|
@@ -6118,7 +6811,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6118
6811
|
runId,
|
|
6119
6812
|
});
|
|
6120
6813
|
|
|
6121
|
-
await
|
|
6814
|
+
await resetInngest();
|
|
6122
6815
|
|
|
6123
6816
|
const { stream, getWorkflowState } = run.stream({ inputData: {} });
|
|
6124
6817
|
|
|
@@ -6131,11 +6824,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6131
6824
|
|
|
6132
6825
|
const executionResult = await getWorkflowState();
|
|
6133
6826
|
|
|
6134
|
-
await
|
|
6827
|
+
await resetInngest();
|
|
6135
6828
|
|
|
6136
6829
|
srv.close();
|
|
6137
6830
|
|
|
6138
|
-
expect(watchData.length).toBe(
|
|
6831
|
+
expect(watchData.length).toBe(11);
|
|
6139
6832
|
expect(watchData).toMatchObject([
|
|
6140
6833
|
{
|
|
6141
6834
|
payload: {
|
|
@@ -6146,6 +6839,9 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6146
6839
|
{
|
|
6147
6840
|
payload: {
|
|
6148
6841
|
id: 'step1',
|
|
6842
|
+
startedAt: expect.any(Number),
|
|
6843
|
+
status: 'running',
|
|
6844
|
+
payload: {},
|
|
6149
6845
|
},
|
|
6150
6846
|
type: 'step-start',
|
|
6151
6847
|
},
|
|
@@ -6155,6 +6851,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6155
6851
|
output: {
|
|
6156
6852
|
result: 'success1',
|
|
6157
6853
|
},
|
|
6854
|
+
endedAt: expect.any(Number),
|
|
6158
6855
|
status: 'success',
|
|
6159
6856
|
},
|
|
6160
6857
|
type: 'step-result',
|
|
@@ -6167,12 +6864,43 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6167
6864
|
type: 'step-finish',
|
|
6168
6865
|
},
|
|
6169
6866
|
{
|
|
6170
|
-
payload: {
|
|
6867
|
+
payload: {
|
|
6868
|
+
id: expect.any(String),
|
|
6869
|
+
startedAt: expect.any(Number),
|
|
6870
|
+
status: 'waiting',
|
|
6871
|
+
payload: {
|
|
6872
|
+
result: 'success1',
|
|
6873
|
+
},
|
|
6874
|
+
},
|
|
6171
6875
|
type: 'step-waiting',
|
|
6172
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
|
+
},
|
|
6173
6896
|
{
|
|
6174
6897
|
payload: {
|
|
6175
6898
|
id: 'step2',
|
|
6899
|
+
payload: {
|
|
6900
|
+
result: 'success1',
|
|
6901
|
+
},
|
|
6902
|
+
startedAt: expect.any(Number),
|
|
6903
|
+
status: 'running',
|
|
6176
6904
|
},
|
|
6177
6905
|
type: 'step-start',
|
|
6178
6906
|
},
|
|
@@ -6182,6 +6910,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6182
6910
|
output: {
|
|
6183
6911
|
result: 'success2',
|
|
6184
6912
|
},
|
|
6913
|
+
endedAt: expect.any(Number),
|
|
6185
6914
|
status: 'success',
|
|
6186
6915
|
},
|
|
6187
6916
|
type: 'step-result',
|
|
@@ -6200,6 +6929,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6200
6929
|
type: 'finish',
|
|
6201
6930
|
},
|
|
6202
6931
|
]);
|
|
6932
|
+
|
|
6203
6933
|
// Verify execution completed successfully
|
|
6204
6934
|
expect(executionResult.steps.step1).toMatchObject({
|
|
6205
6935
|
status: 'success',
|
|
@@ -6219,6 +6949,215 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6219
6949
|
});
|
|
6220
6950
|
});
|
|
6221
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
|
+
|
|
6222
7161
|
it('should handle waitForEvent waiting flow', async ctx => {
|
|
6223
7162
|
const inngest = new Inngest({
|
|
6224
7163
|
id: 'mastra',
|
|
@@ -6272,10 +7211,11 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6272
7211
|
|
|
6273
7212
|
const app = await createHonoServer(mastra);
|
|
6274
7213
|
|
|
6275
|
-
const srv = serve({
|
|
7214
|
+
const srv = (globServer = serve({
|
|
6276
7215
|
fetch: app.fetch,
|
|
6277
7216
|
port: (ctx as any).handlerPort,
|
|
6278
|
-
});
|
|
7217
|
+
}));
|
|
7218
|
+
await resetInngest();
|
|
6279
7219
|
|
|
6280
7220
|
const runId = 'test-run-id';
|
|
6281
7221
|
let watchData: StreamEvent[] = [];
|
|
@@ -6283,7 +7223,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6283
7223
|
runId,
|
|
6284
7224
|
});
|
|
6285
7225
|
|
|
6286
|
-
await
|
|
7226
|
+
await resetInngest();
|
|
6287
7227
|
|
|
6288
7228
|
const { stream, getWorkflowState } = run.stream({ inputData: {} });
|
|
6289
7229
|
|
|
@@ -6303,7 +7243,7 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6303
7243
|
|
|
6304
7244
|
const executionResult = await getWorkflowState();
|
|
6305
7245
|
|
|
6306
|
-
await
|
|
7246
|
+
await resetInngest();
|
|
6307
7247
|
|
|
6308
7248
|
srv.close();
|
|
6309
7249
|
|
|
@@ -6497,12 +7437,12 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6497
7437
|
|
|
6498
7438
|
const app = await createHonoServer(mastra);
|
|
6499
7439
|
|
|
6500
|
-
const srv = serve({
|
|
7440
|
+
const srv = (globServer = serve({
|
|
6501
7441
|
fetch: app.fetch,
|
|
6502
7442
|
port: (ctx as any).handlerPort,
|
|
6503
|
-
});
|
|
7443
|
+
}));
|
|
6504
7444
|
|
|
6505
|
-
await
|
|
7445
|
+
await resetInngest();
|
|
6506
7446
|
|
|
6507
7447
|
const run = await promptEvalWorkflow.createRunAsync();
|
|
6508
7448
|
|
|
@@ -6686,12 +7626,12 @@ describe('MastraInngestWorkflow', () => {
|
|
|
6686
7626
|
|
|
6687
7627
|
const app = await createHonoServer(mastra);
|
|
6688
7628
|
|
|
6689
|
-
const srv = serve({
|
|
7629
|
+
const srv = (globServer = serve({
|
|
6690
7630
|
fetch: app.fetch,
|
|
6691
7631
|
port: (ctx as any).handlerPort,
|
|
6692
|
-
});
|
|
7632
|
+
}));
|
|
6693
7633
|
|
|
6694
|
-
await
|
|
7634
|
+
await resetInngest();
|
|
6695
7635
|
|
|
6696
7636
|
const run = await workflow.createRunAsync({
|
|
6697
7637
|
runId: 'test-run-id',
|