88
99import java .util .HashMap ;
1010import java .util .List ;
11+ import java .util .Map ;
12+ import java .util .concurrent .CompletableFuture ;
1113import java .util .concurrent .TimeUnit ;
1214
1315import org .junit .jupiter .api .AfterAll ;
2325import com .github .copilot .sdk .json .PermissionHandler ;
2426import com .github .copilot .sdk .json .ResumeSessionConfig ;
2527import com .github .copilot .sdk .json .SessionConfig ;
28+ import com .github .copilot .sdk .json .ToolDefinition ;
2629
2730/**
2831 * Tests for MCP Servers and Custom Agents functionality.
@@ -349,17 +352,33 @@ void testShouldHideExcludedToolsFromDefaultAgent() throws Exception {
349352 ctx .configureForTest ("mcp_and_agents" , "should_hide_excluded_tools_from_default_agent" );
350353
351354 try (CopilotClient client = ctx .createClient ()) {
355+ // Register a secret_tool and exclude it from the default agent — the LLM
356+ // should report it has no access to the tool.
357+ Map <String , Object > parameters = new HashMap <>();
358+ parameters .put ("type" , "object" );
359+ parameters .put ("properties" , Map .of ("input" , Map .of ("type" , "string" )));
360+ parameters .put ("required" , List .of ("input" ));
361+
362+ ToolDefinition secretTool = ToolDefinition .create ("secret_tool" ,
363+ "A secret tool hidden from the default agent" , parameters ,
364+ invocation -> CompletableFuture .completedFuture ("SECRET" ));
365+
352366 SessionConfig config = new SessionConfig ().setOnPermissionRequest (PermissionHandler .APPROVE_ALL )
353- .setDefaultAgent (new DefaultAgentConfig ().setExcludedTools (List .of ("view" )));
367+ .setTools (List .of (secretTool ))
368+ .setDefaultAgent (new DefaultAgentConfig ().setExcludedTools (List .of ("secret_tool" )));
354369
355370 CopilotSession session = client .createSession (config ).get ();
356371
357372 assertNotNull (session .getSessionId ());
358373
359- AssistantMessageEvent response = session .sendAndWait (new MessageOptions ().setPrompt ("What is 2+2?" )).get (60 ,
360- TimeUnit .SECONDS );
374+ AssistantMessageEvent response = session
375+ .sendAndWait (new MessageOptions ()
376+ .setPrompt ("Do you have access to a tool called secret_tool? Answer yes or no." ))
377+ .get (60 , TimeUnit .SECONDS );
361378
362379 assertNotNull (response );
380+ assertTrue (response .getData ().content ().toLowerCase ().contains ("no" ),
381+ "Response should indicate that secret_tool is not accessible: " + response .getData ().content ());
363382 session .close ();
364383 }
365384 }
@@ -380,7 +399,11 @@ void testShouldAcceptDefaultAgentConfigurationOnSessionResume() throws Exception
380399
381400 assertNotNull (session .getSessionId ());
382401 String sessionId = session .getSessionId ();
383- session .close ();
402+ // Do not call session.close() here — that invokes session.destroy on the
403+ // server,
404+ // which removes the session and causes the subsequent resumeSession to fail
405+ // with "Session not found". The session handle is simply abandoned and the
406+ // server-side session remains alive for the resume call below.
384407
385408 CopilotSession resumedSession = client .resumeSession (sessionId ,
386409 new ResumeSessionConfig ().setOnPermissionRequest (PermissionHandler .APPROVE_ALL )
0 commit comments