@@ -1353,44 +1353,57 @@ describe("XAiAcpExtension", () => {
13531353 } ) ,
13541354 ) ;
13551355
1356- it . effect ( "cancels pending completions without restarting a stalled runtime" , ( ) =>
1357- Effect . gen ( function * ( ) {
1358- const hungStart = yield * Deferred . make < never > ( ) ;
1359- const hungPrompt = yield * Deferred . make < never > ( ) ;
1360- let startCount = 0 ;
1361- let cancelCalled = false ;
1362- const baseRuntime = {
1363- start : ( ) => {
1364- startCount += 1 ;
1365- return startCount === 1
1366- ? Effect . succeed ( {
1367- sessionId : "root-session" ,
1368- initializeResult : { } ,
1369- sessionSetupResult : { } ,
1370- modelConfigId : undefined ,
1371- } )
1372- : Deferred . await ( hungStart ) ;
1373- } ,
1374- prompt : ( ) => Deferred . await ( hungPrompt ) ,
1375- cancel : Effect . sync ( ( ) => {
1376- cancelCalled = true ;
1377- } ) ,
1378- handleExtNotification : ( ) => Effect . void ,
1379- handleExtRequest : ( ) => Effect . void ,
1380- } as unknown as AcpSessionRuntime . AcpSessionRuntime [ "Service" ] ;
1381-
1382- const runtime = yield * makeXAiPromptCompletionRuntime ( baseRuntime ) ;
1383- const promptFiber = yield * runtime
1384- . prompt ( { prompt : [ { type : "text" , text : "hi" } ] } )
1385- . pipe ( Effect . forkChild ) ;
1386- yield * Effect . yieldNow ;
1387-
1388- yield * runtime . cancel ;
1389-
1390- expect ( cancelCalled ) . toBe ( true ) ;
1391- expect ( startCount ) . toBe ( 1 ) ;
1392- expect ( ( yield * Fiber . join ( promptFiber ) ) . stopReason ) . toBe ( "cancelled" ) ;
1393- } ) ,
1356+ it . effect . each ( [ 0 , 1 , 128 ] ) (
1357+ "cancels %i pending completions without restarting a stalled runtime" ,
1358+ ( promptCount ) =>
1359+ Effect . gen ( function * ( ) {
1360+ const hungStart = yield * Deferred . make < never > ( ) ;
1361+ const hungPrompt = yield * Deferred . make < never > ( ) ;
1362+ const promptsReady = yield * Deferred . make < void > ( ) ;
1363+ let enteredPrompts = 0 ;
1364+ let startCount = 0 ;
1365+ let cancelCount = 0 ;
1366+ const baseRuntime = {
1367+ start : ( ) => {
1368+ startCount += 1 ;
1369+ return startCount <= promptCount
1370+ ? Effect . succeed ( {
1371+ sessionId : "root-session" ,
1372+ initializeResult : { } ,
1373+ sessionSetupResult : { } ,
1374+ modelConfigId : undefined ,
1375+ } )
1376+ : Deferred . await ( hungStart ) ;
1377+ } ,
1378+ prompt : ( ) =>
1379+ Effect . gen ( function * ( ) {
1380+ enteredPrompts += 1 ;
1381+ if ( enteredPrompts === promptCount ) yield * Deferred . succeed ( promptsReady , undefined ) ;
1382+ return yield * Deferred . await ( hungPrompt ) ;
1383+ } ) ,
1384+ cancel : Effect . sync ( ( ) => {
1385+ cancelCount += 1 ;
1386+ } ) ,
1387+ handleExtNotification : ( ) => Effect . void ,
1388+ handleExtRequest : ( ) => Effect . void ,
1389+ } as unknown as AcpSessionRuntime . AcpSessionRuntime [ "Service" ] ;
1390+
1391+ const runtime = yield * makeXAiPromptCompletionRuntime ( baseRuntime ) ;
1392+ const promptFibers = yield * Effect . forEach ( Array . from ( { length : promptCount } ) , ( ) =>
1393+ runtime . prompt ( { prompt : [ { type : "text" , text : "hi" } ] } ) . pipe ( Effect . forkChild ) ,
1394+ ) ;
1395+ if ( promptCount > 0 ) yield * Deferred . await ( promptsReady ) ;
1396+
1397+ yield * runtime . cancel ;
1398+ yield * runtime . cancel ;
1399+
1400+ expect ( cancelCount ) . toBe ( 2 ) ;
1401+ expect ( startCount ) . toBe ( promptCount ) ;
1402+ const responses = yield * Effect . forEach ( promptFibers , Fiber . join ) ;
1403+ expect ( responses . map ( ( response ) => response . stopReason ) ) . toEqual (
1404+ Array . from ( { length : promptCount } , ( ) => "cancelled" ) ,
1405+ ) ;
1406+ } ) ,
13941407 ) ;
13951408} ) ;
13961409
0 commit comments