test-compatibility.sh 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #!/usr/bin/env bash
  2. #############################################################################
  3. # Compatibility Test Script
  4. # Tests the installer across different bash versions and platforms
  5. #############################################################################
  6. set -e
  7. echo "╔════════════════════════════════════════════════════════════════╗"
  8. echo "║ OpenCode Installer Compatibility Test ║"
  9. echo "╚════════════════════════════════════════════════════════════════╝"
  10. echo ""
  11. # Colors
  12. GREEN='\033[0;32m'
  13. RED='\033[0;31m'
  14. YELLOW='\033[1;33m'
  15. NC='\033[0m'
  16. pass() {
  17. echo -e "${GREEN}✓${NC} $1"
  18. }
  19. fail() {
  20. echo -e "${RED}✗${NC} $1"
  21. exit 1
  22. }
  23. warn() {
  24. echo -e "${YELLOW}⚠${NC} $1"
  25. }
  26. echo "System Information:"
  27. echo " Platform: $(uname -s)"
  28. echo " Bash Version: $BASH_VERSION"
  29. echo " Shell: $SHELL"
  30. echo ""
  31. # Test 1: Bash version check
  32. echo "Test 1: Bash Version Compatibility"
  33. bash_major="${BASH_VERSION%%.*}"
  34. if [ "$bash_major" -ge 3 ]; then
  35. pass "Bash version $BASH_VERSION is compatible (3.2+ required)"
  36. else
  37. fail "Bash version $BASH_VERSION is too old (3.2+ required)"
  38. fi
  39. # Test 2: Required commands
  40. echo ""
  41. echo "Test 2: Required Dependencies"
  42. for cmd in curl jq; do
  43. if command -v "$cmd" &> /dev/null; then
  44. pass "$cmd is installed"
  45. else
  46. fail "$cmd is not installed"
  47. fi
  48. done
  49. # Test 3: Script syntax check
  50. echo ""
  51. echo "Test 3: Script Syntax Check"
  52. if bash -n install.sh 2>/dev/null; then
  53. pass "Script syntax is valid"
  54. else
  55. fail "Script has syntax errors"
  56. fi
  57. # Test 4: Help command
  58. echo ""
  59. echo "Test 4: Help Command"
  60. if bash install.sh help 2>&1 | grep -q "Usage:"; then
  61. pass "Help command works"
  62. else
  63. fail "Help command failed"
  64. fi
  65. # Test 5: List command
  66. echo ""
  67. echo "Test 5: List Command"
  68. if bash install.sh list 2>&1 | grep -q "Available Components"; then
  69. pass "List command works"
  70. else
  71. fail "List command failed"
  72. fi
  73. # Test 6: Profile argument parsing
  74. echo ""
  75. echo "Test 6: Profile Argument Parsing"
  76. for profile in essential developer full advanced; do
  77. if echo "n" | bash install.sh "$profile" 2>&1 | grep -q "Profile:"; then
  78. pass "Profile '$profile' argument works"
  79. else
  80. fail "Profile '$profile' argument failed"
  81. fi
  82. done
  83. # Test 7: Profile with dashes
  84. echo ""
  85. echo "Test 7: Profile Arguments with Dashes"
  86. for profile in --essential --developer --full --advanced; do
  87. if echo "n" | bash install.sh "$profile" 2>&1 | grep -q "Profile:"; then
  88. pass "Profile '$profile' argument works"
  89. else
  90. fail "Profile '$profile' argument failed"
  91. fi
  92. done
  93. # Test 8: Array operations
  94. echo ""
  95. echo "Test 8: Array Operations"
  96. test_array=()
  97. test_array+=("item1")
  98. test_array+=("item2")
  99. if [ ${#test_array[@]} -eq 2 ]; then
  100. pass "Array operations work"
  101. else
  102. fail "Array operations failed"
  103. fi
  104. # Test 9: Parameter expansion
  105. echo ""
  106. echo "Test 9: Parameter Expansion"
  107. test_string="type:id"
  108. type="${test_string%%:*}"
  109. id="${test_string##*:}"
  110. if [ "$type" = "type" ] && [ "$id" = "id" ]; then
  111. pass "Parameter expansion works"
  112. else
  113. fail "Parameter expansion failed"
  114. fi
  115. # Test 10: Temp directory creation
  116. echo ""
  117. echo "Test 10: Temp Directory Operations"
  118. test_temp="/tmp/opencode-test-$$"
  119. mkdir -p "$test_temp"
  120. if [ -d "$test_temp" ]; then
  121. pass "Temp directory creation works"
  122. rm -rf "$test_temp"
  123. else
  124. fail "Temp directory creation failed"
  125. fi
  126. # Test 11: File operations
  127. echo ""
  128. echo "Test 11: File Operations"
  129. test_file="/tmp/opencode-test-$$.txt"
  130. echo "test" > "$test_file"
  131. if [ -f "$test_file" ]; then
  132. content=$(cat "$test_file")
  133. if [ "$content" = "test" ]; then
  134. pass "File operations work"
  135. rm -f "$test_file"
  136. else
  137. fail "File read failed"
  138. fi
  139. else
  140. fail "File write failed"
  141. fi
  142. # Test 12: Network connectivity
  143. echo ""
  144. echo "Test 12: Network Connectivity"
  145. if curl -fsSL --max-time 5 https://raw.githubusercontent.com/darrenhinde/OpenAgentsControl/main/README.md > /dev/null 2>&1; then
  146. pass "Network connectivity to GitHub works"
  147. else
  148. warn "Network connectivity test failed (may be offline)"
  149. fi
  150. echo ""
  151. echo "╔════════════════════════════════════════════════════════════════╗"
  152. echo "║ All Tests Passed! ✓ ║"
  153. echo "╚════════════════════════════════════════════════════════════════╝"
  154. echo ""
  155. echo "Your system is compatible with the OpenCode installer."
  156. echo "You can safely run:"
  157. echo " curl -fsSL https://raw.githubusercontent.com/darrenhinde/OpenAgentsControl/main/install.sh | bash"
  158. echo ""