run-skill-tests.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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=600 # Default 10 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-worktree-path-policy.sh"
  71. "test-subagent-driven-development.sh"
  72. )
  73. # Integration tests (slow, full execution)
  74. integration_tests=(
  75. "test-subagent-driven-development-integration.sh"
  76. )
  77. # Add integration tests if requested
  78. if [ "$RUN_INTEGRATION" = true ]; then
  79. tests+=("${integration_tests[@]}")
  80. fi
  81. # Filter to specific test if requested
  82. if [ -n "$SPECIFIC_TEST" ]; then
  83. tests=("$SPECIFIC_TEST")
  84. fi
  85. # Track results
  86. passed=0
  87. failed=0
  88. skipped=0
  89. # Run each test
  90. for test in "${tests[@]}"; do
  91. echo "----------------------------------------"
  92. echo "Running: $test"
  93. echo "----------------------------------------"
  94. test_path="$SCRIPT_DIR/$test"
  95. if [ ! -f "$test_path" ]; then
  96. echo " [SKIP] Test file not found: $test"
  97. skipped=$((skipped + 1))
  98. continue
  99. fi
  100. if [ ! -x "$test_path" ]; then
  101. echo " Making $test executable..."
  102. chmod +x "$test_path"
  103. fi
  104. start_time=$(date +%s)
  105. if [ "$VERBOSE" = true ]; then
  106. if timeout "$TIMEOUT" bash "$test_path"; then
  107. end_time=$(date +%s)
  108. duration=$((end_time - start_time))
  109. echo ""
  110. echo " [PASS] $test (${duration}s)"
  111. passed=$((passed + 1))
  112. else
  113. exit_code=$?
  114. end_time=$(date +%s)
  115. duration=$((end_time - start_time))
  116. echo ""
  117. if [ $exit_code -eq 124 ]; then
  118. echo " [FAIL] $test (timeout after ${TIMEOUT}s)"
  119. else
  120. echo " [FAIL] $test (${duration}s)"
  121. fi
  122. failed=$((failed + 1))
  123. fi
  124. else
  125. # Capture output for non-verbose mode
  126. if output=$(timeout "$TIMEOUT" bash "$test_path" 2>&1); then
  127. end_time=$(date +%s)
  128. duration=$((end_time - start_time))
  129. echo " [PASS] (${duration}s)"
  130. passed=$((passed + 1))
  131. else
  132. exit_code=$?
  133. end_time=$(date +%s)
  134. duration=$((end_time - start_time))
  135. if [ $exit_code -eq 124 ]; then
  136. echo " [FAIL] (timeout after ${TIMEOUT}s)"
  137. else
  138. echo " [FAIL] (${duration}s)"
  139. fi
  140. echo ""
  141. echo " Output:"
  142. echo "$output" | sed 's/^/ /'
  143. failed=$((failed + 1))
  144. fi
  145. fi
  146. echo ""
  147. done
  148. # Print summary
  149. echo "========================================"
  150. echo " Test Results Summary"
  151. echo "========================================"
  152. echo ""
  153. echo " Passed: $passed"
  154. echo " Failed: $failed"
  155. echo " Skipped: $skipped"
  156. echo ""
  157. if [ "$RUN_INTEGRATION" = false ] && [ ${#integration_tests[@]} -gt 0 ]; then
  158. echo "Note: Integration tests were not run (they take 10-30 minutes)."
  159. echo "Use --integration flag to run full workflow execution tests."
  160. echo ""
  161. fi
  162. if [ $failed -gt 0 ]; then
  163. echo "STATUS: FAILED"
  164. exit 1
  165. else
  166. echo "STATUS: PASSED"
  167. exit 0
  168. fi