Skip to content

Commit 2385c59

Browse files
committed
feat(tests): update MCP prompt tests to use example config and enhance backend test script output
1 parent 72a5972 commit 2385c59

File tree

3 files changed

+35
-29
lines changed

3 files changed

+35
-29
lines changed

backend/tests/test_mcp_prompt_override_system_prompt.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import json
2+
from pathlib import Path
3+
14
import pytest
2-
from unittest.mock import patch, Mock
35

46
from modules.mcp_tools.client import MCPToolManager
57
from modules.config import ConfigManager
@@ -14,19 +16,18 @@ async def test_selected_mcp_prompt_overrides_system_prompt(monkeypatch):
1416
"""
1517
# Ensure MCP clients and prompts are ready
1618
# Set up MCP manager directly (avoid importing app_factory/litellm).
17-
# Patch config_manager so MCPToolManager sees a "prompts" server
18-
# without depending on actual file-based config.
19-
with patch("modules.mcp_tools.client.config_manager") as mock_cm:
20-
mock_cm.mcp_config.servers = {
21-
"prompts": Mock(name="prompts_server_config")
22-
}
23-
mock_cm.mcp_config.servers["prompts"].model_dump.return_value = {
24-
"command": ["python", "mcp/prompts/main.py"],
25-
"cwd": "backend",
26-
"groups": ["users"],
27-
}
28-
29-
mcp: MCPToolManager = MCPToolManager()
19+
# Use the example prompts MCP config file so this test uses
20+
# the same JSON configuration as other prompts tests.
21+
# tests run with cwd=backend/, so resolve from backend root
22+
backend_root = Path(__file__).parent.parent
23+
project_root = backend_root.parent
24+
config_path = project_root / "config" / "mcp-example-configs" / "mcp-prompts.json"
25+
assert config_path.exists(), f"Missing example prompts config: {config_path}"
26+
27+
data = json.loads(config_path.read_text())
28+
assert "prompts" in data, "prompts server not defined in example config"
29+
30+
mcp: MCPToolManager = MCPToolManager(config_path=str(config_path))
3031
await mcp.initialize_clients()
3132
await mcp.discover_prompts()
3233
assert "prompts" in mcp.available_prompts, "prompts server not discovered"

backend/tests/test_mcp_prompts_server.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
1+
import json
2+
from pathlib import Path
3+
14
import pytest
2-
from unittest.mock import patch, Mock
35

46
from modules.mcp_tools.client import MCPToolManager
57

68

79
@pytest.mark.asyncio
810
async def test_mcp_prompts_discovery_includes_expert_dog_trainer():
9-
# Use the example prompts MCP config to ensure the prompts
10-
# server is available in tests regardless of app settings
11-
# and avoid depending on the global config manager.
12-
with patch("modules.mcp_tools.client.config_manager") as mock_cm:
13-
mock_cm.mcp_config.servers = {
14-
"prompts": Mock(name="prompts_server_config")
15-
}
16-
mock_cm.mcp_config.servers["prompts"].model_dump.return_value = {
17-
"command": ["python", "mcp/prompts/main.py"],
18-
"cwd": "backend",
19-
"groups": ["users"],
20-
}
21-
22-
mcp = MCPToolManager()
11+
# Use the example prompts MCP config file so this test
12+
# exercises the real JSON configuration used for prompts.
13+
# tests run with cwd=backend/, so resolve from backend root
14+
backend_root = Path(__file__).parent.parent
15+
print(backend_root)
16+
project_root = backend_root.parent
17+
print(project_root)
18+
config_path = project_root / "config" / "mcp-example-configs" / "mcp-prompts.json"
19+
print(config_path)
20+
assert config_path.exists(), f"Missing example prompts config: {config_path}"
21+
22+
# Sanity-check that the JSON contains a "prompts" server.
23+
data = json.loads(config_path.read_text())
24+
assert "prompts" in data, "prompts server not defined in example config"
25+
26+
mcp = MCPToolManager(config_path=str(config_path))
2327

2428
# Ensure fresh clients and prompt discovery
2529
await mcp.initialize_clients()

test/backend_tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ cd "$BACKEND_DIR"
3939

4040
echo ""
4141
echo "\n🧪 Running Backend Tests..."
42+
echo "BACKEND_DIR full path: $(pwd)"
4243
echo "=============================="
4344

4445
# If legacy targeted tests exist, run them; otherwise run all tests in backend/tests

0 commit comments

Comments
 (0)