Skip to content

lint: catch setup_suite PATH rewrites that hide Bats libexec #55

Description

@junior-ricon

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:

  1. call mise env or otherwise clearly evaluate tool-manager env that can rewrite PATH; and
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions