test-priority.sh 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. #!/usr/bin/env bash
  2. # Test: Skill Priority Resolution
  3. # Verifies that skills are resolved with correct priority: project > personal > superpowers
  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: Skill Priority Resolution ==="
  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. # Create same skill "priority-test" in all three locations with different markers
  13. echo "Setting up priority test fixtures..."
  14. # 1. Create in superpowers location (lowest priority)
  15. mkdir -p "$SUPERPOWERS_SKILLS_DIR/priority-test"
  16. cat > "$SUPERPOWERS_SKILLS_DIR/priority-test/SKILL.md" <<'EOF'
  17. ---
  18. name: priority-test
  19. description: Superpowers version of priority test skill
  20. ---
  21. # Priority Test Skill (Superpowers Version)
  22. This is the SUPERPOWERS version of the priority test skill.
  23. PRIORITY_MARKER_SUPERPOWERS_VERSION
  24. EOF
  25. # 2. Create in personal location (medium priority)
  26. mkdir -p "$OPENCODE_CONFIG_DIR/skills/priority-test"
  27. cat > "$OPENCODE_CONFIG_DIR/skills/priority-test/SKILL.md" <<'EOF'
  28. ---
  29. name: priority-test
  30. description: Personal version of priority test skill
  31. ---
  32. # Priority Test Skill (Personal Version)
  33. This is the PERSONAL version of the priority test skill.
  34. PRIORITY_MARKER_PERSONAL_VERSION
  35. EOF
  36. # 3. Create in project location (highest priority)
  37. mkdir -p "$TEST_HOME/test-project/.opencode/skills/priority-test"
  38. cat > "$TEST_HOME/test-project/.opencode/skills/priority-test/SKILL.md" <<'EOF'
  39. ---
  40. name: priority-test
  41. description: Project version of priority test skill
  42. ---
  43. # Priority Test Skill (Project Version)
  44. This is the PROJECT version of the priority test skill.
  45. PRIORITY_MARKER_PROJECT_VERSION
  46. EOF
  47. echo " Created priority-test skill in all three locations"
  48. # Test 1: Verify fixture setup
  49. echo ""
  50. echo "Test 1: Verifying test fixtures..."
  51. if [ -f "$SUPERPOWERS_SKILLS_DIR/priority-test/SKILL.md" ]; then
  52. echo " [PASS] Superpowers version exists"
  53. else
  54. echo " [FAIL] Superpowers version missing"
  55. exit 1
  56. fi
  57. if [ -f "$OPENCODE_CONFIG_DIR/skills/priority-test/SKILL.md" ]; then
  58. echo " [PASS] Personal version exists"
  59. else
  60. echo " [FAIL] Personal version missing"
  61. exit 1
  62. fi
  63. if [ -f "$TEST_HOME/test-project/.opencode/skills/priority-test/SKILL.md" ]; then
  64. echo " [PASS] Project version exists"
  65. else
  66. echo " [FAIL] Project version missing"
  67. exit 1
  68. fi
  69. # Check if opencode is available for integration tests
  70. if ! command -v opencode &> /dev/null; then
  71. echo ""
  72. echo " [SKIP] OpenCode not installed - skipping integration tests"
  73. echo " To run these tests, install OpenCode: https://opencode.ai"
  74. echo ""
  75. echo "=== Priority fixture tests passed (integration tests skipped) ==="
  76. exit 0
  77. fi
  78. # Test 2: Test that personal overrides superpowers
  79. echo ""
  80. echo "Test 2: Testing personal > superpowers priority..."
  81. echo " Running from outside project directory..."
  82. # Run from HOME (not in project) - should get personal version
  83. cd "$HOME"
  84. output=$(timeout 60s opencode run --print-logs "Use the use_skill tool to load the priority-test skill. Show me the exact content including any PRIORITY_MARKER text." 2>&1) || {
  85. exit_code=$?
  86. if [ $exit_code -eq 124 ]; then
  87. echo " [FAIL] OpenCode timed out after 60s"
  88. exit 1
  89. fi
  90. }
  91. if echo "$output" | grep -qi "PRIORITY_MARKER_PERSONAL_VERSION"; then
  92. echo " [PASS] Personal version loaded (overrides superpowers)"
  93. elif echo "$output" | grep -qi "PRIORITY_MARKER_SUPERPOWERS_VERSION"; then
  94. echo " [FAIL] Superpowers version loaded instead of personal"
  95. exit 1
  96. else
  97. echo " [WARN] Could not verify priority marker in output"
  98. echo " Output snippet:"
  99. echo "$output" | grep -i "priority\|personal\|superpowers" | head -10
  100. fi
  101. # Test 3: Test that project overrides both personal and superpowers
  102. echo ""
  103. echo "Test 3: Testing project > personal > superpowers priority..."
  104. echo " Running from project directory..."
  105. # Run from project directory - should get project version
  106. cd "$TEST_HOME/test-project"
  107. output=$(timeout 60s opencode run --print-logs "Use the use_skill tool to load the priority-test skill. Show me the exact content including any PRIORITY_MARKER text." 2>&1) || {
  108. exit_code=$?
  109. if [ $exit_code -eq 124 ]; then
  110. echo " [FAIL] OpenCode timed out after 60s"
  111. exit 1
  112. fi
  113. }
  114. if echo "$output" | grep -qi "PRIORITY_MARKER_PROJECT_VERSION"; then
  115. echo " [PASS] Project version loaded (highest priority)"
  116. elif echo "$output" | grep -qi "PRIORITY_MARKER_PERSONAL_VERSION"; then
  117. echo " [FAIL] Personal version loaded instead of project"
  118. exit 1
  119. elif echo "$output" | grep -qi "PRIORITY_MARKER_SUPERPOWERS_VERSION"; then
  120. echo " [FAIL] Superpowers version loaded instead of project"
  121. exit 1
  122. else
  123. echo " [WARN] Could not verify priority marker in output"
  124. echo " Output snippet:"
  125. echo "$output" | grep -i "priority\|project\|personal" | head -10
  126. fi
  127. # Test 4: Test explicit superpowers: prefix bypasses priority
  128. echo ""
  129. echo "Test 4: Testing superpowers: prefix forces superpowers version..."
  130. cd "$TEST_HOME/test-project"
  131. output=$(timeout 60s opencode run --print-logs "Use the use_skill tool to load superpowers:priority-test specifically. Show me the exact content including any PRIORITY_MARKER text." 2>&1) || {
  132. exit_code=$?
  133. if [ $exit_code -eq 124 ]; then
  134. echo " [FAIL] OpenCode timed out after 60s"
  135. exit 1
  136. fi
  137. }
  138. if echo "$output" | grep -qi "PRIORITY_MARKER_SUPERPOWERS_VERSION"; then
  139. echo " [PASS] superpowers: prefix correctly forces superpowers version"
  140. elif echo "$output" | grep -qi "PRIORITY_MARKER_PROJECT_VERSION\|PRIORITY_MARKER_PERSONAL_VERSION"; then
  141. echo " [FAIL] superpowers: prefix did not force superpowers version"
  142. exit 1
  143. else
  144. echo " [WARN] Could not verify priority marker in output"
  145. fi
  146. # Test 5: Test explicit project: prefix
  147. echo ""
  148. echo "Test 5: Testing project: prefix forces project version..."
  149. cd "$HOME" # Run from outside project but with project: prefix
  150. output=$(timeout 60s opencode run --print-logs "Use the use_skill tool to load project:priority-test specifically. Show me the exact content." 2>&1) || {
  151. exit_code=$?
  152. if [ $exit_code -eq 124 ]; then
  153. echo " [FAIL] OpenCode timed out after 60s"
  154. exit 1
  155. fi
  156. }
  157. # Note: This may fail since we're not in the project directory
  158. # The project: prefix only works when in a project context
  159. if echo "$output" | grep -qi "not found\|error"; then
  160. echo " [PASS] project: prefix correctly fails when not in project context"
  161. else
  162. echo " [INFO] project: prefix behavior outside project context may vary"
  163. fi
  164. echo ""
  165. echo "=== All priority tests passed ==="