|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Final A2A Test Script |
| 4 | +
|
| 5 | +This script performs a final test of the A2A protocol to verify all fixes. |
| 6 | +""" |
| 7 | + |
| 8 | +import requests |
| 9 | +import json |
| 10 | +import time |
| 11 | + |
| 12 | +def test_a2a_final(): |
| 13 | + """Final A2A test""" |
| 14 | + print("🔍 Final A2A Test") |
| 15 | + print("=" * 40) |
| 16 | + |
| 17 | + # Test health check |
| 18 | + print("1. Testing Health Check...") |
| 19 | + try: |
| 20 | + response = requests.get("http://localhost:8000/a2a/health", timeout=5) |
| 21 | + if response.status_code == 200: |
| 22 | + health_data = response.json() |
| 23 | + if "result" in health_data and health_data["result"].get("status") == "healthy": |
| 24 | + print("✅ Health Check: PASSED") |
| 25 | + else: |
| 26 | + print(f"❌ Health Check: FAILED - {health_data}") |
| 27 | + return False |
| 28 | + else: |
| 29 | + print(f"❌ Health Check: FAILED - HTTP {response.status_code}") |
| 30 | + return False |
| 31 | + except Exception as e: |
| 32 | + print(f"❌ Health Check: ERROR - {str(e)}") |
| 33 | + return False |
| 34 | + |
| 35 | + # Test agent discovery |
| 36 | + print("\n2. Testing Agent Discovery...") |
| 37 | + try: |
| 38 | + discover_payload = { |
| 39 | + "jsonrpc": "2.0", |
| 40 | + "method": "agent.discover", |
| 41 | + "params": {"capability": "document.query"}, |
| 42 | + "id": "test-discover" |
| 43 | + } |
| 44 | + |
| 45 | + response = requests.post( |
| 46 | + "http://localhost:8000/a2a", |
| 47 | + json=discover_payload, |
| 48 | + headers={"Content-Type": "application/json"}, |
| 49 | + timeout=10 |
| 50 | + ) |
| 51 | + |
| 52 | + if response.status_code == 200: |
| 53 | + discover_data = response.json() |
| 54 | + print(f"Discovery response: {json.dumps(discover_data, indent=2)}") |
| 55 | + |
| 56 | + if "error" in discover_data: |
| 57 | + print(f"❌ Agent Discovery: FAILED - {discover_data['error']}") |
| 58 | + return False |
| 59 | + else: |
| 60 | + result = discover_data.get("result", {}) |
| 61 | + agents = result.get("agents", []) |
| 62 | + if agents: |
| 63 | + print(f"✅ Agent Discovery: PASSED - Found {len(agents)} agents") |
| 64 | + for i, agent in enumerate(agents, 1): |
| 65 | + agent_id = agent.get('agent_id', 'unknown') |
| 66 | + agent_name = agent.get('name', 'unknown') |
| 67 | + print(f" Agent {i}: {agent_id} - {agent_name}") |
| 68 | + else: |
| 69 | + print("❌ Agent Discovery: FAILED - No agents found") |
| 70 | + print(f" Result: {result}") |
| 71 | + return False |
| 72 | + else: |
| 73 | + print(f"❌ Agent Discovery: FAILED - HTTP {response.status_code}") |
| 74 | + return False |
| 75 | + except Exception as e: |
| 76 | + print(f"❌ Agent Discovery: ERROR - {str(e)}") |
| 77 | + return False |
| 78 | + |
| 79 | + # Test document query |
| 80 | + print("\n3. Testing Document Query...") |
| 81 | + try: |
| 82 | + query_payload = { |
| 83 | + "jsonrpc": "2.0", |
| 84 | + "method": "document.query", |
| 85 | + "params": { |
| 86 | + "query": "What is artificial intelligence?", |
| 87 | + "collection": "General", |
| 88 | + "use_cot": False, |
| 89 | + "max_results": 3 |
| 90 | + }, |
| 91 | + "id": "test-query" |
| 92 | + } |
| 93 | + |
| 94 | + response = requests.post( |
| 95 | + "http://localhost:8000/a2a", |
| 96 | + json=query_payload, |
| 97 | + headers={"Content-Type": "application/json"}, |
| 98 | + timeout=30 |
| 99 | + ) |
| 100 | + |
| 101 | + if response.status_code == 200: |
| 102 | + query_data = response.json() |
| 103 | + if "error" in query_data: |
| 104 | + print(f"❌ Document Query: FAILED - {query_data['error']}") |
| 105 | + return False |
| 106 | + else: |
| 107 | + result = query_data.get("result", {}) |
| 108 | + answer = result.get("answer", "") |
| 109 | + if answer and answer != "No answer provided" and answer.strip(): |
| 110 | + print(f"✅ Document Query: PASSED") |
| 111 | + print(f" Answer: {answer[:100]}...") |
| 112 | + else: |
| 113 | + print(f"❌ Document Query: FAILED - No valid answer") |
| 114 | + print(f" Result: {result}") |
| 115 | + return False |
| 116 | + else: |
| 117 | + print(f"❌ Document Query: FAILED - HTTP {response.status_code}") |
| 118 | + return False |
| 119 | + except Exception as e: |
| 120 | + print(f"❌ Document Query: ERROR - {str(e)}") |
| 121 | + return False |
| 122 | + |
| 123 | + # Test task creation |
| 124 | + print("\n4. Testing Task Creation...") |
| 125 | + try: |
| 126 | + task_payload = { |
| 127 | + "jsonrpc": "2.0", |
| 128 | + "method": "task.create", |
| 129 | + "params": { |
| 130 | + "task_type": "document_processing", |
| 131 | + "params": { |
| 132 | + "command": "test_command", |
| 133 | + "description": "Test task for A2A testing", |
| 134 | + "priority": "high" |
| 135 | + } |
| 136 | + }, |
| 137 | + "id": "test-task" |
| 138 | + } |
| 139 | + |
| 140 | + response = requests.post( |
| 141 | + "http://localhost:8000/a2a", |
| 142 | + json=task_payload, |
| 143 | + headers={"Content-Type": "application/json"}, |
| 144 | + timeout=10 |
| 145 | + ) |
| 146 | + |
| 147 | + if response.status_code == 200: |
| 148 | + task_data = response.json() |
| 149 | + if "error" in task_data: |
| 150 | + print(f"❌ Task Creation: FAILED - {task_data['error']}") |
| 151 | + return False |
| 152 | + else: |
| 153 | + result = task_data.get("result", {}) |
| 154 | + task_id = result.get("task_id") |
| 155 | + if task_id: |
| 156 | + print(f"✅ Task Creation: PASSED - Created task {task_id}") |
| 157 | + |
| 158 | + # Test task status |
| 159 | + time.sleep(1) |
| 160 | + status_payload = { |
| 161 | + "jsonrpc": "2.0", |
| 162 | + "method": "task.status", |
| 163 | + "params": {"task_id": task_id}, |
| 164 | + "id": "test-status" |
| 165 | + } |
| 166 | + |
| 167 | + status_response = requests.post( |
| 168 | + "http://localhost:8000/a2a", |
| 169 | + json=status_payload, |
| 170 | + headers={"Content-Type": "application/json"}, |
| 171 | + timeout=10 |
| 172 | + ) |
| 173 | + |
| 174 | + if status_response.status_code == 200: |
| 175 | + status_data = status_response.json() |
| 176 | + if "error" not in status_data: |
| 177 | + status_result = status_data.get("result", {}) |
| 178 | + task_status = status_result.get("status", "unknown") |
| 179 | + print(f"✅ Task Status: PASSED - Status: {task_status}") |
| 180 | + else: |
| 181 | + print(f"❌ Task Status: FAILED - {status_data['error']}") |
| 182 | + return False |
| 183 | + else: |
| 184 | + print(f"❌ Task Status: FAILED - HTTP {status_response.status_code}") |
| 185 | + return False |
| 186 | + else: |
| 187 | + print(f"❌ Task Creation: FAILED - No task ID returned") |
| 188 | + return False |
| 189 | + else: |
| 190 | + print(f"❌ Task Creation: FAILED - HTTP {response.status_code}") |
| 191 | + return False |
| 192 | + except Exception as e: |
| 193 | + print(f"❌ Task Operations: ERROR - {str(e)}") |
| 194 | + return False |
| 195 | + |
| 196 | + return True |
| 197 | + |
| 198 | +def main(): |
| 199 | + """Main function""" |
| 200 | + print("🤖 Final A2A Test") |
| 201 | + print("Make sure A2A server is running: python main.py") |
| 202 | + print() |
| 203 | + |
| 204 | + success = test_a2a_final() |
| 205 | + |
| 206 | + if success: |
| 207 | + print("\n🎉 All A2A tests passed!") |
| 208 | + print("✅ OK") |
| 209 | + else: |
| 210 | + print("\n❌ Some A2A tests failed.") |
| 211 | + print("❌ NOT OK") |
| 212 | + |
| 213 | +if __name__ == "__main__": |
| 214 | + main() |
0 commit comments