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