-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-acp-functions.py
More file actions
202 lines (174 loc) Β· 6.78 KB
/
Copy pathtest-acp-functions.py
File metadata and controls
202 lines (174 loc) Β· 6.78 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/usr/bin/env python3
"""
Test script for MESH ACP functions
Run this to verify all ACP functions work correctly
"""
import asyncio
import sys
import os
# Add current directory to path to import the ACP modules
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
async def test_acp_server_import():
"""Test that the ACP server can be imported"""
print("π§ͺ Testing ACP server import...")
try:
import importlib.util
spec = importlib.util.spec_from_file_location("acp_server", "acp_server.py")
acp_server = importlib.util.module_from_spec(spec)
spec.loader.exec_module(acp_server)
print("β
ACP server imported successfully")
return True
except Exception as e:
print(f"β Error importing ACP server: {e}")
return False
async def test_acp_client_import():
"""Test that the ACP client can be imported"""
print("\nπ§ͺ Testing ACP client import...")
try:
import importlib.util
spec = importlib.util.spec_from_file_location("acp_client", "acp_client.py")
acp_client = importlib.util.module_from_spec(spec)
spec.loader.exec_module(acp_client)
print("β
ACP client imported successfully")
return True
except Exception as e:
print(f"β Error importing ACP client: {e}")
return False
async def test_acp_models():
"""Test ACP data models"""
print("\nπ§ͺ Testing ACP data models...")
try:
import importlib.util
spec = importlib.util.spec_from_file_location("acp_server", "acp_server.py")
acp_server = importlib.util.module_from_spec(spec)
spec.loader.exec_module(acp_server)
# Test message creation
from datetime import datetime, timezone
# Test TaskMessage
task_msg = acp_server.TaskMessage(
sender="test-client",
task_type="email_draft",
parameters={"test": "value"}
)
print(f"β
TaskMessage created: {task_msg.id}")
# Test ResponseMessage
response_msg = acp_server.ResponseMessage(
sender="test-server",
recipient="test-client",
task_id=task_msg.id,
result={"status": "success"}
)
print(f"β
ResponseMessage created: {response_msg.id}")
# Test ErrorMessage
error_msg = acp_server.ErrorMessage(
sender="test-server",
recipient="test-client",
task_id=task_msg.id,
error_code="TEST_ERROR",
error_details="Test error message"
)
print(f"β
ErrorMessage created: {error_msg.id}")
# Test AgentManifest
manifest = acp_server.AgentManifest(
id="test-agent",
name="Test Agent",
description="A test agent",
version="1.0.0"
)
print(f"β
AgentManifest created: {manifest.id}")
return True
except Exception as e:
print(f"β Error testing ACP models: {e}")
return False
async def test_acp_server_creation():
"""Test ACP server creation"""
print("\nπ§ͺ Testing ACP server creation...")
try:
import importlib.util
spec = importlib.util.spec_from_file_location("acp_server", "acp_server.py")
acp_server = importlib.util.module_from_spec(spec)
spec.loader.exec_module(acp_server)
# Create server instance
server = acp_server.ACPServer()
print(f"β
ACP server created successfully")
print(f" FastAPI app: {server.app.title}")
print(f" Routes: {len(server.app.routes)} registered")
return True
except Exception as e:
print(f"β Error testing ACP server creation: {e}")
return False
async def test_acp_client_creation():
"""Test ACP client creation"""
print("\nπ§ͺ Testing ACP client creation...")
try:
import importlib.util
spec = importlib.util.spec_from_file_location("acp_client", "acp_client.py")
acp_client = importlib.util.module_from_spec(spec)
spec.loader.exec_module(acp_client)
# Create client instance
client = acp_client.ACPClient("http://127.0.0.1:8081")
print(f"β
ACP client created successfully")
print(f" Client ID: {client.client_id}")
print(f" Base URL: {client.base_url}")
return True
except Exception as e:
print(f"β Error testing ACP client creation: {e}")
return False
async def test_acp_agent_manifest():
"""Test ACP agent manifest"""
print("\nπ§ͺ Testing ACP agent manifest...")
try:
import importlib.util
spec = importlib.util.spec_from_file_location("acp_client", "acp_client.py")
acp_client = importlib.util.module_from_spec(spec)
spec.loader.exec_module(acp_client)
# Test manifest structure
manifest = acp_client.EXAMPLE_AGENT_MANIFEST
print(f"β
Example agent manifest loaded")
print(f" Agent ID: {manifest['id']}")
print(f" Name: {manifest['name']}")
print(f" Capabilities: {len(manifest['capabilities'])}")
print(f" Supported Tasks: {len(manifest['supported_tasks'])}")
# Validate required fields
required_fields = ['id', 'name', 'description', 'version']
for field in required_fields:
if field not in manifest:
print(f"β Missing required field: {field}")
return False
print("β
All required fields present")
return True
except Exception as e:
print(f"β Error testing ACP agent manifest: {e}")
return False
async def main():
"""Run all ACP tests"""
print("π MESH ACP Function Test Suite")
print("=" * 50)
tests = [
test_acp_server_import,
test_acp_client_import,
test_acp_models,
test_acp_server_creation,
test_acp_client_creation,
test_acp_agent_manifest
]
passed = 0
total = len(tests)
for test in tests:
if await test():
passed += 1
print("\n" + "=" * 50)
print(f"π Test Results: {passed}/{total} tests passed")
if passed == total:
print("π All tests passed! ACP server is ready for testing.")
print("\nπ‘ Next steps:")
print(" 1. Start the ACP server: python acp_server.py")
print(" 2. Test with the client: python acp_client.py")
print(" 3. Explore the REST API at http://127.0.0.1:8081")
print(" 4. Check the interactive docs at http://127.0.0.1:8081/docs")
else:
print("β οΈ Some tests failed. Please fix the issues before testing the ACP server.")
sys.exit(1)
if __name__ == "__main__":
# Run all tests
asyncio.run(main())