-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.sh
More file actions
405 lines (356 loc) Β· 15 KB
/
test.sh
File metadata and controls
405 lines (356 loc) Β· 15 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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
#!/bin/bash
# ============================================================
# test.sh - Elite Enterprise Test Suite
# Atomic Swarm Gods Elite v1.7.0
# GitHub Actions CI/CD Gatekeeper
# ============================================================
set -euo pipefail # Exit on error, undefined var, pipe failure
# ============================================================
# Colors & Formatting (skip if not a terminal)
# ============================================================
if [ -t 1 ]; then
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
MAGENTA='\033[0;35m'
NC='\033[0m'
BOLD='\033[1m'
else
RED=''; GREEN=''; YELLOW=''; BLUE=''; CYAN=''; MAGENTA=''; NC=''; BOLD=''
fi
# ============================================================
# Configuration
# ============================================================
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
ELITE_VERSION="1.7.0"
TEST_PASSED=0
TEST_FAILED=0
TEST_WARNINGS=0
# ============================================================
# Helper Functions
# ============================================================
test_pass() {
echo -e "${GREEN}β
PASS:${NC} $1"
((TEST_PASSED++))
}
test_fail() {
echo -e "${RED}β FAIL:${NC} $1"
((TEST_FAILED++))
}
test_warning() {
echo -e "${YELLOW}β οΈ WARNING:${NC} $1"
((TEST_WARNINGS++))
}
test_info() {
echo -e "${BLUE}βΉοΈ INFO:${NC} $1"
}
print_section() {
echo ""
echo -e "${CYAN}ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
echo -e "${BOLD}$1${NC}"
echo -e "${CYAN}ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
}
# Safe JSON parsing (returns empty if file missing)
safe_json_field() {
local file="$1"
local field="$2"
if [ -f "$file" ]; then
node -p "try { require('./$file').$field } catch(e) { '' }" 2>/dev/null || echo ""
else
echo ""
fi
}
# ============================================================
# Header
# ============================================================
echo ""
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo "β π§ͺ ATOMIC SWARM GODS ELITE v${ELITE_VERSION} - TEST SUITE β"
echo "β π¬ CI/CD Gatekeeper | Enterprise Validation β"
echo "ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo ""
echo -e "${CYAN}π Test Environment:${NC}"
echo " β’ Timestamp: ${TIMESTAMP}"
echo " β’ Node Version: $(node --version 2>/dev/null || echo 'NOT FOUND')"
echo " β’ OS: $(uname -a 2>/dev/null | cut -d' ' -f1-3 || echo 'unknown')"
echo " β’ CI: ${CI:-false}"
echo ""
# ============================================================
# Phase 1: Environment Validation
# ============================================================
print_section "π§ PHASE 1: Environment Validation"
NODE_VERSION=$(node --version 2>/dev/null || echo "v0.0.0")
NODE_MAJOR=$(echo "$NODE_VERSION" | cut -d'.' -f1 | sed 's/v//')
if [ -n "$NODE_MAJOR" ] && [ "$NODE_MAJOR" -ge 18 ] && [ "$NODE_MAJOR" -le 24 ]; then
test_pass "Node.js version ${NODE_VERSION} (supported: 18-24)"
else
test_fail "Node.js version ${NODE_VERSION} not supported (need 18-24)"
fi
if command -v pnpm &> /dev/null; then
test_pass "pnpm $(pnpm --version) available"
elif command -v npm &> /dev/null; then
test_pass "npm $(npm --version) available"
else
test_fail "No package manager found (npm or pnpm)"
fi
if command -v git &> /dev/null; then
test_pass "git $(git --version | cut -d' ' -f3) available"
else
test_fail "git not available"
fi
# ============================================================
# Phase 2: Project Structure Validation
# ============================================================
print_section "π PHASE 2: Project Structure Validation"
CRITICAL_FILES=("package.json" "tsconfig.json")
for file in "${CRITICAL_FILES[@]}"; do
if [ -f "$file" ]; then
test_pass "Found: $file"
else
test_fail "Missing: $file"
fi
done
# src/index.ts and server.js are optional
for file in "src/index.ts" "server.js"; do
if [ -f "$file" ]; then
test_pass "Found: $file"
else
test_warning "Missing: $file (not required for all setups)"
fi
done
CRITICAL_DIRS=("src" "surgery-room")
for dir in "${CRITICAL_DIRS[@]}"; do
if [ -d "$dir" ]; then
test_pass "Directory exists: $dir"
else
test_fail "Missing directory: $dir"
fi
done
# Optional directories
for dir in "src/core" "src/auditor" "src/enterprise" "src/brain" "dist" "blockchain"; do
if [ -d "$dir" ]; then
test_pass "Directory exists: $dir"
else
test_warning "Missing directory: $dir (will be created during build)"
fi
done
# ============================================================
# Phase 3: Package.json Validation
# ============================================================
print_section "π¦ PHASE 3: Package.json Validation"
if [ -f "package.json" ]; then
if node -e "JSON.parse(require('fs').readFileSync('package.json', 'utf8'))" 2>/dev/null; then
test_pass "package.json syntax is valid"
else
test_fail "package.json syntax is invalid"
fi
PKG_VERSION=$(node -p "require('./package.json').version" 2>/dev/null || echo "unknown")
if [[ "$PKG_VERSION" == *"elite"* ]] || [[ "$PKG_VERSION" == "1.7.0"* ]]; then
test_pass "Version ${PKG_VERSION} (Elite)"
else
test_warning "Version ${PKG_VERSION} - update to 1.7.0-elite recommended"
fi
if grep -q '"elite"' package.json 2>/dev/null; then
test_pass "Elite configuration present"
else
test_warning "No elite configuration in package.json"
fi
REQUIRED_SCRIPTS=("build" "test" "start")
for script in "${REQUIRED_SCRIPTS[@]}"; do
if grep -q "\"${script}\":" package.json 2>/dev/null; then
test_pass "Script exists: ${script}"
else
test_warning "Missing script: ${script}"
fi
done
fi
# ============================================================
# Phase 4: TypeScript Validation
# ============================================================
print_section "π· PHASE 4: TypeScript Validation"
if [ -f "tsconfig.json" ]; then
if node -e "JSON.parse(require('fs').readFileSync('tsconfig.json', 'utf8'))" 2>/dev/null; then
test_pass "tsconfig.json syntax is valid"
else
test_fail "tsconfig.json syntax is invalid"
fi
if grep -q '"strict": true' tsconfig.json 2>/dev/null; then
test_pass "TypeScript strict mode enabled"
else
test_warning "TypeScript strict mode not enabled"
fi
TARGET=$(node -p "require('./tsconfig.json').compilerOptions.target" 2>/dev/null || echo "unknown")
if [[ "$TARGET" == "ES2022" ]] || [[ "$TARGET" == "ESNext" ]]; then
test_pass "Target: ${TARGET}"
else
test_warning "Target: ${TARGET} (recommend ES2022+)"
fi
if [ -d "node_modules" ]; then
echo ""
test_info "Running TypeScript type checker..."
if npx tsc --noEmit --strict --skipLibCheck > /tmp/tsc.out 2>&1; then
test_pass "TypeScript type check passed"
else
test_warning "TypeScript type check had issues (non-blocking)"
cat /tmp/tsc.out | head -10
fi
else
test_warning "node_modules not found, skipping TypeScript type check"
fi
fi
# ============================================================
# Phase 5: Dependency Validation
# ============================================================
print_section "π¦ PHASE 5: Dependency Validation"
if [ -d "node_modules" ]; then
PACKAGE_COUNT=$(find node_modules -maxdepth 1 -type d 2>/dev/null | wc -l)
test_pass "node_modules found (${PACKAGE_COUNT} packages)"
CRITICAL_DEPS=("express" "socket.io" "typescript")
for dep in "${CRITICAL_DEPS[@]}"; do
if [ -d "node_modules/${dep}" ]; then
test_pass "Dependency installed: ${dep}"
else
test_warning "Missing dependency: ${dep}"
fi
done
else
test_warning "node_modules not found - run npm install first"
fi
if [ -f "package-lock.json" ] || [ -f "pnpm-lock.yaml" ]; then
test_info "Checking for security vulnerabilities..."
if command -v npm >/dev/null; then
if npm audit --production --json 2>/dev/null | grep -q '"critical":0'; then
test_pass "No critical vulnerabilities"
else
test_warning "Security vulnerabilities detected - run npm audit fix"
fi
else
test_info "npm not available, skipping audit"
fi
fi
# ============================================================
# Phase 6: Build Validation
# ============================================================
print_section "π¨ PHASE 6: Build Validation"
if [ -d "dist" ] && [ -f "dist/index.js" ]; then
test_pass "Build exists in dist/"
BUILD_SIZE=$(du -sh dist 2>/dev/null | cut -f1)
test_info "Build size: ${BUILD_SIZE}"
else
test_warning "Build not found - run npm run build"
if command -v npm >/dev/null && [ -f "package.json" ]; then
test_info "Attempting build..."
if npm run build 2>&1 | tail -5; then
test_pass "Build successful"
else
test_warning "Build failed - check TypeScript errors"
fi
fi
fi
# ============================================================
# Phase 7: Elite Features Validation
# ============================================================
print_section "π PHASE 7: Elite Features Validation"
if [ -d "blockchain" ]; then
BLOCK_COUNT=$(find blockchain -name "*.json" 2>/dev/null | wc -l)
test_pass "Blockchain directory exists (${BLOCK_COUNT} blocks)"
else
test_warning "Blockchain directory missing"
fi
if [ -f "oracle-memory.json" ] || [ -d ".oracle-memory" ]; then
test_pass "Oracle memory system present"
else
test_info "Oracle memory will be created on first use"
fi
if [ -d "surgery-room" ]; then
test_pass "Surgery room directory exists"
else
test_fail "Surgery room directory missing"
fi
if [ -f "surgery-room/DynamicTestShifter.js" ]; then
test_pass "Dynamic test shifter present"
else
test_warning "DynamicTestShifter.js not found (may be generated later)"
fi
# Optional elite validator
if [ -f "src/enterprise/EliteRepairValidator.ts" ] || [ -f "dist/enterprise/EliteRepairValidator.js" ]; then
test_pass "Elite repair validator present"
else
test_warning "EliteRepairValidator not found (optional)"
fi
# ============================================================
# Phase 8: Runtime Validation (if server is running)
# ============================================================
print_section "π₯ PHASE 8: Runtime Validation"
if curl -s -f -o /dev/null http://localhost:3001/health 2>/dev/null; then
test_pass "Server is running on port 3001"
HEALTH_INFO=$(curl -s http://localhost:3001/health 2>/dev/null || echo "")
if echo "$HEALTH_INFO" | grep -q "elite" || echo "$HEALTH_INFO" | grep -q "1.7"; then
test_pass "Elite version detected in health check"
fi
if curl -s -f -o /dev/null http://localhost:3001/metrics 2>/dev/null; then
test_pass "Metrics endpoint available"
else
test_warning "Metrics endpoint not responding"
fi
else
test_info "Server not running (skip runtime tests)"
test_info "Start server with: npm start"
fi
# ============================================================
# Phase 9: Git & PR Validation
# ============================================================
print_section "π PHASE 9: Git & PR Validation"
if git status &>/dev/null; then
test_pass "Git repository detected"
if [ -z "$(git status --porcelain 2>/dev/null)" ]; then
test_pass "Working directory clean"
else
test_warning "Uncommitted changes detected"
fi
CURRENT_BRANCH=$(git branch --show-current 2>/dev/null || echo "unknown")
test_info "Current branch: ${CURRENT_BRANCH}"
else
test_warning "Not a git repository"
fi
if command -v gh &> /dev/null; then
test_pass "GitHub CLI available"
if gh auth status &>/dev/null; then
test_pass "GitHub CLI authenticated"
else
test_warning "GitHub CLI not authenticated"
fi
else
test_info "GitHub CLI not installed (PR creation will use API)"
fi
# ============================================================
# Test Summary
# ============================================================
print_section "π TEST SUMMARY"
TOTAL_TESTS=$((TEST_PASSED + TEST_FAILED + TEST_WARNINGS))
echo ""
echo -e "${BOLD}Results:${NC}"
echo -e " ${GREEN}β
Passed: ${TEST_PASSED}${NC}"
echo -e " ${RED}β Failed: ${TEST_FAILED}${NC}"
echo -e " ${YELLOW}β οΈ Warnings: ${TEST_WARNINGS}${NC}"
echo -e " ${BLUE}π Total: ${TOTAL_TESTS}${NC}"
echo ""
if [ $TEST_FAILED -gt 0 ]; then
echo -e "${RED}ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
echo -e "${RED}β β TEST SUITE FAILED - ${TEST_FAILED} critical failure(s) β${NC}"
echo -e "${RED}ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
exit 1
elif [ $TEST_WARNINGS -gt 0 ]; then
echo -e "${YELLOW}ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
echo -e "${YELLOW}β β οΈ TEST SUITE PASSED WITH WARNINGS - ${TEST_WARNINGS} warning(s) β${NC}"
echo -e "${YELLOW}ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
exit 0
else
echo -e "${GREEN}ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
echo -e "${GREEN}β β
TEST SUITE PASSED - All checks successful! β${NC}"
echo -e "${GREEN}β π Atomic Swarm Gods Elite v${ELITE_VERSION} is ready! β${NC}"
echo -e "${GREEN}ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
exit 0
fi