From 8661faa4ce8f62dce05bd5aaf29948194a8c01d3 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 14 Jun 2026 22:32:23 -0500 Subject: test(scripts): lock package-inventory behavior with characterization tests package-inventory compares archsetup's declared packages against the live system but had no tests, so a future archsetup edit (a new for-loop shape, a renamed install helper) could silently break the extraction. I added two env seams so the script is testable without the real system. PKGINV_ARCHSETUP points the extractor at a fixture installer, PKGINV_PACMAN swaps in a fake pacman serving controlled query output. Both default to the real targets, so normal use is unchanged, and the seams match the env-override pattern audit-packages.sh already uses. The 7 tests pin the extraction (direct calls, for-loop lists, variable-arg skip) and both diff directions against the fixture, with no network or real pacman db. I also added a make package-diff target so the tool is reachable alongside the test targets. --- scripts/package-inventory | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'scripts/package-inventory') diff --git a/scripts/package-inventory b/scripts/package-inventory index 4742645..2dda44b 100755 --- a/scripts/package-inventory +++ b/scripts/package-inventory @@ -8,7 +8,12 @@ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)" -ARCHSETUP="$SCRIPT_DIR/archsetup" + +# Seams for testing: PKGINV_ARCHSETUP points the extractor at a fixture +# installer; PKGINV_PACMAN swaps in a fake pacman serving controlled +# -Qqe/-Qq/-Qqen/-Qqem output. Both default to the real targets. +ARCHSETUP="${PKGINV_ARCHSETUP:-$SCRIPT_DIR/archsetup}" +PACMAN="${PKGINV_PACMAN:-pacman}" # Colors RED='\033[0;31m' @@ -66,22 +71,22 @@ extract_archsetup_packages() { # Get packages on live system # ============================================================================ get_system_packages_explicit() { - pacman -Qqe | sort -u # explicitly installed + "$PACMAN" -Qqe | sort -u # explicitly installed } get_system_packages_all() { - pacman -Qq | sort -u # all installed (including deps) + "$PACMAN" -Qq | sort -u # all installed (including deps) } # ============================================================================ # Categorize system packages # ============================================================================ get_system_native() { - pacman -Qqen | sort -u # native (official repos) + "$PACMAN" -Qqen | sort -u # native (official repos) } get_system_foreign() { - pacman -Qqem | sort -u # foreign (AUR/manual) + "$PACMAN" -Qqem | sort -u # foreign (AUR/manual) } # ============================================================================ -- cgit v1.2.3