From e3aedce6057e22ddf4e037a27f75b64b34f2a5b0 Mon Sep 17 00:00:00 2001 From: Ramesh Padmanabhaiah Date: Wed, 1 Jul 2026 00:29:30 -0700 Subject: [PATCH] Add BASE_PLATFORM runtime metadata --- README.md | 2 +- STANDARDS.md | 7 +- base_init.sh | 38 ++++++++- bin/base-test | 2 + .../commands/basectl/tests/completions.bats | 2 +- .../basectl/tests/update-profile.bats | 21 ++--- docs/architecture.md | 2 +- docs/execution-model.md | 2 +- docs/linux-support.md | 9 ++- docs/runtime-environment.md | 3 +- docs/technical-overview.md | 3 +- lib/shell/baserc_guard.sh | 1 + lib/shell/zsh_baserc_guard.zsh | 1 + tests/base_init.bats | 80 ++++++++++++++++++- tests/test_helper.sh | 2 + 15 files changed, 150 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index c48705eb..807b78d3 100644 --- a/README.md +++ b/README.md @@ -1275,7 +1275,7 @@ contract and mutability policy. `~/.baserc` must not set Base-owned runtime or profile variables such as `BASE_HOME`, `BASE_BIN_DIR`, `BASE_LIB_DIR`, `BASE_BASH_LIBS_DIR`, -`BASE_BASH_LIBS_SOURCE`, `BASE_OS`, `BASE_SHELL`, +`BASE_BASH_LIBS_SOURCE`, `BASE_OS`, `BASE_PLATFORM`, `BASE_SHELL`, `BASE_PLATFORM_TOOLS_HOME`, `BASE_PLATFORM_TOOLS_BIN_DIR`, `BASE_PROFILE_VERSION`, `BASE_ENABLE_BASH_DEFAULTS`, or `BASE_ENABLE_ZSH_DEFAULTS`. Base startup snippets reject and restore those diff --git a/STANDARDS.md b/STANDARDS.md index bf2125bc..a6a86392 100644 --- a/STANDARDS.md +++ b/STANDARDS.md @@ -110,7 +110,8 @@ call Base's Python layer. - constants - globals intentionally shared across scripts, sourced modules, or subshells 4. Use a common prefix for exported environment variables whenever practical. - For example: `BASE_HOME`, `BASE_HOST`, `BASE_OS`, `BASE_BASH_LIB_DIR`. + For example: `BASE_HOME`, `BASE_HOST`, `BASE_OS`, `BASE_PLATFORM`, + `BASE_BASH_LIB_DIR`. 5. Do not use all-uppercase names for ordinary script-local variables. 6. Use a leading underscore for private variables and functions, especially in libraries or sourced modules where internal names might otherwise collide. @@ -595,8 +596,8 @@ separate explicit opt-in instead of being added to `~/.baserc` is user-managed input for simple Base preferences such as `BASE_DEBUG=1`. It must not set Base-owned runtime or profile state such as -`BASE_HOME`, `BASE_BIN_DIR`, `BASE_LIB_DIR`, `BASE_OS`, `BASE_SHELL`, -`BASE_PROFILE_VERSION`, `BASE_ENABLE_BASH_DEFAULTS`, or +`BASE_HOME`, `BASE_BIN_DIR`, `BASE_LIB_DIR`, `BASE_OS`, `BASE_PLATFORM`, +`BASE_SHELL`, `BASE_PROFILE_VERSION`, `BASE_ENABLE_BASH_DEFAULTS`, or `BASE_ENABLE_ZSH_DEFAULTS`. Shell startup code that sources `~/.baserc` should reject attempts to change those variables and restore the previous values. diff --git a/base_init.sh b/base_init.sh index 79b14d32..2f3d3343 100755 --- a/base_init.sh +++ b/base_init.sh @@ -16,7 +16,7 @@ # - validate that the runtime is Bash 4.2 or newer # - derive or validate BASE_HOME # - export the BASE_* paths that downstream scripts may rely on -# - export BASE_OS and BASE_HOST runtime metadata +# - export BASE_OS, BASE_PLATFORM, and BASE_HOST runtime metadata # - resolve and source the reusable Bash standard library # - add BASE_BIN_DIR to PATH # - provide import_base_lib for convention-based Base Bash library imports @@ -75,6 +75,32 @@ base_init_require_bash() { fi } +base_init_linux_os_release_path() { + printf '%s\n' "${BASE_INIT_TEST_OS_RELEASE_PATH:-/etc/os-release}" +} + +base_init_detect_linux_platform() { + local id id_like os_release_path + local ID="" ID_LIKE="" + + os_release_path="$(base_init_linux_os_release_path)" || return 1 + if [[ -r "$os_release_path" ]]; then + # shellcheck source=/dev/null + source "$os_release_path" + fi + + id="${ID,,}" + id_like="${ID_LIKE,,}" + case " $id $id_like " in + *" ubuntu "*|*" debian "*) + printf 'linux-debian\n' + ;; + *) + printf 'linux-unknown\n' + ;; + esac +} + base_init_resolve_home() { local source_path local source_dir @@ -166,7 +192,7 @@ base_init_set_bash_libs_contract() { } base_init_export_contract() { - local base_home base_os base_host uname_os + local base_home base_os base_platform base_host uname_os base_home="$(base_init_resolve_home)" || return 1 uname_os="$(uname -s)" || { @@ -180,12 +206,15 @@ base_init_export_contract() { case "$uname_os" in Darwin) base_os=macos + base_platform=macos ;; Linux) base_os=linux + base_platform="$(base_init_detect_linux_platform)" || return 1 ;; *) base_os="$(printf '%s\n' "$uname_os" | tr '[:upper:]' '[:lower:]')" + base_platform="$base_os" ;; esac base_host="$(hostname -s)" || { @@ -207,12 +236,13 @@ base_init_export_contract() { base_init_set_bash_libs_contract || return 1 BASE_SHELL_DIR="$BASE_LIB_DIR/shell" BASE_OS="$base_os" + BASE_PLATFORM="$base_platform" BASE_HOST="$base_host" BASE_SHELL="${BASE_SHELL:-bash}" export BASE_HOME BASE_BIN_DIR BASE_CLI_DIR BASE_BASH_DIR BASE_BASH_COMMANDS_DIR - export BASE_LIB_DIR BASE_BASH_LIB_DIR BASE_BASH_LIBS_DIR BASE_BASH_LIBS_SOURCE BASE_SHELL_DIR BASE_OS BASE_HOST BASE_SHELL + export BASE_LIB_DIR BASE_BASH_LIB_DIR BASE_BASH_LIBS_DIR BASE_BASH_LIBS_SOURCE BASE_SHELL_DIR BASE_OS BASE_PLATFORM BASE_HOST BASE_SHELL readonly BASE_HOME BASE_BIN_DIR BASE_CLI_DIR BASE_BASH_DIR BASE_BASH_COMMANDS_DIR - readonly BASE_LIB_DIR BASE_BASH_LIB_DIR BASE_BASH_LIBS_DIR BASE_BASH_LIBS_SOURCE BASE_SHELL_DIR BASE_OS BASE_HOST BASE_SHELL + readonly BASE_LIB_DIR BASE_BASH_LIB_DIR BASE_BASH_LIBS_DIR BASE_BASH_LIBS_SOURCE BASE_SHELL_DIR BASE_OS BASE_PLATFORM BASE_HOST BASE_SHELL } base_init_source_stdlib() { diff --git a/bin/base-test b/bin/base-test index bd823c57..8571eba7 100755 --- a/bin/base-test +++ b/bin/base-test @@ -13,6 +13,7 @@ base_test_unset_env=( -u BASE_BASH_LIBS_SOURCE -u BASE_SHELL_DIR -u BASE_OS + -u BASE_PLATFORM -u BASE_HOST -u BASE_SHELL -u BASE_PLATFORM_TOOLS_HOME @@ -25,6 +26,7 @@ base_test_unset_env=( -u BASE_BASH_COMMAND_DIR -u BASE_BASH_COMMAND_SCRIPT -u BASE_BASH_BOOTSTRAP_SOURCE + -u BASE_INIT_TEST_OS_RELEASE_PATH -u BASE_PROJECT -u BASE_PROJECT_ROOT -u BASE_PROJECT_MANIFEST diff --git a/cli/bash/commands/basectl/tests/completions.bats b/cli/bash/commands/basectl/tests/completions.bats index db45e24c..35384794 100644 --- a/cli/bash/commands/basectl/tests/completions.bats +++ b/cli/bash/commands/basectl/tests/completions.bats @@ -22,7 +22,7 @@ EOF run_base_command update-profile [ "$status" -eq 0 ] - run env -u BASE_HOME -u BASE_HOST -u BASE_OS \ + run env -u BASE_HOME -u BASE_HOST -u BASE_OS -u BASE_PLATFORM \ HOME="$TEST_HOME" \ PATH="/usr/bin:/bin:/usr/sbin:/sbin" \ bash --rcfile "$TEST_HOME/.bashrc" -i -c '\ diff --git a/cli/bash/commands/basectl/tests/update-profile.bats b/cli/bash/commands/basectl/tests/update-profile.bats index 9c22b8e9..6b48052a 100644 --- a/cli/bash/commands/basectl/tests/update-profile.bats +++ b/cli/bash/commands/basectl/tests/update-profile.bats @@ -201,7 +201,7 @@ EOF run_base_command update-profile [ "$status" -eq 0 ] - run env -u BASE_HOME -u BASE_HOST -u BASE_OS \ + run env -u BASE_HOME -u BASE_HOST -u BASE_OS -u BASE_PLATFORM \ HOME="$TEST_HOME" \ PATH="/usr/bin:/bin:/usr/sbin:/sbin" \ bash --rcfile "$TEST_HOME/.bashrc" -i -c 'command -v basectl; printf "BASE_HOME=%s\n" "${BASE_HOME-unset}"' @@ -363,7 +363,7 @@ EOF run_base_command update-profile [ "$status" -eq 0 ] - run env -u BASE_HOME -u BASE_HOST -u BASE_OS \ + run env -u BASE_HOME -u BASE_HOST -u BASE_OS -u BASE_PLATFORM \ HOME="$TEST_HOME" \ BASE_DEBUG=1 \ PATH="/usr/bin:/bin:/usr/sbin:/sbin" \ @@ -381,7 +381,7 @@ EOF [ "$status" -eq 0 ] printf '%s\n' 'BASE_DEBUG=1' > "$TEST_HOME/.baserc" - run env -u BASE_HOME -u BASE_HOST -u BASE_OS -u BASE_DEBUG \ + run env -u BASE_HOME -u BASE_HOST -u BASE_OS -u BASE_PLATFORM -u BASE_DEBUG \ HOME="$TEST_HOME" \ PATH="/usr/bin:/bin:/usr/sbin:/sbin" \ bash --rcfile "$TEST_HOME/.bashrc" -i -c 'command -v basectl >/dev/null' @@ -397,7 +397,7 @@ EOF [ "$status" -eq 0 ] printf '%s\n' 'BASE_DEBUG=1' > "$TEST_HOME/.baserc" - run env -u BASE_HOME -u BASE_HOST -u BASE_OS -u BASE_DEBUG \ + run env -u BASE_HOME -u BASE_HOST -u BASE_OS -u BASE_PLATFORM -u BASE_DEBUG \ HOME="$TEST_HOME" \ PATH="/usr/bin:/bin:/usr/sbin:/sbin" \ bash --norc -i -c 'source "$HOME/.bash_profile"; command -v basectl; printf "BASE_HOME=%s\n" "${BASE_HOME-unset}"' @@ -418,7 +418,7 @@ EOF [ "$status" -eq 0 ] printf '%s\n' 'BASE_DEBUG=1' > "$TEST_HOME/.baserc" - run env -u BASE_HOME -u BASE_HOST -u BASE_OS -u BASE_DEBUG \ + run env -u BASE_HOME -u BASE_HOST -u BASE_OS -u BASE_PLATFORM -u BASE_DEBUG \ HOME="$TEST_HOME" \ PATH="/usr/bin:/bin:/usr/sbin:/sbin" \ zsh -f -i -c 'source "$HOME/.zprofile"; source "$HOME/.zshrc"; command -v basectl; printf "BASE_HOME=%s\n" "${BASE_HOME-unset}"' @@ -437,7 +437,7 @@ EOF [ "$status" -eq 0 ] printf '%s\n' 'BASE_HOME=/tmp/not-base' > "$TEST_HOME/.baserc" - run env -u BASE_HOME -u BASE_HOST -u BASE_OS -u BASE_DEBUG \ + run env -u BASE_HOME -u BASE_HOST -u BASE_OS -u BASE_PLATFORM -u BASE_DEBUG \ HOME="$TEST_HOME" \ PATH="/usr/bin:/bin:/usr/sbin:/sbin" \ bash --rcfile "$TEST_HOME/.bashrc" -i -c 'printf "BASE_HOME=%s\n" "${BASE_HOME-unset}"' @@ -461,6 +461,7 @@ EOF [[ "$output" == *"BASE_BASH_COMMAND_SCRIPT"* ]] [[ "$output" == *"BASE_PROJECT_ROOT"* ]] [[ "$output" == *"BASE_PROJECT_VENV_DIR"* ]] + [[ "$output" == *"BASE_PLATFORM"* ]] [[ "$output" == *"BASE_PLATFORM_TOOLS_HOME"* ]] [[ "$output" == *"BASE_PLATFORM_TOOLS_BIN_DIR"* ]] [[ "$output" != *"BASE_ARCH"* ]] @@ -472,7 +473,7 @@ EOF run_base_command update-profile [ "$status" -eq 0 ] - run env -u BASE_HOME -u BASE_HOST -u BASE_OS \ + run env -u BASE_HOME -u BASE_HOST -u BASE_OS -u BASE_PLATFORM \ HOME="$TEST_HOME" \ PATH="/usr/bin:/bin:/usr/sbin:/sbin" \ zsh -f -i -c 'source "$HOME/.zshrc"; command -v basectl; printf "BASE_HOME=%s\n" "${BASE_HOME-unset}"' @@ -537,7 +538,7 @@ EOF [ "$status" -eq 0 ] printf '%s\n' 'BASE_HOME=/tmp/not-base' > "$TEST_HOME/.baserc" - run env -u BASE_HOME -u BASE_HOST -u BASE_OS -u BASE_DEBUG \ + run env -u BASE_HOME -u BASE_HOST -u BASE_OS -u BASE_PLATFORM -u BASE_DEBUG \ HOME="$TEST_HOME" \ PATH="/usr/bin:/bin:/usr/sbin:/sbin" \ zsh -f -i -c 'source "$HOME/.zshrc"; printf "BASE_HOME=%s\n" "${BASE_HOME-unset}"' @@ -570,7 +571,7 @@ EOF [[ "$(cat "$TEST_HOME/.bashrc")" != *"defaults.sh"* ]] [[ "$(cat "$TEST_HOME/.zshrc")" != *"defaults.sh"* ]] - run env -u BASE_HOME -u BASE_HOST -u BASE_OS -u EDITOR -u VISUAL -u EXINIT \ + run env -u BASE_HOME -u BASE_HOST -u BASE_OS -u BASE_PLATFORM -u EDITOR -u VISUAL -u EXINIT \ -u HISTCONTROL -u HISTSIZE -u HISTFILESIZE \ -u PAGER -u LESS -u MANPAGER -u GIT_PAGER \ HOME="$TEST_HOME" \ @@ -600,7 +601,7 @@ EOF [[ "$output" == *'PS1=\[\033[0;35m\]\T \h\[\033[0;33m\] $(_base_bash_defaults_git_prompt)\w\[\033[00m\]: '* ]] if command -v zsh >/dev/null 2>&1; then - run env -u BASE_HOME -u BASE_HOST -u BASE_OS -u EDITOR -u VISUAL -u EXINIT \ + run env -u BASE_HOME -u BASE_HOST -u BASE_OS -u BASE_PLATFORM -u EDITOR -u VISUAL -u EXINIT \ -u HISTFILE -u HISTSIZE -u SAVEHIST \ -u PAGER -u LESS -u MANPAGER -u GIT_PAGER \ HOME="$TEST_HOME" \ diff --git a/docs/architecture.md b/docs/architecture.md index 1c812075..ec2a1658 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -199,7 +199,7 @@ directory. Contains: - exported Base path contract such as `BASE_HOME`, `BASE_BIN_DIR`, `BASE_BASH_LIB_DIR`, `BASE_BASH_LIBS_DIR`, and `BASE_BASH_LIBS_SOURCE` -- OS and host metadata such as `BASE_OS` and `BASE_HOST` +- OS and host metadata such as `BASE_OS`, `BASE_PLATFORM`, and `BASE_HOST` - Base's Bash standard library - `import_base_lib` for convention-based Base Bash library imports from the resolved reusable Bash library root diff --git a/docs/execution-model.md b/docs/execution-model.md index 07241ab1..977550be 100644 --- a/docs/execution-model.md +++ b/docs/execution-model.md @@ -230,7 +230,7 @@ has decided what should run. - exported Base environment variables such as `BASE_HOME`, `BASE_BIN_DIR`, `BASE_BASH_COMMANDS_DIR`, `BASE_BASH_LIB_DIR`, `BASE_BASH_LIBS_DIR`, and `BASE_BASH_LIBS_SOURCE` -- OS and host metadata such as `BASE_OS` and `BASE_HOST` +- OS and host metadata such as `BASE_OS`, `BASE_PLATFORM`, and `BASE_HOST` - the reusable Bash standard library, resolved from `base-bash-libs` - `import_base_lib`, the convention-based helper for sourcing Base Bash libraries from the resolved reusable root diff --git a/docs/linux-support.md b/docs/linux-support.md index 50da679b..bae48d35 100644 --- a/docs/linux-support.md +++ b/docs/linux-support.md @@ -18,7 +18,9 @@ Full bootstrap support can come after runtime support is stable. ## Platform Detection -Use `/etc/os-release` for Linux distribution detection: +Use `/etc/os-release` for Linux distribution detection and expose the result +through `BASE_PLATFORM`. Keep `BASE_OS` coarse: `BASE_OS=linux` on Linux, with +`BASE_PLATFORM` carrying the supported distribution family. ```bash if [[ -r /etc/os-release ]]; then @@ -36,6 +38,11 @@ The setup layer should classify platforms into: Unsupported platforms should fail with explicit guidance rather than falling through to macOS assumptions. +Do not add public `BASE_DISTRO_ID` or `BASE_ARCH` until diagnostics or package +selection need them. Distribution ID and CPU architecture are separate axes: +`BASE_PLATFORM` answers "which supported platform family is this?", while a +future `BASE_ARCH` would answer "which binary/package architecture is this?". + ## Package Manager Mapping Initial Ubuntu/Debian mappings: diff --git a/docs/runtime-environment.md b/docs/runtime-environment.md index 0d625515..fcce55f5 100644 --- a/docs/runtime-environment.md +++ b/docs/runtime-environment.md @@ -49,7 +49,7 @@ boundary. `~/.baserc` may set user knobs such as `BASE_DEBUG`. It must not set Base-owned runtime or profile variables such as `BASE_HOME`, `BASE_BIN_DIR`, `BASE_LIB_DIR`, -`BASE_OS`, `BASE_HOST`, `BASE_SHELL`, `BASE_BASH_LIBS_DIR`, +`BASE_OS`, `BASE_PLATFORM`, `BASE_HOST`, `BASE_SHELL`, `BASE_BASH_LIBS_DIR`, `BASE_BASH_LIBS_SOURCE`, `BASE_PLATFORM_TOOLS_HOME`, `BASE_PLATFORM_TOOLS_BIN_DIR`, `BASE_PROFILE_VERSION`, `BASE_ENABLE_BASH_DEFAULTS`, or `BASE_ENABLE_ZSH_DEFAULTS`. It must also not @@ -74,6 +74,7 @@ explicit Bash script, or starts a Base runtime Bash shell. | `BASE_BASH_LIBS_SOURCE` | Base | Source category for `BASE_BASH_LIBS_DIR`: `explicit`, `sibling`, or `homebrew`. `basectl check` and `basectl doctor` use this to report how Base is consuming external reusable Bash libraries. | Do not set. Readonly after `base_init.sh`. | | `BASE_SHELL_DIR` | Base | `$BASE_HOME/lib/shell`. Root for managed shell startup snippets and completions. | Do not set. Readonly after `base_init.sh`. | | `BASE_OS` | Base | Normalized host OS metadata such as `macos` or `linux`. Used by runtime decisions and diagnostics. | Do not set. Readonly after `base_init.sh`. | +| `BASE_PLATFORM` | Base | Normalized runtime platform metadata such as `macos`, `linux-debian`, or `linux-unknown`. Used when Base needs distribution-family behavior without overloading `BASE_OS`. | Do not set. Readonly after `base_init.sh`. | | `BASE_HOST` | Base | Short host name from `hostname -s`. Used by runtime metadata and prompts. | Do not set. Readonly after `base_init.sh`. | | `BASE_SHELL` | Base | Legacy runtime marker. Plain `base_init.sh` defaults it to `bash`; Base runtime shells seed it as `1` before `base_init.sh`. New code should avoid adding new meanings to it. | Do not set in user config. Readonly after `base_init.sh`. | diff --git a/docs/technical-overview.md b/docs/technical-overview.md index 3f795319..380889cb 100644 --- a/docs/technical-overview.md +++ b/docs/technical-overview.md @@ -70,7 +70,8 @@ Markers look like: **Layer 2 — Base runtime** (`base_init.sh`, sourced on every `basectl` invocation) Exports `BASE_HOME`, `BASE_BIN_DIR`, `BASE_BASH_LIB_DIR`, -`BASE_BASH_LIBS_DIR`, `BASE_BASH_LIBS_SOURCE`, `BASE_OS`, `BASE_HOST`, and +`BASE_BASH_LIBS_DIR`, `BASE_BASH_LIBS_SOURCE`, `BASE_OS`, `BASE_PLATFORM`, +`BASE_HOST`, and `BASE_SHELL`. Loads the Bash standard library from the resolved reusable library root. Sets up `import_base_lib` for convention-based library imports from that reusable root. diff --git a/lib/shell/baserc_guard.sh b/lib/shell/baserc_guard.sh index 4411d9b1..c20d41b2 100644 --- a/lib/shell/baserc_guard.sh +++ b/lib/shell/baserc_guard.sh @@ -42,6 +42,7 @@ BASE_LIB_DIR BASE_BASH_LIB_DIR BASE_SHELL_DIR BASE_OS +BASE_PLATFORM BASE_HOST BASE_SHELL BASE_PLATFORM_TOOLS_HOME diff --git a/lib/shell/zsh_baserc_guard.zsh b/lib/shell/zsh_baserc_guard.zsh index 76c85a41..2332a03d 100644 --- a/lib/shell/zsh_baserc_guard.zsh +++ b/lib/shell/zsh_baserc_guard.zsh @@ -37,6 +37,7 @@ BASE_LIB_DIR BASE_BASH_LIB_DIR BASE_SHELL_DIR BASE_OS +BASE_PLATFORM BASE_HOST BASE_SHELL BASE_PLATFORM_TOOLS_HOME diff --git a/tests/base_init.bats b/tests/base_init.bats index cdd59bf4..04ff76c5 100644 --- a/tests/base_init.bats +++ b/tests/base_init.bats @@ -45,11 +45,29 @@ run_base_init_script() { -u BASE_BASH_LIBS_SOURCE \ -u BASE_SHELL_DIR \ -u BASE_OS \ + -u BASE_PLATFORM \ -u BASE_HOST \ -u BASE_SHELL \ bash -c "$script" bash "$TEST_BASE_HOME" } +create_uname_stub() { + local mockbin="$1" + local uname_os="$2" + + mkdir -p "$mockbin" + cat > "$mockbin/uname" <&2 +exit 1 +EOF + chmod +x "$mockbin/uname" +} + @test "base_init exports the Base runtime path contract" { local expected_bash_libs_dir @@ -117,11 +135,12 @@ run_base_init_script() { [[ "$output" == *"BASE_BIN_DIR=$opt_base/bin"* ]] } -@test "base_init exports host operating system and shell metadata" { +@test "base_init exports host operating system platform and shell metadata" { run_base_init_script ' base_home="$1" source "$base_home/base_init.sh" printf "BASE_OS=%s\n" "$BASE_OS" + printf "BASE_PLATFORM=%s\n" "$BASE_PLATFORM" printf "BASE_HOST=%s\n" "$BASE_HOST" printf "BASE_SHELL=%s\n" "$BASE_SHELL" ' @@ -130,6 +149,62 @@ run_base_init_script() { [[ "$output" == *"BASE_HOST="* ]] [[ "$output" == *"BASE_SHELL=bash"* ]] [[ "$output" == *"BASE_OS=linux"* || "$output" == *"BASE_OS=macos"* ]] + [[ "$output" == *"BASE_PLATFORM=linux-debian"* || "$output" == *"BASE_PLATFORM=linux-unknown"* || "$output" == *"BASE_PLATFORM=macos"* ]] +} + +@test "base_init keeps BASE_OS coarse while classifying Ubuntu as linux-debian" { + local mockbin="$TEST_TMPDIR/mockbin" + local os_release="$TEST_TMPDIR/os-release" + + create_uname_stub "$mockbin" Linux + printf 'ID=ubuntu\nID_LIKE=debian\n' > "$os_release" + + PATH="$mockbin:$PATH" BASE_INIT_TEST_OS_RELEASE_PATH="$os_release" run_base_init_script ' + base_home="$1" + source "$base_home/base_init.sh" + printf "BASE_OS=%s\n" "$BASE_OS" + printf "BASE_PLATFORM=%s\n" "$BASE_PLATFORM" + ' + + [ "$status" -eq 0 ] + [[ "$output" == *"BASE_OS=linux"* ]] + [[ "$output" == *"BASE_PLATFORM=linux-debian"* ]] +} + +@test "base_init classifies non-Debian Linux as linux-unknown" { + local mockbin="$TEST_TMPDIR/mockbin" + local os_release="$TEST_TMPDIR/os-release" + + create_uname_stub "$mockbin" Linux + printf 'ID=fedora\nID_LIKE="rhel fedora"\n' > "$os_release" + + PATH="$mockbin:$PATH" BASE_INIT_TEST_OS_RELEASE_PATH="$os_release" run_base_init_script ' + base_home="$1" + source "$base_home/base_init.sh" + printf "BASE_OS=%s\n" "$BASE_OS" + printf "BASE_PLATFORM=%s\n" "$BASE_PLATFORM" + ' + + [ "$status" -eq 0 ] + [[ "$output" == *"BASE_OS=linux"* ]] + [[ "$output" == *"BASE_PLATFORM=linux-unknown"* ]] +} + +@test "base_init classifies macOS platform from uname" { + local mockbin="$TEST_TMPDIR/mockbin" + + create_uname_stub "$mockbin" Darwin + + PATH="$mockbin:$PATH" run_base_init_script ' + base_home="$1" + source "$base_home/base_init.sh" + printf "BASE_OS=%s\n" "$BASE_OS" + printf "BASE_PLATFORM=%s\n" "$BASE_PLATFORM" + ' + + [ "$status" -eq 0 ] + [[ "$output" == *"BASE_OS=macos"* ]] + [[ "$output" == *"BASE_PLATFORM=macos"* ]] } @test "base_init marks the Base runtime contract readonly" { @@ -150,6 +225,7 @@ run_base_init_script() { BASE_BASH_LIBS_SOURCE \ BASE_SHELL_DIR \ BASE_OS \ + BASE_PLATFORM \ BASE_HOST \ BASE_SHELL; do declare -p "$var" @@ -169,6 +245,7 @@ run_base_init_script() { BASE_BASH_LIBS_SOURCE \ BASE_SHELL_DIR \ BASE_OS \ + BASE_PLATFORM \ BASE_HOST \ BASE_SHELL; do [[ "$output" == *"declare -rx $var="* ]] @@ -205,6 +282,7 @@ run_base_init_script() { BASE_BASH_LIBS_SOURCE \ BASE_SHELL_DIR \ BASE_OS \ + BASE_PLATFORM \ BASE_HOST \ BASE_SHELL; do grep -F "| \`$var\` |" "$BASE_REPO_ROOT/docs/runtime-environment.md" diff --git a/tests/test_helper.sh b/tests/test_helper.sh index 5696825f..518462c3 100644 --- a/tests/test_helper.sh +++ b/tests/test_helper.sh @@ -26,6 +26,7 @@ unset_base_runtime_env() { BASE_BASH_LIBS_SOURCE \ BASE_SHELL_DIR \ BASE_OS \ + BASE_PLATFORM \ BASE_HOST \ BASE_SHELL \ BASE_PLATFORM_TOOLS_HOME \ @@ -38,6 +39,7 @@ unset_base_runtime_env() { BASE_BASH_COMMAND_DIR \ BASE_BASH_COMMAND_SCRIPT \ BASE_BASH_BOOTSTRAP_SOURCE \ + BASE_INIT_TEST_OS_RELEASE_PATH \ BASE_PROJECT \ BASE_PROJECT_ROOT \ BASE_PROJECT_MANIFEST \