fix(tests): make runner worktree exclusions relative to the search root

Both runners excluded */.claude/worktrees/* by absolute path, which
filtered out every test when the repo itself is a Claude worktree.
Search from inside the root so only nested worktrees are skipped.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-16 15:27:25 +00:00
parent 8ce539238c
commit 7380bed6da
4 changed files with 87 additions and 8 deletions

View File

@@ -45,8 +45,8 @@ trap cleanup EXIT
# substitution's subshell and be lost. Registration is the caller's job. Same
# convention as tests/test-run-bats.sh.
make_fake_repo() {
local dir
dir="$(mktemp -d)"
local dir="${1:-}"
[[ -n "$dir" ]] || dir="$(mktemp -d)"
mkdir -p "$dir/tests" "$dir/scripts/lib" "$dir/cases"
cp "$REPO_ROOT/scripts/lib/batch-run.sh" "$dir/scripts/lib/batch-run.sh"
cp "$RUN_TESTS" "$dir/tests/run-tests.sh"
@@ -670,6 +670,39 @@ else
pass "--strict and RUN_TESTS_STRICT=1 both dispatch children with RUN_TESTS_STRICT absent"
fi
# --- A search root that itself sits under .claude/worktrees/ still runs. The
# worktree exclusion used to match the absolute path, so every suite in a Claude
# worktree (<repo>/.claude/worktrees/<name>/) was filtered out. It is now
# relative to the search root, so a worktree nested BELOW the root is still
# skipped.
echo ""
echo "--- a root under .claude/worktrees/ discovers its own suites and still skips nested worktrees ---"
WT_PARENT="$(mktemp -d)"
FIXTURES+=("$WT_PARENT")
WT_DIR="$WT_PARENT/repo/.claude/worktrees/agent-x"
make_fake_repo "$WT_DIR" >/dev/null
install_healthy_bats_runner "$WT_DIR"
add_case "$WT_DIR" test-own.sh <<'EOF'
#!/usr/bin/env bash
echo "own suite ran"
EOF
mkdir -p "$WT_DIR/cases/.claude/worktrees/nested"
cat > "$WT_DIR/cases/.claude/worktrees/nested/test-nested.sh" <<'EOF'
#!/usr/bin/env bash
echo "nested suite ran"
exit 1
EOF
run_fake "$WT_DIR"
if [[ $FAKE_RC -ne 0 ]]; then
fail "a root under .claude/worktrees/ failed: $FAKE_OUT"
elif ! grep -q "own suite ran" <<< "$FAKE_OUT"; then
fail "a root under .claude/worktrees/ did not run its own suite: $FAKE_OUT"
elif grep -q "nested suite ran" <<< "$FAKE_OUT"; then
fail "a worktree nested below the root was discovered and run: $FAKE_OUT"
else
pass "a root under .claude/worktrees/ runs its own suites and skips nested worktrees"
fi
echo ""
echo "Results: $PASS passed, $FAIL failed"
[[ $FAIL -eq 0 ]]