|
13 | 13 | from pytest_mock import MockerFixture |
14 | 14 |
|
15 | 15 | from app.endpoints.responses import ( |
| 16 | + _is_server_mcp_output_item, |
16 | 17 | handle_non_streaming_response, |
17 | 18 | handle_streaming_response, |
18 | 19 | responses_endpoint_handler, |
@@ -1372,3 +1373,55 @@ async def test_handle_streaming_connection_error_raises_503( |
1372 | 1373 | ) |
1373 | 1374 |
|
1374 | 1375 | 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