Propagate package discovery failures before removal

This commit is contained in:
Afonso Oliveira committed 2026-09-16 21:49:50 +01:00
1 parent ea21c37d98
commit 71be7b16af
2 files changed
+33 -3

No files matched your search

+9 -2
View File
@@ -8,9 +8,16 @@ installed=()
declare -A installed_exact=() declare -A installed_exact=()
declare -A selected=() declare -A selected=()
if ! installed_packages=$(pacman -Qq); then
echo "Unable to query installed packages; no packages were removed." >&2
exit 1
fi
while IFS= read -r package_name; do while IFS= read -r package_name; do
installed_exact[$package_name]=1 if [[ -n $package_name ]]; then
done < <(pacman -Qq) installed_exact[$package_name]=1
fi
done <<< "$installed_packages"
for pkg in "$@"; do for pkg in "$@"; do
if [[ -n ${installed_exact[$pkg]} && -z ${selected[$pkg]} ]]; then if [[ -n ${installed_exact[$pkg]} && -z ${selected[$pkg]} ]]; then
+24 -1
View File
@@ -13,13 +13,17 @@ mkdir -p "$mock_path"
cat >"$mock_path/pacman" <<'EOF' cat >"$mock_path/pacman" <<'EOF'
#!/bin/bash #!/bin/bash
if [[ $1 == "-Qq" ]]; then if [[ $1 == "-Qq" ]]; then
printf '%s\n' exact-package provider-package if [[ ${TEST_PACKAGES_EMPTY:-0} == "0" ]]; then
printf '%s\n' exact-package provider-package
fi
exit "${TEST_QUERY_STATUS:-0}"
fi fi
EOF EOF
cat >"$mock_path/sudo" <<'EOF' cat >"$mock_path/sudo" <<'EOF'
#!/bin/bash #!/bin/bash
printf '%s\n' "$*" >"$TEST_TMP/pkg-drop-command" printf '%s\n' "$*" >"$TEST_TMP/pkg-drop-command"
exit "${TEST_REMOVE_STATUS:-0}"
EOF EOF
chmod +x "$mock_path/pacman" "$mock_path/sudo" chmod +x "$mock_path/pacman" "$mock_path/sudo"
@@ -30,3 +34,22 @@ PATH="$mock_path:$PATH" TEST_TMP="$test_tmp" \
[[ $(<"$test_tmp/pkg-drop-command") == "pacman -Rns --noconfirm exact-package provider-package" ]] || [[ $(<"$test_tmp/pkg-drop-command") == "pacman -Rns --noconfirm exact-package provider-package" ]] ||
fail "package removal targets exact installed names only" fail "package removal targets exact installed names only"
pass "package removal ignores providers and duplicate arguments" pass "package removal ignores providers and duplicate arguments"
rm "$test_tmp/pkg-drop-command"
if PATH="$mock_path:$PATH" TEST_TMP="$test_tmp" TEST_QUERY_STATUS=1 \
"$ROOT/bin/omarchy-pkg-drop" exact-package >"$test_tmp/output" 2>&1; then
fail "failed package discovery must fail removal even with partial output"
fi
[[ ! -e $test_tmp/pkg-drop-command ]] || fail "failed discovery must not request privileges"
pass "package removal propagates discovery errors before requesting privileges"
PATH="$mock_path:$PATH" TEST_TMP="$test_tmp" TEST_PACKAGES_EMPTY=1 \
"$ROOT/bin/omarchy-pkg-drop" exact-package
[[ ! -e $test_tmp/pkg-drop-command ]] || fail "empty package database must not request privileges"
pass "an empty package database is a successful no-op"
if PATH="$mock_path:$PATH" TEST_TMP="$test_tmp" TEST_REMOVE_STATUS=1 \
"$ROOT/bin/omarchy-pkg-drop" exact-package; then
fail "failed package transaction must fail removal"
fi
pass "package removal propagates transaction failures"