test(bats): filter _acq_coreutils_path to absolute dirs, assert absence premise - #397
Conversation
…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.
wz-gsa
left a comment
There was a problem hiding this comment.
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).
|
Closes #396 |
Context
Follow-up to #392 (merged). Review feedback on the
_acq_coreutils_pathtest helper introduced there:This is the small follow-up in the spirit of #393's repair of vacuous assertions.
Plan / Changes
test/bats/helper.bash—_acq_coreutils_pathnow skips anycommand -vresult that is not absolute (/-prefixed) before taking itsdirname. Shell builtins likeprintfresolve to a bare name whosedirnameis., 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
Rollback
Revert this commit; the helper returns to unioning all
command -vdirnames.Security Impact
None. Test-only change; hardens a test premise. No runtime/auth/data-handling surface.
AI-assisted (OpenCode).