run-tests.sh 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #!/usr/bin/env bash
  2. # Main test runner for OpenCode plugin test suite
  3. # Runs all tests and reports results
  4. set -euo pipefail
  5. SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
  6. cd "$SCRIPT_DIR"
  7. echo "========================================"
  8. echo " OpenCode Plugin Test Suite"
  9. echo "========================================"
  10. echo ""
  11. echo "Repository: $(cd ../.. && pwd)"
  12. echo "Test time: $(date)"
  13. echo ""
  14. # Parse command line arguments
  15. RUN_INTEGRATION=false
  16. VERBOSE=false
  17. SPECIFIC_TEST=""
  18. while [[ $# -gt 0 ]]; do
  19. case $1 in
  20. --integration|-i)
  21. RUN_INTEGRATION=true
  22. shift
  23. ;;
  24. --verbose|-v)
  25. VERBOSE=true
  26. shift
  27. ;;
  28. --test|-t)
  29. SPECIFIC_TEST="$2"
  30. shift 2
  31. ;;
  32. --help|-h)
  33. echo "Usage: $0 [options]"
  34. echo ""
  35. echo "Options:"
  36. echo " --integration, -i Run integration tests (requires OpenCode)"
  37. echo " --verbose, -v Show verbose output"
  38. echo " --test, -t NAME Run only the specified test"
  39. echo " --help, -h Show this help"
  40. echo ""
  41. echo "Tests:"
  42. echo " test-plugin-loading.sh Verify plugin installation and structure"
  43. echo " test-bootstrap-caching.sh Verify bootstrap content caching"
  44. echo " test-session-bootstrap.sh Verify session classification and lookup recovery"
  45. echo " test-skill-registration.sh Verify V2 skill registration contract (2.0.4 path field)"
  46. echo " test-tools.sh Test use_skill and find_skills tools (integration)"
  47. echo " test-priority.sh Test skill priority resolution (integration)"
  48. exit 0
  49. ;;
  50. *)
  51. echo "Unknown option: $1"
  52. echo "Use --help for usage information"
  53. exit 1
  54. ;;
  55. esac
  56. done
  57. # List of tests to run (no external dependencies)
  58. tests=(
  59. "test-plugin-loading.sh"
  60. "test-bootstrap-caching.sh"
  61. "test-session-bootstrap.sh"
  62. "test-skill-registration.sh"
  63. )
  64. # Integration tests (require OpenCode)
  65. integration_tests=(
  66. "test-tools.sh"
  67. "test-priority.sh"
  68. )
  69. # Add integration tests if requested
  70. if [ "$RUN_INTEGRATION" = true ]; then
  71. tests+=("${integration_tests[@]}")
  72. fi
  73. # Filter to specific test if requested
  74. if [ -n "$SPECIFIC_TEST" ]; then
  75. tests=("$SPECIFIC_TEST")
  76. fi
  77. # Track results
  78. passed=0
  79. failed=0
  80. skipped=0
  81. # Run each test
  82. for test in "${tests[@]}"; do
  83. echo "----------------------------------------"
  84. echo "Running: $test"
  85. echo "----------------------------------------"
  86. test_path="$SCRIPT_DIR/$test"
  87. if [ ! -f "$test_path" ]; then
  88. echo " [SKIP] Test file not found: $test"
  89. skipped=$((skipped + 1))
  90. continue
  91. fi
  92. if [ ! -x "$test_path" ]; then
  93. echo " Making $test executable..."
  94. chmod +x "$test_path"
  95. fi
  96. start_time=$(date +%s)
  97. if [ "$VERBOSE" = true ]; then
  98. if bash "$test_path"; then
  99. end_time=$(date +%s)
  100. duration=$((end_time - start_time))
  101. echo ""
  102. echo " [PASS] $test (${duration}s)"
  103. passed=$((passed + 1))
  104. else
  105. end_time=$(date +%s)
  106. duration=$((end_time - start_time))
  107. echo ""
  108. echo " [FAIL] $test (${duration}s)"
  109. failed=$((failed + 1))
  110. fi
  111. else
  112. # Capture output for non-verbose mode
  113. if output=$(bash "$test_path" 2>&1); then
  114. end_time=$(date +%s)
  115. duration=$((end_time - start_time))
  116. echo " [PASS] (${duration}s)"
  117. passed=$((passed + 1))
  118. else
  119. end_time=$(date +%s)
  120. duration=$((end_time - start_time))
  121. echo " [FAIL] (${duration}s)"
  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 [ "$RUN_INTEGRATION" = false ] && [ ${#integration_tests[@]} -gt 0 ]; then
  140. echo "Note: Integration tests were not run."
  141. echo "Use --integration flag to run tests that require OpenCode."
  142. echo ""
  143. fi
  144. if [ $failed -gt 0 ]; then
  145. echo "STATUS: FAILED"
  146. exit 1
  147. else
  148. echo "STATUS: PASSED"
  149. exit 0
  150. fi