-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathULTIMATE_TEST.sh
More file actions
executable file
·352 lines (294 loc) · 11.8 KB
/
ULTIMATE_TEST.sh
File metadata and controls
executable file
·352 lines (294 loc) · 11.8 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
#!/bin/bash
# 🔮 ULTIMATE SOVEREIGNCORE TEST SUITE
# Comprehensive validation of all systems
set -e # Exit on any error
echo "╔════════════════════════════════════════════════════════════════╗"
echo "║ 🔮 SOVEREIGNCORE ULTIMATE TEST SUITE 🔮 ║"
echo "╚════════════════════════════════════════════════════════════════╝"
echo ""
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
PASSED=0
FAILED=0
WARNINGS=0
# Test result tracking
test_result() {
if [ $1 -eq 0 ]; then
echo -e "${GREEN}✅ PASSED${NC}: $2"
((PASSED++))
else
echo -e "${RED}❌ FAILED${NC}: $2"
((FAILED++))
fi
}
warning() {
echo -e "${YELLOW}⚠️ WARNING${NC}: $1"
((WARNINGS++))
}
section() {
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BLUE} $1${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
}
cd /Users/lordwilson/SovereignCore
# ============================================================================
# PHASE 1: ENVIRONMENT VALIDATION
# ============================================================================
section "PHASE 1: Environment Validation"
# Check Python version
echo "Checking Python version..."
python3 --version
test_result $? "Python 3 installed"
# Check virtual environment
if [ -d ".venv" ]; then
test_result 0 "Virtual environment exists"
source .venv/bin/activate
else
warning "No virtual environment found - using system Python"
fi
# Check dependencies
echo "Checking critical dependencies..."
python3 -c "import fastapi" 2>/dev/null
test_result $? "FastAPI installed"
python3 -c "import jwt" 2>/dev/null
test_result $? "PyJWT installed"
python3 -c "import pytest" 2>/dev/null
test_result $? "Pytest installed"
# Check database
if [ -f "sovereign_users.db" ]; then
test_result 0 "User database exists"
else
warning "User database not found - will be created on first run"
fi
# Check .env file
if [ -f ".env" ]; then
test_result 0 ".env configuration file exists"
else
warning ".env file not found - using defaults"
fi
# ============================================================================
# PHASE 2: UNIT TESTS
# ============================================================================
section "PHASE 2: Unit Tests"
echo "Running pytest unit tests..."
if pytest tests/ -v --tb=short -m "not integration" 2>&1 | tee /tmp/pytest_output.txt; then
test_result 0 "Unit tests passed"
else
test_result 1 "Unit tests failed - check output above"
fi
# ============================================================================
# PHASE 3: INTEGRATION TESTS
# ============================================================================
section "PHASE 3: Integration Tests"
echo "Running integration tests..."
if pytest tests/ -v --tb=short -m "integration" 2>&1; then
test_result 0 "Integration tests passed"
else
warning "Integration tests failed or skipped (may require Redis)"
fi
# ============================================================================
# PHASE 4: CODE COVERAGE
# ============================================================================
section "PHASE 4: Code Coverage Analysis"
echo "Running coverage analysis..."
if pytest --cov=api_server --cov=consciousness_bridge --cov=database --cov-report=term-missing --cov-report=html tests/ 2>&1 | tee /tmp/coverage_output.txt; then
# Extract coverage percentage
COVERAGE=$(grep "TOTAL" /tmp/coverage_output.txt | awk '{print $NF}' | sed 's/%//')
if [ ! -z "$COVERAGE" ]; then
echo "Coverage: ${COVERAGE}%"
if [ $(echo "$COVERAGE >= 80" | bc -l) -eq 1 ]; then
test_result 0 "Code coverage ≥80% (${COVERAGE}%)"
elif [ $(echo "$COVERAGE >= 60" | bc -l) -eq 1 ]; then
warning "Code coverage is ${COVERAGE}% (target: 80%)"
else
test_result 1 "Code coverage too low: ${COVERAGE}% (minimum: 60%)"
fi
else
warning "Could not extract coverage percentage"
fi
else
test_result 1 "Coverage analysis failed"
fi
# ============================================================================
# PHASE 5: API SERVER STARTUP TEST
# ============================================================================
section "PHASE 5: API Server Startup Test"
echo "Testing API server startup..."
# Start server in background
python3 api_server.py &
SERVER_PID=$!
# Wait for server to start
sleep 3
# Check if server is running
if kill -0 $SERVER_PID 2>/dev/null; then
test_result 0 "API server started successfully (PID: $SERVER_PID)"
# Test health endpoint
echo "Testing /health endpoint..."
if curl -s http://localhost:8528/health | grep -q "healthy"; then
test_result 0 "Health endpoint responding"
else
test_result 1 "Health endpoint not responding correctly"
fi
# Test root endpoint
echo "Testing / endpoint..."
if curl -s http://localhost:8528/ | grep -q "SovereignCore"; then
test_result 0 "Root endpoint responding"
else
test_result 1 "Root endpoint not responding correctly"
fi
# Test metrics endpoint
echo "Testing /metrics endpoint..."
if curl -s http://localhost:8528/metrics | grep -q "python_info"; then
test_result 0 "Metrics endpoint responding"
else
test_result 1 "Metrics endpoint not responding correctly"
fi
# Cleanup: Stop server
echo "Stopping test server..."
kill $SERVER_PID 2>/dev/null
wait $SERVER_PID 2>/dev/null
test_result 0 "Server stopped cleanly"
else
test_result 1 "API server failed to start"
fi
# ============================================================================
# PHASE 6: AUTHENTICATION FLOW TEST
# ============================================================================
section "PHASE 6: Authentication Flow Test"
echo "Starting server for auth tests..."
python3 api_server.py &
SERVER_PID=$!
sleep 3
if kill -0 $SERVER_PID 2>/dev/null; then
# Test login endpoint
echo "Testing authentication flow..."
# Try to get token (may fail if no test user exists)
TOKEN_RESPONSE=$(curl -s -X POST http://localhost:8528/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "username=admin&password=admin123" 2>/dev/null)
if echo "$TOKEN_RESPONSE" | grep -q "access_token"; then
test_result 0 "Authentication endpoint working"
# Extract token
ACCESS_TOKEN=$(echo "$TOKEN_RESPONSE" | python3 -c "import sys, json; print(json.load(sys.stdin)['access_token'])" 2>/dev/null)
if [ ! -z "$ACCESS_TOKEN" ]; then
test_result 0 "Access token generated"
# Test protected endpoint with token
PROTECTED_RESPONSE=$(curl -s http://localhost:8528/api/v1/consciousness/status \
-H "Authorization: Bearer $ACCESS_TOKEN" 2>/dev/null)
if [ $? -eq 0 ]; then
test_result 0 "Protected endpoint accessible with token"
else
warning "Protected endpoint test inconclusive"
fi
else
warning "Could not extract access token"
fi
else
warning "Authentication test skipped (no test user configured)"
fi
# Cleanup
kill $SERVER_PID 2>/dev/null
wait $SERVER_PID 2>/dev/null
else
test_result 1 "Could not start server for auth tests"
fi
# ============================================================================
# PHASE 7: SECURITY CHECKS
# ============================================================================
section "PHASE 7: Security Validation"
# Check for .env.example
if [ -f ".env.example" ]; then
test_result 0 ".env.example template exists"
else
warning ".env.example not found"
fi
# Check TLS certificates
if [ -d "certs" ]; then
test_result 0 "TLS certificates directory exists"
if [ -f "certs/server.crt" ] && [ -f "certs/server.key" ]; then
test_result 0 "TLS certificates present"
else
warning "TLS certificates not generated (run generate_certs.sh)"
fi
else
warning "TLS certificates directory not found"
fi
# Check for security headers in code
if grep -q "X-Content-Type-Options" api_server.py; then
test_result 0 "Security headers implemented"
else
warning "Security headers may not be configured"
fi
# ============================================================================
# PHASE 8: PRODUCTION READINESS
# ============================================================================
section "PHASE 8: Production Readiness Checks"
# Check for Docker support
if [ -f "Dockerfile" ]; then
test_result 0 "Dockerfile exists"
else
warning "Dockerfile not found"
fi
if [ -f "docker-compose.yml" ]; then
test_result 0 "Docker Compose configuration exists"
else
warning "docker-compose.yml not found"
fi
# Check for monitoring
if [ -f "prometheus.yml" ]; then
test_result 0 "Prometheus configuration exists"
else
warning "Prometheus configuration not found"
fi
# Check for backup scripts
if [ -f "backup.sh" ]; then
test_result 0 "Backup script exists"
else
warning "Backup script not found"
fi
# Check for CI/CD
if [ -d ".github/workflows" ]; then
test_result 0 "GitHub Actions workflows configured"
else
warning "CI/CD workflows not found"
fi
# ============================================================================
# FINAL REPORT
# ============================================================================
section "FINAL REPORT"
TOTAL=$((PASSED + FAILED))
PASS_RATE=0
if [ $TOTAL -gt 0 ]; then
PASS_RATE=$((PASSED * 100 / TOTAL))
fi
echo ""
echo "╔════════════════════════════════════════════════════════════════╗"
echo "║ TEST RESULTS SUMMARY ║"
echo "╠════════════════════════════════════════════════════════════════╣"
printf "║ ✅ Passed: %-3d ║\n" $PASSED
printf "║ ❌ Failed: %-3d ║\n" $FAILED
printf "║ ⚠️ Warnings: %-3d ║\n" $WARNINGS
printf "║ 📊 Pass Rate: %-3d%% ║\n" $PASS_RATE
echo "╚════════════════════════════════════════════════════════════════╝"
echo ""
# Determine overall status
if [ $FAILED -eq 0 ]; then
if [ $WARNINGS -eq 0 ]; then
echo -e "${GREEN}🎉 PERFECT! All tests passed with no warnings!${NC}"
echo -e "${GREEN}✨ SovereignCore is PRODUCTION READY! ✨${NC}"
exit 0
else
echo -e "${YELLOW}✅ All tests passed, but there are $WARNINGS warnings to address.${NC}"
echo -e "${YELLOW}📋 Review warnings above for optimization opportunities.${NC}"
exit 0
fi
else
echo -e "${RED}⚠️ ATTENTION: $FAILED test(s) failed!${NC}"
echo -e "${RED}🔧 Please review and fix the failed tests above.${NC}"
exit 1
fi