test-tools.sh 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/usr/bin/env bash
  2. # Test: Native Skill Tool Functionality
  3. # Verifies that OpenCode's native skill tool can load personal, project,
  4. # and bundled superpowers skills.
  5. # NOTE: These tests require OpenCode to be installed and configured
  6. set -euo pipefail
  7. SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
  8. OPENCODE_TEST_TIMEOUT_SECONDS="${OPENCODE_TEST_TIMEOUT_SECONDS:-120}"
  9. echo "=== Test: Tools Functionality ==="
  10. # Source setup to create isolated environment
  11. source "$SCRIPT_DIR/setup.sh"
  12. # Trap to cleanup on exit
  13. trap cleanup_test_env EXIT
  14. # Check if opencode is available
  15. if ! command -v opencode &> /dev/null; then
  16. echo " [SKIP] OpenCode not installed - skipping integration tests"
  17. echo " To run these tests, install OpenCode: https://opencode.ai"
  18. exit 0
  19. fi
  20. run_opencode() {
  21. local result_var="$1"
  22. local dir="$2"
  23. local prompt="$3"
  24. local command_output
  25. local exit_code
  26. set +e
  27. command_output=$(cd "$dir" && timeout "${OPENCODE_TEST_TIMEOUT_SECONDS}s" opencode run --print-logs --format json "$prompt" 2>&1)
  28. exit_code=$?
  29. set -e
  30. if [ $exit_code -eq 124 ]; then
  31. echo " [FAIL] OpenCode timed out after ${OPENCODE_TEST_TIMEOUT_SECONDS}s"
  32. exit 1
  33. fi
  34. if [ $exit_code -ne 0 ]; then
  35. echo " [FAIL] OpenCode returned non-zero exit code: $exit_code"
  36. echo " Output was:"
  37. awk 'NR <= 80 { print }' <<<"$command_output"
  38. exit 1
  39. fi
  40. printf -v "$result_var" '%s' "$command_output"
  41. }
  42. assert_contains() {
  43. local output="$1"
  44. local needle="$2"
  45. local message="$3"
  46. if [[ "$output" == *"$needle"* ]]; then
  47. echo " [PASS] $message"
  48. else
  49. echo " [FAIL] $message"
  50. echo " Expected to find: $needle"
  51. echo " Output was:"
  52. awk 'NR <= 80 { print }' <<<"$output"
  53. exit 1
  54. fi
  55. }
  56. # Test 1: Test personal skill loading via OpenCode's native skill tool
  57. echo "Test 1: Testing native skill tool with a personal skill..."
  58. echo " Running opencode with personal-test request..."
  59. run_opencode output "$TEST_HOME/test-project" "Call the skill tool with name \"personal-test\". Then print the PERSONAL_SKILL_MARKER_12345 marker."
  60. assert_contains "$output" '"tool":"skill"' "OpenCode called the native skill tool"
  61. assert_contains "$output" "PERSONAL_SKILL_MARKER_12345" "native skill tool loaded personal-test skill content"
  62. # Test 2: Test project skill loading
  63. echo ""
  64. echo "Test 2: Testing native skill tool with a project skill..."
  65. echo " Running opencode with project-test request..."
  66. run_opencode output "$TEST_HOME/test-project" "Call the skill tool with name \"project-test\". Then print the PROJECT_SKILL_MARKER_67890 marker."
  67. assert_contains "$output" "PROJECT_SKILL_MARKER_67890" "native skill tool loaded project-test skill content"
  68. # Test 3: Test bundled superpowers skill loading
  69. echo ""
  70. echo "Test 3: Testing native skill tool with a superpowers skill..."
  71. echo " Running opencode with brainstorming skill..."
  72. run_opencode output "$TEST_HOME/test-project" "Call the skill tool with name \"brainstorming\". Then tell me the loaded skill title."
  73. assert_contains "$output" '"name":"brainstorming"' "native skill tool loaded bundled brainstorming skill"
  74. assert_contains "$output" "Brainstorming Ideas Into Designs" "brainstorming skill content was returned"
  75. echo ""
  76. echo "=== All native skill tool tests passed ==="