Skip to content

Commit 3c47d34

Browse files
milos85vasicclaude
andcommitted
Add fallback visualization challenge script
Added comprehensive challenge script for validating the fallback chain visualization system with 20 tests covering: - FormatFallbackChainIndicator function existence and behavior - FormatFallbackChainWithContent function existence and behavior - formatFallbackReason helper for user-friendly error messages - FallbackAttempt struct with required fields - Darker timing colors (ANSIDim+ANSIBrightBlack) - Rate limit, timeout, connection error reason formatting - Service unavailable, quota exceeded, overloaded reasons - Error message truncation (>30 chars) - Complex fallback scenarios with multiple chained fallbacks - Full unit test validation All 20 tests pass successfully. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 24b38b6 commit 3c47d34

File tree

1 file changed

+235
-0
lines changed

1 file changed

+235
-0
lines changed
Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
#!/bin/bash
2+
# ============================================================================
3+
# Fallback Visualization Challenge
4+
# ============================================================================
5+
# Validates the fallback chain visualization system including:
6+
# - Fallback chain indicators with timing
7+
# - User-friendly fallback reasons
8+
# - Darker timing colors
9+
# - Multiple chained fallbacks support
10+
# ============================================================================
11+
12+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
13+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
14+
15+
# Source common utilities
16+
source "$SCRIPT_DIR/common.sh" 2>/dev/null || true
17+
18+
# Colors for output
19+
RED='\033[0;31m'
20+
GREEN='\033[0;32m'
21+
YELLOW='\033[1;33m'
22+
BLUE='\033[0;34m'
23+
NC='\033[0m'
24+
25+
# Test counters
26+
TOTAL_TESTS=0
27+
PASSED_TESTS=0
28+
FAILED_TESTS=0
29+
30+
pass_test() {
31+
PASSED_TESTS=$((PASSED_TESTS + 1))
32+
TOTAL_TESTS=$((TOTAL_TESTS + 1))
33+
echo -e "${GREEN}✓ PASS:${NC} $1"
34+
}
35+
36+
fail_test() {
37+
FAILED_TESTS=$((FAILED_TESTS + 1))
38+
TOTAL_TESTS=$((TOTAL_TESTS + 1))
39+
echo -e "${RED}✗ FAIL:${NC} $1"
40+
}
41+
42+
echo "============================================================================"
43+
echo "FALLBACK VISUALIZATION CHALLENGE"
44+
echo "============================================================================"
45+
echo ""
46+
echo "Testing the fallback chain visualization system..."
47+
echo ""
48+
49+
cd "$PROJECT_ROOT"
50+
51+
# Test 1: Run debate visualization unit tests
52+
echo -e "${BLUE}[Test 1] Running debate visualization unit tests...${NC}"
53+
if go test -run "TestFormat|TestFallback|TestTiming|TestComplex" ./internal/handlers/... > /dev/null 2>&1; then
54+
pass_test "Debate visualization unit tests pass"
55+
else
56+
fail_test "Debate visualization unit tests failed"
57+
fi
58+
59+
# Test 2: FormatFallbackChainIndicator exists
60+
echo -e "${BLUE}[Test 2] Verifying FormatFallbackChainIndicator function...${NC}"
61+
if grep -q "func FormatFallbackChainIndicator" internal/handlers/debate_visualization.go; then
62+
pass_test "FormatFallbackChainIndicator function exists"
63+
else
64+
fail_test "FormatFallbackChainIndicator function not found"
65+
fi
66+
67+
# Test 3: FormatFallbackChainWithContent exists
68+
echo -e "${BLUE}[Test 3] Verifying FormatFallbackChainWithContent function...${NC}"
69+
if grep -q "func FormatFallbackChainWithContent" internal/handlers/debate_visualization.go; then
70+
pass_test "FormatFallbackChainWithContent function exists"
71+
else
72+
fail_test "FormatFallbackChainWithContent function not found"
73+
fi
74+
75+
# Test 4: formatFallbackReason helper exists
76+
echo -e "${BLUE}[Test 4] Verifying formatFallbackReason helper...${NC}"
77+
if grep -q "func formatFallbackReason" internal/handlers/debate_visualization.go; then
78+
pass_test "formatFallbackReason helper exists"
79+
else
80+
fail_test "formatFallbackReason helper not found"
81+
fi
82+
83+
# Test 5: FallbackAttempt struct exists
84+
echo -e "${BLUE}[Test 5] Verifying FallbackAttempt struct...${NC}"
85+
if grep -q "type FallbackAttempt struct" internal/handlers/debate_visualization.go; then
86+
pass_test "FallbackAttempt struct exists"
87+
else
88+
fail_test "FallbackAttempt struct not found"
89+
fi
90+
91+
# Test 6: Darker timing color
92+
echo -e "${BLUE}[Test 6] Verifying darker timing colors...${NC}"
93+
if grep -q "ANSIDim+ANSIBrightBlack" internal/handlers/debate_visualization.go; then
94+
pass_test "Darker timing colors implemented"
95+
else
96+
fail_test "Darker timing colors not found"
97+
fi
98+
99+
# Test 7: Rate limit reason formatting
100+
echo -e "${BLUE}[Test 7] Verifying rate limit reason formatting...${NC}"
101+
if grep -q 'Rate limit reached' internal/handlers/debate_visualization.go; then
102+
pass_test "Rate limit reason formatting implemented"
103+
else
104+
fail_test "Rate limit reason formatting not found"
105+
fi
106+
107+
# Test 8: Timeout reason formatting
108+
echo -e "${BLUE}[Test 8] Verifying timeout reason formatting...${NC}"
109+
if grep -q 'return "Timeout"' internal/handlers/debate_visualization.go; then
110+
pass_test "Timeout reason formatting implemented"
111+
else
112+
fail_test "Timeout reason formatting not found"
113+
fi
114+
115+
# Test 9: Connection error reason formatting
116+
echo -e "${BLUE}[Test 9] Verifying connection error reason formatting...${NC}"
117+
if grep -q 'Connection error' internal/handlers/debate_visualization.go; then
118+
pass_test "Connection error reason formatting implemented"
119+
else
120+
fail_test "Connection error reason formatting not found"
121+
fi
122+
123+
# Test 10: Service unavailable reason formatting
124+
echo -e "${BLUE}[Test 10] Verifying service unavailable reason formatting...${NC}"
125+
if grep -q 'Service unavailable' internal/handlers/debate_visualization.go; then
126+
pass_test "Service unavailable reason formatting implemented"
127+
else
128+
fail_test "Service unavailable reason formatting not found"
129+
fi
130+
131+
# Test 11: Quota exceeded reason formatting
132+
echo -e "${BLUE}[Test 11] Verifying quota exceeded reason formatting...${NC}"
133+
if grep -q 'Quota exceeded' internal/handlers/debate_visualization.go; then
134+
pass_test "Quota exceeded reason formatting implemented"
135+
else
136+
fail_test "Quota exceeded reason formatting not found"
137+
fi
138+
139+
# Test 12: Service overloaded reason formatting
140+
echo -e "${BLUE}[Test 12] Verifying service overloaded reason formatting...${NC}"
141+
if grep -q 'Service overloaded' internal/handlers/debate_visualization.go; then
142+
pass_test "Service overloaded reason formatting implemented"
143+
else
144+
fail_test "Service overloaded reason formatting not found"
145+
fi
146+
147+
# Test 13: FormatFallbackReason tests
148+
echo -e "${BLUE}[Test 13] Running FormatFallbackReason tests...${NC}"
149+
if go test -run "TestFormatFallbackReason" ./internal/handlers/... > /dev/null 2>&1; then
150+
pass_test "FormatFallbackReason tests pass"
151+
else
152+
fail_test "FormatFallbackReason tests failed"
153+
fi
154+
155+
# Test 14: Timing color tests
156+
echo -e "${BLUE}[Test 14] Running timing color tests...${NC}"
157+
if go test -run "TestTimingColorIsDarker" ./internal/handlers/... > /dev/null 2>&1; then
158+
pass_test "Timing color tests pass"
159+
else
160+
fail_test "Timing color tests failed"
161+
fi
162+
163+
# Test 15: Complex fallback scenario tests
164+
echo -e "${BLUE}[Test 15] Running complex fallback scenario tests...${NC}"
165+
if go test -run "TestComplexFallbackScenarios" ./internal/handlers/... > /dev/null 2>&1; then
166+
pass_test "Complex fallback scenario tests pass"
167+
else
168+
fail_test "Complex fallback scenario tests failed"
169+
fi
170+
171+
# Test 16: Fallback chain indicator format
172+
echo -e "${BLUE}[Test 16] Verifying fallback chain indicator format...${NC}"
173+
if grep -q '<---' internal/handlers/debate_visualization.go && grep -q 'Fallback' internal/handlers/debate_visualization.go; then
174+
pass_test "Fallback chain uses proper format with <--- indicator"
175+
else
176+
fail_test "Fallback chain format incorrect"
177+
fi
178+
179+
# Test 17: FormatFallbackChainIndicator tests
180+
echo -e "${BLUE}[Test 17] Running FormatFallbackChainIndicator tests...${NC}"
181+
if go test -run "TestFormatFallbackChainIndicator" ./internal/handlers/... > /dev/null 2>&1; then
182+
pass_test "FormatFallbackChainIndicator tests pass"
183+
else
184+
fail_test "FormatFallbackChainIndicator tests failed"
185+
fi
186+
187+
# Test 18: FormatFallbackChainWithContent tests
188+
echo -e "${BLUE}[Test 18] Running FormatFallbackChainWithContent tests...${NC}"
189+
if go test -run "TestFormatFallbackChainWithContent" ./internal/handlers/... > /dev/null 2>&1; then
190+
pass_test "FormatFallbackChainWithContent tests pass"
191+
else
192+
fail_test "FormatFallbackChainWithContent tests failed"
193+
fi
194+
195+
# Test 19: Error message truncation
196+
echo -e "${BLUE}[Test 19] Verifying error message truncation...${NC}"
197+
if grep -q 'len(errorMsg) > 30' internal/handlers/debate_visualization.go; then
198+
pass_test "Error message truncation implemented"
199+
else
200+
fail_test "Error message truncation not found"
201+
fi
202+
203+
# Test 20: FallbackAttempt struct fields
204+
echo -e "${BLUE}[Test 20] Verifying FallbackAttempt struct fields...${NC}"
205+
if grep -q 'Provider' internal/handlers/debate_visualization.go && \
206+
grep -q 'Success' internal/handlers/debate_visualization.go && \
207+
grep -q 'Duration' internal/handlers/debate_visualization.go && \
208+
grep -q 'AttemptNum' internal/handlers/debate_visualization.go; then
209+
pass_test "FallbackAttempt struct has all required fields"
210+
else
211+
fail_test "FallbackAttempt struct missing fields"
212+
fi
213+
214+
# Summary
215+
echo ""
216+
echo "============================================================================"
217+
echo "CHALLENGE SUMMARY"
218+
echo "============================================================================"
219+
echo ""
220+
echo -e "Total Tests: ${TOTAL_TESTS}"
221+
echo -e "Passed: ${GREEN}${PASSED_TESTS}${NC}"
222+
echo -e "Failed: ${RED}${FAILED_TESTS}${NC}"
223+
echo ""
224+
225+
if [ $FAILED_TESTS -eq 0 ]; then
226+
echo -e "${GREEN}============================================================================${NC}"
227+
echo -e "${GREEN} ALL TESTS PASSED - Fallback Visualization Challenge Complete!${NC}"
228+
echo -e "${GREEN}============================================================================${NC}"
229+
exit 0
230+
else
231+
echo -e "${RED}============================================================================${NC}"
232+
echo -e "${RED} CHALLENGE FAILED - ${FAILED_TESTS} test(s) failed${NC}"
233+
echo -e "${RED}============================================================================${NC}"
234+
exit 1
235+
fi

0 commit comments

Comments
 (0)