@@ -2204,3 +2204,79 @@ describe("OrchestratorMcpService provider resolution", () => {
22042204 ) ;
22052205 } ) ;
22062206} ) ;
2207+
2208+ describe ( "OrchestratorMcpService thread lookup" , ( ) => {
2209+ const bareId = ThreadId . make ( "5d0b4a3e-8c1f-4a52-9d37-2f6c7e1b9a04" ) ;
2210+ const launched = liveThreadShell ( ThreadId . make ( `mcp:${ bareId } ` ) ) ;
2211+ const deletedLaunched = { ...launched , deletedAt : DateTime . makeUnsafe ( "2026-10-05T00:00:00Z" ) } ;
2212+ const client : McpInvocationScope = {
2213+ environmentId : EnvironmentId . make ( "environment:thread-lookup" ) ,
2214+ requestNamespace : "client:thread-lookup" ,
2215+ thread : undefined ,
2216+ client : { sessionId : "thread-lookup" , label : "Claude Code" , access : "full-access" } ,
2217+ capabilities : new Set ( [ "orchestration" ] ) ,
2218+ issuedAt : 1 ,
2219+ } ;
2220+ const service = ( shells : ReadonlyArray < OrchestrationV2ThreadShell > , sent : Ref . Ref < number > ) =>
2221+ layerOrchestratorService . pipe (
2222+ Layer . provide (
2223+ Layer . mergeAll (
2224+ NodeServices . layer ,
2225+ Layer . mock ( ThreadManagementService . ThreadManagementService ) ( {
2226+ getThreadShell : ( threadId ) =>
2227+ Effect . succeed ( shells . find ( ( shell ) => shell . id === threadId ) ?? null ) ,
2228+ sendToThread : ( ) => Ref . update ( sent , ( count ) => count + 1 ) . pipe ( Effect . as ( { } as never ) ) ,
2229+ } ) ,
2230+ ServerSettings . layerTest ( ) ,
2231+ Layer . mock ( ProviderRegistry . ProviderRegistry ) ( { getProviders : Effect . succeed ( [ ] ) } ) ,
2232+ Layer . mock ( ProviderAdapterRegistry . ProviderAdapterRegistryV2 ) ( {
2233+ list : ( ) => Effect . succeed ( [ ] ) ,
2234+ } ) ,
2235+ Layer . mock ( ProjectService . ProjectService ) ( { } ) ,
2236+ Layer . mock ( SecretRequests . SecretRequests ) ( { } ) ,
2237+ Layer . mock ( ScheduledTaskService . ScheduledTaskService ) ( { } ) ,
2238+ ) ,
2239+ ) ,
2240+ ) ;
2241+ const failuresFor = ( shells : ReadonlyArray < OrchestrationV2ThreadShell > ) =>
2242+ Effect . gen ( function * ( ) {
2243+ const sent = yield * Ref . make ( 0 ) ;
2244+ return yield * Effect . gen ( function * ( ) {
2245+ const mcp = yield * OrchestratorMcpService . OrchestratorMcpService ;
2246+ const read = yield * mcp . readThread ( client , { threadId : bareId } ) . pipe ( Effect . flip ) ;
2247+ const send = yield * mcp
2248+ . sendToThread ( client , { threadId : bareId , message : "hello" } )
2249+ . pipe ( Effect . flip ) ;
2250+ return { read, send, sends : yield * Ref . get ( sent ) } ;
2251+ } ) . pipe ( Effect . provide ( service ( shells , sent ) ) ) ;
2252+ } ) ;
2253+
2254+ it . effect ( "points a bare uuid at the mcp: thread it belongs to" , ( ) =>
2255+ Effect . gen ( function * ( ) {
2256+ const { read, send, sends } = yield * failuresFor ( [ launched ] ) ;
2257+ for ( const error of [ read , send ] ) {
2258+ assert . equal ( error . code , "thread_not_found" ) ;
2259+ assert . include ( error . message , `mcp:${ bareId } ` ) ;
2260+ }
2261+ assert . equal ( sends , 0 ) ;
2262+ } ) ,
2263+ ) ;
2264+
2265+ it . effect ( "keeps the plain message for an id that matches nothing" , ( ) =>
2266+ Effect . gen ( function * ( ) {
2267+ const { read, send } = yield * failuresFor ( [ ] ) ;
2268+ assert . equal ( read . code , "thread_not_found" ) ;
2269+ assert . equal ( read . message , `Thread ${ bareId } is no longer available.` ) ;
2270+ assert . equal ( send . code , "thread_not_found" ) ;
2271+ assert . equal ( send . message , `Thread ${ bareId } was not found.` ) ;
2272+ } ) ,
2273+ ) ;
2274+
2275+ it . effect ( "does not name an mcp: thread that was deleted" , ( ) =>
2276+ Effect . gen ( function * ( ) {
2277+ const { read, send } = yield * failuresFor ( [ deletedLaunched ] ) ;
2278+ assert . equal ( read . message , `Thread ${ bareId } is no longer available.` ) ;
2279+ assert . equal ( send . message , `Thread ${ bareId } was not found.` ) ;
2280+ } ) ,
2281+ ) ;
2282+ } ) ;
0 commit comments