test-priority.sh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #!/usr/bin/env bash
  2. # Test: Skill Priority Resolution
  3. # Documents current OpenCode duplicate-name behavior for local and bundled
  4. # skills. The desired local-shadowing behavior is tracked separately; this
  5. # test keeps the integration suite honest without adding a plugin workaround.
  6. # NOTE: These tests require OpenCode to be installed and configured
  7. set -euo pipefail
  8. SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
  9. OPENCODE_TEST_TIMEOUT_SECONDS="${OPENCODE_TEST_TIMEOUT_SECONDS:-120}"
  10. echo "=== Test: Skill Priority Resolution ==="
  11. # Source setup to create isolated environment
  12. source "$SCRIPT_DIR/setup.sh"
  13. # Trap to cleanup on exit
  14. trap cleanup_test_env EXIT
  15. # Create same skill "priority-test" in all three locations with different markers
  16. echo "Setting up priority test fixtures..."
  17. # 1. Create in superpowers location (lowest priority)
  18. mkdir -p "$SUPERPOWERS_SKILLS_DIR/priority-test"
  19. cat > "$SUPERPOWERS_SKILLS_DIR/priority-test/SKILL.md" <<'EOF'
  20. ---
  21. name: priority-test
  22. description: Superpowers version of priority test skill
  23. ---
  24. # Priority Test Skill (Superpowers Version)
  25. This is the SUPERPOWERS version of the priority test skill.
  26. PRIORITY_MARKER_SUPERPOWERS_VERSION
  27. EOF
  28. # 2. Create in personal location (medium priority)
  29. mkdir -p "$OPENCODE_CONFIG_DIR/skills/priority-test"
  30. cat > "$OPENCODE_CONFIG_DIR/skills/priority-test/SKILL.md" <<'EOF'
  31. ---
  32. name: priority-test
  33. description: Personal version of priority test skill
  34. ---
  35. # Priority Test Skill (Personal Version)
  36. This is the PERSONAL version of the priority test skill.
  37. PRIORITY_MARKER_PERSONAL_VERSION
  38. EOF
  39. # 3. Create in project location (highest priority)
  40. mkdir -p "$TEST_HOME/test-project/.opencode/skills/priority-test"
  41. cat > "$TEST_HOME/test-project/.opencode/skills/priority-test/SKILL.md" <<'EOF'
  42. ---
  43. name: priority-test
  44. description: Project version of priority test skill
  45. ---
  46. # Priority Test Skill (Project Version)
  47. This is the PROJECT version of the priority test skill.
  48. PRIORITY_MARKER_PROJECT_VERSION
  49. EOF
  50. echo " Created priority-test skill in all three locations"
  51. # Test 1: Verify fixture setup
  52. echo ""
  53. echo "Test 1: Verifying test fixtures..."
  54. if [ -f "$SUPERPOWERS_SKILLS_DIR/priority-test/SKILL.md" ]; then
  55. echo " [PASS] Superpowers version exists"
  56. else
  57. echo " [FAIL] Superpowers version missing"
  58. exit 1
  59. fi
  60. if [ -f "$OPENCODE_CONFIG_DIR/skills/priority-test/SKILL.md" ]; then
  61. echo " [PASS] Personal version exists"
  62. else
  63. echo " [FAIL] Personal version missing"
  64. exit 1
  65. fi
  66. if [ -f "$TEST_HOME/test-project/.opencode/skills/priority-test/SKILL.md" ]; then
  67. echo " [PASS] Project version exists"
  68. else
  69. echo " [FAIL] Project version missing"
  70. exit 1
  71. fi
  72. # Check if opencode is available for integration tests
  73. if ! command -v opencode &> /dev/null; then
  74. echo ""
  75. echo " [SKIP] OpenCode not installed - skipping integration tests"
  76. echo " To run these tests, install OpenCode: https://opencode.ai"
  77. echo ""
  78. echo "=== Priority fixture tests passed (integration tests skipped) ==="
  79. exit 0
  80. fi
  81. run_opencode() {
  82. local result_var="$1"
  83. local dir="$2"
  84. local prompt="$3"
  85. local command_output
  86. local exit_code
  87. set +e
  88. command_output=$(cd "$dir" && timeout "${OPENCODE_TEST_TIMEOUT_SECONDS}s" opencode run --print-logs --format json "$prompt" 2>&1)
  89. exit_code=$?
  90. set -e
  91. if [ $exit_code -eq 124 ]; then
  92. echo " [FAIL] OpenCode timed out after ${OPENCODE_TEST_TIMEOUT_SECONDS}s"
  93. exit 1
  94. fi
  95. if [ $exit_code -ne 0 ]; then
  96. echo " [FAIL] OpenCode returned non-zero exit code: $exit_code"
  97. echo " Output was:"
  98. awk 'NR <= 80 { print }' <<<"$command_output"
  99. exit 1
  100. fi
  101. printf -v "$result_var" '%s' "$command_output"
  102. }
  103. assert_contains() {
  104. local output="$1"
  105. local needle="$2"
  106. local message="$3"
  107. if [[ "$output" == *"$needle"* ]]; then
  108. echo " [PASS] $message"
  109. else
  110. echo " [FAIL] $message"
  111. echo " Expected to find: $needle"
  112. echo " Output was:"
  113. awk 'NR <= 80 { print }' <<<"$output"
  114. exit 1
  115. fi
  116. }
  117. first_skill_tool_event() {
  118. awk '/"type":"tool_use"/ && /"tool":"skill"/ { print; exit }' <<<"$1"
  119. }
  120. describe_priority_result() {
  121. local output="$1"
  122. local expected_marker="$2"
  123. local fallback_marker="$3"
  124. local pass_message="$4"
  125. local known_bug_message="$5"
  126. local loaded_skill
  127. loaded_skill="$(first_skill_tool_event "$output")"
  128. if [[ "$loaded_skill" == *"$expected_marker"* ]]; then
  129. echo " [PASS] $pass_message"
  130. elif [[ "$loaded_skill" == *"$fallback_marker"* ]]; then
  131. echo " [INFO] $known_bug_message"
  132. echo " [INFO] Tracked separately: OpenCode bundled skills can shadow local skills with duplicate native names"
  133. else
  134. echo " [FAIL] Could not verify priority marker in native skill tool output"
  135. echo " Output was:"
  136. awk 'NR <= 80 { print }' <<<"$output"
  137. exit 1
  138. fi
  139. }
  140. # Test 2: Document personal vs bundled superpowers priority
  141. echo ""
  142. echo "Test 2: Documenting personal vs superpowers priority..."
  143. echo " Running from outside project directory..."
  144. run_opencode output "$HOME" "Call the skill tool with name \"priority-test\". Show the exact content including any PRIORITY_MARKER text."
  145. describe_priority_result \
  146. "$output" \
  147. "PRIORITY_MARKER_PERSONAL_VERSION" \
  148. "PRIORITY_MARKER_SUPERPOWERS_VERSION" \
  149. "Personal version loaded for duplicate native skill name" \
  150. "Current OpenCode behavior loaded bundled superpowers version instead of personal version"
  151. # Test 3: Document project vs bundled superpowers priority
  152. echo ""
  153. echo "Test 3: Documenting project vs personal/superpowers priority..."
  154. echo " Running from project directory..."
  155. run_opencode output "$TEST_HOME/test-project" "Call the skill tool with name \"priority-test\". Show the exact content including any PRIORITY_MARKER text."
  156. describe_priority_result \
  157. "$output" \
  158. "PRIORITY_MARKER_PROJECT_VERSION" \
  159. "PRIORITY_MARKER_SUPERPOWERS_VERSION" \
  160. "Project version loaded for duplicate native skill name" \
  161. "Current OpenCode behavior loaded bundled superpowers version instead of project version"
  162. # Test 4: Test a non-colliding bundled superpowers skill is still available
  163. echo ""
  164. echo "Test 4: Testing non-colliding superpowers skill remains available..."
  165. mkdir -p "$SUPERPOWERS_SKILLS_DIR/superpowers-only-test"
  166. cat > "$SUPERPOWERS_SKILLS_DIR/superpowers-only-test/SKILL.md" <<'EOF'
  167. ---
  168. name: superpowers-only-test
  169. description: Superpowers-only priority test skill
  170. ---
  171. # Superpowers Only Test Skill
  172. PRIORITY_MARKER_SUPERPOWERS_ONLY_VERSION
  173. EOF
  174. run_opencode output "$TEST_HOME/test-project" "Call the skill tool with name \"superpowers-only-test\". Show the exact content including any PRIORITY_MARKER text."
  175. assert_contains "$output" "PRIORITY_MARKER_SUPERPOWERS_ONLY_VERSION" "Non-colliding superpowers skill is still registered"
  176. echo ""
  177. echo "=== All priority tests passed ==="