|
| 1 | +#!/bin/bash |
| 2 | +# messaging_migration_challenge.sh - Migration Challenge |
| 3 | +# Tests migration capabilities and backward compatibility |
| 4 | + |
| 5 | +set -e |
| 6 | + |
| 7 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 8 | +PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" |
| 9 | +source "$SCRIPT_DIR/common.sh" |
| 10 | + |
| 11 | +CHALLENGE_NAME="Messaging Migration Challenge" |
| 12 | +PASSED=0 |
| 13 | +FAILED=0 |
| 14 | +TOTAL=0 |
| 15 | + |
| 16 | +log_test() { |
| 17 | + local test_name="$1" |
| 18 | + local status="$2" |
| 19 | + TOTAL=$((TOTAL + 1)) |
| 20 | + if [ "$status" = "PASS" ]; then |
| 21 | + PASSED=$((PASSED + 1)) |
| 22 | + echo -e " \e[32m✓\e[0m $test_name" |
| 23 | + else |
| 24 | + FAILED=$((FAILED + 1)) |
| 25 | + echo -e " \e[31m✗\e[0m $test_name" |
| 26 | + fi |
| 27 | +} |
| 28 | + |
| 29 | +echo "==============================================" |
| 30 | +echo " $CHALLENGE_NAME" |
| 31 | +echo "==============================================" |
| 32 | +echo "" |
| 33 | + |
| 34 | +cd "$PROJECT_ROOT" |
| 35 | + |
| 36 | +# Test 1: Fallback broker exists |
| 37 | +echo "[1] Fallback Mechanism" |
| 38 | +if [ -d "internal/messaging/inmemory" ]; then |
| 39 | + log_test "In-memory fallback broker exists" "PASS" |
| 40 | +else |
| 41 | + log_test "In-memory fallback broker exists" "FAIL" |
| 42 | +fi |
| 43 | + |
| 44 | +if grep -q "BrokerTypeInMemory" internal/messaging/broker.go 2>/dev/null; then |
| 45 | + log_test "In-memory broker type defined" "PASS" |
| 46 | +else |
| 47 | + log_test "In-memory broker type defined" "FAIL" |
| 48 | +fi |
| 49 | + |
| 50 | +# Test 2: Multiple broker implementations |
| 51 | +echo "" |
| 52 | +echo "[2] Multiple Broker Implementations" |
| 53 | +broker_count=0 |
| 54 | +for dir in internal/messaging/*/; do |
| 55 | + if [ -f "${dir}broker.go" ]; then |
| 56 | + broker_count=$((broker_count + 1)) |
| 57 | + fi |
| 58 | +done |
| 59 | + |
| 60 | +if [ "$broker_count" -ge 2 ]; then |
| 61 | + log_test "Multiple broker implementations (${broker_count})" "PASS" |
| 62 | +else |
| 63 | + log_test "Multiple broker implementations (${broker_count})" "FAIL" |
| 64 | +fi |
| 65 | + |
| 66 | +# Test 3: Message broker interface |
| 67 | +echo "" |
| 68 | +echo "[3] Unified Broker Interface" |
| 69 | +if grep -q "type MessageBroker interface" internal/messaging/broker.go 2>/dev/null; then |
| 70 | + log_test "MessageBroker interface defined" "PASS" |
| 71 | +else |
| 72 | + log_test "MessageBroker interface defined" "FAIL" |
| 73 | +fi |
| 74 | + |
| 75 | +if grep -q "BrokerType()" internal/messaging/broker.go 2>/dev/null; then |
| 76 | + log_test "BrokerType method in interface" "PASS" |
| 77 | +else |
| 78 | + log_test "BrokerType method in interface" "FAIL" |
| 79 | +fi |
| 80 | + |
| 81 | +# Test 4: Configuration validation |
| 82 | +echo "" |
| 83 | +echo "[4] Configuration Validation" |
| 84 | +if grep -q "func.*Validate" internal/messaging/broker.go 2>/dev/null; then |
| 85 | + log_test "Config validation method" "PASS" |
| 86 | +else |
| 87 | + log_test "Config validation method" "FAIL" |
| 88 | +fi |
| 89 | + |
| 90 | +if grep -q "func.*Validate" internal/messaging/rabbitmq/config.go 2>/dev/null; then |
| 91 | + log_test "RabbitMQ config validation" "PASS" |
| 92 | +else |
| 93 | + log_test "RabbitMQ config validation" "FAIL" |
| 94 | +fi |
| 95 | + |
| 96 | +if grep -q "func.*Validate" internal/messaging/kafka/config.go 2>/dev/null; then |
| 97 | + log_test "Kafka config validation" "PASS" |
| 98 | +else |
| 99 | + log_test "Kafka config validation" "FAIL" |
| 100 | +fi |
| 101 | + |
| 102 | +# Test 5: Error handling |
| 103 | +echo "" |
| 104 | +echo "[5] Error Handling" |
| 105 | +if [ -f "internal/messaging/errors.go" ]; then |
| 106 | + log_test "Errors file exists" "PASS" |
| 107 | +else |
| 108 | + log_test "Errors file exists" "FAIL" |
| 109 | +fi |
| 110 | + |
| 111 | +if grep -q "IsRetryable" internal/messaging/errors.go 2>/dev/null; then |
| 112 | + log_test "Retryable error support" "PASS" |
| 113 | +else |
| 114 | + log_test "Retryable error support" "FAIL" |
| 115 | +fi |
| 116 | + |
| 117 | +# Test 6: Metrics support |
| 118 | +echo "" |
| 119 | +echo "[6] Metrics Support" |
| 120 | +if [ -f "internal/messaging/metrics.go" ]; then |
| 121 | + log_test "Metrics file exists" "PASS" |
| 122 | +else |
| 123 | + log_test "Metrics file exists" "FAIL" |
| 124 | +fi |
| 125 | + |
| 126 | +if grep -q "BrokerMetrics" internal/messaging/metrics.go 2>/dev/null; then |
| 127 | + log_test "BrokerMetrics type defined" "PASS" |
| 128 | +else |
| 129 | + log_test "BrokerMetrics type defined" "FAIL" |
| 130 | +fi |
| 131 | + |
| 132 | +# Test 7: CLI agents still work |
| 133 | +echo "" |
| 134 | +echo "[7] Backward Compatibility - CLI Agents" |
| 135 | +if [ -f "internal/agents/registry.go" ]; then |
| 136 | + log_test "Agent registry exists" "PASS" |
| 137 | +else |
| 138 | + log_test "Agent registry exists" "FAIL" |
| 139 | +fi |
| 140 | + |
| 141 | +# Check that agent registry is not broken |
| 142 | +if grep -q "OpenCode\|Crush\|HelixCode\|Kiro" internal/agents/registry.go 2>/dev/null; then |
| 143 | + log_test "CLI agents still registered" "PASS" |
| 144 | +else |
| 145 | + log_test "CLI agents still registered" "FAIL" |
| 146 | +fi |
| 147 | + |
| 148 | +# Test 8: Background tasks compatibility |
| 149 | +echo "" |
| 150 | +echo "[8] Backward Compatibility - Background Tasks" |
| 151 | +if [ -f "internal/background/task_queue.go" ]; then |
| 152 | + log_test "Background task queue exists" "PASS" |
| 153 | +else |
| 154 | + log_test "Background task queue exists" "FAIL" |
| 155 | +fi |
| 156 | + |
| 157 | +if [ -f "internal/background/worker_pool.go" ]; then |
| 158 | + log_test "Worker pool exists" "PASS" |
| 159 | +else |
| 160 | + log_test "Worker pool exists" "FAIL" |
| 161 | +fi |
| 162 | + |
| 163 | +# Test 9: Zero-downtime capability |
| 164 | +echo "" |
| 165 | +echo "[9] Zero-Downtime Migration Support" |
| 166 | +# Check for connection recovery/reconnection support |
| 167 | +if grep -q "reconnect\|Reconnect" internal/messaging/rabbitmq/broker.go 2>/dev/null; then |
| 168 | + log_test "RabbitMQ reconnection support" "PASS" |
| 169 | +else |
| 170 | + log_test "RabbitMQ reconnection support" "FAIL" |
| 171 | +fi |
| 172 | + |
| 173 | +# Check for health checks |
| 174 | +if grep -q "HealthCheck" internal/messaging/broker.go 2>/dev/null; then |
| 175 | + log_test "Health check method in interface" "PASS" |
| 176 | +else |
| 177 | + log_test "Health check method in interface" "FAIL" |
| 178 | +fi |
| 179 | + |
| 180 | +# Test 10: All existing tests still pass |
| 181 | +echo "" |
| 182 | +echo "[10] Existing Tests Compatibility" |
| 183 | +if go test ./internal/messaging/... -count=1 2>&1 | grep -q "^ok"; then |
| 184 | + log_test "Messaging tests pass" "PASS" |
| 185 | +else |
| 186 | + log_test "Messaging tests pass" "FAIL" |
| 187 | +fi |
| 188 | + |
| 189 | +if go test ./internal/toon/... -count=1 2>&1 | grep -q "^ok"; then |
| 190 | + log_test "TOON tests pass" "PASS" |
| 191 | +else |
| 192 | + log_test "TOON tests pass" "FAIL" |
| 193 | +fi |
| 194 | + |
| 195 | +if go test ./internal/graphql/... -count=1 2>&1 | grep -q "^ok"; then |
| 196 | + log_test "GraphQL tests pass" "PASS" |
| 197 | +else |
| 198 | + log_test "GraphQL tests pass" "FAIL" |
| 199 | +fi |
| 200 | + |
| 201 | +echo "" |
| 202 | +echo "==============================================" |
| 203 | +echo " Results: $PASSED/$TOTAL tests passed" |
| 204 | +echo "==============================================" |
| 205 | + |
| 206 | +if [ $FAILED -gt 0 ]; then |
| 207 | + echo -e "\e[31m$FAILED test(s) failed\e[0m" |
| 208 | + exit 1 |
| 209 | +else |
| 210 | + echo -e "\e[32mAll tests passed!\e[0m" |
| 211 | + exit 0 |
| 212 | +fi |
0 commit comments