Uh oh!
There was an error while loading. Please reload this page.
fix(test): make install_docker_engine os-release detection mockable so setup-linux.bats passes on macOS - #233
Merged
Conversation
…232) The Amazon Linux and AlmaLinux/Rocky branches of install_docker_engine gated on `[[ -f /etc/os-release ]] && grep ... /etc/os-release`. The bats suite mocks `grep`, but a bash builtin file-test can't be intercepted by a function mock — so on macOS (no /etc/os-release) both branches short-circuited and the two install_docker_engine distro tests fell through to the get.docker.com path and failed. CI was green because unit-bash runs on ubuntu. Read the os-release path from `${TB_OS_RELEASE_FILE:-/etc/os-release}` for both the file-test and the grep. The bats setup() now writes a real os-release fixture per $TEST_DISTRO to a temp file and exports TB_OS_RELEASE_FILE, so distro detection runs for real (real `[[ -f ]]` + real `grep`) on every dev host. Behaviour is unchanged when the env var is unset (production / Linux CI). All 20 tests in scripts/tests/setup-linux.bats now pass on macOS. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
aptracebloc
approved these changes
Jun 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes#232.
Problem
Two
batstests inscripts/tests/setup-linux.batsfailed on macOS dev hosts (green in CI on Linux):install_docker_engine: Amazon Linux -> dnf dockerinstall_docker_engine: RHEL clone (#719) -> docker-ce dnf repoinstall_docker_engine()gated the Amazon Linux and AlmaLinux/Rocky branches on[[ -f /etc/os-release ]] && grep -qi ... /etc/os-release. The suite mocksgrep, but a bash builtin file-test ([[ -f /etc/os-release ]]) can't be intercepted by a function mock. On macOS/etc/os-releasedoesn't exist, so both branches short-circuited and the function fell through to the get.docker.com path — the asserted strings were never recorded. The pacman/zypper/ubuntu branches passed because they gate onhas <cmd>(mockable viaPRESENT_CMDS).CI was unaffected:
unit-bashruns on ubuntu (os-release present), and the real RHEL/Amazon docker paths are independently exercised by thedistro-prereqsmatrix in actual almalinux/amazonlinux containers.Fix
scripts/lib/setup-linux.sh—install_docker_enginereads the os-release path from${TB_OS_RELEASE_FILE:-/etc/os-release}, used for both the[[ -f ]]test and thegrep. Defaults to the exact prior behaviour when the env var is unset (production / CI).scripts/tests/setup-linux.bats—setup()writes a real os-release fixture per$TEST_DISTROto a temp file and exportsTB_OS_RELEASE_FILE. This replaces the oldgrepmock, so distro detection (real[[ -f ]]+ realgrep) is exercised on every dev host — keeping the coverage meaningful on macOS rather than skipping it.Verification
bats scripts/tests/setup-linux.bats→ 20/20 pass on macOS (was 18/20).grep(ugrep 7.5.0) and stock/usr/bin/grep(BSD grep 2.6.0-FreeBSD, GNU-compatible) — the\|BRE and ERE alternations both match, so real grep is robust across macOS dev hosts.TB_OS_RELEASE_FILEis unset.🤖 Generated with Claude Code
Note
Low Risk
Test-only hook with default path unchanged; no change to installer behavior when TB_OS_RELEASE_FILE is unset.
Overview
Fixes macOS failures in
setup-linux.batsfor Amazon Linux and AlmaLinux Docker install paths by making os-release detection testable without mocking bash[[ -f ]].install_docker_enginenow reads the os-release path fromTB_OS_RELEASE_FILE(default/etc/os-release), used for both the file existence check andgrepdistro matching. Unset env var keeps production/CI behavior unchanged.The bats
setup()drops thegrepmock and addswrite_os_release, which writes a temp fixture perTEST_DISTROand exportsTB_OS_RELEASE_FILE. Amazon and RHEL-clone tests callwrite_os_releaseso real[[ -f ]]+grepexercise the intended branches on hosts without/etc/os-release.Reviewed by Cursor Bugbot for commit 2c1d6da. Bugbot is set up for automated code reviews on this repo. Configure here.