run-skill-tests.sh 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. #!/usr/bin/env bash
  2. # Test runner for Claude Code skills
  3. # Tests skills by invoking Claude Code CLI and verifying behavior
  4. set -euo pipefail
  5. SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
  6. cd "$SCRIPT_DIR"
  7. echo "========================================"
  8. echo " Claude Code Skills Test Suite"
  9. echo "========================================"
  10. echo ""
  11. echo "Repository: $(cd ../.. && pwd)"
  12. echo "Test time: $(date)"
  13. echo "Claude version: $(claude --version 2>/dev/null || echo 'not found')"
  14. echo ""
  15. # Check if Claude Code is available
  16. if ! command -v claude &> /dev/null; then
  17. echo "ERROR: Claude Code CLI not found"
  18. echo "Install Claude Code first: https://code.claude.com"
  19. exit 1
  20. fi
  21. # Parse command line arguments
  22. VERBOSE=false
  23. SPECIFIC_TEST=""
  24. TIMEOUT=300 # Default 5 minute timeout per test
  25. RUN_INTEGRATION=false
  26. while [[ $# -gt 0 ]]; do
  27. case $1 in
  28. --verbose|-v)
  29. VERBOSE=true
  30. shift
  31. ;;
  32. --test|-t)
  33. SPECIFIC_TEST="$2"
  34. shift 2
  35. ;;
  36. --timeout)
  37. TIMEOUT="$2"
  38. shift 2
  39. ;;
  40. --integration|-i)
  41. RUN_INTEGRATION=true
  42. shift
  43. ;;
  44. --help|-h)
  45. echo "Usage: $0 [options]"
  46. echo ""
  47. echo "Options:"
  48. echo " --verbose, -v Show verbose output"
  49. echo " --test, -t NAME Run only the specified test"
  50. echo " --timeout SECONDS Set timeout per test (default: 300)"
  51. echo " --integration, -i Run integration tests (slow, 10-30 min)"
  52. echo " --help, -h Show this help"
  53. echo ""
  54. echo "Tests:"
  55. echo " test-subagent-driven-development.sh Test skill loading and requirements"
  56. echo ""
  57. echo "Integration Tests (use --integration):"
  58. echo " test-subagent-driven-development-integration.sh Full workflow execution"
  59. exit 0
  60. ;;
  61. *)
  62. echo "Unknown option: $1"
  63. echo "Use --help for usage information"
  64. exit 1
  65. ;;
  66. esac
  67. done
  68. # List of skill tests to run (fast unit tests)
  69. tests=(
  70. "test-subagent-driven-development.sh"
  71. )
  72. # Integration tests (slow, full execution)
  73. integration_tests=(
  74. "test-subagent-driven-development-integration.sh"
  75. )
  76. # Add integration tests if requested
  77. if [ "$RUN_INTEGRATION" = true ]; then
  78. tests+=("${integration_tests[@]}")
  79. fi
  80. # Filter to specific test if requested
  81. if [ -n "$SPECIFIC_TEST" ]; then
  82. tests=("$SPECIFIC_TEST")
  83. fi
  84. # Track results
  85. passed=0
  86. failed=0
  87. skipped=0
  88. # Run each test
  89. for test in "${tests[@]}"; do
  90. echo "----------------------------------------"
  91. echo "Running: $test"
  92. echo "----------------------------------------"
  93. test_path="$SCRIPT_DIR/$test"
  94. if [ ! -f "$test_path" ]; then
  95. echo " [SKIP] Test file not found: $test"
  96. skipped=$((skipped + 1))
  97. continue
  98. fi
  99. if [ ! -x "$test_path" ]; then
  100. echo " Making $test executable..."
  101. chmod +x "$test_path"
  102. fi
  103. start_time=$(date +%s)
  104. if [ "$VERBOSE" = true ]; then
  105. if timeout "$TIMEOUT" bash "$test_path"; then
  106. end_time=$(date +%s)
  107. duration=$((end_time - start_time))
  108. echo ""
  109. echo " [PASS] $test (${duration}s)"
  110. passed=$((passed + 1))
  111. else
  112. exit_code=$?
  113. end_time=$(date +%s)
  114. duration=$((end_time - start_time))
  115. echo ""
  116. if [ $exit_code -eq 124 ]; then
  117. echo " [FAIL] $test (timeout after ${TIMEOUT}s)"
  118. else
  119. echo " [FAIL] $test (${duration}s)"
  120. fi
  121. failed=$((failed + 1))
  122. fi
  123. else
  124. # Capture output for non-verbose mode
  125. if output=$(timeout "$TIMEOUT" bash "$test_path" 2>&1); then
  126. end_time=$(date +%s)
  127. duration=$((end_time - start_time))
  128. echo " [PASS] (${duration}s)"
  129. passed=$((passed + 1))
  130. else
  131. exit_code=$?
  132. end_time=$(date +%s)
  133. duration=$((end_time - start_time))
  134. if [ $exit_code -eq 124 ]; then
  135. echo " [FAIL] (timeout after ${TIMEOUT}s)"
  136. else
  137. echo " [FAIL] (${duration}s)"
  138. fi
  139. echo ""
  140. echo " Output:"
  141. echo "$output" | sed 's/^/ /'
  142. failed=$((failed + 1))
  143. fi
  144. fi
  145. echo ""
  146. done
  147. # Print summary
  148. echo "========================================"
  149. echo " Test Results Summary"
  150. echo "========================================"
  151. echo ""
  152. echo " Passed: $passed"
  153. echo " Failed: $failed"
  154. echo " Skipped: $skipped"
  155. echo ""
  156. if [ "$RUN_INTEGRATION" = false ] && [ ${#integration_tests[@]} -gt 0 ]; then
  157. echo "Note: Integration tests were not run (they take 10-30 minutes)."
  158. echo "Use --integration flag to run full workflow execution tests."
  159. echo ""
  160. fi
  161. if [ $failed -gt 0 ]; then
  162. echo "STATUS: FAILED"
  163. exit 1
  164. else
  165. echo "STATUS: PASSED"
  166. exit 0
  167. fi