test-e2e-install.sh 9.6 KB

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