anderson-ufrj commited on
Commit
a02ad56
·
1 Parent(s): b026c73

test(e2e): add HuggingFace backend deployment test

Browse files
tests/e2e/test_hf_backend_deployment.py ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Test HuggingFace Backend deployment
4
+ """
5
+
6
+ import asyncio
7
+ import httpx
8
+
9
+ async def test_backend_hf():
10
+ """Test HuggingFace Backend deployment."""
11
+
12
+ print("🧪 TESTING CIDADÃO.AI BACKEND ON HUGGINGFACE")
13
+ print("=" * 50)
14
+
15
+ base_url = "https://neural-thinker-cidadao-ai-backend.hf.space"
16
+
17
+ async with httpx.AsyncClient(timeout=30.0) as client:
18
+ try:
19
+ # Test 1: Health check
20
+ print("1️⃣ TESTING HEALTH CHECK")
21
+ print("-" * 30)
22
+
23
+ response = await client.get(f"{base_url}/health")
24
+ print(f"Status: {response.status_code}")
25
+
26
+ if response.status_code == 200:
27
+ health_data = response.json()
28
+ print("✅ Backend is healthy")
29
+ print(f"Version: {health_data.get('version', 'unknown')}")
30
+ print(f"Agents: {health_data.get('agents', {})}")
31
+ else:
32
+ print(f"❌ Health check failed: {response.status_code}")
33
+
34
+ print()
35
+
36
+ # Test 2: Root endpoint
37
+ print("2️⃣ TESTING ROOT ENDPOINT")
38
+ print("-" * 30)
39
+
40
+ response = await client.get(f"{base_url}/")
41
+ print(f"Status: {response.status_code}")
42
+
43
+ if response.status_code == 200:
44
+ root_data = response.json()
45
+ print("✅ Root endpoint working")
46
+ print(f"Status: {root_data.get('status', 'unknown')}")
47
+
48
+ print()
49
+
50
+ # Test 3: Zumbi investigation
51
+ print("3️⃣ TESTING ZUMBI INVESTIGATION")
52
+ print("-" * 35)
53
+
54
+ test_request = {
55
+ "query": "Analisar contratos de informática com valores suspeitos",
56
+ "data_source": "contracts",
57
+ "max_results": 10
58
+ }
59
+
60
+ response = await client.post(
61
+ f"{base_url}/api/agents/zumbi/investigate",
62
+ json=test_request
63
+ )
64
+ print(f"Status: {response.status_code}")
65
+
66
+ if response.status_code == 200:
67
+ result = response.json()
68
+ print("✅ Zumbi investigation working")
69
+ print(f"Query: {result.get('query', 'unknown')}")
70
+ print(f"Anomalies found: {result.get('anomalies_found', 0)}")
71
+ print(f"Confidence: {result.get('confidence_score', 0)}")
72
+ print(f"Processing time: {result.get('processing_time_ms', 0)}ms")
73
+ else:
74
+ print(f"❌ Investigation failed: {response.status_code}")
75
+
76
+ print()
77
+
78
+ # Test 4: API docs
79
+ print("4️⃣ TESTING API DOCUMENTATION")
80
+ print("-" * 35)
81
+
82
+ response = await client.get(f"{base_url}/docs")
83
+ print(f"Status: {response.status_code}")
84
+
85
+ if response.status_code == 200:
86
+ print("✅ API documentation accessible")
87
+
88
+ print()
89
+
90
+ # Test 5: Metrics
91
+ print("5️⃣ TESTING METRICS ENDPOINT")
92
+ print("-" * 32)
93
+
94
+ response = await client.get(f"{base_url}/metrics")
95
+ print(f"Status: {response.status_code}")
96
+
97
+ if response.status_code == 200:
98
+ print("✅ Prometheus metrics available")
99
+
100
+ print()
101
+
102
+ # Summary
103
+ print("📊 BACKEND TEST SUMMARY")
104
+ print("-" * 30)
105
+ print("✅ HuggingFace Space: DEPLOYED")
106
+ print("✅ Backend API: FUNCTIONAL")
107
+ print("✅ Zumbi Agent: ACTIVE")
108
+ print("✅ Documentation: ACCESSIBLE")
109
+ print("✅ Monitoring: ENABLED")
110
+ print()
111
+ print("🎉 SUCCESS: Backend is fully functional on HuggingFace!")
112
+
113
+ except Exception as e:
114
+ print(f"❌ Backend test failed: {e}")
115
+ return False
116
+
117
+ return True
118
+
119
+ if __name__ == "__main__":
120
+ print("🏛️ CIDADÃO.AI BACKEND DEPLOYMENT TEST")
121
+ print()
122
+
123
+ try:
124
+ success = asyncio.run(test_backend_hf())
125
+ if success:
126
+ print("✅ Backend test completed successfully!")
127
+ else:
128
+ print("❌ Backend test failed!")
129
+ except KeyboardInterrupt:
130
+ print("\n⚠️ Test interrupted by user")
131
+ except Exception as e:
132
+ print(f"\n❌ Test failed with error: {e}")