@@ -4150,26 +4150,37 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
41504150 promptAccepted ,
41514151 event ( "session.execution.succeeded" , { sessionID : SESSION } ) ,
41524152 ] ;
4153+ const prompts : Array < unknown > = [ ] ;
41534154 // Idle Location eviction drops OpenCode's runtime MCP servers without a reconnect.
4154- const { runtime, thread } = yield * resumed ( [
4155- add ,
4156- reply ( "mcp.add" , null ) ,
4157- ...turn ,
4158- add ,
4159- reply ( "mcp.add" , { status : 500 , body : { message : "MCP unavailable" } } ) ,
4160- out ( "session.instructions.entry.put" , {
4161- sessionID : SESSION ,
4162- key : "t3-code" ,
4163- value : buildRuntimeInstructions ( { harness : "OpenCode" , model : bigPickle . model } ) ,
4164- } ) ,
4165- reply ( "session.instructions.entry.put" , null ) ,
4166- ...turn ,
4167- out ( "mcp.remove" , { server, "location[directory]" : WORK } ) ,
4168- reply ( "mcp.remove" , null ) ,
4169- ] ) ;
4155+ const { runtime, thread } = yield * resumed (
4156+ [
4157+ add ,
4158+ reply ( "mcp.add" , null ) ,
4159+ ...turn ,
4160+ add ,
4161+ reply ( "mcp.add" , { status : 500 , body : { message : "MCP unavailable" } } ) ,
4162+ out ( "session.instructions.entry.put" , {
4163+ sessionID : SESSION ,
4164+ key : "t3-code" ,
4165+ value : buildRuntimeInstructions ( { harness : "OpenCode" , model : bigPickle . model } ) ,
4166+ } ) ,
4167+ reply ( "session.instructions.entry.put" , null ) ,
4168+ ...turn ,
4169+ out ( "mcp.remove" , { server, "location[directory]" : WORK } ) ,
4170+ reply ( "mcp.remove" , null ) ,
4171+ ] ,
4172+ { onPrompt : ( input ) => prompts . push ( input ) } ,
4173+ ) ;
41704174 for ( let index = 0 ; index < 2 ; index ++ ) {
41714175 const terminal = yield * terminalOf ( runtime ) . pipe ( Effect . forkScoped ) ;
4172- yield * runtime . startTurn ( turnInput ( thread ) ) ;
4176+ const started = yield * runtime . startTurn ( turnInput ( thread ) ) . pipe ( Effect . forkScoped ) ;
4177+ // OpenCode before 2.2.6 loads a newly added server's tools after a debounce.
4178+ if ( index === 0 ) {
4179+ yield * TestClock . adjust ( "249 millis" ) ;
4180+ assert . lengthOf ( prompts , 0 , "prompted before OpenCode loaded the new MCP server's tools" ) ;
4181+ yield * TestClock . adjust ( "1 millis" ) ;
4182+ }
4183+ yield * Fiber . join ( started ) ;
41734184 assert . equal ( ( yield * Fiber . join ( terminal ) ) ?. status , "completed" ) ;
41744185 }
41754186 } ) . pipe ( Effect . scoped ) ,
@@ -4230,7 +4241,11 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
42304241 runtimePolicy : policy ( ) ,
42314242 } ) ;
42324243 const terminal = yield * terminalOf ( runtime ) . pipe ( Effect . forkScoped ) ;
4233- yield * runtime . startTurn ( { ...turnInput ( thread ) , threadId : child } ) ;
4244+ const started = yield * runtime
4245+ . startTurn ( { ...turnInput ( thread ) , threadId : child } )
4246+ . pipe ( Effect . forkScoped ) ;
4247+ yield * TestClock . adjust ( "250 millis" ) ;
4248+ yield * Fiber . join ( started ) ;
42344249 assert . equal ( ( yield * Fiber . join ( terminal ) ) ?. status , "completed" ) ;
42354250 yield * runtime . unloadThread ! ( { providerThread : thread } ) ;
42364251 } ) . pipe ( Effect . scoped ) ,
0 commit comments