@@ -1540,3 +1540,95 @@ async def mock_receive_generator():
15401540 responses [0 ].turn_complete_reason
15411541 == types .TurnCompleteReason .RESPONSE_REJECTED
15421542 )
1543+
1544+
1545+ @pytest .mark .asyncio
1546+ async def test_receive_multiplexed_parts (gemini_connection , mock_gemini_session ):
1547+ """Test receive with multiplexed inline data and text content."""
1548+ mock_content = types .Content (
1549+ role = 'model' ,
1550+ parts = [
1551+ types .Part (
1552+ inline_data = types .Blob (data = b'audio_data' , mime_type = 'audio/pcm' )
1553+ ),
1554+ types .Part .from_text (text = 'transcription text' ),
1555+ ],
1556+ )
1557+ mock_server_content = mock .Mock ()
1558+ mock_server_content .model_turn = mock_content
1559+ mock_server_content .interrupted = False
1560+ mock_server_content .input_transcription = None
1561+ mock_server_content .output_transcription = None
1562+ mock_server_content .turn_complete = False
1563+ mock_server_content .grounding_metadata = None
1564+
1565+ mock_message = mock .AsyncMock ()
1566+ mock_message .usage_metadata = None
1567+ mock_message .server_content = mock_server_content
1568+ mock_message .tool_call = None
1569+ mock_message .session_resumption_update = None
1570+ mock_message .go_away = None
1571+
1572+ async def mock_receive_generator ():
1573+ yield mock_message
1574+
1575+ receive_mock = mock .Mock (return_value = mock_receive_generator ())
1576+ mock_gemini_session .receive = receive_mock
1577+
1578+ responses = [resp async for resp in gemini_connection .receive ()]
1579+
1580+ assert responses
1581+ content_response = next ((r for r in responses if r .content ), None )
1582+ assert content_response is not None
1583+ assert content_response .content == mock_content
1584+ assert content_response .partial is True
1585+
1586+
1587+ @pytest .mark .asyncio
1588+ async def test_send_history_gemini_31_turn_complete (mock_gemini_session ):
1589+ """Verify Gemini 3.1 Live history seeding explicitly appends turn_complete=True."""
1590+ from google .adk .models .google_llm import GoogleLLMVariant
1591+ conn = GeminiLlmConnection (
1592+ mock_gemini_session ,
1593+ api_backend = GoogleLLMVariant .GEMINI_API ,
1594+ model_version = 'gemini-3.1-flash-live-preview' ,
1595+ )
1596+ mock_gemini_session .send_client_content = mock .AsyncMock ()
1597+
1598+ mock_contents = [
1599+ types .Content (role = 'user' , parts = [types .Part .from_text (text = 'hi' )]),
1600+ types .Content (role = 'model' , parts = [types .Part .from_text (text = 'hello' )]),
1601+ ]
1602+ await conn .send_history (mock_contents )
1603+
1604+ mock_gemini_session .send_client_content .assert_called_once_with (
1605+ turns = mock_contents ,
1606+ turn_complete = True ,
1607+ )
1608+
1609+
1610+ @pytest .mark .asyncio
1611+ async def test_send_history_collapse_vertex_ai (mock_gemini_session ):
1612+ """Verify history prompt collapse when seeding Gemini 3.1 Live on Vertex AI backend."""
1613+ from google .adk .models .google_llm import GoogleLLMVariant
1614+ conn = GeminiLlmConnection (
1615+ mock_gemini_session ,
1616+ api_backend = GoogleLLMVariant .VERTEX_AI ,
1617+ model_version = 'gemini-3.1-flash-live-preview' ,
1618+ )
1619+ mock_gemini_session .send_client_content = mock .AsyncMock ()
1620+
1621+ mock_contents = [
1622+ types .Content (role = 'user' , parts = [types .Part .from_text (text = 'hi' )]),
1623+ types .Content (role = 'model' , parts = [types .Part .from_text (text = 'hello' )]),
1624+ ]
1625+ await conn .send_history (mock_contents )
1626+
1627+ assert mock_gemini_session .send_client_content .call_count == 1
1628+ called_turns = mock_gemini_session .send_client_content .call_args .kwargs ['turns' ]
1629+ assert len (called_turns ) == 1
1630+ assert called_turns [0 ].role == 'user'
1631+ assert 'Previous conversation history:' in called_turns [0 ].parts [0 ].text
1632+ assert '[user]: hi' in called_turns [0 ].parts [0 ].text
1633+ assert '[model]: hello' in called_turns [0 ].parts [0 ].text
1634+ assert mock_gemini_session .send_client_content .call_args .kwargs ['turn_complete' ] is True
0 commit comments