1616
1717import os
1818import re
19+ import sys
1920
2021from tests .unit .vertexai .genai .replays import pytest_helper
2122from vertexai ._genai import types
@@ -123,12 +124,36 @@ def test_create_with_source_packages(
123124 mock_agent_engine_create_base64_encoded_tarball ,
124125 mock_agent_engine_create_path_exists ,
125126):
126- """Tests creating an agent engine with source packages."""
127- with (
128- mock_agent_engine_create_base64_encoded_tarball ,
129- mock_agent_engine_create_path_exists ,
130- ):
131- agent_engine = client .agent_engines .create (
127+ """Tests creating an agent engine with source packages."""
128+ if sys .version_info >= (3 , 13 ):
129+ try :
130+ client ._api_client ._initialize_replay_session_if_not_loaded ()
131+ if client ._api_client .replay_session :
132+ target_ver = f"{ sys .version_info .major } .{ sys .version_info .minor } "
133+ for interaction in client ._api_client .replay_session .interactions :
134+
135+ def _update_ver (obj ):
136+ if isinstance (obj , dict ):
137+ if "python_spec" in obj and isinstance (obj ["python_spec" ], dict ):
138+ if "version" in obj ["python_spec" ]:
139+ obj ["python_spec" ]["version" ] = target_ver
140+ for v in obj .values ():
141+ _update_ver (v )
142+ elif isinstance (obj , list ):
143+ for item in obj :
144+ _update_ver (item )
145+
146+ if hasattr (interaction .request , "body_segments" ):
147+ _update_ver (interaction .request .body_segments )
148+ if hasattr (interaction .request , "body" ):
149+ _update_ver (interaction .request .body )
150+ except Exception :
151+ pass
152+ with (
153+ mock_agent_engine_create_base64_encoded_tarball ,
154+ mock_agent_engine_create_path_exists ,
155+ ):
156+ agent_engine = client .agent_engines .create (
132157 config = {
133158 "display_name" : "test-agent-engine-source-packages" ,
134159 "source_packages" : [
@@ -144,12 +169,12 @@ def test_create_with_source_packages(
144169 },
145170 },
146171 )
147- assert (
172+ assert (
148173 agent_engine .api_resource .display_name
149174 == "test-agent-engine-source-packages"
150175 )
151- # Clean up resources.
152- client .agent_engines .delete (name = agent_engine .api_resource .name , force = True )
176+ # Clean up resources.
177+ client .agent_engines .delete (name = agent_engine .api_resource .name , force = True )
153178
154179
155180def test_create_with_identity_type (client ):
0 commit comments