2828_OPEN_MODEL = "google/gemma3@gemma-3-12b-it"
2929
3030
31+ _CATALOG_HTTP_OPTIONS = model_garden .genai_types .HttpOptions (
32+ base_url = "https://us-central1-aiplatform.googleapis.com/"
33+ )
34+
35+
3136@pytest .fixture
3237def mock_client ():
3338 mock_api_client = mock .Mock (spec = client .Client )
3439 mock_api_client .project = _TEST_PROJECT
3540 mock_api_client .location = _TEST_LOCATION
3641 mock_api_client .vertexai = True
42+ mock_api_client .custom_base_url = None
3743
3844 return model_garden .ModelGarden (mock_api_client )
3945
@@ -44,6 +50,7 @@ def mock_async_client():
4450 mock_api_client .project = _TEST_PROJECT
4551 mock_api_client .location = _TEST_LOCATION
4652 mock_api_client .vertexai = True
53+ mock_api_client .custom_base_url = None
4754
4855 return model_garden .AsyncModelGarden (mock_api_client )
4956
@@ -488,6 +495,7 @@ def test_list_publisher_model_deploy_options_basic(mock_client):
488495 config = types .GetPublisherModelConfig (
489496 is_hugging_face_model = False ,
490497 include_equivalent_model_garden_model_deployment_configs = True ,
498+ http_options = _CATALOG_HTTP_OPTIONS ,
491499 ),
492500 )
493501 assert len (options ) == 1
@@ -826,10 +834,125 @@ def test_list_publisher_model_deploy_options_hugging_face_model(mock_client):
826834 config = types .GetPublisherModelConfig (
827835 is_hugging_face_model = True ,
828836 include_equivalent_model_garden_model_deployment_configs = True ,
837+ http_options = _CATALOG_HTTP_OPTIONS ,
829838 ),
830839 )
831840
832841
842+ # --- Catalog reads are served from us-central1 ---------------------------
843+
844+
845+ def test_list_models_catalog_routed_to_us_central1 (mock_client ):
846+ """A client outside us-central1 still lists the catalog from us-central1."""
847+ mock_client ._api_client .location = "europe-west4"
848+ with mock .patch .object (
849+ mock_client ,
850+ "_list_publisher_models" ,
851+ return_value = types .ListPublisherModelsResponse (publisher_models = []),
852+ ) as mock_list :
853+ mock_client .list_deployable_models ()
854+ mock_client .list_models ()
855+
856+ for call in mock_list .call_args_list :
857+ assert call .kwargs ["config" ].http_options == _CATALOG_HTTP_OPTIONS
858+
859+
860+ def test_list_models_catalog_routing_kept_across_pages (mock_client ):
861+ """Every page request carries the us-central1 base URL, not just the first."""
862+ pages = [
863+ types .ListPublisherModelsResponse (
864+ publisher_models = [
865+ _make_deployable_model ("publishers/google/models/a" )
866+ ],
867+ next_page_token = "page-2" ,
868+ ),
869+ types .ListPublisherModelsResponse (
870+ publisher_models = [
871+ _make_deployable_model ("publishers/google/models/b" )
872+ ],
873+ ),
874+ ]
875+ with mock .patch .object (
876+ mock_client , "_list_publisher_models" , side_effect = pages
877+ ) as mock_list :
878+ models = mock_client .list_models ()
879+
880+ assert models == ["google/a@001" , "google/b@001" ]
881+ second_config = mock_list .call_args_list [1 ].kwargs ["config" ]
882+ assert second_config .page_token == "page-2"
883+ assert second_config .http_options == _CATALOG_HTTP_OPTIONS
884+
885+
886+ def test_list_publisher_model_deploy_options_routed_to_us_central1 (
887+ mock_client ,
888+ ):
889+ """GetPublisherModel is sent to us-central1 for a client in another region."""
890+ mock_client ._api_client .location = "asia-southeast1"
891+ dummy_model = _make_model_with_deploy_options ([_make_deploy_option ()])
892+ with mock .patch .object (
893+ mock_client , "_get_publisher_model" , return_value = dummy_model
894+ ) as mock_get :
895+ mock_client .list_publisher_model_deploy_options (model = _OPEN_MODEL )
896+
897+ assert mock_get .call_args .kwargs ["config" ].http_options == (
898+ _CATALOG_HTTP_OPTIONS
899+ )
900+
901+
902+ def test_catalog_reads_keep_custom_base_url (mock_client ):
903+ """A client created with a custom base_url is not redirected."""
904+ mock_client ._api_client .custom_base_url = "https://my-proxy.example.com/"
905+ dummy_model = _make_model_with_deploy_options ([_make_deploy_option ()])
906+ with (
907+ mock .patch .object (
908+ mock_client ,
909+ "_list_publisher_models" ,
910+ return_value = types .ListPublisherModelsResponse (publisher_models = []),
911+ ) as mock_list ,
912+ mock .patch .object (
913+ mock_client , "_get_publisher_model" , return_value = dummy_model
914+ ) as mock_get ,
915+ ):
916+ mock_client .list_models ()
917+ mock_client .list_publisher_model_deploy_options (model = _OPEN_MODEL )
918+
919+ assert mock_list .call_args .kwargs ["config" ].http_options is None
920+ assert mock_get .call_args .kwargs ["config" ].http_options is None
921+
922+
923+ def test_catalog_reads_routed_to_us_central1_async (mock_async_client ):
924+ """The async surface routes catalog reads the same way."""
925+ mock_async_client ._api_client .location = "europe-west4"
926+ dummy_model = _make_model_with_deploy_options ([_make_deploy_option ()])
927+ with (
928+ mock .patch .object (
929+ mock_async_client ,
930+ "_list_publisher_models" ,
931+ new = mock .AsyncMock (
932+ return_value = types .ListPublisherModelsResponse (
933+ publisher_models = []
934+ )
935+ ),
936+ ) as mock_list ,
937+ mock .patch .object (
938+ mock_async_client ,
939+ "_get_publisher_model" ,
940+ new = mock .AsyncMock (return_value = dummy_model ),
941+ ) as mock_get ,
942+ ):
943+ asyncio .run (mock_async_client .list_deployable_models ())
944+ asyncio .run (
945+ mock_async_client .list_publisher_model_deploy_options (model = _OPEN_MODEL )
946+ )
947+
948+ assert mock_list .call_args .kwargs ["config" ].http_options == (
949+ _CATALOG_HTTP_OPTIONS
950+ )
951+ assert mock_get .call_args .kwargs ["config" ].http_options == (
952+ _CATALOG_HTTP_OPTIONS
953+ )
954+
955+
833956def test_list_publisher_model_deploy_options_async (mock_async_client ):
834957 """Tests the async client returns deploy options."""
835958 dummy_model = _make_model_with_deploy_options ([_make_deploy_option ()])
0 commit comments