@@ -254,6 +254,7 @@ it.effect("reopens a stalled MCP registration before delivering the resumed prom
254254 if ( typeof prompt === "string" ) throw new Error ( "Expected streaming input" ) ;
255255 prompts . push ( prompt ) ;
256256 return {
257+ initializationResult : async ( ) => ( { } ) ,
257258 setMcpServers : prompts . length === 1 ? firstRegistration : secondRegistration ,
258259 close : prompts . length === 1 ? firstClose : secondClose ,
259260 [ Symbol . asyncDispose ] : async ( ) => {
@@ -360,6 +361,7 @@ it.effect.each([true, false])("only retries after confirmed process exit: %s", (
360361 cleanupProgress . resolve ( "retry" ) ;
361362 }
362363 return {
364+ initializationResult : async ( ) => ( { } ) ,
363365 setMcpServers : ( ) => {
364366 registrationStarted . resolve ( ) ;
365367 return first
@@ -410,6 +412,7 @@ it.effect("stops retrying MCP registration after two timeouts and reports the ca
410412 const querySpy = vi . spyOn ( ClaudeSdk , "query" ) . mockImplementation ( ( ) => {
411413 const started = querySpy . mock . calls . length === 1 ? firstRegistration : secondRegistration ;
412414 return {
415+ initializationResult : async ( ) => ( { } ) ,
413416 setMcpServers : ( ) => {
414417 started . resolve ( ) ;
415418 return new Promise < ClaudeSdk . McpSetServersResult > ( ( ) => { } ) ;
@@ -450,6 +453,7 @@ it.effect("cancels a stalled registration without retrying or retaining its prom
450453 const querySpy = vi . spyOn ( ClaudeSdk , "query" ) . mockImplementation (
451454 ( ) =>
452455 ( {
456+ initializationResult : async ( ) => ( { } ) ,
453457 setMcpServers : ( ) => {
454458 registrationStarted . resolve ( ) ;
455459 return new Promise < ClaudeSdk . McpSetServersResult > ( ( ) => { } ) ;
@@ -480,6 +484,7 @@ it.effect("does not reuse a fresh session ID after MCP registration times out",
480484 const querySpy = vi . spyOn ( ClaudeSdk , "query" ) . mockImplementation (
481485 ( ) =>
482486 ( {
487+ initializationResult : async ( ) => ( { } ) ,
483488 setMcpServers : ( ) => {
484489 registrationStarted . resolve ( ) ;
485490 return new Promise < ClaudeSdk . McpSetServersResult > ( ( ) => { } ) ;
@@ -507,6 +512,55 @@ it.effect("does not reuse a fresh session ID after MCP registration times out",
507512 ) ,
508513) ;
509514
515+ it . effect . each ( [
516+ [ "opens after a slow CLI boot" , "120 seconds" , true ] ,
517+ [ "times out a CLI that never boots" , "5 minutes" , false ] ,
518+ ] as const ) ( "%s" , ( [ , bootWait , boots ] ) =>
519+ Effect . scoped (
520+ Effect . gen ( function * ( ) {
521+ const waiting = Promise . withResolvers < void > ( ) ;
522+ const booted = Promise . withResolvers < void > ( ) ;
523+ const querySpy = vi . spyOn ( ClaudeSdk , "query" ) . mockImplementation (
524+ ( ) =>
525+ ( {
526+ initializationResult : ( ) => {
527+ waiting . resolve ( ) ;
528+ return booted . promise ;
529+ } ,
530+ // The CLI answers control requests only after it has booted.
531+ setMcpServers : async ( ) => {
532+ waiting . resolve ( ) ;
533+ await booted . promise ;
534+ return { added : [ "t3-code" ] , removed : [ ] , errors : { } } ;
535+ } ,
536+ close : vi . fn ( ) ,
537+ [ Symbol . asyncDispose ] : async ( ) => { } ,
538+ } ) as unknown as ClaudeSdk . Query ,
539+ ) ;
540+ yield * Effect . addFinalizer ( ( ) => Effect . sync ( ( ) => querySpy . mockRestore ( ) ) ) ;
541+ const runner = yield * ClaudeAgentSdkQueryRunner ;
542+ const { resume, ...options } = resumedMcpQueryInput . options ;
543+ const opening = yield * runner
544+ . open ( { ...resumedMcpQueryInput , options : { ...options , sessionId : resume } } )
545+ . pipe ( Effect . result , Effect . forkChild ) ;
546+ yield * Effect . promise ( ( ) => waiting . promise ) ;
547+ yield * TestClock . adjust ( bootWait ) ;
548+ if ( boots ) booted . resolve ( ) ;
549+ const result = yield * Fiber . join ( opening ) ;
550+
551+ assert . equal ( result . _tag , boots ? "Success" : "Failure" ) ;
552+ if ( result . _tag === "Success" ) yield * result . success . close ;
553+ else
554+ assert . equal (
555+ makeProviderFailure ( {
556+ cause : { _tag : "ProviderAdapterTurnStartError" , cause : result . failure } ,
557+ } ) . message ,
558+ "Claude timed out while starting up. Retry the turn; if it keeps failing, check Claude and the server logs." ,
559+ ) ;
560+ } ) . pipe ( Effect . provide ( realQueryRunner ) ) ,
561+ ) ,
562+ ) ;
563+
510564function fakeClaudeCli ( script : string ) : string {
511565 const dir = NodeFS . mkdtempSync ( NodePath . join ( NodeOS . tmpdir ( ) , "t3-claude-cli-" ) ) ;
512566 const cli = NodePath . join ( dir , "claude" ) ;
0 commit comments