fix: raise ValueError when sessionId and userId are incorrect combination(#1653)

Merge https://github.com/google/adk-python/pull/1655

Fix #1653

When session_id and user_id are incorrect combination on vertex ai session service, it should not return the session.

COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/1655 from soundTricker:fix/1653-invalid-session 7a3dee2fc75602a2685ea922799cc5f5ba666e97
PiperOrigin-RevId: 776648361
This commit is contained in:
Keisuke Oohashi
2025-06-27 11:06:15 -07:00
committed by Copybara-Service
parent c13c9875cf
commit 4e765ae2f3
2 changed files with 18 additions and 0 deletions
@@ -292,6 +292,21 @@ async def test_get_empty_session(agent_engine_id):
assert str(excinfo.value) == 'Session not found: 0'
@pytest.mark.asyncio
@pytest.mark.usefixtures('mock_get_api_client')
@pytest.mark.parametrize('agent_engine_id', [None, '123'])
async def test_get_another_user_session(agent_engine_id):
if agent_engine_id:
session_service = mock_vertex_ai_session_service(agent_engine_id)
else:
session_service = mock_vertex_ai_session_service()
with pytest.raises(ValueError) as excinfo:
await session_service.get_session(
app_name='123', user_id='user2', session_id='1'
)
assert str(excinfo.value) == 'Session not found: 1'
@pytest.mark.asyncio
@pytest.mark.usefixtures('mock_get_api_client')
async def test_get_and_delete_session():