1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-22 20:15:07 +00:00

Refine update/uninstall UX and stabilize brew flows

This commit is contained in:
tw93
2026-03-05 17:46:05 +08:00
parent 9ee425766d
commit f91975e5be
5 changed files with 207 additions and 73 deletions

View File

@@ -123,7 +123,56 @@ EOF
[ "$status" -eq 0 ]
}
@test "batch_uninstall_applications tolerates brew autoremove timeout" {
@test "batch_uninstall_applications does not pre-auth sudo for brew-only casks" {
local app_bundle="$HOME/Applications/BrewPreAuth.app"
mkdir -p "$app_bundle"
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc << 'EOF'
set -euo pipefail
source "$PROJECT_ROOT/lib/core/common.sh"
source "$PROJECT_ROOT/lib/uninstall/batch.sh"
start_inline_spinner() { :; }
stop_inline_spinner() { :; }
get_file_owner() { whoami; }
get_path_size_kb() { echo "100"; }
bytes_to_human() { echo "$1"; }
drain_pending_input() { :; }
print_summary_block() { :; }
remove_apps_from_dock() { :; }
force_kill_app() { return 0; }
run_with_timeout() { shift; "$@"; }
export -f run_with_timeout
ensure_sudo_session() {
echo "UNEXPECTED_ENSURE_SUDO:$*" >> "$HOME/order.log"
return 1
}
brew() {
echo "BREW_CALL:$*" >> "$HOME/order.log"
return 0
}
export -f brew
get_brew_cask_name() { echo "brew-preauth-cask"; return 0; }
export -f get_brew_cask_name
selected_apps=("0|$HOME/Applications/BrewPreAuth.app|BrewPreAuth|com.example.brewpreauth|0|Never")
files_cleaned=0
total_items=0
total_size_cleaned=0
printf '\n' | batch_uninstall_applications > /dev/null 2>&1
grep -q "BREW_CALL:uninstall --cask --zap brew-preauth-cask" "$HOME/order.log"
! grep -q "UNEXPECTED_ENSURE_SUDO:" "$HOME/order.log"
EOF
[ "$status" -eq 0 ]
}
@test "batch_uninstall_applications runs silent brew autoremove without UX noise" {
local app_bundle="$HOME/Applications/BrewTimeout.app"
mkdir -p "$app_bundle"
@@ -151,9 +200,6 @@ run_with_timeout() {
local duration="$1"
shift
echo "TIMEOUT_CALL:$duration:$*" >> "$HOME/timeout_calls.log"
if [[ "$duration" == "30" ]]; then
return 124
fi
"$@"
}
@@ -164,10 +210,51 @@ total_size_cleaned=0
printf '\n' | batch_uninstall_applications
cat "$HOME/timeout_calls.log"
sleep 0.2
if [[ -f "$HOME/timeout_calls.log" ]]; then
cat "$HOME/timeout_calls.log"
else
echo "NO_TIMEOUT_CALL"
fi
EOF
[ "$status" -eq 0 ]
[[ "$output" == *"TIMEOUT_CALL:30:bash -c HOMEBREW_NO_ENV_HINTS=1 brew autoremove 2>/dev/null"* ]]
[[ "$output" == *"LS_REFRESH"* ]]
[[ "$output" == *"TIMEOUT_CALL:30:brew autoremove"* ]]
[[ "$output" != *"Checking brew dependencies"* ]]
}
@test "brew_uninstall_cask does not trigger extra sudo pre-auth" {
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc << 'EOF'
set -euo pipefail
source "$PROJECT_ROOT/lib/core/common.sh"
source "$PROJECT_ROOT/lib/uninstall/brew.sh"
debug_log() { :; }
get_path_size_kb() { echo "0"; }
run_with_timeout() { local _timeout="$1"; shift; "$@"; }
sudo() {
echo "UNEXPECTED_SUDO_CALL:$*"
return 1
}
brew() {
if [[ "${1:-}" == "uninstall" ]]; then
return 0
fi
if [[ "${1:-}" == "list" && "${2:-}" == "--cask" ]]; then
return 0
fi
return 0
}
export -f sudo brew
brew_uninstall_cask "mock-cask"
echo "DONE"
EOF
[ "$status" -eq 0 ]
[[ "$output" == *"DONE"* ]]
[[ "$output" != *"UNEXPECTED_SUDO_CALL:"* ]]
}