1 Commits
Author SHA1 Message Date
Defame1297andClaude Opus 5.5 bc7673d4f0 fix(scripts): discover agents when the checkout is a Claude worktree
check-apm-agents-valid.sh filtered find output with
`-not -path '*/.claude/worktrees/*'`, matched against absolute paths.
When the checkout itself lives at <repo>/.claude/worktrees/<name>/,
every path contains that segment, so every agent file was excluded
and the gate reported "N of N tracked agent files were not discovered".

The walk starts at $REPO_ROOT/plugins, so a nested worktree is
unreachable and the filter is dropped. The test suite gains a case that
runs the gate from a fixture under .claude/worktrees/, and now unsets
inherited GIT_* variables so its git fixtures never resolve to the
caller's repository.

Fixes #199

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-11-26 22:31:05 +00:00
2 changed files with 40 additions and 3 deletions

No files matched your search

+6 -3
View File
@@ -58,15 +58,18 @@ if ! command -v python3 >/dev/null 2>&1; then
fi fi
# --- Discover the agent files --- # --- Discover the agent files ---
# `-not -path` mirrors tests/run-bats.sh: worktrees under .claude/ are other # No `.claude/worktrees` exclusion, unlike tests/run-bats.sh: the walk starts at
# checkouts of this same repo, not additional content. # $REPO_ROOT/plugins, so a worktree nested at $REPO_ROOT/.claude/worktrees/ is
# unreachable and there is nothing to exclude. A `-not -path` glob here would
# match against ABSOLUTE paths, and when this checkout is itself a Claude
# worktree (<repo>/.claude/worktrees/<name>/) every path contains that segment,
# so it excluded every agent file and failed the derived check below (#199).
AGENT_FILES=() AGENT_FILES=()
while IFS= read -r f; do while IFS= read -r f; do
[[ -n "$f" ]] && AGENT_FILES+=("$f") [[ -n "$f" ]] && AGENT_FILES+=("$f")
done < <( done < <(
find "$REPO_ROOT/plugins" -type f -name '*.agent.md' \ find "$REPO_ROOT/plugins" -type f -name '*.agent.md' \
-path '*/.apm/agents/*' \ -path '*/.apm/agents/*' \
-not -path '*/.claude/worktrees/*' \
2>/dev/null | sort 2>/dev/null | sort
) )
+34
View File
@@ -17,6 +17,12 @@ set -euo pipefail
# defect it exists to close — so the clean run's own count is asserted against # defect it exists to close — so the clean run's own count is asserted against
# the index rather than taken on trust. # the index rather than taken on trust.
# Fixtures below run `git init`/`git commit` in temp dirs. Under a git hook,
# git exports GIT_DIR (and can export GIT_WORK_TREE / GIT_INDEX_FILE), which
# would point every `git -C "$fixture"` at THIS repo instead (see
# tests/run-tests.sh). Never inherit the caller's repository.
unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE GIT_OBJECT_DIRECTORY GIT_COMMON_DIR
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
SCRIPT="$REPO_ROOT/scripts/check-apm-agents-valid.sh" SCRIPT="$REPO_ROOT/scripts/check-apm-agents-valid.sh"
PASS=0 PASS=0
@@ -277,6 +283,34 @@ else
pass "a missing validate.sh exits 1 and names the stale path" pass "a missing validate.sh exits 1 and names the stale path"
fi fi
# --- 8. A checkout that itself sits under .claude/worktrees/ discovers its agents ---
# A Claude Code worktree lives at <repo>/.claude/worktrees/<name>/, so every
# absolute path the script sees contains /.claude/worktrees/. A filter matched
# against that absolute path excluded every agent file and the gate reported
# "N of N tracked agent file(s) were not discovered" (#199).
echo ""
echo "--- a checkout under .claude/worktrees/ discovers its own agent files ---"
FIX8_PARENT="$(make_fixture)"
FIXTURES+=("$FIX8_PARENT")
FIX8="$FIX8_PARENT/.claude/worktrees/agent-x"
mkdir -p "$FIX8"
mv "$FIX8_PARENT/plugins" "$FIX8/plugins"
git -C "$FIX8" init -q
git -C "$FIX8" add -A
git -C "$FIX8" -c user.email=[email protected] -c user.name=t commit -qm "fixture"
if ! bash "$SCRIPT" "$FIX8" > "$RUN_TMP/worktree.out" 2>&1; then
fail "a checkout under .claude/worktrees/ failed — its own agent files were excluded"
sed 's/^/ /' "$RUN_TMP/worktree.out"
elif grep -q 'not a git worktree root' "$RUN_TMP/worktree.out"; then
fail "the fixture did not resolve as its own git worktree root, so the derived check never ran"
sed 's/^/ /' "$RUN_TMP/worktree.out"
elif ! grep -q 'APM agent validation passed: 1 plugin-scope' "$RUN_TMP/worktree.out"; then
fail "a checkout under .claude/worktrees/ passed but did not validate its one agent file"
sed 's/^/ /' "$RUN_TMP/worktree.out"
else
pass "a checkout under .claude/worktrees/ discovers and validates its own agent file"
fi
echo "" echo ""
echo "Results: $PASS passed, $FAIL failed" echo "Results: $PASS passed, $FAIL failed"
[[ $FAIL -eq 0 ]] [[ $FAIL -eq 0 ]]