@@ -1070,6 +1070,95 @@ it.effect("hides tools for links and refuses another environment while the beta
10701070 ) . pipe ( Effect . provide ( NodeHttpServer . layerTest ) ) ,
10711071) ;
10721072
1073+ it . effect ( "lists pull request watch tools for parents and delegated children" , ( ) =>
1074+ Effect . scoped (
1075+ Effect . gen ( function * ( ) {
1076+ const scopeFor = (
1077+ token : string ,
1078+ subagent : boolean ,
1079+ ) : McpInvocationContext . McpThreadInvocationScope => ( {
1080+ environmentId,
1081+ requestNamespace : token ,
1082+ thread : {
1083+ threadId : ThreadId . make ( `thread-${ token } ` ) ,
1084+ providerSessionId : token ,
1085+ providerInstanceId : ProviderInstanceId . make ( "codex" ) ,
1086+ subagent,
1087+ } ,
1088+ client : undefined ,
1089+ capabilities : new Set ( [ "pull-requests" ] ) ,
1090+ issuedAt : 1 ,
1091+ } ) ;
1092+ const scopes = new Map ( [
1093+ [ "parentToken" , scopeFor ( "parentToken" , false ) ] ,
1094+ [ "childToken" , scopeFor ( "childToken" , true ) ] ,
1095+ ] ) ;
1096+ const serverLayer = McpHttpServer . layerPullRequestsToolkit . pipe (
1097+ Layer . provideMerge (
1098+ McpHttpServer . layerMcpTransport . pipe ( Layer . provide ( ServerSettings . layerTest ( ) ) ) ,
1099+ ) ,
1100+ Layer . provide (
1101+ Layer . mock ( McpSessionRegistry . McpSessionRegistry ) ( {
1102+ resolve : ( token ) => Effect . succeed ( scopes . get ( token ) ) ,
1103+ } ) ,
1104+ ) ,
1105+ Layer . provide (
1106+ Layer . mergeAll (
1107+ McpToolAccessTestkit . liveThreadsLayer ,
1108+ Layer . mock ( ProjectService . ProjectService ) ( { } ) ,
1109+ Layer . mock ( PullRequestReviewGuideService . PullRequestReviewGuideService ) ( { } ) ,
1110+ Layer . mock ( Orchestrator . OrchestratorV2 ) ( { } ) ,
1111+ Layer . mock ( ProjectionStore . ProjectionStoreV2 ) ( { } ) ,
1112+ NodeServices . layer ,
1113+ ) ,
1114+ ) ,
1115+ ) ;
1116+ yield * HttpRouter . serve ( serverLayer , { disableListenLog : true , disableLogger : true } ) . pipe (
1117+ Layer . build ,
1118+ ) ;
1119+ const httpClient = yield * HttpClient . HttpClient ;
1120+ const listedTools = ( token : string ) =>
1121+ Effect . gen ( function * ( ) {
1122+ const headers = {
1123+ accept : "application/json, text/event-stream" ,
1124+ authorization : `Bearer ${ token } ` ,
1125+ } ;
1126+ const initialize = yield * httpClient . post ( "/mcp" , {
1127+ headers,
1128+ body : HttpBody . text (
1129+ `{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"probe","version":"1.0.0"}}}` ,
1130+ "application/json" ,
1131+ ) ,
1132+ } ) ;
1133+ const listed = yield * httpClient . post ( "/mcp" , {
1134+ headers : {
1135+ ...headers ,
1136+ "mcp-session-id" : initialize . headers [ "mcp-session-id" ] ! ,
1137+ "mcp-protocol-version" : "2025-06-18" ,
1138+ } ,
1139+ body : HttpBody . text (
1140+ `{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}` ,
1141+ "application/json" ,
1142+ ) ,
1143+ } ) ;
1144+ const body = ( yield * listed . json ) as {
1145+ readonly result : { readonly tools : ReadonlyArray < { readonly name : string } > } ;
1146+ } ;
1147+ return body . result . tools . map ( ( tool ) => tool . name ) ;
1148+ } ) ;
1149+
1150+ const parentTools = yield * listedTools ( "parentToken" ) ;
1151+ const childTools = yield * listedTools ( "childToken" ) ;
1152+ expect ( parentTools ) . toEqual (
1153+ expect . arrayContaining ( [ "link_pull_request" , "watch_pull_request" , "unwatch_pull_request" ] ) ,
1154+ ) ;
1155+ expect ( childTools ) . toContain ( "link_pull_request" ) ;
1156+ expect ( childTools ) . toContain ( "watch_pull_request" ) ;
1157+ expect ( childTools ) . toContain ( "unwatch_pull_request" ) ;
1158+ } ) ,
1159+ ) . pipe ( Effect . provide ( NodeHttpServer . layerTest ) ) ,
1160+ ) ;
1161+
10731162it . effect (
10741163 "narrows an OAuth client's modes to the T3-Mode-Limit it sends, and never widens them" ,
10751164 ( ) =>
0 commit comments