test-e2e-install.sh 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. #!/usr/bin/env bash
  2. set -e
  3. GREEN='\033[0;32m'
  4. RED='\033[0;31m'
  5. YELLOW='\033[1;33m'
  6. CYAN='\033[0;36m'
  7. BOLD='\033[1m'
  8. NC='\033[0m'
  9. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  10. REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
  11. TEST_DIR="/tmp/opencode-e2e-test-$$"
  12. PASSED=0
  13. FAILED=0
  14. pass() {
  15. echo -e "${GREEN}✓${NC} $1"
  16. PASSED=$((PASSED + 1))
  17. }
  18. fail() {
  19. echo -e "${RED}✗${NC} $1"
  20. FAILED=$((FAILED + 1))
  21. }
  22. warn() {
  23. echo -e "${YELLOW}⚠${NC} $1"
  24. }
  25. setup() {
  26. rm -rf "$TEST_DIR"
  27. mkdir -p "$TEST_DIR"
  28. }
  29. # shellcheck disable=SC2329
  30. cleanup() {
  31. rm -rf "$TEST_DIR"
  32. }
  33. trap cleanup EXIT
  34. print_header() {
  35. echo -e "${CYAN}${BOLD}"
  36. echo "╔════════════════════════════════════════════════════════════════╗"
  37. echo "║ End-to-End Installation Test Suite ║"
  38. echo "╚════════════════════════════════════════════════════════════════╝"
  39. echo -e "${NC}"
  40. }
  41. test_essential_profile() {
  42. echo -e "\n${BOLD}Test: Essential Profile Installation${NC}"
  43. local install_dir="$TEST_DIR/essential/.opencode"
  44. bash "$REPO_ROOT/install.sh" essential --install-dir="$install_dir" > "$TEST_DIR/essential.log" 2>&1
  45. local expected_files=(
  46. "agent/core/openagent.md"
  47. "agent/subagents/core/task-manager.md"
  48. "agent/subagents/core/documentation.md"
  49. "command/context.md"
  50. "command/clean.md"
  51. "context/core/essential-patterns.md"
  52. "context/project/project-context.md"
  53. )
  54. local missing=0
  55. for file in "${expected_files[@]}"; do
  56. if [ -f "$install_dir/$file" ]; then
  57. pass "Found: $file"
  58. else
  59. fail "Missing: $file"
  60. missing=$((missing + 1))
  61. fi
  62. done
  63. if [ $missing -eq 0 ]; then
  64. pass "Essential profile: all expected files present"
  65. fi
  66. }
  67. test_developer_profile() {
  68. echo -e "\n${BOLD}Test: Developer Profile Installation${NC}"
  69. local install_dir="$TEST_DIR/developer/.opencode"
  70. bash "$REPO_ROOT/install.sh" developer --install-dir="$install_dir" > "$TEST_DIR/developer.log" 2>&1
  71. local expected_files=(
  72. "agent/core/openagent.md"
  73. "agent/core/opencoder.md"
  74. "agent/subagents/code/tester.md"
  75. "agent/subagents/code/reviewer.md"
  76. "agent/subagents/code/build-agent.md"
  77. "command/commit.md"
  78. "command/test.md"
  79. "context/core/standards/code.md"
  80. )
  81. local found=0
  82. for file in "${expected_files[@]}"; do
  83. if [ -f "$install_dir/$file" ]; then
  84. found=$((found + 1))
  85. fi
  86. done
  87. if [ $found -ge 6 ]; then
  88. pass "Developer profile: $found/${#expected_files[@]} key files present"
  89. else
  90. fail "Developer profile: only $found/${#expected_files[@]} key files found"
  91. fi
  92. }
  93. test_custom_install_dir() {
  94. echo -e "\n${BOLD}Test: Custom Installation Directory${NC}"
  95. local custom_dir="$TEST_DIR/custom-location/my-agents"
  96. bash "$REPO_ROOT/install.sh" essential --install-dir="$custom_dir" > "$TEST_DIR/custom.log" 2>&1
  97. if [ -d "$custom_dir" ]; then
  98. pass "Custom directory created: $custom_dir"
  99. else
  100. fail "Custom directory not created"
  101. fi
  102. if [ -f "$custom_dir/agent/core/openagent.md" ]; then
  103. pass "Files installed to custom location"
  104. else
  105. fail "Files not found in custom location"
  106. fi
  107. }
  108. test_skip_existing_files() {
  109. echo -e "\n${BOLD}Test: Skip Existing Files Strategy${NC}"
  110. local install_dir="$TEST_DIR/skip-test/.opencode"
  111. mkdir -p "$install_dir/agent/core"
  112. echo "CUSTOM CONTENT - DO NOT OVERWRITE" > "$install_dir/agent/core/openagent.md"
  113. bash "$REPO_ROOT/install.sh" essential --install-dir="$install_dir" > "$TEST_DIR/skip.log" 2>&1
  114. local content
  115. content=$(cat "$install_dir/agent/core/openagent.md")
  116. if [[ "$content" == "CUSTOM CONTENT - DO NOT OVERWRITE" ]]; then
  117. pass "Existing file preserved (skip strategy working)"
  118. else
  119. fail "Existing file was overwritten"
  120. fi
  121. }
  122. test_file_content_validity() {
  123. echo -e "\n${BOLD}Test: File Content Validity${NC}"
  124. local install_dir="$TEST_DIR/content-test/.opencode"
  125. bash "$REPO_ROOT/install.sh" essential --install-dir="$install_dir" > "$TEST_DIR/content.log" 2>&1
  126. local agent_file="$install_dir/agent/core/openagent.md"
  127. if [ -f "$agent_file" ]; then
  128. if grep -q "OpenAgent\|openagent" "$agent_file"; then
  129. pass "Agent file contains expected content"
  130. else
  131. fail "Agent file appears empty or corrupted"
  132. fi
  133. local size
  134. size=$(wc -c < "$agent_file")
  135. if [ "$size" -gt 100 ]; then
  136. pass "Agent file has substantial content ($size bytes)"
  137. else
  138. fail "Agent file too small ($size bytes)"
  139. fi
  140. else
  141. fail "Agent file not found"
  142. fi
  143. }
  144. test_directory_structure() {
  145. echo -e "\n${BOLD}Test: Directory Structure${NC}"
  146. local install_dir="$TEST_DIR/structure-test/.opencode"
  147. bash "$REPO_ROOT/install.sh" developer --install-dir="$install_dir" > "$TEST_DIR/structure.log" 2>&1
  148. local expected_dirs=(
  149. "agent"
  150. "agent/core"
  151. "agent/subagents"
  152. "command"
  153. "context"
  154. "context/core"
  155. )
  156. for dir in "${expected_dirs[@]}"; do
  157. if [ -d "$install_dir/$dir" ]; then
  158. pass "Directory exists: $dir"
  159. else
  160. fail "Missing directory: $dir"
  161. fi
  162. done
  163. }
  164. test_registry_consistency() {
  165. echo -e "\n${BOLD}Test: Registry Consistency${NC}"
  166. if [ -f "$REPO_ROOT/registry.json" ]; then
  167. if command -v jq &> /dev/null; then
  168. local agent_count
  169. agent_count=$(jq '.components.agents | length' "$REPO_ROOT/registry.json")
  170. if [ "$agent_count" -gt 0 ]; then
  171. pass "Registry has $agent_count agents defined"
  172. else
  173. fail "Registry has no agents"
  174. fi
  175. local profile_count
  176. profile_count=$(jq '.profiles | keys | length' "$REPO_ROOT/registry.json")
  177. if [ "$profile_count" -ge 4 ]; then
  178. pass "Registry has $profile_count profiles"
  179. else
  180. fail "Registry missing profiles (found $profile_count)"
  181. fi
  182. else
  183. warn "jq not installed, skipping JSON validation"
  184. fi
  185. else
  186. fail "registry.json not found"
  187. fi
  188. }
  189. test_help_and_list() {
  190. echo -e "\n${BOLD}Test: Help and List Commands${NC}"
  191. if bash "$REPO_ROOT/install.sh" --help 2>&1 | grep -q "Usage:"; then
  192. pass "Help command works"
  193. else
  194. fail "Help command failed"
  195. fi
  196. if bash "$REPO_ROOT/install.sh" list 2>&1 | grep "Available Components\|Agents" > /dev/null; then
  197. pass "List command works"
  198. else
  199. fail "List command failed"
  200. fi
  201. }
  202. main() {
  203. print_header
  204. echo "Repository: $REPO_ROOT"
  205. echo "Test directory: $TEST_DIR"
  206. echo ""
  207. setup
  208. test_help_and_list
  209. test_essential_profile
  210. test_developer_profile
  211. test_custom_install_dir
  212. test_skip_existing_files
  213. test_file_content_validity
  214. test_directory_structure
  215. test_registry_consistency
  216. echo ""
  217. echo -e "${BOLD}═══════════════════════════════════════════════════════════════${NC}"
  218. echo -e "${BOLD}E2E Test Summary${NC}"
  219. echo -e " ${GREEN}Passed: $PASSED${NC}"
  220. echo -e " ${RED}Failed: $FAILED${NC}"
  221. echo -e "${BOLD}═══════════════════════════════════════════════════════════════${NC}"
  222. if [ $FAILED -gt 0 ]; then
  223. echo -e "\n${RED}Some tests failed!${NC}"
  224. exit 1
  225. else
  226. echo -e "\n${GREEN}All E2E tests passed!${NC}"
  227. exit 0
  228. fi
  229. }
  230. main "$@"