test-e2e-install.sh 8.2 KB

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