run-tests.sh 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. #!/bin/bash
  2. # Main test runner for skill tests
  3. # Runs all validation and functional tests
  4. set -euo pipefail
  5. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  6. # Colors
  7. RED='\033[0;31m'
  8. GREEN='\033[0;32m'
  9. YELLOW='\033[1;33m'
  10. BLUE='\033[0;34m'
  11. BOLD='\033[1m'
  12. NC='\033[0m'
  13. # Test results
  14. SUITE_PASSED=0
  15. SUITE_FAILED=0
  16. usage() {
  17. cat << EOF
  18. Usage: $(basename "$0") [OPTIONS] [TEST...]
  19. Run skill tests.
  20. Options:
  21. -h, --help Show this help message
  22. -v, --verbose Show detailed output
  23. -q, --quiet Only show failures
  24. --triggers Run trigger validation only
  25. --functional Run functional tests only
  26. --list List available tests
  27. --report Generate timestamped report in reports/
  28. Tests:
  29. all Run all tests (default)
  30. triggers Trigger keyword validation
  31. data-processing Functional tests for data-processing skill
  32. code-stats Functional tests for code-stats skill
  33. git-workflow Functional tests for git-workflow skill
  34. structural-search Functional tests for structural-search skill
  35. Examples:
  36. $(basename "$0") # Run all tests
  37. $(basename "$0") triggers # Run trigger validation only
  38. $(basename "$0") data-processing # Run data-processing tests only
  39. $(basename "$0") --functional # Run all functional tests
  40. EOF
  41. }
  42. run_test_suite() {
  43. local name="$1"
  44. local script="$2"
  45. echo -e "\n${BOLD}${BLUE}════════════════════════════════════════${NC}"
  46. echo -e "${BOLD} $name${NC}"
  47. echo -e "${BLUE}════════════════════════════════════════${NC}\n"
  48. if [[ -x "$script" ]]; then
  49. if "$script"; then
  50. ((SUITE_PASSED++))
  51. echo -e "\n${GREEN}✓ $name passed${NC}"
  52. else
  53. ((SUITE_FAILED++))
  54. echo -e "\n${RED}✗ $name failed${NC}"
  55. fi
  56. else
  57. echo -e "${RED}Script not found or not executable: $script${NC}"
  58. ((SUITE_FAILED++))
  59. fi
  60. }
  61. run_triggers() {
  62. run_test_suite "Trigger Validation" "$SCRIPT_DIR/validate-triggers.sh"
  63. }
  64. run_functional() {
  65. local tests=("$@")
  66. if [[ ${#tests[@]} -eq 0 ]]; then
  67. tests=(data-processing code-stats git-workflow structural-search)
  68. fi
  69. for test in "${tests[@]}"; do
  70. local script="$SCRIPT_DIR/functional/${test}.sh"
  71. if [[ -f "$script" ]]; then
  72. run_test_suite "$test" "$script"
  73. else
  74. echo -e "${YELLOW}Skipping $test: no test script found${NC}"
  75. fi
  76. done
  77. }
  78. list_tests() {
  79. echo "Available tests:"
  80. echo ""
  81. echo " Validation:"
  82. echo " triggers - Validate skill frontmatter and trigger keywords"
  83. echo ""
  84. echo " Functional:"
  85. for script in "$SCRIPT_DIR"/functional/*.sh; do
  86. if [[ -f "$script" ]]; then
  87. local name
  88. name=$(basename "$script" .sh)
  89. echo " $name"
  90. fi
  91. done
  92. echo ""
  93. echo " Groups:"
  94. echo " all - Run all tests"
  95. echo " --triggers - Run trigger validation only"
  96. echo " --functional - Run all functional tests"
  97. }
  98. print_summary() {
  99. echo -e "\n${BOLD}════════════════════════════════════════${NC}"
  100. echo -e "${BOLD} Test Summary${NC}"
  101. echo -e "${BOLD}════════════════════════════════════════${NC}"
  102. echo -e " Suites passed: ${GREEN}$SUITE_PASSED${NC}"
  103. echo -e " Suites failed: ${RED}$SUITE_FAILED${NC}"
  104. echo ""
  105. if [[ $SUITE_FAILED -eq 0 ]]; then
  106. echo -e "${GREEN}${BOLD}All tests passed!${NC}"
  107. else
  108. echo -e "${RED}${BOLD}Some tests failed.${NC}"
  109. fi
  110. }
  111. # === Main ===
  112. generate_report() {
  113. local timestamp
  114. timestamp=$(date '+%Y-%m-%d_%H%M%S')
  115. local report_dir="$SCRIPT_DIR/reports"
  116. local report_file="$report_dir/report_${timestamp}.md"
  117. mkdir -p "$report_dir"
  118. {
  119. echo "# Skill Test Report"
  120. echo ""
  121. # Re-run tests and capture output (strip colors)
  122. "$0" 2>&1 | sed 's/\x1b\[[0-9;]*m//g'
  123. echo ""
  124. echo "---"
  125. echo "Generated: $(date '+%Y-%m-%d %H:%M:%S')"
  126. echo "Host: $(hostname)"
  127. } > "$report_file"
  128. echo -e "${GREEN}Report saved: $report_file${NC}"
  129. }
  130. main() {
  131. local run_triggers=false
  132. local run_functional=false
  133. local generate_report=false
  134. local specific_tests=()
  135. # Parse arguments
  136. while [[ $# -gt 0 ]]; do
  137. case "$1" in
  138. -h|--help)
  139. usage
  140. exit 0
  141. ;;
  142. -v|--verbose)
  143. set -x
  144. shift
  145. ;;
  146. -q|--quiet)
  147. # Quiet mode - could redirect stdout
  148. shift
  149. ;;
  150. --triggers)
  151. run_triggers=true
  152. shift
  153. ;;
  154. --functional)
  155. run_functional=true
  156. shift
  157. ;;
  158. --list)
  159. list_tests
  160. exit 0
  161. ;;
  162. --report)
  163. generate_report
  164. exit 0
  165. ;;
  166. all)
  167. run_triggers=true
  168. run_functional=true
  169. shift
  170. ;;
  171. triggers)
  172. run_triggers=true
  173. shift
  174. ;;
  175. *)
  176. specific_tests+=("$1")
  177. shift
  178. ;;
  179. esac
  180. done
  181. # Default: run everything
  182. if [[ $run_triggers == false && $run_functional == false && ${#specific_tests[@]} -eq 0 ]]; then
  183. run_triggers=true
  184. run_functional=true
  185. fi
  186. echo -e "${BOLD}${BLUE}"
  187. echo "╔══════════════════════════════════════════╗"
  188. echo "║ Skill Test Runner ║"
  189. echo "╚══════════════════════════════════════════╝"
  190. echo -e "${NC}"
  191. # Make scripts executable
  192. chmod +x "$SCRIPT_DIR"/*.sh 2>/dev/null || true
  193. chmod +x "$SCRIPT_DIR"/functional/*.sh 2>/dev/null || true
  194. # Run requested tests
  195. if [[ $run_triggers == true ]]; then
  196. run_triggers
  197. fi
  198. if [[ ${#specific_tests[@]} -gt 0 ]]; then
  199. run_functional "${specific_tests[@]}"
  200. elif [[ $run_functional == true ]]; then
  201. run_functional
  202. fi
  203. print_summary
  204. [[ $SUITE_FAILED -eq 0 ]]
  205. }
  206. main "$@"