run-skill-tests.sh 5.1 KB

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