diff options
| author | Craig Jennings <c@cjennings.net> | 2026-06-14 22:32:23 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-06-14 22:32:23 -0500 |
| commit | 8661faa4ce8f62dce05bd5aaf29948194a8c01d3 (patch) | |
| tree | a2d9b1c12f9f33e69a0eafbfa63e92e8468a57fe /scripts | |
| parent | 9e426241e1632fe9d5c9ee6c7cb60d11c13ac1fa (diff) | |
| download | archsetup-8661faa4ce8f62dce05bd5aaf29948194a8c01d3.tar.gz archsetup-8661faa4ce8f62dce05bd5aaf29948194a8c01d3.zip | |
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.
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/package-inventory | 15 |
1 files changed, 10 insertions, 5 deletions
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) } # ============================================================================ |
