@@ -861,6 +861,7 @@ async def test_session_resumed_for_same_session(
861861 streaming = unittest .mock .ANY ,
862862 tools = unittest .mock .ANY ,
863863 mcp_servers = unittest .mock .ANY ,
864+ provider = unittest .mock .ANY ,
864865 )
865866
866867 async def test_session_config_includes_model (
@@ -1084,6 +1085,198 @@ async def test_session_config_excludes_mcp_servers_when_not_set(
10841085 assert config ["mcp_servers" ] is None
10851086
10861087
1088+ class TestGitHubCopilotAgentProvider :
1089+ """Test cases for provider configuration (BYOK / Managed Identity)."""
1090+
1091+ async def test_provider_passed_to_create_session (
1092+ self ,
1093+ mock_client : MagicMock ,
1094+ ) -> None :
1095+ """Test that provider config is passed through to create_session."""
1096+ from copilot .session import ProviderConfig
1097+
1098+ provider : ProviderConfig = {
1099+ "type" : "azure" ,
1100+ "base_url" : "https://my-resource.openai.azure.com" ,
1101+ "bearer_token" : "test-token" ,
1102+ }
1103+
1104+ agent : GitHubCopilotAgent [GitHubCopilotOptions ] = GitHubCopilotAgent (
1105+ client = mock_client ,
1106+ default_options = {"provider" : provider },
1107+ )
1108+ await agent .start ()
1109+
1110+ await agent ._get_or_create_session (AgentSession ()) # type: ignore
1111+
1112+ call_args = mock_client .create_session .call_args
1113+ config = call_args .kwargs
1114+ assert config ["provider" ]["type" ] == "azure"
1115+ assert config ["provider" ]["base_url" ] == "https://my-resource.openai.azure.com"
1116+ assert config ["provider" ]["bearer_token" ] == "test-token"
1117+
1118+ async def test_provider_passed_to_resume_session (
1119+ self ,
1120+ mock_client : MagicMock ,
1121+ ) -> None :
1122+ """Test that provider config is passed through to resume_session."""
1123+ from copilot .session import ProviderConfig
1124+
1125+ provider : ProviderConfig = {
1126+ "type" : "azure" ,
1127+ "base_url" : "https://my-resource.openai.azure.com" ,
1128+ "bearer_token" : "test-token" ,
1129+ }
1130+
1131+ agent : GitHubCopilotAgent [GitHubCopilotOptions ] = GitHubCopilotAgent (
1132+ client = mock_client ,
1133+ default_options = {"provider" : provider },
1134+ )
1135+ await agent .start ()
1136+
1137+ session = AgentSession ()
1138+ session .service_session_id = "existing-session-id"
1139+
1140+ await agent ._get_or_create_session (session ) # type: ignore
1141+
1142+ mock_client .resume_session .assert_called_once ()
1143+ call_args = mock_client .resume_session .call_args
1144+ config = call_args .kwargs
1145+ assert config ["provider" ]["type" ] == "azure"
1146+
1147+ async def test_session_config_excludes_provider_when_not_set (
1148+ self ,
1149+ mock_client : MagicMock ,
1150+ ) -> None :
1151+ """Test that provider is None in session config when not set."""
1152+ agent = GitHubCopilotAgent (client = mock_client )
1153+ await agent .start ()
1154+
1155+ await agent ._get_or_create_session (AgentSession ()) # type: ignore
1156+
1157+ call_args = mock_client .create_session .call_args
1158+ config = call_args .kwargs
1159+ assert config ["provider" ] is None
1160+
1161+ async def test_resume_session_excludes_provider_when_not_set (
1162+ self ,
1163+ mock_client : MagicMock ,
1164+ ) -> None :
1165+ """Test that provider is None in resume session config when not set."""
1166+ agent = GitHubCopilotAgent (client = mock_client )
1167+ await agent .start ()
1168+
1169+ session = AgentSession ()
1170+ session .service_session_id = "existing-session-id"
1171+
1172+ await agent ._get_or_create_session (session ) # type: ignore
1173+
1174+ call_args = mock_client .resume_session .call_args
1175+ config = call_args .kwargs
1176+ assert config ["provider" ] is None
1177+
1178+ async def test_runtime_provider_takes_precedence (
1179+ self ,
1180+ mock_client : MagicMock ,
1181+ ) -> None :
1182+ """Test that runtime provider options override default_options provider."""
1183+ from copilot .session import ProviderConfig
1184+
1185+ default_provider : ProviderConfig = {
1186+ "type" : "azure" ,
1187+ "base_url" : "https://default.openai.azure.com" ,
1188+ "bearer_token" : "default-token" ,
1189+ }
1190+ runtime_provider : ProviderConfig = {
1191+ "type" : "openai" ,
1192+ "base_url" : "https://runtime.openai.com" ,
1193+ "api_key" : "runtime-key" ,
1194+ }
1195+
1196+ agent : GitHubCopilotAgent [GitHubCopilotOptions ] = GitHubCopilotAgent (
1197+ client = mock_client ,
1198+ default_options = {"provider" : default_provider },
1199+ )
1200+ await agent .start ()
1201+
1202+ await agent ._get_or_create_session ( # type: ignore
1203+ AgentSession (),
1204+ runtime_options = {"provider" : runtime_provider },
1205+ )
1206+
1207+ call_args = mock_client .create_session .call_args
1208+ config = call_args .kwargs
1209+ assert config ["provider" ]["type" ] == "openai"
1210+ assert config ["provider" ]["base_url" ] == "https://runtime.openai.com"
1211+
1212+ async def test_provider_not_leaked_into_default_options (
1213+ self ,
1214+ mock_client : MagicMock ,
1215+ ) -> None :
1216+ """Test that provider is popped from opts and not left in _default_options."""
1217+ from copilot .session import ProviderConfig
1218+
1219+ provider : ProviderConfig = {
1220+ "type" : "azure" ,
1221+ "base_url" : "https://my-resource.openai.azure.com" ,
1222+ "bearer_token" : "test-token" ,
1223+ }
1224+
1225+ agent : GitHubCopilotAgent [GitHubCopilotOptions ] = GitHubCopilotAgent (
1226+ client = mock_client ,
1227+ default_options = {"provider" : provider , "model" : "gpt-5" },
1228+ )
1229+
1230+ assert "provider" not in agent ._default_options
1231+ assert agent ._provider is not None
1232+ assert agent ._provider ["type" ] == "azure"
1233+
1234+ async def test_provider_coexists_with_other_options (
1235+ self ,
1236+ mock_client : MagicMock ,
1237+ ) -> None :
1238+ """Test that provider works alongside model, tools, and mcp_servers."""
1239+ from copilot .session import MCPServerConfig , ProviderConfig
1240+
1241+ provider : ProviderConfig = {
1242+ "type" : "azure" ,
1243+ "base_url" : "https://my-resource.openai.azure.com" ,
1244+ "bearer_token" : "test-token" ,
1245+ }
1246+ mcp_servers : dict [str , MCPServerConfig ] = {
1247+ "test-server" : {
1248+ "type" : "stdio" ,
1249+ "command" : "echo" ,
1250+ "args" : ["hello" ],
1251+ "tools" : ["*" ],
1252+ },
1253+ }
1254+
1255+ def my_tool (arg : str ) -> str :
1256+ """A test tool."""
1257+ return arg
1258+
1259+ agent : GitHubCopilotAgent [GitHubCopilotOptions ] = GitHubCopilotAgent (
1260+ client = mock_client ,
1261+ tools = [my_tool ],
1262+ default_options = {
1263+ "model" : "gpt-5" ,
1264+ "provider" : provider ,
1265+ "mcp_servers" : mcp_servers ,
1266+ },
1267+ )
1268+ await agent .start ()
1269+
1270+ await agent ._get_or_create_session (AgentSession ()) # type: ignore
1271+
1272+ call_args = mock_client .create_session .call_args
1273+ config = call_args .kwargs
1274+ assert config ["provider" ]["type" ] == "azure"
1275+ assert config ["model" ] == "gpt-5"
1276+ assert config ["mcp_servers" ] is not None
1277+ assert config ["tools" ] is not None
1278+
1279+
10871280class TestGitHubCopilotAgentToolConversion :
10881281 """Test cases for tool conversion."""
10891282
0 commit comments