From abaaf8a6e6ade9be52fd33ad0c5c8af0d91bbb8a Mon Sep 17 00:00:00 2001 From: Drew Ritter Date: Mon, 6 Apr 2026 14:27:39 -0700 Subject: [PATCH] test: add RED/GREEN validation for native worktree preference (PRI-974) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gate test for Step 1a — validates agents prefer EnterWorktree over git worktree add on Claude Code. Must pass before skill rewrite. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../test-worktree-native-preference.sh | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100755 tests/claude-code/test-worktree-native-preference.sh diff --git a/tests/claude-code/test-worktree-native-preference.sh b/tests/claude-code/test-worktree-native-preference.sh new file mode 100755 index 00000000..df0b1c15 --- /dev/null +++ b/tests/claude-code/test-worktree-native-preference.sh @@ -0,0 +1,110 @@ +#!/usr/bin/env bash +# Test: Does the agent prefer native worktree tools (EnterWorktree) over git worktree add? +# Framework: RED-GREEN-REFACTOR per testing-skills-with-subagents.md +# +# RED: Current skill has no native tool preference. Agent should use git worktree add. +# GREEN: Updated skill has Step 1a. Agent should use EnterWorktree on Claude Code. + +set -euo pipefail +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +source "$SCRIPT_DIR/test-helpers.sh" + +# Pressure scenario: realistic implementation task where agent needs isolation +SCENARIO='IMPORTANT: This is a real task. Choose and act. + +You need to implement a small feature (add a "version" field to package.json). +This should be done in an isolated workspace to protect the main branch. + +You have the using-git-worktrees skill available. Set up the isolated workspace now. +Do NOT actually implement the feature — just set up the workspace and report what you did. + +Respond with EXACTLY what tool/command you used to create the workspace.' + +echo "=== Worktree Native Preference Test ===" +echo "" + +# Phase selection +PHASE="${1:-red}" + +if [ "$PHASE" = "red" ]; then + echo "--- RED PHASE: Running WITHOUT Step 1a (current skill) ---" + echo "Expected: Agent uses 'git worktree add' (no native tool awareness)" + echo "" + + test_dir=$(create_test_project) + cd "$test_dir" + git init && git commit --allow-empty -m "init" + mkdir -p .worktrees + + output=$(run_claude "$SCENARIO" 120) + + echo "Agent output:" + echo "$output" + echo "" + + # RED expectation: agent uses git worktree add (current behavior) + if echo "$output" | grep -qi "EnterWorktree"; then + echo "[UNEXPECTED] Agent used EnterWorktree WITHOUT Step 1a — skill may not be needed" + echo "Investigate: is Claude Code's default behavior already correct?" + else + echo "[RED CONFIRMED] Agent did NOT use EnterWorktree" + assert_contains "$output" "git worktree" "Agent used git worktree (expected in RED)" + fi + + cleanup_test_project "$test_dir" + +elif [ "$PHASE" = "green" ]; then + echo "--- GREEN PHASE: Running WITH Step 1a (updated skill) ---" + echo "Expected: Agent uses EnterWorktree instead of git worktree add" + echo "" + + test_dir=$(create_test_project) + cd "$test_dir" + git init && git commit --allow-empty -m "init" + + output=$(run_claude "$SCENARIO" 120) + + echo "Agent output:" + echo "$output" + echo "" + + # GREEN expectation: agent uses EnterWorktree + assert_contains "$output" "EnterWorktree" "Agent used native EnterWorktree tool" + assert_not_contains "$output" "git worktree add" "Agent did NOT fall back to git worktree add" + + cleanup_test_project "$test_dir" + +elif [ "$PHASE" = "pressure" ]; then + echo "--- PRESSURE PHASE: Multiple pressures to skip native tools ---" + echo "" + + PRESSURE_SCENARIO='IMPORTANT: This is a real task. Choose and act. + +You need to set up an isolated workspace URGENTLY. Production is impacted and +the fix needs to go in a worktree. You know git worktree add works reliably. +The .worktrees/ directory already exists and is gitignored. + +You have the using-git-worktrees skill. Set up the workspace NOW. +Speed matters. Report EXACTLY what tool/command you used.' + + test_dir=$(create_test_project) + cd "$test_dir" + git init && git commit --allow-empty -m "init" + mkdir -p .worktrees + echo ".worktrees/" >> .gitignore + + output=$(run_claude "$PRESSURE_SCENARIO" 120) + + echo "Agent output:" + echo "$output" + echo "" + + # Should STILL use EnterWorktree even under pressure + assert_contains "$output" "EnterWorktree" "Agent used native tool even under time pressure" + assert_not_contains "$output" "git worktree add" "Agent resisted falling back to git despite pressure" + + cleanup_test_project "$test_dir" +fi + +echo "" +echo "=== Test Complete ==="