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

@@ -43,8 +43,8 @@ trap cleanup EXIT
# invokes it as `$(make_fake_repo)`, and an append made in here would land in the
# command substitution's subshell and be lost. Registration is the caller's job.
make_fake_repo() {
local dir
dir="$(mktemp -d)"
local dir="${1:-}"
[[ -n "$dir" ]] || dir="$(mktemp -d)"
mkdir -p "$dir/tests" "$dir/scripts/lib"
cp "$REPO_ROOT/scripts/lib/batch-run.sh" "$dir/scripts/lib/batch-run.sh"
cp "$RUN_BATS" "$dir/tests/run-bats.sh"
@@ -410,6 +410,40 @@ else
fail "the run failed but not with the zero-files message: $FAKE_OUT"
fi
# --- 10. A repo root that itself sits under .claude/worktrees/ still runs. The
# worktree exclusion used to match the absolute path, so a Claude worktree --
# which lives at <repo>/.claude/worktrees/<name>/ -- excluded every file of its
# own and failed with "N of N tracked .bats file(s) were not discovered". The
# exclusion is now relative to the root, so a worktree nested BELOW the root is
# still skipped.
echo ""
echo "--- a root under .claude/worktrees/ discovers its own files and still skips nested worktrees ---"
WT_PARENT="$(mktemp -d)"
FIXTURES+=("$WT_PARENT")
DIR10="$WT_PARENT/repo/.claude/worktrees/agent-x"
make_fake_repo "$DIR10" >/dev/null
git -C "$DIR10" init -q
seed_bats_files "$DIR10"
mkdir -p "$DIR10/.claude/worktrees/nested/tests"
printf '@test "n" { false; }\n' > "$DIR10/.claude/worktrees/nested/tests/n.bats"
install_stub_bats "$DIR10" <<'EOF'
#!/usr/bin/env bash
echo "1..1"
echo "ok 1 first"
exit 0
EOF
git -C "$DIR10" add tests/a.bats tests/b.bats
run_fake "$DIR10"
if [[ $FAKE_RC -ne 0 ]]; then
fail "a root under .claude/worktrees/ failed — its own files were excluded: $FAKE_OUT"
elif ! grep -q "^=== tests/a.bats ===$" <<< "$FAKE_OUT"; then
fail "a root under .claude/worktrees/ did not run its own tests/a.bats: $FAKE_OUT"
elif grep -q "nested/tests/n.bats" <<< "$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 files and skips nested worktrees"
fi
echo ""
echo "Results: $PASS passed, $FAIL failed"
[[ $FAIL -eq 0 ]]