@@ -883,6 +883,10 @@ def test_get_service(self, mock_control_api_class):
883883 mock_control_api_class .return_value = mock_control_api
884884
885885 mock_result = MagicMock ()
886+ mock_result .to_map .return_value = {
887+ "modelServiceName" : "test" ,
888+ "providerSettings" : {"baseUrl" : "https://example.com/v1" },
889+ }
886890 mock_control_api .get_model_service .return_value = mock_result
887891
888892 client = ModelClient ()
@@ -906,6 +910,10 @@ def test_get_auto_detect(self, mock_control_api_class):
906910 mock_control_api_class .return_value = mock_control_api
907911
908912 mock_result = MagicMock ()
913+ mock_result .to_map .return_value = {
914+ "modelServiceName" : "test" ,
915+ "providerSettings" : {"baseUrl" : "https://example.com/v1" },
916+ }
909917 mock_control_api .get_model_service .return_value = mock_result
910918
911919 client = ModelClient ()
@@ -944,6 +952,35 @@ def test_get_auto_detect_falls_back_to_proxy(self, mock_control_api_class):
944952 mock_control_api .get_model_proxy .assert_called_once ()
945953 assert isinstance (result , ModelProxy )
946954
955+ @patch .dict (
956+ os .environ ,
957+ {
958+ "AGENTRUN_ACCESS_KEY_ID" : "test-access-key" ,
959+ "AGENTRUN_ACCESS_KEY_SECRET" : "test-secret" ,
960+ "AGENTRUN_ACCOUNT_ID" : "test-account" ,
961+ },
962+ )
963+ @patch ("agentrun.model.client.ModelControlAPI" )
964+ def test_get_auto_detect_falls_back_when_service_is_incomplete (
965+ self , mock_control_api_class
966+ ):
967+ """A service-shaped response without provider settings is not usable."""
968+ mock_control_api = MagicMock ()
969+ mock_control_api_class .return_value = mock_control_api
970+
971+ service_result = MagicMock ()
972+ service_result .to_map .return_value = {"modelServiceName" : "test" }
973+ mock_control_api .get_model_service .return_value = service_result
974+ proxy_result = MagicMock ()
975+ proxy_result .to_map .return_value = {"modelProxyName" : "test" }
976+ mock_control_api .get_model_proxy .return_value = proxy_result
977+
978+ result = ModelClient ().get ("test" )
979+
980+ mock_control_api .get_model_service .assert_called_once ()
981+ mock_control_api .get_model_proxy .assert_called_once ()
982+ assert isinstance (result , ModelProxy )
983+
947984 @patch .dict (
948985 os .environ ,
949986 {
@@ -1029,6 +1066,40 @@ async def test_get_async_auto_detect_fallback(self, mock_control_api_class):
10291066 mock_control_api .get_model_proxy_async .assert_called_once ()
10301067 assert isinstance (result , ModelProxy )
10311068
1069+ @patch .dict (
1070+ os .environ ,
1071+ {
1072+ "AGENTRUN_ACCESS_KEY_ID" : "test-access-key" ,
1073+ "AGENTRUN_ACCESS_KEY_SECRET" : "test-secret" ,
1074+ "AGENTRUN_ACCOUNT_ID" : "test-account" ,
1075+ },
1076+ )
1077+ @patch ("agentrun.model.client.ModelControlAPI" )
1078+ @pytest .mark .asyncio
1079+ async def test_get_async_falls_back_when_service_is_incomplete (
1080+ self , mock_control_api_class
1081+ ):
1082+ """Async auto-detection also rejects an incomplete service response."""
1083+ mock_control_api = MagicMock ()
1084+ mock_control_api_class .return_value = mock_control_api
1085+
1086+ service_result = MagicMock ()
1087+ service_result .to_map .return_value = {"modelServiceName" : "test" }
1088+ mock_control_api .get_model_service_async = AsyncMock (
1089+ return_value = service_result
1090+ )
1091+ proxy_result = MagicMock ()
1092+ proxy_result .to_map .return_value = {"modelProxyName" : "test" }
1093+ mock_control_api .get_model_proxy_async = AsyncMock (
1094+ return_value = proxy_result
1095+ )
1096+
1097+ result = await ModelClient ().get_async ("test" )
1098+
1099+ mock_control_api .get_model_service_async .assert_called_once ()
1100+ mock_control_api .get_model_proxy_async .assert_called_once ()
1101+ assert isinstance (result , ModelProxy )
1102+
10321103 @patch .dict (
10331104 os .environ ,
10341105 {
0 commit comments