Skip to content

Commit f02648d

Browse files
committed
Add unit tests for server-tool merging and filtering
Cover the new functions introduced in the server-tool merging feature: - is_server_deployed_output: classify output items as server vs client - _merge_tools: merge client and server tools with conflict detection - resolve_tool_choice: X-LCS-Merge-Server-Tools header integration - _is_server_mcp_output_item: filter serialized MCP items in streaming 29 new tests across utils/test_responses.py and endpoints/test_responses.py validating correct behavior for MCP label matching, 409 conflict rejection, file_search deduplication, and pass-through of non-MCP item types.
1 parent fae411a commit f02648d

2 files changed

Lines changed: 375 additions & 0 deletions

File tree

tests/unit/app/endpoints/test_responses.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from pytest_mock import MockerFixture
1414

1515
from app.endpoints.responses import (
16+
_is_server_mcp_output_item,
1617
handle_non_streaming_response,
1718
handle_streaming_response,
1819
responses_endpoint_handler,
@@ -1372,3 +1373,55 @@ async def test_handle_streaming_connection_error_raises_503(
13721373
)
13731374

13741375
assert exc_info.value.status_code == 503
1376+
1377+
1378+
class TestIsServerMcpOutputItem:
1379+
"""Tests for _is_server_mcp_output_item helper."""
1380+
1381+
def test_mcp_call_with_matching_label(self) -> None:
1382+
"""Test mcp_call item with a configured server_label returns True."""
1383+
item: dict[str, Any] = {"type": "mcp_call", "server_label": "my-server"}
1384+
assert _is_server_mcp_output_item(item, {"my-server"}) is True
1385+
1386+
def test_mcp_call_with_non_matching_label(self) -> None:
1387+
"""Test mcp_call item with unconfigured server_label returns False."""
1388+
item: dict[str, Any] = {"type": "mcp_call", "server_label": "client-server"}
1389+
assert _is_server_mcp_output_item(item, {"my-server"}) is False
1390+
1391+
def test_mcp_list_tools_with_matching_label(self) -> None:
1392+
"""Test mcp_list_tools item with configured label returns True."""
1393+
item: dict[str, Any] = {"type": "mcp_list_tools", "server_label": "fs"}
1394+
assert _is_server_mcp_output_item(item, {"fs", "other"}) is True
1395+
1396+
def test_mcp_approval_request_with_matching_label(self) -> None:
1397+
"""Test mcp_approval_request item with configured label returns True."""
1398+
item: dict[str, Any] = {
1399+
"type": "mcp_approval_request",
1400+
"server_label": "tool-a",
1401+
}
1402+
assert _is_server_mcp_output_item(item, {"tool-a"}) is True
1403+
1404+
def test_mcp_call_missing_server_label(self) -> None:
1405+
"""Test mcp_call without server_label returns False."""
1406+
item: dict[str, Any] = {"type": "mcp_call"}
1407+
assert _is_server_mcp_output_item(item, {"my-server"}) is False
1408+
1409+
def test_message_type_returns_false(self) -> None:
1410+
"""Test non-MCP type returns False."""
1411+
item: dict[str, Any] = {"type": "message", "role": "assistant"}
1412+
assert _is_server_mcp_output_item(item, {"my-server"}) is False
1413+
1414+
def test_function_call_type_returns_false(self) -> None:
1415+
"""Test function_call type returns False."""
1416+
item: dict[str, Any] = {"type": "function_call", "name": "get_weather"}
1417+
assert _is_server_mcp_output_item(item, {"my-server"}) is False
1418+
1419+
def test_empty_configured_labels(self) -> None:
1420+
"""Test mcp_call with empty configured labels returns False."""
1421+
item: dict[str, Any] = {"type": "mcp_call", "server_label": "any-server"}
1422+
assert _is_server_mcp_output_item(item, set()) is False
1423+
1424+
def test_file_search_call_returns_false(self) -> None:
1425+
"""Test file_search_call type returns False."""
1426+
item: dict[str, Any] = {"type": "file_search_call"}
1427+
assert _is_server_mcp_output_item(item, {"my-server"}) is False

0 commit comments

Comments
 (0)