1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-04 19:09:43 +00:00

Tighten macOS update check and add empty-output test

This commit is contained in:
amanthanvi
2025-12-28 11:18:12 -05:00
parent 014e15f721
commit 9239571be1
2 changed files with 54 additions and 2 deletions

View File

@@ -246,7 +246,7 @@ check_macos_update() {
fi
if sw_output=$(run_with_timeout 10 softwareupdate -l --no-scan 2> /dev/null); then
sw_status=0
:
else
sw_status=$?
fi
@@ -257,7 +257,7 @@ check_macos_update() {
# Prefer avoiding false negatives: if the system indicates updates are pending,
# only clear the flag when softwareupdate explicitly reports no updates.
if [[ $sw_status -eq 0 && -n "$sw_output" ]] && echo "$sw_output" | grep -q "No new software available"; then
if [[ $sw_status -eq 0 && -n "$sw_output" ]] && echo "$sw_output" | grep -qE '^[[:space:]]*No new software available'; then
updates_available="false"
fi
fi

View File

@@ -195,7 +195,12 @@ source "$PROJECT_ROOT/lib/check/all.sh"
defaults() { echo "1"; }
run_with_timeout() {
local timeout="${1:-}"
shift
if [[ "$timeout" != "10" ]]; then
echo "BAD_TIMEOUT:$timeout"
return 124
fi
if [[ "${1:-}" == "softwareupdate" && "${2:-}" == "-l" && "${3:-}" == "--no-scan" ]]; then
cat <<'OUT'
Software Update Tool
@@ -218,6 +223,7 @@ EOF
[ "$status" -eq 0 ]
[[ "$output" == *"Update available"* ]]
[[ "$output" == *"MACOS_UPDATE_AVAILABLE=true"* ]]
[[ "$output" != *"BAD_TIMEOUT:"* ]]
}
@test "check_macos_update clears update flag when softwareupdate reports no updates" {
@@ -229,7 +235,12 @@ source "$PROJECT_ROOT/lib/check/all.sh"
defaults() { echo "1"; }
run_with_timeout() {
local timeout="${1:-}"
shift
if [[ "$timeout" != "10" ]]; then
echo "BAD_TIMEOUT:$timeout"
return 124
fi
if [[ "${1:-}" == "softwareupdate" && "${2:-}" == "-l" && "${3:-}" == "--no-scan" ]]; then
cat <<'OUT'
Software Update Tool
@@ -252,6 +263,7 @@ EOF
[ "$status" -eq 0 ]
[[ "$output" == *"System up to date"* ]]
[[ "$output" == *"MACOS_UPDATE_AVAILABLE=false"* ]]
[[ "$output" != *"BAD_TIMEOUT:"* ]]
}
@test "check_macos_update keeps update flag when softwareupdate times out" {
@@ -263,7 +275,12 @@ source "$PROJECT_ROOT/lib/check/all.sh"
defaults() { echo "1"; }
run_with_timeout() {
local timeout="${1:-}"
shift
if [[ "$timeout" != "10" ]]; then
echo "BAD_TIMEOUT:$timeout"
return 124
fi
if [[ "${1:-}" == "softwareupdate" && "${2:-}" == "-l" && "${3:-}" == "--no-scan" ]]; then
return 124
fi
@@ -280,6 +297,41 @@ EOF
[ "$status" -eq 0 ]
[[ "$output" == *"Update available"* ]]
[[ "$output" == *"MACOS_UPDATE_AVAILABLE=true"* ]]
[[ "$output" != *"BAD_TIMEOUT:"* ]]
}
@test "check_macos_update keeps update flag when softwareupdate returns empty output" {
run bash --noprofile --norc <<'EOF'
set -euo pipefail
source "$PROJECT_ROOT/lib/core/common.sh"
source "$PROJECT_ROOT/lib/check/all.sh"
defaults() { echo "1"; }
run_with_timeout() {
local timeout="${1:-}"
shift
if [[ "$timeout" != "10" ]]; then
echo "BAD_TIMEOUT:$timeout"
return 124
fi
if [[ "${1:-}" == "softwareupdate" && "${2:-}" == "-l" && "${3:-}" == "--no-scan" ]]; then
return 0
fi
return 124
}
start_inline_spinner(){ :; }
stop_inline_spinner(){ :; }
check_macos_update
echo "MACOS_UPDATE_AVAILABLE=$MACOS_UPDATE_AVAILABLE"
EOF
[ "$status" -eq 0 ]
[[ "$output" == *"Update available"* ]]
[[ "$output" == *"MACOS_UPDATE_AVAILABLE=true"* ]]
[[ "$output" != *"BAD_TIMEOUT:"* ]]
}
@test "check_macos_update skips softwareupdate when defaults shows no updates" {