run-test.sh 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/bash
  2. # Test skill triggering with naive prompts
  3. # Usage: ./run-test.sh <skill-name> <prompt-file>
  4. #
  5. # Tests whether Claude triggers a skill based on a natural prompt
  6. # (without explicitly mentioning the skill)
  7. set -e
  8. SKILL_NAME="$1"
  9. PROMPT_FILE="$2"
  10. MAX_TURNS="${3:-3}"
  11. if [ -z "$SKILL_NAME" ] || [ -z "$PROMPT_FILE" ]; then
  12. echo "Usage: $0 <skill-name> <prompt-file> [max-turns]"
  13. echo "Example: $0 systematic-debugging ./test-prompts/debugging.txt"
  14. exit 1
  15. fi
  16. # Get the directory where this script lives (should be tests/skill-triggering)
  17. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  18. # Get the superpowers plugin root (two levels up from tests/skill-triggering)
  19. PLUGIN_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
  20. TIMESTAMP=$(date +%s)
  21. OUTPUT_DIR="/tmp/superpowers-tests/${TIMESTAMP}/skill-triggering/${SKILL_NAME}"
  22. mkdir -p "$OUTPUT_DIR"
  23. # Read prompt from file
  24. PROMPT=$(cat "$PROMPT_FILE")
  25. echo "=== Skill Triggering Test ==="
  26. echo "Skill: $SKILL_NAME"
  27. echo "Prompt file: $PROMPT_FILE"
  28. echo "Max turns: $MAX_TURNS"
  29. echo "Output dir: $OUTPUT_DIR"
  30. echo ""
  31. # Copy prompt for reference
  32. cp "$PROMPT_FILE" "$OUTPUT_DIR/prompt.txt"
  33. # Run Claude
  34. LOG_FILE="$OUTPUT_DIR/claude-output.json"
  35. cd "$OUTPUT_DIR"
  36. echo "Plugin dir: $PLUGIN_DIR"
  37. echo "Running claude -p with naive prompt..."
  38. timeout 300 claude -p "$PROMPT" \
  39. --plugin-dir "$PLUGIN_DIR" \
  40. --dangerously-skip-permissions \
  41. --max-turns "$MAX_TURNS" \
  42. --output-format stream-json \
  43. > "$LOG_FILE" 2>&1 || true
  44. echo ""
  45. echo "=== Results ==="
  46. # Check if skill was triggered (look for Skill tool invocation)
  47. # In stream-json, tool invocations have "name":"Skill" (not "tool":"Skill")
  48. # Match either "skill":"skillname" or "skill":"namespace:skillname"
  49. SKILL_PATTERN='"skill":"([^"]*:)?'"${SKILL_NAME}"'"'
  50. if grep -q '"name":"Skill"' "$LOG_FILE" && grep -qE "$SKILL_PATTERN" "$LOG_FILE"; then
  51. echo "✅ PASS: Skill '$SKILL_NAME' was triggered"
  52. TRIGGERED=true
  53. else
  54. echo "❌ FAIL: Skill '$SKILL_NAME' was NOT triggered"
  55. TRIGGERED=false
  56. fi
  57. # Show what skills WERE triggered
  58. echo ""
  59. echo "Skills triggered in this run:"
  60. grep -o '"skill":"[^"]*"' "$LOG_FILE" 2>/dev/null | sort -u || echo " (none)"
  61. # Show first assistant message
  62. echo ""
  63. echo "First assistant response (truncated):"
  64. grep '"type":"assistant"' "$LOG_FILE" | head -1 | jq -r '.message.content[0].text // .message.content' 2>/dev/null | head -c 500 || echo " (could not extract)"
  65. echo ""
  66. echo "Full log: $LOG_FILE"
  67. echo "Timestamp: $TIMESTAMP"
  68. if [ "$TRIGGERED" = "true" ]; then
  69. exit 0
  70. else
  71. exit 1
  72. fi