Skip to content

test(bats): filter _acq_coreutils_path to absolute dirs, assert absence premise - #397

Merged
mogul merged 3 commits into
mainfrom
test/coreutils-path-absolute-filter
Aug 27, 2026
Merged

test(bats): filter _acq_coreutils_path to absolute dirs, assert absence premise#397
mogul merged 3 commits into
mainfrom
test/coreutils-path-absolute-filter

Conversation

@mogul

@mogul mogul commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Context

Follow-up to #392 (merged). Review feedback on the _acq_coreutils_path test helper introduced there:

_acq_coreutils_path still unions dirname of 12 tools without filtering non-absolute entries — command -v printf hits the builtin and yields ., so the current directory ends up on the "just coreutils" PATH (reproduced: a stray msb file in the CWD becomes callable). And on a Homebrew-coreutils host the union pulls in /opt/homebrew/bin — the same dir as msb/sbx — so the test meant to prove "the backend CLI is provably absent" can silently have it present. Filter to absolute paths, and assert the premise (command -v msb; assert_failure).

This is the small follow-up in the spirit of #393's repair of vacuous assertions.

Plan / Changes

  • test/bats/helper.bash_acq_coreutils_path now skips any command -v result that is not absolute (/-prefixed) before taking its dirname. Shell builtins like printf resolve to a bare name whose dirname is ., which would otherwise put the CWD on the narrowed PATH.
  • test/bats/20-backend-resolution.bats — the self-repair test now asserts its premise: after narrowing PATH to coreutils, run command -v msb; assert_failure. If the narrowed PATH ever exposes the backend, the test fails loudly instead of passing hollowly.

Verification

$ ./scripts/test-acq-bats
... 1..345 all ok (exit 0)

$ ./scripts/test-acq-bats test/bats/20-backend-resolution.bats
1..10 ... ok 9 self-repair: backend in ~/.local/bin is detected + hinted (premise now asserted)

$ shellcheck --severity=warning test/bats/helper.bash
(clean)

Rollback

Revert this commit; the helper returns to unioning all command -v dirnames.

Security Impact

None. Test-only change; hardens a test premise. No runtime/auth/data-handling surface.

AI-assisted (OpenCode).

…ce premise

_acq_coreutils_path unioned dirname of `command -v <tool>` for 12 tools without
filtering non-absolute results. `command -v printf` resolves to the shell
builtin (a bare name), so `dirname` yielded "." — putting the current directory
on the narrowed "just coreutils" PATH. A stray file in the CWD then became
callable, and on a Homebrew-coreutils host the union also pulled in
/opt/homebrew/bin (the same dir as msb/sbx), so the "backend provably absent"
test could silently have the backend present.

- Skip any `command -v` result that is not absolute (/-prefixed) before taking
  its dirname, so builtins never contribute "." to PATH.
- Assert the premise in the self-repair test: `run command -v msb;
  assert_failure` so it fails loudly if the narrowed PATH ever exposes the
  backend, rather than passing hollowly.
@mogul
mogul requested a review from a team as a code owner August 25, 2026 21:42

@wz-gsa wz-gsa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adversarial review — LGTM, verified both fixes directly

This is the follow-up I filed as #396; both asks are addressed correctly.

Fix 1 (. on PATH): ran the patched `_acq_coreutils_path` on this host — before: `…:/bin:/usr/bin:.`; after: `/Users/…/.local/bin:/bin:/usr/bin`, no `.` entry. Confirmed the filter is surgical, not overbroad: real tools (`cat`/`rm`/`mkdir`) still resolve correctly from the narrowed PATH afterward — it drops only the builtin-derived bare name (`printf` → `.`), nothing else.

Fix 2 (assert the premise): `run command -v msb; assert_failure` is placed at the one call site whose premise depends on it (`self-repair: backend in ~/.local/bin is detected + hinted`) — correctly NOT added to the sibling `does not shadow a system backend already on PATH` test, which deliberately puts a backend on PATH.

Test-only change, no runtime/auth surface. `case "$_d" in /*) ;; *) continue ;; esac` is portable POSIX glob matching, no bashisms. Approve.

One housekeeping note: this closes #396 but doesn't reference it — worth adding `Closes #396` (or I'll close it manually once this merges).

AI-assisted (OpenCode).

@mogul

mogul commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

Closes #396

@mogul
mogul enabled auto-merge (squash) August 27, 2026 00:27
@mogul
mogul merged commit d05108a into main Aug 27, 2026
3 checks passed
@mogul
mogul deleted the test/coreutils-path-absolute-filter branch August 27, 2026 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants