@@ -2652,7 +2652,11 @@ describe("OrchestratorMcpService thread lookup", () => {
26522652 capabilities : new Set ( [ "orchestration" ] ) ,
26532653 issuedAt : 1 ,
26542654 } ;
2655- const service = ( shells : ReadonlyArray < OrchestrationV2ThreadShell > , sent : Ref . Ref < number > ) =>
2655+ const service = (
2656+ shells : ReadonlyArray < OrchestrationV2ThreadShell > ,
2657+ sent : Ref . Ref < number > ,
2658+ overrides : Partial < ThreadManagementService . ThreadManagementService [ "Service" ] > = { } ,
2659+ ) =>
26562660 layerOrchestratorService . pipe (
26572661 Layer . provide (
26582662 Layer . mergeAll (
@@ -2661,6 +2665,7 @@ describe("OrchestratorMcpService thread lookup", () => {
26612665 getThreadShell : ( threadId ) =>
26622666 Effect . succeed ( shells . find ( ( shell ) => shell . id === threadId ) ?? null ) ,
26632667 sendToThread : ( ) => Ref . update ( sent , ( count ) => count + 1 ) . pipe ( Effect . as ( { } as never ) ) ,
2668+ ...overrides ,
26642669 } ) ,
26652670 ServerSettings . layerTest ( ) ,
26662671 Layer . mock ( ProviderRegistry . ProviderRegistry ) ( { getProviders : Effect . succeed ( [ ] ) } ) ,
@@ -2683,14 +2688,15 @@ describe("OrchestratorMcpService thread lookup", () => {
26832688 const send = yield * mcp
26842689 . sendToThread ( client , { threadId : bareId , message : "hello" } )
26852690 . pipe ( Effect . flip ) ;
2686- return { read, send, sends : yield * Ref . get ( sent ) } ;
2691+ const wait = yield * mcp . waitForThread ( client , { threadId : bareId } ) . pipe ( Effect . flip ) ;
2692+ return { read, send, wait, sends : yield * Ref . get ( sent ) } ;
26872693 } ) . pipe ( Effect . provide ( service ( shells , sent ) ) ) ;
26882694 } ) ;
26892695
26902696 it . effect ( "points a bare uuid at the mcp: thread it belongs to" , ( ) =>
26912697 Effect . gen ( function * ( ) {
2692- const { read, send, sends } = yield * failuresFor ( [ launched ] ) ;
2693- for ( const error of [ read , send ] ) {
2698+ const { read, send, wait , sends } = yield * failuresFor ( [ launched ] ) ;
2699+ for ( const error of [ read , send , wait ] ) {
26942700 assert . equal ( error . code , "thread_not_found" ) ;
26952701 assert . include ( error . message , `mcp:${ bareId } ` ) ;
26962702 }
@@ -2700,19 +2706,76 @@ describe("OrchestratorMcpService thread lookup", () => {
27002706
27012707 it . effect ( "keeps the plain message for an id that matches nothing" , ( ) =>
27022708 Effect . gen ( function * ( ) {
2703- const { read, send } = yield * failuresFor ( [ ] ) ;
2709+ const { read, send, wait } = yield * failuresFor ( [ ] ) ;
27042710 assert . equal ( read . code , "thread_not_found" ) ;
27052711 assert . equal ( read . message , `Thread ${ bareId } is no longer available.` ) ;
27062712 assert . equal ( send . code , "thread_not_found" ) ;
27072713 assert . equal ( send . message , `Thread ${ bareId } was not found.` ) ;
2714+ assert . equal ( wait . code , "thread_not_found" ) ;
2715+ assert . equal ( wait . message , send . message ) ;
27082716 } ) ,
27092717 ) ;
27102718
27112719 it . effect ( "does not name an mcp: thread that was deleted" , ( ) =>
27122720 Effect . gen ( function * ( ) {
2713- const { read, send } = yield * failuresFor ( [ deletedLaunched ] ) ;
2721+ const { read, send, wait } = yield * failuresFor ( [ deletedLaunched ] ) ;
27142722 assert . equal ( read . message , `Thread ${ bareId } is no longer available.` ) ;
27152723 assert . equal ( send . message , `Thread ${ bareId } was not found.` ) ;
2724+ assert . equal ( wait . message , send . message ) ;
2725+ } ) ,
2726+ ) ;
2727+
2728+ it . effect ( "refuses waiting without orchestration capability before reading the target" , ( ) =>
2729+ Effect . gen ( function * ( ) {
2730+ const sent = yield * Ref . make ( 0 ) ;
2731+ return yield * Effect . gen ( function * ( ) {
2732+ const mcp = yield * OrchestratorMcpService . OrchestratorMcpService ;
2733+ const error = yield * mcp
2734+ . waitForThread ( { ...client , capabilities : new Set ( ) } , { threadId : bareId } )
2735+ . pipe ( Effect . flip ) ;
2736+ assert . equal ( error . code , "capability_denied" ) ;
2737+ } ) . pipe (
2738+ Effect . provide (
2739+ service ( [ ] , sent , {
2740+ getThreadShell : ( ) => Effect . die ( "Unauthorized target access" ) ,
2741+ } ) ,
2742+ ) ,
2743+ ) ;
2744+ } ) ,
2745+ ) ;
2746+
2747+ it . effect ( "waits on the caller's own thread without a separate shell lookup" , ( ) =>
2748+ Effect . gen ( function * ( ) {
2749+ const sent = yield * Ref . make ( 0 ) ;
2750+ return yield * Effect . gen ( function * ( ) {
2751+ const mcp = yield * OrchestratorMcpService . OrchestratorMcpService ;
2752+ const result = yield * mcp . waitForThread (
2753+ {
2754+ ...client ,
2755+ thread : {
2756+ threadId : launched . id ,
2757+ providerSessionId : "provider-session:wait-self" ,
2758+ providerInstanceId : ProviderInstanceId . make ( "codex" ) ,
2759+ } ,
2760+ } ,
2761+ { threadId : launched . id } ,
2762+ ) ;
2763+ assert . deepEqual ( result , {
2764+ threadId : launched . id ,
2765+ runId : null ,
2766+ status : "idle" ,
2767+ timedOut : false ,
2768+ } ) ;
2769+ } ) . pipe (
2770+ Effect . provide (
2771+ service ( [ ] , sent , {
2772+ getThreadShell : ( ) => Effect . die ( "Unexpected shell lookup for the caller" ) ,
2773+ getThreadRecords : ( ) => Effect . succeed ( idleThreadProjection ( launched ) ) ,
2774+ waitForThread : ( ) =>
2775+ Effect . succeed ( { threadId : launched . id , run : null , timedOut : false } ) ,
2776+ } ) ,
2777+ ) ,
2778+ ) ;
27162779 } ) ,
27172780 ) ;
27182781} ) ;
0 commit comments