Skip to content

Commit 87d6a9c

Browse files
author
jiangpeiling
committed
✨ MCP Tool test run #541
1 parent 45d5aec commit 87d6a9c

File tree

5 files changed

+19
-25
lines changed

5 files changed

+19
-25
lines changed

backend/apps/tool_config_app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
update_tool_list,
1414
list_all_tools,
1515
load_last_tool_config_impl,
16-
validate_tools,
16+
validate_tool_impl,
1717
)
1818
from utils.auth_utils import get_current_user_id
1919

@@ -110,7 +110,7 @@ async def validate_tool(
110110
"""Validate specific tool based on source type"""
111111
try:
112112
_, tenant_id = get_current_user_id(authorization)
113-
result = await validate_tools(request, tenant_id)
113+
result = await validate_tool_impl(request, tenant_id)
114114

115115
return JSONResponse(
116116
status_code=HTTPStatus.OK,

backend/services/tool_configuration_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ def _validate_langchain_tool(
628628
f"LangChain tool '{tool_name}' validation failed: {e}")
629629

630630

631-
async def validate_tools(
631+
async def validate_tool_impl(
632632
request: ToolValidateRequest,
633633
tenant_id: Optional[str] = None
634634
) -> Dict[str, Any]:

test/backend/app/test_tool_config_app.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from consts.exceptions import MCPConnectionError, NotFoundException
21
from unittest.mock import patch, MagicMock
32
import sys
43
import os
@@ -10,6 +9,7 @@
109
sys.modules['boto3'] = MagicMock()
1110

1211
# Import exception classes
12+
from consts.exceptions import MCPConnectionError, NotFoundException
1313

1414
# Mock dependencies before importing the actual app - using the same pattern as test_remote_mcp_app.py
1515
with patch('database.client.MinioClient', MagicMock()):
@@ -305,7 +305,7 @@ def test_missing_parameters(self):
305305
assert response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY
306306

307307
@patch('apps.tool_config_app.get_current_user_id')
308-
@patch('apps.tool_config_app.validate_tools')
308+
@patch('apps.tool_config_app.validate_tool_impl')
309309
def test_validate_tool_success(self, mock_validate_tool, mock_get_user_id):
310310
"""Test successful tool validation"""
311311
mock_get_user_id.return_value = ("user123", "tenant456")
@@ -332,7 +332,7 @@ def test_validate_tool_success(self, mock_validate_tool, mock_get_user_id):
332332
mock_validate_tool.assert_called_once()
333333

334334
@patch('apps.tool_config_app.get_current_user_id')
335-
@patch('apps.tool_config_app.validate_tools')
335+
@patch('apps.tool_config_app.validate_tool_impl')
336336
def test_validate_tool_mcp_connection_error(self, mock_validate_tool, mock_get_user_id):
337337
"""Test MCP connection error during tool validation"""
338338
mock_get_user_id.return_value = ("user123", "tenant456")
@@ -357,7 +357,7 @@ def test_validate_tool_mcp_connection_error(self, mock_validate_tool, mock_get_u
357357
mock_validate_tool.assert_called_once()
358358

359359
@patch('apps.tool_config_app.get_current_user_id')
360-
@patch('apps.tool_config_app.validate_tools')
360+
@patch('apps.tool_config_app.validate_tool_impl')
361361
def test_validate_tool_not_found_error(self, mock_validate_tool, mock_get_user_id):
362362
"""Test tool not found error during validation"""
363363
mock_get_user_id.return_value = ("user123", "tenant456")
@@ -381,7 +381,7 @@ def test_validate_tool_not_found_error(self, mock_validate_tool, mock_get_user_i
381381
mock_validate_tool.assert_called_once()
382382

383383
@patch('apps.tool_config_app.get_current_user_id')
384-
@patch('apps.tool_config_app.validate_tools')
384+
@patch('apps.tool_config_app.validate_tool_impl')
385385
def test_validate_tool_general_error(self, mock_validate_tool, mock_get_user_id):
386386
"""Test general error during tool validation"""
387387
mock_get_user_id.return_value = ("user123", "tenant456")
@@ -426,7 +426,7 @@ def test_validate_tool_auth_error(self, mock_get_user_id):
426426
mock_get_user_id.assert_called_once_with(None)
427427

428428
@patch('apps.tool_config_app.get_current_user_id')
429-
@patch('apps.tool_config_app.validate_tools')
429+
@patch('apps.tool_config_app.validate_tool_impl')
430430
def test_validate_tool_with_authorization_header(self, mock_validate_tool, mock_get_user_id):
431431
"""Test tool validation with authorization header"""
432432
mock_get_user_id.return_value = ("user123", "tenant456")

test/backend/services/test_config_sync_service.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,6 @@ async def test_load_config_impl_chinese(self, service_mocks):
754754

755755
# Check Chinese default values
756756
assert result["app"]["name"] == "Nexent 智能体"
757-
assert "Nexent 是一个开源智能体SDK和平台" in result["app"]["description"]
758757

759758
@pytest.mark.asyncio
760759
async def test_load_config_impl_with_embedding_dimension(self, service_mocks):

test/backend/services/test_tool_configuration_service.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
from apps.tool_config_app import validate_tool
2-
from consts.exceptions import MCPConnectionError, NotFoundException, ToolExecutionException
3-
from consts.model import ToolInfo, ToolSourceEnum, ToolInstanceInfoRequest, ToolValidateRequest
41
import asyncio
52
import inspect
63
import sys
@@ -21,8 +18,10 @@
2118
search_tool_info_impl,
2219
update_tool_info_impl,
2320
list_all_tools,
24-
load_last_tool_config_impl, validate_tools
21+
load_last_tool_config_impl, validate_tool_impl
2522
)
23+
from consts.exceptions import MCPConnectionError, NotFoundException, ToolExecutionException
24+
from consts.model import ToolInfo, ToolSourceEnum, ToolInstanceInfoRequest, ToolValidateRequest
2625

2726

2827
class TestPythonTypeToJsonSchema:
@@ -1422,7 +1421,7 @@ async def test_validate_tool_nexent(self, mock_validate_nexent):
14221421
inputs={"param": "value"}
14231422
)
14241423

1425-
result = await validate_tools(request, "tenant1")
1424+
result = await validate_tool_impl(request, "tenant1")
14261425

14271426
assert result == "nexent result"
14281427
mock_validate_nexent.assert_called_once_with(
@@ -1440,7 +1439,7 @@ async def test_validate_tool_remote(self, mock_validate_remote):
14401439
inputs={"param": "value"}
14411440
)
14421441

1443-
result = await validate_tools(request, "tenant1")
1442+
result = await validate_tool_impl(request, "tenant1")
14441443

14451444
assert result == "remote result"
14461445
mock_validate_remote.assert_called_once_with(
@@ -1459,7 +1458,7 @@ async def test_validate_tool_local(self, mock_validate_local):
14591458
params={"config": "value"}
14601459
)
14611460

1462-
result = await validate_tools(request, "tenant1")
1461+
result = await validate_tool_impl(request, "tenant1")
14631462

14641463
assert result == "local result"
14651464
mock_validate_local.assert_called_once_with(
@@ -1477,7 +1476,7 @@ async def test_validate_tool_langchain(self, mock_validate_langchain):
14771476
inputs={"param": "value"}
14781477
)
14791478

1480-
result = await validate_tools(request, "tenant1")
1479+
result = await validate_tool_impl(request, "tenant1")
14811480

14821481
assert result == "langchain result"
14831482
mock_validate_langchain.assert_called_once_with(
@@ -1493,7 +1492,7 @@ async def test_validate_tool_unsupported_source(self):
14931492
)
14941493

14951494
with pytest.raises(ToolExecutionException, match="Validate Tool failed"):
1496-
await validate_tools(request, "tenant1")
1495+
await validate_tool_impl(request, "tenant1")
14971496

14981497
@patch('backend.services.tool_configuration_service._validate_mcp_tool_nexent')
14991498
async def test_validate_tool_nexent_connection_error(self, mock_validate_nexent):
@@ -1508,10 +1507,8 @@ async def test_validate_tool_nexent_connection_error(self, mock_validate_nexent)
15081507
inputs={"param": "value"}
15091508
)
15101509

1511-
from backend.services.tool_configuration_service import validate_tools
1512-
15131510
with pytest.raises(MCPConnectionError, match="MCP connection failed: Connection failed"):
1514-
await validate_tools(request, "tenant1")
1511+
await validate_tool_impl(request, "tenant1")
15151512

15161513
@patch('backend.services.tool_configuration_service._validate_local_tool')
15171514
async def test_validate_tool_local_execution_error(self, mock_validate_local):
@@ -1526,10 +1523,8 @@ async def test_validate_tool_local_execution_error(self, mock_validate_local):
15261523
params={"config": "value"}
15271524
)
15281525

1529-
from backend.services.tool_configuration_service import validate_tools
1530-
15311526
with pytest.raises(ToolExecutionException, match="Validate Tool failed"):
1532-
await validate_tools(request, "tenant1")
1527+
await validate_tool_impl(request, "tenant1")
15331528

15341529

15351530
if __name__ == '__main__':

0 commit comments

Comments
 (0)