1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-22 23:05:08 +00:00

Improve update checks and cleanup UX, add timeout regressions

This commit is contained in:
tw93
2026-03-05 12:00:07 +08:00
parent fbee8da9f7
commit 8e4b8a5e0d
21 changed files with 948 additions and 164 deletions

View File

@@ -420,6 +420,80 @@ EOF
[[ "$output" == *"COUNT=0"* ]]
}
@test "check_homebrew_updates reports counts and exports update variables" {
run bash --noprofile --norc << 'EOF'
set -euo pipefail
source "$PROJECT_ROOT/lib/core/common.sh"
source "$PROJECT_ROOT/lib/check/all.sh"
run_with_timeout() {
local timeout="${1:-}"
shift
"$@"
}
brew() {
if [[ "$1" == "outdated" && "$2" == "--formula" && "$3" == "--quiet" ]]; then
printf "wget\njq\n"
return 0
fi
if [[ "$1" == "outdated" && "$2" == "--cask" && "$3" == "--quiet" ]]; then
printf "iterm2\n"
return 0
fi
return 0
}
check_homebrew_updates
echo "COUNTS=${BREW_OUTDATED_COUNT}:${BREW_FORMULA_OUTDATED_COUNT}:${BREW_CASK_OUTDATED_COUNT}"
EOF
[ "$status" -eq 0 ]
[[ "$output" == *"Homebrew"* ]]
[[ "$output" == *"2 formula, 1 cask available"* ]]
[[ "$output" == *"COUNTS=3:2:1"* ]]
}
@test "check_homebrew_updates shows timeout warning when brew query times out" {
run bash --noprofile --norc << 'EOF'
set -euo pipefail
source "$PROJECT_ROOT/lib/core/common.sh"
source "$PROJECT_ROOT/lib/check/all.sh"
run_with_timeout() { return 124; }
brew() { return 0; }
rm -f "$HOME/.cache/mole/brew_updates"
check_homebrew_updates
echo "COUNTS=${BREW_OUTDATED_COUNT}:${BREW_FORMULA_OUTDATED_COUNT}:${BREW_CASK_OUTDATED_COUNT}"
EOF
[ "$status" -eq 0 ]
[[ "$output" == *"Homebrew"* ]]
[[ "$output" == *"Check timed out"* ]]
[[ "$output" == *"COUNTS=0:0:0"* ]]
}
@test "check_homebrew_updates shows failure warning when brew query fails" {
run bash --noprofile --norc << 'EOF'
set -euo pipefail
source "$PROJECT_ROOT/lib/core/common.sh"
source "$PROJECT_ROOT/lib/check/all.sh"
run_with_timeout() { return 1; }
brew() { return 0; }
rm -f "$HOME/.cache/mole/brew_updates"
check_homebrew_updates
echo "COUNTS=${BREW_OUTDATED_COUNT}:${BREW_FORMULA_OUTDATED_COUNT}:${BREW_CASK_OUTDATED_COUNT}"
EOF
[ "$status" -eq 0 ]
[[ "$output" == *"Homebrew"* ]]
[[ "$output" == *"Check failed"* ]]
[[ "$output" == *"COUNTS=0:0:0"* ]]
}
@test "check_macos_update avoids slow softwareupdate scans" {
run bash --noprofile --norc << 'EOF'
set -euo pipefail