run-test.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/usr/bin/env bash
  2. # Run a subagent-driven-development test
  3. # Usage: ./run-test.sh <test-name> [--plugin-dir <path>]
  4. #
  5. # Example:
  6. # ./run-test.sh go-fractals
  7. # ./run-test.sh svelte-todo --plugin-dir /path/to/superpowers
  8. set -e
  9. SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
  10. TEST_NAME="${1:?Usage: $0 <test-name> [--plugin-dir <path>]}"
  11. shift
  12. # Parse optional arguments
  13. PLUGIN_DIR=""
  14. while [[ $# -gt 0 ]]; do
  15. case $1 in
  16. --plugin-dir)
  17. PLUGIN_DIR="$2"
  18. shift 2
  19. ;;
  20. *)
  21. echo "Unknown option: $1"
  22. exit 1
  23. ;;
  24. esac
  25. done
  26. # Default plugin dir to parent of tests directory
  27. if [[ -z "$PLUGIN_DIR" ]]; then
  28. PLUGIN_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
  29. fi
  30. # Verify test exists
  31. TEST_DIR="$SCRIPT_DIR/$TEST_NAME"
  32. if [[ ! -d "$TEST_DIR" ]]; then
  33. echo "Error: Test '$TEST_NAME' not found at $TEST_DIR"
  34. echo "Available tests:"
  35. ls -1 "$SCRIPT_DIR" | grep -v '\.sh$' | grep -v '\.md$'
  36. exit 1
  37. fi
  38. # Create timestamped output directory
  39. TIMESTAMP=$(date +%s)
  40. OUTPUT_BASE="/tmp/superpowers-tests/$TIMESTAMP/subagent-driven-development"
  41. OUTPUT_DIR="$OUTPUT_BASE/$TEST_NAME"
  42. mkdir -p "$OUTPUT_DIR"
  43. echo "=== Subagent-Driven Development Test ==="
  44. echo "Test: $TEST_NAME"
  45. echo "Output: $OUTPUT_DIR"
  46. echo "Plugin: $PLUGIN_DIR"
  47. echo ""
  48. # Scaffold the project
  49. echo ">>> Scaffolding project..."
  50. "$TEST_DIR/scaffold.sh" "$OUTPUT_DIR/project"
  51. echo ""
  52. # Prepare the prompt
  53. PLAN_PATH="$OUTPUT_DIR/project/plan.md"
  54. PROMPT="Execute this plan using superpowers:subagent-driven-development. The plan is at: $PLAN_PATH"
  55. # Run Claude with JSON output for token tracking
  56. LOG_FILE="$OUTPUT_DIR/claude-output.json"
  57. echo ">>> Running Claude..."
  58. echo "Prompt: $PROMPT"
  59. echo "Log file: $LOG_FILE"
  60. echo ""
  61. # Run claude and capture output
  62. # Using stream-json to get token usage stats
  63. # --dangerously-skip-permissions for automated testing (subagents don't inherit parent settings)
  64. cd "$OUTPUT_DIR/project"
  65. claude -p "$PROMPT" \
  66. --plugin-dir "$PLUGIN_DIR" \
  67. --dangerously-skip-permissions \
  68. --output-format stream-json \
  69. --verbose \
  70. > "$LOG_FILE" 2>&1 || true
  71. # Extract final stats
  72. echo ""
  73. echo ">>> Test complete"
  74. echo "Project directory: $OUTPUT_DIR/project"
  75. echo "Claude log: $LOG_FILE"
  76. echo ""
  77. # Show token usage if available
  78. if command -v jq &> /dev/null; then
  79. echo ">>> Token usage:"
  80. # Extract usage from the last message with usage info
  81. jq -s '[.[] | select(.type == "result")] | last | .usage' "$LOG_FILE" 2>/dev/null || echo "(could not parse usage)"
  82. echo ""
  83. fi
  84. echo ">>> Next steps:"
  85. echo "1. Review the project: cd $OUTPUT_DIR/project"
  86. echo "2. Review Claude's log: less $LOG_FILE"
  87. echo "3. Check if tests pass:"
  88. if [[ "$TEST_NAME" == "go-fractals" ]]; then
  89. echo " cd $OUTPUT_DIR/project && go test ./..."
  90. elif [[ "$TEST_NAME" == "svelte-todo" ]]; then
  91. echo " cd $OUTPUT_DIR/project && npm test && npx playwright test"
  92. fi