fix(tests): exclude build/ from bats test discovery
Why tests/run-bats.sh's discovery walk already excludes apm_modules/ and .claude/skills/ because those hold apm-installed copies of the same *.bats files one directory level shallower than their plugins/*/.apm/ source, which overshoots the hardcoded six-levels-up REPO_ROOT walk each test's setup() does and fails to find the bats-support helper. build/ was missing the same exclusion: apm pack stages an identical copy under build/<package>-<version>/ before archiving, hitting the exact same failure mode from a different apm subcommand. A stray local `apm pack` run leaves that directory on disk (gitignored, regenerable) and silently doubles the suite (846 tests instead of 423) with 423 of them failing. Implementation Notes Added `-not -path "*/build/*"` to the find walk and the matching git ls-files grep exclusion, mirroring the existing apm_modules/ and .claude/skills/ entries. Extended tests/test-run-bats.sh with a case following the same pattern as the existing exclusion-bug fixtures. Impact Unblocks the run-tests pre-commit/pre-push hook for any checkout that has ever run a bare `apm pack` locally.
This commit is contained in:
@@ -476,6 +476,40 @@ else
|
||||
fail "the plan-shortfall run failed with the wrong count: $FAKE_OUT"
|
||||
fi
|
||||
|
||||
# --- 12. A build/ directory (apm pack's staging output) is excluded, the same
|
||||
# way apm_modules/ and .claude/skills/ above are. A stray local `apm pack` run
|
||||
# leaves build/<pkg>-<version>/ on disk holding a full copy of every packaged
|
||||
# skill's tests/ directory, gitignored and regenerable, but discoverable by a
|
||||
# bare `find` all the same. Those staged .bats files carry the same
|
||||
# several-levels-up REPO_ROOT walk-up as any other copy, which overshoots this
|
||||
# fixture's root, so an unexcluded build/ turns into the same
|
||||
# bats-support-not-found failure apm_modules/ and .claude/skills/ already guard
|
||||
# against -- this was caught live with 423 duplicate failures against a real
|
||||
# checkout holding a stray build/holocron-*/ from an earlier `apm pack`.
|
||||
echo ""
|
||||
echo "--- a build/ directory holding staged .bats copies is excluded ---"
|
||||
DIR12="$(make_fake_repo)"
|
||||
FIXTURES+=("$DIR12")
|
||||
seed_bats_files "$DIR12"
|
||||
mkdir -p "$DIR12/build/some-pkg-1.0.0/tests"
|
||||
printf '@test "staged" { false; }\n' > "$DIR12/build/some-pkg-1.0.0/tests/staged.bats"
|
||||
install_stub_bats "$DIR12" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
echo "1..1"
|
||||
echo "ok 1 first"
|
||||
exit 0
|
||||
EOF
|
||||
run_fake "$DIR12"
|
||||
if [[ $FAKE_RC -ne 0 ]]; then
|
||||
fail "a tree holding a build/ directory failed the run: $FAKE_OUT"
|
||||
elif grep -q "build/some-pkg-1.0.0" <<< "$FAKE_OUT"; then
|
||||
fail "a .bats file staged under build/ was discovered and run: $FAKE_OUT"
|
||||
elif grep -q "^2 tests, 0 failures$" <<< "$FAKE_OUT"; then
|
||||
pass "a build/ directory's staged .bats copies are excluded from discovery"
|
||||
else
|
||||
fail "the build/-exclusion run passed with an unexpected count: $FAKE_OUT"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Results: $PASS passed, $FAIL failed"
|
||||
[[ $FAIL -eq 0 ]]
|
||||
|
||||
Reference in New Issue
Block a user