Download tests/test_mcp_server.py from lhc-lab/AI-Colab: direct link, hf CLI and curl.
- Browser
- Download file 1.43 kB
-
https://huggingface.co/datasets/lhc-lab/AI-Colab/resolve/main/tests/test_mcp_server.py
- Command line
-
hf download hf://datasets/lhc-lab/AI-Colab/tests/test_mcp_server.py
-
curl -L -o test_mcp_server.py https://huggingface.co/datasets/lhc-lab/AI-Colab/resolve/main/tests/test_mcp_server.py
1.43 kB
| import pytest | |
| import asyncio | |
| import websockets | |
| import json | |
| import os | |
| PORT = 8765 | |
| URL = f"ws://127.0.0.1:{PORT}" | |
| async def test_message(): | |
| async with websockets.connect(URL) as ws: | |
| await ws.send(json.dumps({"message": "Hello"})) | |
| response = await ws.recv() | |
| data = json.loads(response) | |
| assert "response" in data | |
| assert isinstance(data["response"], str) | |
| async def test_directive(): | |
| async with websockets.connect(URL) as ws: | |
| cmd = {"directive": {"action": "shell", "tool": "shell", "parameters": {"command": "echo MCP_TEST"}}} | |
| await ws.send(json.dumps(cmd)) | |
| response = await ws.recv() | |
| data = json.loads(response) | |
| assert data["type"] == "execution_result" | |
| assert "MCP_TEST" in data["result"]["output"] | |
| async def test_invalid_keys(): | |
| async with websockets.connect(URL) as ws: | |
| await ws.send(json.dumps({"message": "Hi", "extra": "field"})) | |
| response = await ws.recv() | |
| data = json.loads(response) | |
| assert data["type"] == "error" | |
| assert "Invalid request format" in data["message"] | |
| async def test_text_key(): | |
| async with websockets.connect(URL) as ws: | |
| await ws.send(json.dumps({"text": "Hello"})) | |
| response = await ws.recv() | |
| data = json.loads(response) | |
| assert "response" in data | |