11import { describe , it , expect , beforeEach , afterEach , vi } from 'vitest' ;
22import { InMemoryTaskStore , InMemoryTaskMessageQueue } from '../../../../src/experimental/tasks/stores/in-memory.js' ;
3- import { TaskCreationParams , Request } from '../../../../src/types.js' ;
3+ import { TaskCreationParams , RequestBase , NotificationBase , ResultBase } from '../../../../src/types.js' ;
44import { QueuedMessage } from '../../../../src/experimental/tasks/interfaces.js' ;
55
66describe ( 'InMemoryTaskStore' , ( ) => {
@@ -19,12 +19,12 @@ describe('InMemoryTaskStore', () => {
1919 const taskParams : TaskCreationParams = {
2020 ttl : 60000
2121 } ;
22- const request : Request = {
23- method : 'tools/call' ,
24- params : { name : 'test-tool' }
22+ const request = {
23+ method : 'tools/call' as const ,
24+ params : { name : 'test-tool' , arguments : { } }
2525 } ;
2626
27- const task = await store . createTask ( taskParams , 123 , request ) ;
27+ const task = await store . createTask ( taskParams , 123 , request as any ) ;
2828
2929 expect ( task ) . toBeDefined ( ) ;
3030 expect ( task . taskId ) . toBeDefined ( ) ;
@@ -39,26 +39,26 @@ describe('InMemoryTaskStore', () => {
3939
4040 it ( 'should create task without ttl' , async ( ) => {
4141 const taskParams : TaskCreationParams = { } ;
42- const request : Request = {
43- method : 'tools/call' ,
44- params : { }
42+ const request = {
43+ method : 'tools/call' as const ,
44+ params : { name : 'test-tool' , arguments : { } }
4545 } ;
4646
47- const task = await store . createTask ( taskParams , 456 , request ) ;
47+ const task = await store . createTask ( taskParams , 456 , request as any ) ;
4848
4949 expect ( task ) . toBeDefined ( ) ;
5050 expect ( task . ttl ) . toBeNull ( ) ;
5151 } ) ;
5252
5353 it ( 'should generate unique taskIds' , async ( ) => {
5454 const taskParams : TaskCreationParams = { } ;
55- const request : Request = {
56- method : 'tools/call' ,
57- params : { }
55+ const request = {
56+ method : 'tools/call' as const ,
57+ params : { name : 'test-tool' , arguments : { } }
5858 } ;
5959
60- const task1 = await store . createTask ( taskParams , 789 , request ) ;
61- const task2 = await store . createTask ( taskParams , 790 , request ) ;
60+ const task1 = await store . createTask ( taskParams , 789 , request as any ) ;
61+ const task2 = await store . createTask ( taskParams , 790 , request as any ) ;
6262
6363 expect ( task1 . taskId ) . not . toBe ( task2 . taskId ) ;
6464 } ) ;
@@ -72,12 +72,12 @@ describe('InMemoryTaskStore', () => {
7272
7373 it ( 'should return task state' , async ( ) => {
7474 const taskParams : TaskCreationParams = { } ;
75- const request : Request = {
76- method : 'tools/call' ,
77- params : { }
75+ const request = {
76+ method : 'tools/call' as const ,
77+ params : { name : 'test-tool' , arguments : { } }
7878 } ;
7979
80- const createdTask = await store . createTask ( taskParams , 111 , request ) ;
80+ const createdTask = await store . createTask ( taskParams , 111 , request as any ) ;
8181 await store . updateTaskStatus ( createdTask . taskId , 'working' ) ;
8282
8383 const task = await store . getTask ( createdTask . taskId ) ;
@@ -92,9 +92,9 @@ describe('InMemoryTaskStore', () => {
9292 beforeEach ( async ( ) => {
9393 const taskParams : TaskCreationParams = { } ;
9494 const createdTask = await store . createTask ( taskParams , 222 , {
95- method : 'tools/call' ,
96- params : { }
97- } ) ;
95+ method : 'tools/call' as const ,
96+ params : { name : 'test-tool' , arguments : { } }
97+ } as RequestBase ) ;
9898 taskId = createdTask . taskId ;
9999 } ) ;
100100
@@ -223,9 +223,9 @@ describe('InMemoryTaskStore', () => {
223223 ttl : 60000
224224 } ;
225225 const createdTask = await store . createTask ( taskParams , 333 , {
226- method : 'tools/call' ,
227- params : { }
228- } ) ;
226+ method : 'tools/call' as const ,
227+ params : { name : 'test-tool' , arguments : { } }
228+ } as RequestBase ) ;
229229 taskId = createdTask . taskId ;
230230 } ) ;
231231
@@ -328,19 +328,19 @@ describe('InMemoryTaskStore', () => {
328328 it ( 'should throw if task has no result stored' , async ( ) => {
329329 const taskParams : TaskCreationParams = { } ;
330330 const createdTask = await store . createTask ( taskParams , 444 , {
331- method : 'tools/call' ,
332- params : { }
333- } ) ;
331+ method : 'tools/call' as const ,
332+ params : { name : 'test-tool' , arguments : { } }
333+ } as RequestBase ) ;
334334
335335 await expect ( store . getTaskResult ( createdTask . taskId ) ) . rejects . toThrow ( `Task ${ createdTask . taskId } has no result stored` ) ;
336336 } ) ;
337337
338338 it ( 'should return stored result' , async ( ) => {
339339 const taskParams : TaskCreationParams = { } ;
340340 const createdTask = await store . createTask ( taskParams , 555 , {
341- method : 'tools/call' ,
342- params : { }
343- } ) ;
341+ method : 'tools/call' as const ,
342+ params : { name : 'test-tool' , arguments : { } }
343+ } as RequestBase ) ;
344344
345345 const result = {
346346 content : [ { type : 'text' as const , text : 'Result data' } ]
@@ -366,7 +366,7 @@ describe('InMemoryTaskStore', () => {
366366 ttl : 1000
367367 } ;
368368 const createdTask = await store . createTask ( taskParams , 666 , {
369- method : 'tools/call' ,
369+ method : 'tools/call' as const ,
370370 params : { }
371371 } ) ;
372372
@@ -387,7 +387,7 @@ describe('InMemoryTaskStore', () => {
387387 ttl : 1000
388388 } ;
389389 const createdTask = await store . createTask ( taskParams , 777 , {
390- method : 'tools/call' ,
390+ method : 'tools/call' as const ,
391391 params : { }
392392 } ) ;
393393
@@ -417,7 +417,7 @@ describe('InMemoryTaskStore', () => {
417417 it ( 'should not cleanup tasks without ttl' , async ( ) => {
418418 const taskParams : TaskCreationParams = { } ;
419419 const createdTask = await store . createTask ( taskParams , 888 , {
420- method : 'tools/call' ,
420+ method : 'tools/call' as const ,
421421 params : { }
422422 } ) ;
423423
@@ -434,7 +434,7 @@ describe('InMemoryTaskStore', () => {
434434 ttl : 1000
435435 } ;
436436 const createdTask = await store . createTask ( taskParams , 999 , {
437- method : 'tools/call' ,
437+ method : 'tools/call' as const ,
438438 params : { }
439439 } ) ;
440440
@@ -450,7 +450,7 @@ describe('InMemoryTaskStore', () => {
450450 ttl : 2000
451451 } ;
452452 const createdTask2 = await store . createTask ( taskParams2 , 1000 , {
453- method : 'tools/call' ,
453+ method : 'tools/call' as const ,
454454 params : { }
455455 } ) ;
456456
@@ -474,7 +474,7 @@ describe('InMemoryTaskStore', () => {
474474 ttl : requestedTtl
475475 } ;
476476 const createdTask = await store . createTask ( taskParams , 1111 , {
477- method : 'tools/call' ,
477+ method : 'tools/call' as const ,
478478 params : { }
479479 } ) ;
480480
@@ -493,7 +493,7 @@ describe('InMemoryTaskStore', () => {
493493 ttl : null
494494 } ;
495495 const createdTask = await store . createTask ( taskParams , 2222 , {
496- method : 'tools/call' ,
496+ method : 'tools/call' as const ,
497497 params : { }
498498 } ) ;
499499
@@ -515,20 +515,20 @@ describe('InMemoryTaskStore', () => {
515515
516516 // Create tasks in different statuses
517517 const workingTask = await store . createTask ( taskParams , 3333 , {
518- method : 'tools/call' ,
518+ method : 'tools/call' as const ,
519519 params : { }
520520 } ) ;
521521
522522 const completedTask = await store . createTask ( taskParams , 4444 , {
523- method : 'tools/call' ,
523+ method : 'tools/call' as const ,
524524 params : { }
525525 } ) ;
526526 await store . storeTaskResult ( completedTask . taskId , 'completed' , {
527527 content : [ { type : 'text' as const , text : 'Done' } ]
528528 } ) ;
529529
530530 const failedTask = await store . createTask ( taskParams , 5555 , {
531- method : 'tools/call' ,
531+ method : 'tools/call' as const ,
532532 params : { }
533533 } ) ;
534534 await store . storeTaskResult ( failedTask . taskId , 'failed' , {
@@ -548,15 +548,15 @@ describe('InMemoryTaskStore', () => {
548548 describe ( 'getAllTasks' , ( ) => {
549549 it ( 'should return all tasks' , async ( ) => {
550550 await store . createTask ( { } , 1 , {
551- method : 'tools/call' ,
551+ method : 'tools/call' as const ,
552552 params : { }
553553 } ) ;
554554 await store . createTask ( { } , 2 , {
555- method : 'tools/call' ,
555+ method : 'tools/call' as const ,
556556 params : { }
557557 } ) ;
558558 await store . createTask ( { } , 3 , {
559- method : 'tools/call' ,
559+ method : 'tools/call' as const ,
560560 params : { }
561561 } ) ;
562562
@@ -582,15 +582,15 @@ describe('InMemoryTaskStore', () => {
582582
583583 it ( 'should return all tasks when less than page size' , async ( ) => {
584584 await store . createTask ( { } , 1 , {
585- method : 'tools/call' ,
585+ method : 'tools/call' as const ,
586586 params : { }
587587 } ) ;
588588 await store . createTask ( { } , 2 , {
589- method : 'tools/call' ,
589+ method : 'tools/call' as const ,
590590 params : { }
591591 } ) ;
592592 await store . createTask ( { } , 3 , {
593- method : 'tools/call' ,
593+ method : 'tools/call' as const ,
594594 params : { }
595595 } ) ;
596596
@@ -603,7 +603,7 @@ describe('InMemoryTaskStore', () => {
603603 // Create 15 tasks (page size is 10)
604604 for ( let i = 1 ; i <= 15 ; i ++ ) {
605605 await store . createTask ( { } , i , {
606- method : 'tools/call' ,
606+ method : 'tools/call' as const ,
607607 params : { }
608608 } ) ;
609609 }
@@ -621,7 +621,7 @@ describe('InMemoryTaskStore', () => {
621621
622622 it ( 'should throw error for invalid cursor' , async ( ) => {
623623 await store . createTask ( { } , 1 , {
624- method : 'tools/call' ,
624+ method : 'tools/call' as const ,
625625 params : { }
626626 } ) ;
627627
@@ -632,7 +632,7 @@ describe('InMemoryTaskStore', () => {
632632 // Create 5 tasks
633633 for ( let i = 1 ; i <= 5 ; i ++ ) {
634634 await store . createTask ( { } , i , {
635- method : 'tools/call' ,
635+ method : 'tools/call' as const ,
636636 params : { }
637637 } ) ;
638638 }
@@ -649,11 +649,11 @@ describe('InMemoryTaskStore', () => {
649649 describe ( 'cleanup' , ( ) => {
650650 it ( 'should clear all timers and tasks' , async ( ) => {
651651 await store . createTask ( { ttl : 1000 } , 1 , {
652- method : 'tools/call' ,
652+ method : 'tools/call' as const ,
653653 params : { }
654654 } ) ;
655655 await store . createTask ( { ttl : 2000 } , 2 , {
656- method : 'tools/call' ,
656+ method : 'tools/call' as const ,
657657 params : { }
658658 } ) ;
659659
@@ -680,7 +680,7 @@ describe('InMemoryTaskMessageQueue', () => {
680680 message : {
681681 jsonrpc : '2.0' ,
682682 id : 1 ,
683- method : 'tools/call' ,
683+ method : 'tools/call' as const ,
684684 params : { name : 'test-tool' , arguments : { } }
685685 } ,
686686 timestamp : Date . now ( )
@@ -697,7 +697,7 @@ describe('InMemoryTaskMessageQueue', () => {
697697 type : 'notification' ,
698698 message : {
699699 jsonrpc : '2.0' ,
700- method : 'notifications/progress' ,
700+ method : 'notifications/progress' as const ,
701701 params : { progress : 50 , total : 100 }
702702 } ,
703703 timestamp : Date . now ( )
@@ -737,7 +737,7 @@ describe('InMemoryTaskMessageQueue', () => {
737737 message : {
738738 jsonrpc : '2.0' ,
739739 id : 1 ,
740- method : 'tools/call' ,
740+ method : 'tools/call' as const ,
741741 params : { }
742742 } ,
743743 timestamp : 1000
@@ -747,7 +747,7 @@ describe('InMemoryTaskMessageQueue', () => {
747747 type : 'notification' ,
748748 message : {
749749 jsonrpc : '2.0' ,
750- method : 'notifications/progress' ,
750+ method : 'notifications/progress' as const ,
751751 params : { }
752752 } ,
753753 timestamp : 2000
@@ -781,7 +781,7 @@ describe('InMemoryTaskMessageQueue', () => {
781781 message : {
782782 jsonrpc : '2.0' ,
783783 id : 1 ,
784- method : 'tools/call' ,
784+ method : 'tools/call' as const ,
785785 params : { }
786786 } ,
787787 timestamp : 1000
@@ -801,7 +801,7 @@ describe('InMemoryTaskMessageQueue', () => {
801801 type : 'notification' ,
802802 message : {
803803 jsonrpc : '2.0' ,
804- method : 'notifications/progress' ,
804+ method : 'notifications/progress' as const ,
805805 params : { }
806806 } ,
807807 timestamp : 3000
@@ -830,7 +830,7 @@ describe('InMemoryTaskMessageQueue', () => {
830830 message : {
831831 jsonrpc : '2.0' ,
832832 id : 1 ,
833- method : 'test' ,
833+ method : 'test' as const ,
834834 params : { }
835835 } ,
836836 timestamp : Date . now ( )
@@ -851,7 +851,7 @@ describe('InMemoryTaskMessageQueue', () => {
851851 message : {
852852 jsonrpc : '2.0' ,
853853 id : 1 ,
854- method : 'test' ,
854+ method : 'test' as const ,
855855 params : { }
856856 } ,
857857 timestamp : Date . now ( )
@@ -885,7 +885,7 @@ describe('InMemoryTaskMessageQueue', () => {
885885 message : {
886886 jsonrpc : '2.0' ,
887887 id : 1 ,
888- method : 'test1' ,
888+ method : 'test1' as const ,
889889 params : { }
890890 } ,
891891 timestamp : 1000
0 commit comments