run-skill-tests.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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=900 # Per-test-file budget; must exceed the file's worst case
  25. # (test-subagent-driven-development.sh: 9 prompts x 90s each)
  26. RUN_INTEGRATION=false
  27. while [[ $# -gt 0 ]]; do
  28. case $1 in
  29. --verbose|-v)
  30. VERBOSE=true
  31. shift
  32. ;;
  33. --test|-t)
  34. SPECIFIC_TEST="$2"
  35. shift 2
  36. ;;
  37. --timeout)
  38. TIMEOUT="$2"
  39. shift 2
  40. ;;
  41. --integration|-i)
  42. RUN_INTEGRATION=true
  43. shift
  44. ;;
  45. --help|-h)
  46. echo "Usage: $0 [options]"
  47. echo ""
  48. echo "Options:"
  49. echo " --verbose, -v Show verbose output"
  50. echo " --test, -t NAME Run only the specified test"
  51. echo " --timeout SECONDS Set timeout per test (default: 900)"
  52. echo " --integration, -i Run integration tests (slow, 10-30 min)"
  53. echo " --help, -h Show this help"
  54. echo ""
  55. echo "Tests:"
  56. echo " test-subagent-driven-development.sh Test skill loading and requirements"
  57. echo ""
  58. echo "Integration Tests (use --integration):"
  59. echo " test-subagent-driven-development-integration.sh Full workflow execution"
  60. exit 0
  61. ;;
  62. *)
  63. echo "Unknown option: $1"
  64. echo "Use --help for usage information"
  65. exit 1
  66. ;;
  67. esac
  68. done
  69. # List of skill tests to run (fast unit tests)
  70. tests=(
  71. "test-worktree-path-policy.sh"
  72. "test-sdd-workspace.sh"
  73. "test-executing-plans-scripts.sh"
  74. "test-plan-directories.sh"
  75. "test-subagent-driven-development.sh"
  76. )
  77. # Integration tests (slow, full execution)
  78. integration_tests=(
  79. "test-subagent-driven-development-integration.sh"
  80. )
  81. # Add integration tests if requested
  82. if [ "$RUN_INTEGRATION" = true ]; then
  83. tests+=("${integration_tests[@]}")
  84. fi
  85. # Filter to specific test if requested
  86. if [ -n "$SPECIFIC_TEST" ]; then
  87. tests=("$SPECIFIC_TEST")
  88. fi
  89. # Track results
  90. passed=0
  91. failed=0
  92. skipped=0
  93. # Run each test
  94. for test in "${tests[@]}"; do
  95. echo "----------------------------------------"
  96. echo "Running: $test"
  97. echo "----------------------------------------"
  98. test_path="$SCRIPT_DIR/$test"
  99. if [ ! -f "$test_path" ]; then
  100. echo " [SKIP] Test file not found: $test"
  101. skipped=$((skipped + 1))
  102. continue
  103. fi
  104. if [ ! -x "$test_path" ]; then
  105. echo " Making $test executable..."
  106. chmod +x "$test_path"
  107. fi
  108. start_time=$(date +%s)
  109. if [ "$VERBOSE" = true ]; then
  110. if timeout "$TIMEOUT" bash "$test_path"; then
  111. end_time=$(date +%s)
  112. duration=$((end_time - start_time))
  113. echo ""
  114. echo " [PASS] $test (${duration}s)"
  115. passed=$((passed + 1))
  116. else
  117. exit_code=$?
  118. end_time=$(date +%s)
  119. duration=$((end_time - start_time))
  120. echo ""
  121. if [ $exit_code -eq 124 ]; then
  122. echo " [FAIL] $test (timeout after ${TIMEOUT}s)"
  123. else
  124. echo " [FAIL] $test (${duration}s)"
  125. fi
  126. failed=$((failed + 1))
  127. fi
  128. else
  129. # Capture output for non-verbose mode
  130. if output=$(timeout "$TIMEOUT" bash "$test_path" 2>&1); then
  131. end_time=$(date +%s)
  132. duration=$((end_time - start_time))
  133. echo " [PASS] (${duration}s)"
  134. passed=$((passed + 1))
  135. else
  136. exit_code=$?
  137. end_time=$(date +%s)
  138. duration=$((end_time - start_time))
  139. if [ $exit_code -eq 124 ]; then
  140. echo " [FAIL] (timeout after ${TIMEOUT}s)"
  141. else
  142. echo " [FAIL] (${duration}s)"
  143. fi
  144. echo ""
  145. echo " Output:"
  146. echo "$output" | sed 's/^/ /'
  147. failed=$((failed + 1))
  148. fi
  149. fi
  150. echo ""
  151. done
  152. # Print summary
  153. echo "========================================"
  154. echo " Test Results Summary"
  155. echo "========================================"
  156. echo ""
  157. echo " Passed: $passed"
  158. echo " Failed: $failed"
  159. echo " Skipped: $skipped"
  160. echo ""
  161. if [ "$RUN_INTEGRATION" = false ] && [ ${#integration_tests[@]} -gt 0 ]; then
  162. echo "Note: Integration tests were not run (they take 10-30 minutes)."
  163. echo "Use --integration flag to run full workflow execution tests."
  164. echo ""
  165. fi
  166. if [ $failed -gt 0 ]; then
  167. echo "STATUS: FAILED"
  168. exit 1
  169. else
  170. echo "STATUS: PASSED"
  171. exit 0
  172. fi