Problem
BATS 1.13.0 can fail before running any tests when test/setup_suite.bash mutates PATH after Bats has started.
The common KKL pattern is:
setup_suite() {
REPO_DIR="$(cd "$BATS_TEST_DIRNAME/.." && pwd)"
export REPO_DIR
eval "$(cd "$REPO_DIR" && mise env)"
}
mise env may rebuild PATH and drop Bats' libexec directory. Bats 1.13.0 then calls bats-exec-file by bare name from bats-exec-suite, producing:
bats-exec-suite: line 323: bats-exec-file: command not found
# bats warning: Executed 0 instead of expected N tests
This showed up in KnickKnackLabs/template after copying the skeleton into a workbench and running mise run test locally.
Related upstream fix: bats-core/bats-core#1209
Current local workaround
Preserve Bats' libexec path across mise env:
setup_suite() {
REPO_DIR="$(cd "$BATS_TEST_DIRNAME/.." && pwd)"
export REPO_DIR
bats_libexec="${BATS_LIBEXEC:-}"
eval "$(cd "$REPO_DIR" && mise env)"
if [ -n "$bats_libexec" ]; then
export PATH="$bats_libexec:$PATH"
fi
}
This pattern already existed in KnickKnackLabs/emails; it was ported to KnickKnackLabs/template in 40be222.
Proposed lint
Add a codebase lint rule that flags test/setup_suite.bash files that:
- call
mise env or otherwise clearly evaluate tool-manager env that can rewrite PATH; and
- do not preserve
BATS_LIBEXEC across that call.
Possible rule name: bats-setup-suite-path or bats-libexec-preserved.
Suggested fixtures
Passing:
- setup suite with no
mise env / no PATH rewrite;
- setup suite that saves
${BATS_LIBEXEC:-} before mise env and prepends it afterward;
- no
test/setup_suite.bash.
Failing:
- current old template shape:
eval "$(cd "$REPO_DIR" && mise env)" with no BATS_LIBEXEC preservation.
Notes
When upstream Bats releases the fix and KKL repos move past Bats 1.13.0, this rule may become less necessary. Until then, the lint would prevent template-seeded repos from inheriting a known local/macOS failure mode.
Problem
BATS 1.13.0 can fail before running any tests when
test/setup_suite.bashmutatesPATHafter Bats has started.The common KKL pattern is:
mise envmay rebuildPATHand drop Bats' libexec directory. Bats 1.13.0 then callsbats-exec-fileby bare name frombats-exec-suite, producing:This showed up in
KnickKnackLabs/templateafter copying the skeleton into a workbench and runningmise run testlocally.Related upstream fix: bats-core/bats-core#1209
Current local workaround
Preserve Bats' libexec path across
mise env:This pattern already existed in
KnickKnackLabs/emails; it was ported toKnickKnackLabs/templatein40be222.Proposed lint
Add a codebase lint rule that flags
test/setup_suite.bashfiles that:mise envor otherwise clearly evaluate tool-manager env that can rewritePATH; andBATS_LIBEXECacross that call.Possible rule name:
bats-setup-suite-pathorbats-libexec-preserved.Suggested fixtures
Passing:
mise env/ no PATH rewrite;${BATS_LIBEXEC:-}beforemise envand prepends it afterward;test/setup_suite.bash.Failing:
eval "$(cd "$REPO_DIR" && mise env)"with noBATS_LIBEXECpreservation.Notes
When upstream Bats releases the fix and KKL repos move past Bats 1.13.0, this rule may become less necessary. Until then, the lint would prevent template-seeded repos from inheriting a known local/macOS failure mode.