From ea408931700c6fa136d88caddf202e537e6d47e8 Mon Sep 17 00:00:00 2001 From: Jinzhengxu Date: Thu, 17 Sep 2026 19:26:57 +0800 Subject: [PATCH] fix(tests): isolate mock session payloads in Vertex AI session service tests The mock_api_client_instance fixture registered the module-level MOCK_SESSION_JSON_* dicts directly in session_dict, while MockAsyncClient rewrites session_dict[id]['update_time'] whenever an event is appended. Any test that appends an event to session '1' therefore mutated the shared dict, and later tests comparing get_session() against MOCK_SESSION (built at import time from the original timestamp) failed depending on execution order. Deep-copy the session payloads in the fixture, matching how the fixture already copies the event payloads. --- .../sessions/test_vertex_ai_session_service.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/unittests/sessions/test_vertex_ai_session_service.py b/tests/unittests/sessions/test_vertex_ai_session_service.py index eb9b4a1213..68f4524e7c 100644 --- a/tests/unittests/sessions/test_vertex_ai_session_service.py +++ b/tests/unittests/sessions/test_vertex_ai_session_service.py @@ -620,12 +620,16 @@ def mock_vertex_ai_session_service( def mock_api_client_instance(): """Creates a mock API client instance for testing.""" api_client = MockAsyncClient() + # Deep-copy the session payloads like the events below: the mock client + # mutates `session_dict[...]['update_time']` when an event is appended, and + # sharing the module-level dicts across tests would leak that update into + # later tests that compare against `MOCK_SESSION`. api_client.session_dict = { - '1': MOCK_SESSION_JSON_1, - '2': MOCK_SESSION_JSON_2, - '3': MOCK_SESSION_JSON_3, - 'page1': MOCK_SESSION_JSON_PAGE1, - 'page2': MOCK_SESSION_JSON_PAGE2, + '1': copy.deepcopy(MOCK_SESSION_JSON_1), + '2': copy.deepcopy(MOCK_SESSION_JSON_2), + '3': copy.deepcopy(MOCK_SESSION_JSON_3), + 'page1': copy.deepcopy(MOCK_SESSION_JSON_PAGE1), + 'page2': copy.deepcopy(MOCK_SESSION_JSON_PAGE2), } api_client.event_dict = { '1': (copy.deepcopy(MOCK_EVENT_JSON), None),