run-skill-tests.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. while [[ $# -gt 0 ]]; do
  26. case $1 in
  27. --verbose|-v)
  28. VERBOSE=true
  29. shift
  30. ;;
  31. --test|-t)
  32. SPECIFIC_TEST="$2"
  33. shift 2
  34. ;;
  35. --timeout)
  36. TIMEOUT="$2"
  37. shift 2
  38. ;;
  39. --help|-h)
  40. echo "Usage: $0 [options]"
  41. echo ""
  42. echo "Options:"
  43. echo " --verbose, -v Show verbose output"
  44. echo " --test, -t NAME Run only the specified test"
  45. echo " --timeout SECONDS Set timeout per test (default: 300)"
  46. echo " --help, -h Show this help"
  47. echo ""
  48. echo "Tests:"
  49. echo " test-subagent-driven-development.sh Test subagent-driven-development workflow"
  50. exit 0
  51. ;;
  52. *)
  53. echo "Unknown option: $1"
  54. echo "Use --help for usage information"
  55. exit 1
  56. ;;
  57. esac
  58. done
  59. # List of skill tests to run
  60. tests=(
  61. "test-subagent-driven-development.sh"
  62. )
  63. # Filter to specific test if requested
  64. if [ -n "$SPECIFIC_TEST" ]; then
  65. tests=("$SPECIFIC_TEST")
  66. fi
  67. # Track results
  68. passed=0
  69. failed=0
  70. skipped=0
  71. # Run each test
  72. for test in "${tests[@]}"; do
  73. echo "----------------------------------------"
  74. echo "Running: $test"
  75. echo "----------------------------------------"
  76. test_path="$SCRIPT_DIR/$test"
  77. if [ ! -f "$test_path" ]; then
  78. echo " [SKIP] Test file not found: $test"
  79. skipped=$((skipped + 1))
  80. continue
  81. fi
  82. if [ ! -x "$test_path" ]; then
  83. echo " Making $test executable..."
  84. chmod +x "$test_path"
  85. fi
  86. start_time=$(date +%s)
  87. if [ "$VERBOSE" = true ]; then
  88. if timeout "$TIMEOUT" bash "$test_path"; then
  89. end_time=$(date +%s)
  90. duration=$((end_time - start_time))
  91. echo ""
  92. echo " [PASS] $test (${duration}s)"
  93. passed=$((passed + 1))
  94. else
  95. exit_code=$?
  96. end_time=$(date +%s)
  97. duration=$((end_time - start_time))
  98. echo ""
  99. if [ $exit_code -eq 124 ]; then
  100. echo " [FAIL] $test (timeout after ${TIMEOUT}s)"
  101. else
  102. echo " [FAIL] $test (${duration}s)"
  103. fi
  104. failed=$((failed + 1))
  105. fi
  106. else
  107. # Capture output for non-verbose mode
  108. if output=$(timeout "$TIMEOUT" bash "$test_path" 2>&1); then
  109. end_time=$(date +%s)
  110. duration=$((end_time - start_time))
  111. echo " [PASS] (${duration}s)"
  112. passed=$((passed + 1))
  113. else
  114. exit_code=$?
  115. end_time=$(date +%s)
  116. duration=$((end_time - start_time))
  117. if [ $exit_code -eq 124 ]; then
  118. echo " [FAIL] (timeout after ${TIMEOUT}s)"
  119. else
  120. echo " [FAIL] (${duration}s)"
  121. fi
  122. echo ""
  123. echo " Output:"
  124. echo "$output" | sed 's/^/ /'
  125. failed=$((failed + 1))
  126. fi
  127. fi
  128. echo ""
  129. done
  130. # Print summary
  131. echo "========================================"
  132. echo " Test Results Summary"
  133. echo "========================================"
  134. echo ""
  135. echo " Passed: $passed"
  136. echo " Failed: $failed"
  137. echo " Skipped: $skipped"
  138. echo ""
  139. if [ $failed -gt 0 ]; then
  140. echo "STATUS: FAILED"
  141. exit 1
  142. else
  143. echo "STATUS: PASSED"
  144. exit 0
  145. fi