@@ -2948,7 +2948,7 @@ def test_run_query_job_agent_engine(self, mock_uuid, get_mock, mock_storage_clie
29482948 name = _TEST_AGENT_ENGINE_RESOURCE_NAME ,
29492949 config = {
29502950 "query" : _TEST_QUERY_PROMPT ,
2951- "gcs_bucket " : "gs://my-input-bucket/" ,
2951+ "output_gcs_uri " : "gs://my-input-bucket/" ,
29522952 },
29532953 )
29542954
@@ -2959,17 +2959,17 @@ def test_run_query_job_agent_engine(self, mock_uuid, get_mock, mock_storage_clie
29592959
29602960 assert result == _genai_types .RunQueryJobResult (
29612961 job_name = "projects/123/locations/us-central1/reasoningEngines/456/operations/789" ,
2962- input_gcs_uri = "gs://my-input-bucket/input_b92b9b89 -4585-4146-8ee5-22fe99802a8e .json" ,
2963- output_gcs_uri = "gs://my-input-bucket/output_b92b9b89 -4585-4146-8ee5-22fe99802a8e .json" ,
2962+ input_gcs_uri = "gs://my-input-bucket/b92b9b89 -4585-4146-8ee5-22fe99802a8e_input .json" ,
2963+ output_gcs_uri = "gs://my-input-bucket/b92b9b89 -4585-4146-8ee5-22fe99802a8e_output .json" ,
29642964 )
29652965
29662966 request_mock .assert_called_with (
29672967 "post" ,
29682968 f"{ _TEST_AGENT_ENGINE_RESOURCE_NAME } :asyncQuery" ,
29692969 {
29702970 "_url" : {"name" : _TEST_AGENT_ENGINE_RESOURCE_NAME },
2971- "inputGcsUri" : "gs://my-input-bucket/input_b92b9b89 -4585-4146-8ee5-22fe99802a8e .json" ,
2972- "outputGcsUri" : "gs://my-input-bucket/output_b92b9b89 -4585-4146-8ee5-22fe99802a8e .json" ,
2971+ "inputGcsUri" : "gs://my-input-bucket/b92b9b89 -4585-4146-8ee5-22fe99802a8e_input .json" ,
2972+ "outputGcsUri" : "gs://my-input-bucket/b92b9b89 -4585-4146-8ee5-22fe99802a8e_output .json" ,
29732973 },
29742974 None ,
29752975 )
@@ -2980,38 +2980,18 @@ def test_run_query_job_agent_engine_missing_query(self):
29802980 ):
29812981 self .client .agent_engines .run_query_job (
29822982 name = _TEST_AGENT_ENGINE_RESOURCE_NAME ,
2983- config = {"gcs_bucket " : "gs://my-input-bucket/" },
2983+ config = {"output_gcs_uri " : "gs://my-input-bucket/" },
29842984 )
29852985
2986- def test_run_query_job_agent_engine_missing_bucket (self ):
2986+ def test_run_query_job_agent_engine_missing_uri (self ):
29872987 with pytest .raises (
2988- ValueError , match = "`gcs_bucket ` is required in the config object."
2988+ ValueError , match = "`output_gcs_uri ` is required in the config object."
29892989 ):
29902990 self .client .agent_engines .run_query_job (
29912991 name = _TEST_AGENT_ENGINE_RESOURCE_NAME ,
29922992 config = {"query" : _TEST_QUERY_PROMPT },
29932993 )
29942994
2995- @mock .patch .object (agent_engines .AgentEngines , "_get" )
2996- def test_run_query_job_agent_engine_missing_cloud_run_job (self , get_mock ):
2997- get_mock .return_value = _genai_types .ReasoningEngine (
2998- name = _TEST_AGENT_ENGINE_RESOURCE_NAME ,
2999- spec = _genai_types .ReasoningEngineSpec (
3000- deployment_spec = _genai_types .ReasoningEngineSpecDeploymentSpec (env = [])
3001- ),
3002- )
3003- with pytest .raises (
3004- ValueError ,
3005- match = "Your ReasoningEngine does not support long running queries, please update your ReasoningEngine and try again." ,
3006- ):
3007- self .client .agent_engines .run_query_job (
3008- name = _TEST_AGENT_ENGINE_RESOURCE_NAME ,
3009- config = {
3010- "query" : _TEST_QUERY_PROMPT ,
3011- "gcs_bucket" : "gs://my-input-bucket/" ,
3012- },
3013- )
3014-
30152995 @mock .patch ("google.cloud.storage.Client" )
30162996 @mock .patch .object (agent_engines .AgentEngines , "_get" )
30172997 @mock .patch ("uuid.uuid4" )
@@ -3053,10 +3033,103 @@ def test_run_query_job_agent_engine_bucket_creation_forbidden(
30533033 name = _TEST_AGENT_ENGINE_RESOURCE_NAME ,
30543034 config = {
30553035 "query" : _TEST_QUERY_PROMPT ,
3056- "gcs_bucket " : "gs://my-input-bucket/" ,
3036+ "output_gcs_uri " : "gs://my-input-bucket/" ,
30573037 },
30583038 )
30593039
3040+ @mock .patch ("google.cloud.storage.Client" )
3041+ @mock .patch .object (agent_engines .AgentEngines , "_get" )
3042+ @mock .patch ("uuid.uuid4" )
3043+ def test_run_query_job_agent_engine_file_uri (
3044+ self , mock_uuid , get_mock , mock_storage_client
3045+ ):
3046+ with mock .patch .object (
3047+ self .client .agent_engines ._api_client , "request"
3048+ ) as request_mock :
3049+ request_mock .return_value = genai_types .HttpResponse (
3050+ body = '{"name": "projects/123/locations/us-central1/reasoningEngines/456/operations/789"}'
3051+ )
3052+
3053+ mock_bucket = mock .Mock ()
3054+ mock_bucket .exists .return_value = True
3055+ mock_blob = mock .Mock ()
3056+ mock_bucket .blob .return_value = mock_blob
3057+ mock_storage_client .return_value .bucket .return_value = mock_bucket
3058+
3059+ get_mock .return_value = _genai_types .ReasoningEngine (
3060+ name = _TEST_AGENT_ENGINE_RESOURCE_NAME ,
3061+ spec = _genai_types .ReasoningEngineSpec (
3062+ deployment_spec = _genai_types .ReasoningEngineSpecDeploymentSpec (
3063+ env = [_genai_types .EnvVar (name = "input_gcs_uri" , value = "" )]
3064+ )
3065+ ),
3066+ )
3067+
3068+ result = self .client .agent_engines .run_query_job (
3069+ name = _TEST_AGENT_ENGINE_RESOURCE_NAME ,
3070+ config = {
3071+ "query" : _TEST_QUERY_PROMPT ,
3072+ "output_gcs_uri" : "gs://my-input-bucket/path/output.json" ,
3073+ },
3074+ )
3075+
3076+ mock_blob .upload_from_string .assert_called_once_with (_TEST_QUERY_PROMPT )
3077+ mock_bucket .blob .assert_called_with ("path/output_input.json" )
3078+
3079+ assert result == _genai_types .RunQueryJobResult (
3080+ job_name = "projects/123/locations/us-central1/reasoningEngines/456/operations/789" ,
3081+ input_gcs_uri = "gs://my-input-bucket/path/output_input.json" ,
3082+ output_gcs_uri = "gs://my-input-bucket/path/output.json" ,
3083+ )
3084+
3085+ @mock .patch ("google.cloud.storage.Client" )
3086+ @mock .patch .object (agent_engines .AgentEngines , "_get" )
3087+ @mock .patch ("uuid.uuid4" )
3088+ def test_run_query_job_agent_engine_directory_no_slash (
3089+ self , mock_uuid , get_mock , mock_storage_client
3090+ ):
3091+ with mock .patch .object (
3092+ self .client .agent_engines ._api_client , "request"
3093+ ) as request_mock :
3094+ request_mock .return_value = genai_types .HttpResponse (
3095+ body = '{"name": "projects/123/locations/us-central1/reasoningEngines/456/operations/789"}'
3096+ )
3097+
3098+ mock_bucket = mock .Mock ()
3099+ mock_bucket .exists .return_value = True
3100+ mock_blob = mock .Mock ()
3101+ mock_bucket .blob .return_value = mock_blob
3102+ mock_storage_client .return_value .bucket .return_value = mock_bucket
3103+
3104+ mock_uuid .return_value .hex = "b92b9b89-4585-4146-8ee5-22fe99802a8e"
3105+
3106+ get_mock .return_value = _genai_types .ReasoningEngine (
3107+ name = _TEST_AGENT_ENGINE_RESOURCE_NAME ,
3108+ spec = _genai_types .ReasoningEngineSpec (
3109+ deployment_spec = _genai_types .ReasoningEngineSpecDeploymentSpec (
3110+ env = [_genai_types .EnvVar (name = "input_gcs_uri" , value = "" )]
3111+ )
3112+ ),
3113+ )
3114+
3115+ result = self .client .agent_engines .run_query_job (
3116+ name = _TEST_AGENT_ENGINE_RESOURCE_NAME ,
3117+ config = {
3118+ "query" : _TEST_QUERY_PROMPT ,
3119+ "output_gcs_uri" : "gs://my-input-bucket/path" ,
3120+ },
3121+ )
3122+
3123+ mock_bucket .blob .assert_called_with (
3124+ "path/b92b9b89-4585-4146-8ee5-22fe99802a8e_input.json"
3125+ )
3126+
3127+ assert result == _genai_types .RunQueryJobResult (
3128+ job_name = "projects/123/locations/us-central1/reasoningEngines/456/operations/789" ,
3129+ input_gcs_uri = "gs://my-input-bucket/path/b92b9b89-4585-4146-8ee5-22fe99802a8e_input.json" ,
3130+ output_gcs_uri = "gs://my-input-bucket/path/b92b9b89-4585-4146-8ee5-22fe99802a8e_output.json" ,
3131+ )
3132+
30603133 def test_query_agent_engine_async (self ):
30613134 agent = self .client .agent_engines ._register_api_methods (
30623135 agent_engine = _genai_types .AgentEngine (
0 commit comments