@@ -1040,6 +1040,94 @@ describe("OpenCodeAdapterV2", () => {
10401040 } ) . pipe ( Effect . provide ( IdAllocator . layer ) , Effect . scoped ) ,
10411041 ) ;
10421042
1043+ it . effect . each ( [ "failure" , "timeout" ] as const ) ( "retries MCP status after %s" , ( failure ) =>
1044+ Effect . gen ( function * ( ) {
1045+ const nativeEvents = asyncEventStream ( ) ;
1046+ const called = promiseGate < void > ( ) ;
1047+ const sessionId = `mcp-status-${ failure } ` ;
1048+ let statusReads = 0 ;
1049+ let signal : AbortSignal | undefined ;
1050+ const harness = yield * makeOpenCodeRuntimeHarness ( sessionId , sessionId , {
1051+ event : { subscribe : async ( ) => ( { stream : nativeEvents . stream } ) } ,
1052+ session : {
1053+ create : async ( ) => ( { data : { id : sessionId , time : { created : 1 , updated : 1 } } } ) ,
1054+ promptAsync : async ( ) => ( { data : true } ) ,
1055+ } ,
1056+ mcp : {
1057+ status : async ( _input : unknown , options : { signal ?: AbortSignal } ) => {
1058+ statusReads ++ ;
1059+ if ( statusReads === 1 ) {
1060+ signal = options ?. signal ;
1061+ called . resolve ( ) ;
1062+ if ( failure === "timeout" ) return new Promise ( ( ) => { } ) ;
1063+ throw new Error ( "MCP status unavailable" ) ;
1064+ }
1065+ return { data : { weather : { status : "connected" } } } ;
1066+ } ,
1067+ } ,
1068+ } ) ;
1069+ yield * harness . startTurn ( ) ;
1070+ const received = yield * harness . runtime . events . pipe (
1071+ Stream . takeUntil (
1072+ ( event ) => event . type === "turn_item.updated" && event . turnItem . type === "compaction" ,
1073+ ) ,
1074+ Stream . runCollect ,
1075+ Effect . forkScoped ,
1076+ ) ;
1077+ for ( const status of [ "running" , "completed" ] as const ) {
1078+ const emitted = yield * Effect . promise ( ( ) =>
1079+ nativeEvents . push ( {
1080+ type : "message.part.updated" ,
1081+ properties : {
1082+ sessionID : sessionId ,
1083+ part : {
1084+ id : "weather-part" ,
1085+ sessionID : sessionId ,
1086+ messageID : "weather-message" ,
1087+ type : "tool" ,
1088+ callID : "weather-call" ,
1089+ tool : "weather_edit_document" ,
1090+ state : {
1091+ status,
1092+ input : { document : "remote-doc" } ,
1093+ title : "Edit remote document" ,
1094+ metadata : { } ,
1095+ output : "saved" ,
1096+ time : { start : 1 , end : 2 } ,
1097+ } ,
1098+ } ,
1099+ } ,
1100+ } ) ,
1101+ ) . pipe ( Effect . forkScoped ) ;
1102+ if ( status === "running" && failure === "timeout" ) {
1103+ yield * Effect . promise ( ( ) => called . promise ) ;
1104+ yield * TestClock . adjust ( "1 second" ) ;
1105+ }
1106+ yield * Fiber . join ( emitted ) ;
1107+ }
1108+ yield * Effect . promise ( ( ) =>
1109+ nativeEvents . push ( { type : "session.compacted" , properties : { sessionID : sessionId } } ) ,
1110+ ) ;
1111+ const completed = ( yield * Fiber . join ( received ) ) . find (
1112+ ( event ) =>
1113+ event . type === "turn_item.updated" &&
1114+ event . turnItem . type === "dynamic_tool" &&
1115+ event . turnItem . status === "completed" ,
1116+ ) ;
1117+ assert . equal ( statusReads , 2 ) ;
1118+ assert . equal (
1119+ completed ?. type === "turn_item.updated" && completed . turnItem . title ,
1120+ "Edit remote document" ,
1121+ ) ;
1122+ assert . deepEqual ( completed ?. type === "turn_item.updated" && completed . turnItem . toolSource , {
1123+ key : "mcp:weather" ,
1124+ name : "weather" ,
1125+ kind : "integration" ,
1126+ } ) ;
1127+ if ( failure === "timeout" ) assert . isTrue ( signal ?. aborted ) ;
1128+ } ) . pipe ( Effect . provide ( IdAllocator . layer ) , Effect . scoped ) ,
1129+ ) ;
1130+
10431131 it . effect ( "admits a native command on its user receipt before generation completes" , ( ) =>
10441132 Effect . gen ( function * ( ) {
10451133 const nativeEvents = asyncEventStream ( ) ;
0 commit comments