1
0

test-tools.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/usr/bin/env bash
  2. # Test: Tools Functionality
  3. # Verifies that use_skill and find_skills tools work correctly
  4. # NOTE: These tests require OpenCode to be installed and configured
  5. set -euo pipefail
  6. SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
  7. echo "=== Test: Tools Functionality ==="
  8. # Source setup to create isolated environment
  9. source "$SCRIPT_DIR/setup.sh"
  10. # Trap to cleanup on exit
  11. trap cleanup_test_env EXIT
  12. # Check if opencode is available
  13. if ! command -v opencode &> /dev/null; then
  14. echo " [SKIP] OpenCode not installed - skipping integration tests"
  15. echo " To run these tests, install OpenCode: https://opencode.ai"
  16. exit 0
  17. fi
  18. # Test 1: Test find_skills tool via direct invocation
  19. echo "Test 1: Testing find_skills tool..."
  20. echo " Running opencode with find_skills request..."
  21. # Use timeout to prevent hanging, capture both stdout and stderr
  22. output=$(timeout 60s opencode run --print-logs "Use the find_skills tool to list available skills. Just call the tool and show me the raw output." 2>&1) || {
  23. exit_code=$?
  24. if [ $exit_code -eq 124 ]; then
  25. echo " [FAIL] OpenCode timed out after 60s"
  26. exit 1
  27. fi
  28. echo " [WARN] OpenCode returned non-zero exit code: $exit_code"
  29. }
  30. # Check for expected patterns in output
  31. if echo "$output" | grep -qi "superpowers:brainstorming\|superpowers:using-superpowers\|Available skills"; then
  32. echo " [PASS] find_skills tool discovered superpowers skills"
  33. else
  34. echo " [FAIL] find_skills did not return expected skills"
  35. echo " Output was:"
  36. echo "$output" | head -50
  37. exit 1
  38. fi
  39. # Check if personal test skill was found
  40. if echo "$output" | grep -qi "personal-test"; then
  41. echo " [PASS] find_skills found personal test skill"
  42. else
  43. echo " [WARN] personal test skill not found in output (may be ok if tool returned subset)"
  44. fi
  45. # Test 2: Test use_skill tool
  46. echo ""
  47. echo "Test 2: Testing use_skill tool..."
  48. echo " Running opencode with use_skill request..."
  49. output=$(timeout 60s opencode run --print-logs "Use the use_skill tool to load the personal-test skill and show me what you get." 2>&1) || {
  50. exit_code=$?
  51. if [ $exit_code -eq 124 ]; then
  52. echo " [FAIL] OpenCode timed out after 60s"
  53. exit 1
  54. fi
  55. echo " [WARN] OpenCode returned non-zero exit code: $exit_code"
  56. }
  57. # Check for the skill marker we embedded
  58. if echo "$output" | grep -qi "PERSONAL_SKILL_MARKER_12345\|Personal Test Skill\|Launching skill"; then
  59. echo " [PASS] use_skill loaded personal-test skill content"
  60. else
  61. echo " [FAIL] use_skill did not load personal-test skill correctly"
  62. echo " Output was:"
  63. echo "$output" | head -50
  64. exit 1
  65. fi
  66. # Test 3: Test use_skill with superpowers: prefix
  67. echo ""
  68. echo "Test 3: Testing use_skill with superpowers: prefix..."
  69. echo " Running opencode with superpowers:brainstorming skill..."
  70. output=$(timeout 60s opencode run --print-logs "Use the use_skill tool to load superpowers:brainstorming and tell me the first few lines of what you received." 2>&1) || {
  71. exit_code=$?
  72. if [ $exit_code -eq 124 ]; then
  73. echo " [FAIL] OpenCode timed out after 60s"
  74. exit 1
  75. fi
  76. echo " [WARN] OpenCode returned non-zero exit code: $exit_code"
  77. }
  78. # Check for expected content from brainstorming skill
  79. if echo "$output" | grep -qi "brainstorming\|Launching skill\|skill.*loaded"; then
  80. echo " [PASS] use_skill loaded superpowers:brainstorming skill"
  81. else
  82. echo " [FAIL] use_skill did not load superpowers:brainstorming correctly"
  83. echo " Output was:"
  84. echo "$output" | head -50
  85. exit 1
  86. fi
  87. echo ""
  88. echo "=== All tools tests passed ==="