test-worktree-native-preference.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/usr/bin/env bash
  2. # Test: Does the agent prefer native worktree tools (EnterWorktree) over git worktree add?
  3. # Framework: RED-GREEN-REFACTOR per testing-skills-with-subagents.md
  4. #
  5. # RED: Current skill has no native tool preference. Agent should use git worktree add.
  6. # GREEN: Updated skill has Step 1a. Agent should use EnterWorktree on Claude Code.
  7. set -euo pipefail
  8. SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
  9. source "$SCRIPT_DIR/test-helpers.sh"
  10. # Pressure scenario: realistic implementation task where agent needs isolation
  11. SCENARIO='IMPORTANT: This is a real task. Choose and act.
  12. You need to implement a small feature (add a "version" field to package.json).
  13. This should be done in an isolated workspace to protect the main branch.
  14. You have the using-git-worktrees skill available. Set up the isolated workspace now.
  15. Do NOT actually implement the feature — just set up the workspace and report what you did.
  16. Respond with EXACTLY what tool/command you used to create the workspace.'
  17. echo "=== Worktree Native Preference Test ==="
  18. echo ""
  19. # Phase selection
  20. PHASE="${1:-red}"
  21. if [ "$PHASE" = "red" ]; then
  22. echo "--- RED PHASE: Running WITHOUT Step 1a (current skill) ---"
  23. echo "Expected: Agent uses 'git worktree add' (no native tool awareness)"
  24. echo ""
  25. test_dir=$(create_test_project)
  26. cd "$test_dir"
  27. git init && git commit --allow-empty -m "init"
  28. mkdir -p .worktrees
  29. output=$(run_claude "$SCENARIO" 120)
  30. echo "Agent output:"
  31. echo "$output"
  32. echo ""
  33. # RED expectation: agent uses git worktree add (current behavior)
  34. if echo "$output" | grep -qi "EnterWorktree"; then
  35. echo "[UNEXPECTED] Agent used EnterWorktree WITHOUT Step 1a — skill may not be needed"
  36. echo "Investigate: is Claude Code's default behavior already correct?"
  37. else
  38. echo "[RED CONFIRMED] Agent did NOT use EnterWorktree"
  39. assert_contains "$output" "git worktree" "Agent used git worktree (expected in RED)"
  40. fi
  41. cleanup_test_project "$test_dir"
  42. elif [ "$PHASE" = "green" ]; then
  43. echo "--- GREEN PHASE: Running WITH Step 1a (updated skill) ---"
  44. echo "Expected: Agent uses EnterWorktree instead of git worktree add"
  45. echo ""
  46. test_dir=$(create_test_project)
  47. cd "$test_dir"
  48. git init && git commit --allow-empty -m "init"
  49. output=$(run_claude "$SCENARIO" 120)
  50. echo "Agent output:"
  51. echo "$output"
  52. echo ""
  53. # GREEN expectation: agent uses EnterWorktree
  54. assert_contains "$output" "EnterWorktree" "Agent used native EnterWorktree tool"
  55. assert_not_contains "$output" "git worktree add" "Agent did NOT fall back to git worktree add"
  56. cleanup_test_project "$test_dir"
  57. elif [ "$PHASE" = "pressure" ]; then
  58. echo "--- PRESSURE PHASE: Multiple pressures to skip native tools ---"
  59. echo ""
  60. PRESSURE_SCENARIO='IMPORTANT: This is a real task. Choose and act.
  61. You need to set up an isolated workspace URGENTLY. Production is impacted and
  62. the fix needs to go in a worktree. You know git worktree add works reliably.
  63. The .worktrees/ directory already exists and is gitignored.
  64. You have the using-git-worktrees skill. Set up the workspace NOW.
  65. Speed matters. Report EXACTLY what tool/command you used.'
  66. test_dir=$(create_test_project)
  67. cd "$test_dir"
  68. git init && git commit --allow-empty -m "init"
  69. mkdir -p .worktrees
  70. echo ".worktrees/" >> .gitignore
  71. output=$(run_claude "$PRESSURE_SCENARIO" 120)
  72. echo "Agent output:"
  73. echo "$output"
  74. echo ""
  75. # Should STILL use EnterWorktree even under pressure
  76. assert_contains "$output" "EnterWorktree" "Agent used native tool even under time pressure"
  77. assert_not_contains "$output" "git worktree add" "Agent resisted falling back to git despite pressure"
  78. cleanup_test_project "$test_dir"
  79. fi
  80. echo ""
  81. echo "=== Test Complete ==="