42 lines
1.5 KiB
Python
42 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
class MCPServerTests(unittest.TestCase):
|
|
def test_initialize_and_list_tools(self) -> None:
|
|
with tempfile.TemporaryDirectory() as home:
|
|
subprocess.run(
|
|
[str(ROOT / "bin/datatest"), "--home", home, "demo"],
|
|
cwd=ROOT, check=True, capture_output=True, text=True,
|
|
)
|
|
messages = "\n".join(
|
|
[
|
|
json.dumps({"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {}}),
|
|
json.dumps({"jsonrpc": "2.0", "id": 2, "method": "tools/list", "params": {}}),
|
|
"",
|
|
]
|
|
)
|
|
completed = subprocess.run(
|
|
[str(ROOT / "bin/datatest"), "--home", home, "mcp"],
|
|
cwd=ROOT, input=messages, capture_output=True, text=True, check=True,
|
|
)
|
|
responses = [json.loads(line) for line in completed.stdout.splitlines()]
|
|
self.assertEqual(responses[0]["result"]["serverInfo"]["name"], "datatest")
|
|
names = {item["name"] for item in responses[1]["result"]["tools"]}
|
|
self.assertIn("inspect_metadata", names)
|
|
self.assertIn("run_test_cases", names)
|
|
self.assertIn("analyze_failure", names)
|
|
self.assertIn("adjust_test_cases", names)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|