-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_examples.py
More file actions
124 lines (100 loc) · 4.18 KB
/
test_examples.py
File metadata and controls
124 lines (100 loc) · 4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env python3
"""
Test script to validate the MCP server works with pysimplicityhl examples
"""
import asyncio
import sys
from pathlib import Path
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
async def test_example(session, name: str, source_file: str, witness_file: str):
"""Test a single example"""
print(f"\n{'='*60}")
print(f"Testing: {name}")
print(f"{'='*60}")
# Read files
source_code = Path(source_file).read_text()
witness_data = Path(witness_file).read_text() if Path(witness_file).exists() else ""
print(f"\n[Source] {len(source_code)} chars:")
print(source_code[:200] + "..." if len(source_code) > 200 else source_code)
if witness_data:
print(f"\n[Witness] {len(witness_data)} chars:")
print(witness_data[:100] + "..." if len(witness_data) > 100 else witness_data)
# Call compilation
try:
result = await session.call_tool(
"compile_simplicity",
arguments={
"source_code": source_code,
"witness_data": witness_data
}
)
content = result.content[0].text if result.content else "No content"
# Remove unicode for Windows
content_safe = content.encode('ascii', 'ignore').decode('ascii')
print(f"\n[Result]:")
print(content_safe)
return "Compilation successful!" in content_safe
except Exception as e:
print(f"\n[Error] {e}")
return False
async def main():
"""Run all example tests"""
# Check if we should use docker or local
use_docker = "--docker" in sys.argv
if use_docker:
server_params = StdioServerParameters(
command="docker",
args=["exec", "-i", "mcp-simplicity-server", "python", "server.py"]
)
else:
# Run server locally
server_params = StdioServerParameters(
command="python",
args=["server.py"]
)
print("Starting MCP Server tests...")
print(f"Mode: {'Docker' if use_docker else 'Local'}")
async with stdio_client(server_params) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
print("\n[OK] Server initialized!")
# Test getting pysimplicityhl info
print("\n" + "="*60)
print("Getting pysimplicityhl info...")
print("="*60)
try:
info = await session.call_tool("get_pysimplicityhl_info", arguments={})
print(info.content[0].text if info.content else "No info")
except Exception as e:
print(f"[Error] Could not get info: {e}")
# Define test cases
examples = [
("Arithmetic", "examples/arithmetic.simf", "examples/arithmetic.wit"),
("Scoping", "examples/scoping.simf", "examples/scoping.wit"),
("Witness Equality", "examples/witness_equality.simf", "examples/witness_equality.wit"),
("Witness Computation", "examples/witness_computation.simf", "examples/witness_computation.wit"),
]
results = {}
for name, source, witness in examples:
success = await test_example(session, name, source, witness)
results[name] = success
# Summary
print("\n" + "="*60)
print("TEST SUMMARY")
print("="*60)
for name, success in results.items():
status = "[PASS]" if success else "[FAIL]"
print(f"{status}: {name}")
total = len(results)
passed = sum(results.values())
print(f"\nTotal: {passed}/{total} passed")
if passed == total:
print("\n[SUCCESS] All tests passed!")
return 0
else:
print(f"\n[Warning] {total - passed} test(s) failed")
return 1
if __name__ == "__main__":
exit_code = asyncio.run(main())
sys.exit(exit_code)