@@ -251,13 +251,18 @@ def adk_version_mock():
251251 yield adk_version_mock
252252
253253
254- @pytest .fixture
254+ @pytest .fixture ( autouse = True )
255255def get_project_id_mock ():
256256 with mock .patch (
257257 "google.cloud.aiplatform.aiplatform.utils.resource_manager_utils.get_project_id"
258258 ) as get_project_id_mock :
259259 get_project_id_mock .return_value = _TEST_PROJECT_ID
260- yield get_project_id_mock
260+ with mock .patch .object (initializer .global_config , "_project" , _TEST_PROJECT ):
261+ with mock .patch (
262+ "google.cloud.aiplatform.vertexai.preview.reasoning_engines.templates.adk.AdkApp._warn_if_telemetry_api_disabled" ,
263+ return_value = None ,
264+ ):
265+ yield get_project_id_mock
261266
262267
263268class _MockRunner :
@@ -376,7 +381,7 @@ def test_initialization(self):
376381 app = reasoning_engines .AdkApp (
377382 agent = Agent (name = _TEST_AGENT_NAME , model = _TEST_MODEL ),
378383 )
379- assert app ._tmpl_attrs .get ("project" ) == _TEST_PROJECT
384+ assert app ._tmpl_attrs .get ("project" ) == _TEST_PROJECT_ID
380385 assert app ._tmpl_attrs .get ("location" ) == _TEST_LOCATION
381386 assert app ._tmpl_attrs .get ("runner" ) is None
382387
@@ -568,7 +573,17 @@ def test_streaming_agent_run_with_events(self):
568573 "artifacts" : [
569574 {
570575 "file_name" : "test_file_name" ,
571- "versions" : [{"version" : "v1" , "data" : "v1data" }],
576+ "versions" : [
577+ {
578+ "version" : "v1" ,
579+ "data" : {
580+ "inline_data" : {
581+ "data" : "djFkYXRh" ,
582+ "mime_type" : "text/plain" ,
583+ }
584+ },
585+ }
586+ ],
572587 }
573588 ],
574589 "authorizations" : {
@@ -606,7 +621,17 @@ async def test_streaming_agent_run_with_events_force_flush_otel(
606621 "artifacts" : [
607622 {
608623 "file_name" : "test_file_name" ,
609- "versions" : [{"version" : "v1" , "data" : "v1data" }],
624+ "versions" : [
625+ {
626+ "version" : "v1" ,
627+ "data" : {
628+ "inline_data" : {
629+ "data" : "djFkYXRh" ,
630+ "mime_type" : "text/plain" ,
631+ }
632+ },
633+ }
634+ ],
610635 }
611636 ],
612637 "authorizations" : {
@@ -682,12 +707,12 @@ def test_create_session(self):
682707 agent = Agent (name = _TEST_AGENT_NAME , model = _TEST_MODEL )
683708 )
684709 session1 = app .create_session (user_id = _TEST_USER_ID )
685- assert session1 . user_id == _TEST_USER_ID
710+ assert session1 [ " user_id" ] == _TEST_USER_ID
686711 session2 = app .create_session (
687712 user_id = _TEST_USER_ID , session_id = "test_session_id"
688713 )
689- assert session2 . user_id == _TEST_USER_ID
690- assert session2 . id == "test_session_id"
714+ assert session2 [ " user_id" ] == _TEST_USER_ID
715+ assert session2 [ "id" ] == "test_session_id"
691716
692717 def test_get_session (self ):
693718 app = reasoning_engines .AdkApp (
@@ -696,10 +721,10 @@ def test_get_session(self):
696721 session1 = app .create_session (user_id = _TEST_USER_ID )
697722 session2 = app .get_session (
698723 user_id = _TEST_USER_ID ,
699- session_id = session1 . id ,
724+ session_id = session1 [ "id" ] ,
700725 )
701726 assert session2 .user_id == _TEST_USER_ID
702- assert session1 . id == session2 .id
727+ assert session1 [ "id" ] == session2 .id
703728
704729 def test_list_sessions (self ):
705730 app = reasoning_engines .AdkApp (
@@ -710,12 +735,12 @@ def test_list_sessions(self):
710735 session = app .create_session (user_id = _TEST_USER_ID )
711736 response1 = app .list_sessions (user_id = _TEST_USER_ID )
712737 assert len (response1 .sessions ) == 1
713- assert response1 .sessions [0 ].id == session . id
738+ assert response1 .sessions [0 ].id == session [ "id" ]
714739 session2 = app .create_session (user_id = _TEST_USER_ID )
715740 response2 = app .list_sessions (user_id = _TEST_USER_ID )
716741 assert len (response2 .sessions ) == 2
717- assert response2 .sessions [0 ].id == session . id
718- assert response2 .sessions [1 ].id == session2 . id
742+ assert response2 .sessions [0 ].id == session [ "id" ]
743+ assert response2 .sessions [1 ].id == session2 [ "id" ]
719744
720745 def test_delete_session (self ):
721746 app = reasoning_engines .AdkApp (
@@ -726,7 +751,7 @@ def test_delete_session(self):
726751 session = app .create_session (user_id = _TEST_USER_ID )
727752 response1 = app .list_sessions (user_id = _TEST_USER_ID )
728753 assert len (response1 .sessions ) == 1
729- app .delete_session (user_id = _TEST_USER_ID , session_id = session . id )
754+ app .delete_session (user_id = _TEST_USER_ID , session_id = session [ "id" ] )
730755 response0 = app .list_sessions (user_id = _TEST_USER_ID )
731756 assert not response0 .sessions
732757
@@ -740,14 +765,14 @@ async def test_async_add_session_to_memory(self):
740765 list (
741766 app .stream_query (
742767 user_id = _TEST_USER_ID ,
743- session_id = session . id ,
768+ session_id = session [ "id" ] ,
744769 message = "My cat's name is Garfield" ,
745770 )
746771 )
747772 await app .async_add_session_to_memory (
748773 session = app .get_session (
749774 user_id = _TEST_USER_ID ,
750- session_id = session . id ,
775+ session_id = session [ "id" ] ,
751776 )
752777 )
753778 response = await app .async_search_memory (
@@ -838,7 +863,7 @@ def test_default_instrumentor_enablement(
838863
839864 # Assert
840865 default_instrumentor_builder_mock .assert_called_once_with (
841- _TEST_PROJECT ,
866+ _TEST_PROJECT_ID ,
842867 enable_tracing = want_tracing_setup ,
843868 enable_logging = want_logging_setup ,
844869 )
@@ -863,11 +888,16 @@ def test_tracing_setup(
863888 monkeypatch .setattr ("os.getpid" , lambda : 123123123 )
864889 app = reasoning_engines .AdkApp (agent = _TEST_AGENT , enable_tracing = True )
865890 app ._warn_if_telemetry_api_disabled = lambda : None
866- app .set_up ()
891+ with mock .patch (
892+ "google.cloud.aiplatform.vertexai.agent_engines._utils.is_noop_or_proxy_tracer_provider" ,
893+ return_value = True ,
894+ ):
895+ app .set_up ()
867896
868897 expected_attributes = {
869898 "cloud.account.id" : _TEST_PROJECT_ID ,
870899 "cloud.platform" : "gcp.agent_engine" ,
900+ "cloud.provider" : "gcp" ,
871901 "cloud.region" : "us-central1" ,
872902 "cloud.resource_id" : "//aiplatform.googleapis.com/projects/test-project-id/locations/us-central1/reasoningEngines/test_agent_id" ,
873903 "gcp.project_id" : _TEST_PROJECT_ID ,
@@ -876,7 +906,7 @@ def test_tracing_setup(
876906 "some-attribute" : "some-value" ,
877907 "telemetry.sdk.language" : "python" ,
878908 "telemetry.sdk.name" : "opentelemetry" ,
879- "telemetry.sdk.version" : "1.36 .0" ,
909+ "telemetry.sdk.version" : "1.39 .0" ,
880910 "some-attribute" : "some-value" ,
881911 }
882912
@@ -886,7 +916,11 @@ def test_tracing_setup(
886916 headers = mock .ANY ,
887917 )
888918
889- get_project_id_mock .assert_called_once_with (_TEST_PROJECT )
919+ calls = [
920+ mock .call (project_number = _TEST_PROJECT_ID , credentials = mock .ANY ),
921+ mock .call (_TEST_PROJECT_ID ),
922+ ]
923+ get_project_id_mock .assert_has_calls (calls )
890924
891925 user_agent = otlp_span_exporter_mock .call_args .kwargs ["headers" ]["User-Agent" ]
892926 assert (
0 commit comments