run-skill-tests.sh 5.2 KB

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