Skip to content

Commit eb79c97

Browse files
tests: make function-call detection assertion semantic
1 parent 812ab7f commit eb79c97

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

typescript-sdk/integrations/adk-middleware/python/tests/test_event_translator_comprehensive.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,33 @@ async def test_translate_event_with_empty_parts(self, translator, mock_adk_event
9090

9191
@pytest.mark.asyncio
9292
async def test_translate_function_calls_detection(self, translator, mock_adk_event):
93-
"""Test function calls detection and logging."""
94-
# Mock event with function calls
93+
"""Test function calls detection by asserting tool events are emitted.
94+
95+
This avoids brittle checks on debug log wording and instead
96+
verifies that function calls result in ToolCall events.
97+
"""
98+
# Mock event with one function call
9599
mock_function_call = MagicMock()
96100
mock_function_call.name = "test_function"
101+
mock_function_call.id = "call_123"
102+
mock_function_call.args = {"param": "value"}
97103
mock_adk_event.get_function_calls = MagicMock(return_value=[mock_function_call])
98104

99-
with patch('ag_ui_adk.event_translator.logger') as mock_logger:
100-
events = []
101-
async for event in translator.translate(mock_adk_event, "thread_1", "run_1"):
102-
events.append(event)
105+
events = []
106+
async for event in translator.translate(mock_adk_event, "thread_1", "run_1"):
107+
events.append(event)
103108

104-
# Should log function calls detection (along with the ADK Event debug log)
105-
debug_calls = [str(call) for call in mock_logger.debug.call_args_list]
106-
assert any("ADK function calls detected: 1 calls" in call for call in debug_calls)
109+
# Expect a START, ARGS, END sequence for the function call
110+
types = [e.type for e in events]
111+
type_names = [str(t).split('.')[-1] for t in types]
112+
assert type_names == [
113+
"TOOL_CALL_START",
114+
"TOOL_CALL_ARGS",
115+
"TOOL_CALL_END",
116+
]
117+
# And the tool_call_id should match the mocked id
118+
ids = [getattr(e, 'tool_call_id', None) for e in events]
119+
assert all(tc_id == "call_123" for tc_id in ids)
107120

108121
@pytest.mark.asyncio
109122
async def test_translate_function_responses_handling(self, translator, mock_adk_event):
@@ -781,4 +794,4 @@ async def test_partial_streaming_continuation(self, translator, mock_adk_event_w
781794

782795
# Should reset streaming state
783796
assert translator._is_streaming is False
784-
assert translator._streaming_message_id is None
797+
assert translator._streaming_message_id is None

0 commit comments

Comments
 (0)