testsAndMisc/linux_configuration/fixes/lib/tests/test_nvidia_config_pyroveil.sh
Krzysztof kuhy Rudnicki 4f2b0ccdf7 Dissolve linux_configuration/scripts/ and single_use/
Two levels of pure taxonomy carrying no information, and a 2-directory
cap leaves no room for them. Categories now sit directly under
linux_configuration/: features, fixes, utils, misc, fresh-install,
installers, diagnostics, gaming, boot_recovery, periodic_background, lib,
meta, tests. A script's own lib/ and tests/ are exempt from the cap, so
those stay put.

Depth violations 248 -> 139; roughly 40 of the remainder are inside
digital_wellbeing and hosts, deferred until the guard-lib repoint.

The moves are the easy half. What breaks is every path that counted
levels, and three classes of it had to be found by resolving paths rather
than reading diffs:

  - 52 relative `source` lines for lib/common.sh and lib/android.sh. The
    correct prefix differs per file: 40 were ../../ and 12 were ../../../,
    so a blanket replace would have fixed one set and broken the other.
  - REPO_ROOT in 7 fixes/lib/tests harnesses and setup_syncyomi_guard.sh,
    each walking up four levels from a directory now two levels shallower.
    This caused a real regression -- the fixes suite went red with
    "log_warn: command not found" -- caught by running it and comparing
    against the pre-move baseline worktree.
  - conftest.py's sys.path entries, which took the pytest gate down with
    14 collection errors, and the `# shellcheck source=` directives, which
    took shellcheck down with SC1091.

16 symlinks in $HOME broke, including the entire i3blocks bar. All
repointed, and cpu_monitor/memory/disk/time/volume were run to confirm
they emit real output rather than merely resolving.

Verified: 1798 tests pass at 100% coverage, 8 of 9 lib/tests suites pass
(the ninth needs the coverage jail, identically at baseline), pre-commit
is clean, and the two untracked secret configs are still ignored after
their gitignore paths changed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
2026-08-23 18:53:30 +02:00

106 lines
4.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# lib/tests/test_nvidia_config_pyroveil.sh — tests for nvidia_config.sh's
# install_pyroveil.
#
# Split from test_nvidia_config.sh to hold every file under the 250-line cap.
#
# The interactive arm BLOCKS on `read -p`, so the two cases that exercise it
# feed stdin explicitly. A case that leaves the read waiting hangs the whole
# suite, and under the coverage jail that presents as a case timeout rather
# than as a hang.
set -uo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=nvidia_config_harness.sh
. "${SCRIPT_DIR}/nvidia_config_harness.sh"
# shellcheck source=../nvidia_config.sh
. "${FIXES_DIR}/lib/nvidia_config.sh"
printf '\n-- install_pyroveil --\n'
# Case 1: non-interactive -> auto-installs without prompting.
nvidia_reset
_t_run install_pyroveil
_t_eq "0" "$?" "install_pyroveil: returns 0 on a clean auto-install"
_t_contains "$out" "Auto-installing Pyroveil" "install_pyroveil: says it is auto-installing"
calls="$(_t_calls)"
_t_contains "$calls" "git clone" "install_pyroveil: clones the repository"
_t_contains "$calls" "sudo -u testuser" \
"install_pyroveil: drops to the invoking user rather than building as root"
_t_contains "$out" "installed successfully" "install_pyroveil: reports success"
# Case 2: the helper script is written, executable, and owned by the user.
nvidia_reset
_t_run install_pyroveil
helper="${USER_HOME}/run-with-pyroveil.sh"
_t_eq "yes" "$([[ -f "$helper" ]] && echo yes || echo no)" \
"install_pyroveil: creates the helper script"
_t_eq "yes" "$([[ -x "$helper" ]] && echo yes || echo no)" \
"install_pyroveil: makes the helper executable"
_t_contains "$(cat "$helper")" 'export PYROVEIL=1' \
"install_pyroveil: the helper sets PYROVEIL"
_t_contains "$(cat "$helper")" 'PYROVEIL_DIR="'"${USER_HOME}"'/pyroveil"' \
"install_pyroveil: the helper points at the install dir"
_t_contains "$(_t_calls)" "chown testuser:testuser" \
"install_pyroveil: hands the helper to the user, not root"
# Case 3: an existing checkout is updated rather than re-cloned.
nvidia_reset
mkdir -p "${USER_HOME}/pyroveil"
_t_run install_pyroveil
_t_contains "$out" "already exists. Updating" "install_pyroveil: reports the update path"
_t_lacks "$(_t_calls)" "git clone" "install_pyroveil: does not re-clone over a checkout"
# Case 4: a missing build dependency -> refuse, with the package hint, and
# return non-zero so the caller knows nothing was installed.
nvidia_reset
_t_unstub ninja
_t_hide ninja
rc=0
_t_run install_pyroveil || rc=$?
_t_eq "1" "$rc" "install_pyroveil: returns 1 when a dependency is missing"
_t_contains "$out" "Missing dependencies: ninja" "install_pyroveil: names the missing tool"
_t_contains "$out" "pacman -S base-devel git cmake ninja" \
"install_pyroveil: gives the install command"
_t_lacks "$(_t_calls)" "git clone" "install_pyroveil: clones nothing when deps are missing"
_t_full_path
# Case 5: several missing dependencies are all listed, not just the first.
nvidia_reset
_t_unstub ninja cmake
_t_hide ninja cmake
rc=0
_t_run install_pyroveil || rc=$?
_t_eq "1" "$rc" "install_pyroveil: still returns 1 with several missing"
_t_contains "$out" "cmake" "install_pyroveil: lists cmake"
_t_contains "$out" "ninja" "install_pyroveil: lists ninja too"
_t_full_path
# Case 6: interactive, answered "y" -> installs.
nvidia_reset
INTERACTIVE_MODE="true"
install_pyroveil <<<"y" >"${TEST_TMPDIR}/o" 2>&1
out="$(cat "${TEST_TMPDIR}/o")"
# `read -p` writes its prompt straight to the terminal, not to stdout or
# stderr, so it is not observable in captured output. What IS observable is
# that the interactive arm did not auto-install: the "Auto-installing" line
# belongs to the non-interactive branch only.
_t_lacks "$out" "Auto-installing Pyroveil" \
"install_pyroveil: takes the prompt branch, not the auto branch"
_t_contains "$(_t_calls)" "git clone" "install_pyroveil: installs when the answer is y"
# Case 7: interactive, answered "n" -> skipped, nothing installed.
nvidia_reset
INTERACTIVE_MODE="true"
install_pyroveil <<<"n" >"${TEST_TMPDIR}/o" 2>&1
out="$(cat "${TEST_TMPDIR}/o")"
_t_contains "$out" "Skipping Pyroveil installation" "install_pyroveil: honours a no"
_t_lacks "$(_t_calls)" "git clone" "install_pyroveil: clones nothing when declined"
_t_eq "no" "$([[ -f "${USER_HOME}/run-with-pyroveil.sh" ]] && echo yes || echo no)" \
"install_pyroveil: writes no helper when declined"
printf '\nnvidia_config (pyroveil): %d passed, %d failed\n' "$PASS" "$FAIL"
[[ $FAIL -eq 0 ]]