test: cover install_terminal_prereqs apt branch and Hyprland-skip/TerminalLook-completes composition

- install_terminal_prereqs's apt branch was untested even though the
  existing test already stubbed apt-get; added a dedicated test asserting
  the exact apt-get update / apt-get install -y zsh git curl fzf calls with
  no pacman on PATH.
- Added an end-to-end test (both components picked, Hyprland's prerequisite
  missing) exercising the exact composition Task 2's refactor exists for:
  Hyprland skips cleanly via check_arch failing, and TerminalLook (Kali
  look) still runs to completion in the same main() invocation. Uses a
  clean-room PATH (real coreutils/git/bash symlinked in, no-op stand-ins for
  apt-get/sudo/zsh/chsh, pacman never added) so the assertion holds
  regardless of whether the host running the tests actually has pacman.

Addresses findings 5 and 6 from the final whole-branch review.
This commit is contained in:
edemilov committed 2026-08-30 17:46:56 +03:00
1 parent cc9282dfd4
commit 8a6f0fe413
1 file changed
+70
+70
View File
@@ -486,6 +486,55 @@ EOF
rm -rf "$tmp_home" "$stub_bin"
}
@test "main runs both components: Hyprland skips cleanly on missing prereq, TerminalLook still completes" {
# Regression test for the Global Constraint that one module's failed
# prerequisite check must never block another module from running.
# Both components are picked; PATH is a clean room containing only the
# exact binaries this path needs, with pacman deliberately never added
# (not stubbed out -- simply absent), so apply_hyprland's check_arch
# fails regardless of whether the host machine actually has pacman, and
# it must skip via `return 0`, not abort the script under
# `set -euo pipefail`. apply_terminal_look (Kali look, no oh-my-zsh clone
# needed) must still run to completion afterward.
local tmp_home
tmp_home="$(mktemp -d)"
local stub_bin
stub_bin="$(mktemp -d)"
# Real passthrough binaries the Hyprland-skip + Kali terminal-look path
# actually calls (bash for the outer `run bash -c`, plus coreutils/git
# used by ensure_repo_files/apply_terminal_look_kali/write_zshrc_kali).
for real in bash dirname mkdir cp cat git; do
ln -s "$(command -v "$real")" "$stub_bin/$real"
done
# No-op stand-ins for everything else the script shells out to on this
# path -- deliberately no pacman here.
for cmd in curl apt-get sudo zsh chsh; do
cat > "$stub_bin/$cmd" <<'EOF'
#!/bin/bash
exit 0
EOF
chmod +x "$stub_bin/$cmd"
done
PATH="$stub_bin" \
HOME="$tmp_home" \
DOTEVO_NONINTERACTIVE=1 \
DOTEVO_COMPONENTS="Hyprland TerminalLook" \
DOTEVO_TERMINAL_LOOK="Kali" \
run bash -c "$(cat "${BATS_TEST_DIRNAME}/../install.sh")"
[ "$status" -eq 0 ]
[[ "$output" == *"skipping Hyprland rice"* ]]
[[ "$output" != *"unbound variable"* ]]
[[ "$output" != *"install.sh: line"* ]]
[[ "$output" == *"dotevo: done."* ]]
[ -f "$tmp_home/.zshrc" ]
rm -rf "$tmp_home" "$stub_bin"
}
@test "detect_pkg_manager finds pacman first when present" {
source "${BATS_TEST_DIRNAME}/../install.sh"
local stub_bin
@@ -547,6 +596,27 @@ EOF
rm -rf "$tmp_home" "$stub_bin"
}
@test "install_terminal_prereqs calls the right install command on apt (no pacman on PATH)" {
source "${BATS_TEST_DIRNAME}/../install.sh"
local tmp_home stub_bin
tmp_home="$(mktemp -d)"
stub_bin="$(mktemp -d)"
for cmd in apt-get sudo; do
cat > "$stub_bin/$cmd" <<EOF
#!/bin/bash
echo "$cmd \$*" >> "$tmp_home/log"
EOF
chmod +x "$stub_bin/$cmd"
done
PATH="$stub_bin" install_terminal_prereqs
grep -q 'apt-get update' "$tmp_home/log"
grep -q 'apt-get install -y zsh git curl fzf' "$tmp_home/log"
rm -rf "$tmp_home" "$stub_bin"
}
@test "install_terminal_prereqs fails clearly on an unrecognized package manager" {
source "${BATS_TEST_DIRNAME}/../install.sh"
local stub_bin