test-e2e-install.sh 9.1 KB

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