mirror of
https://github.com/tw93/Mole.git
synced 2026-02-15 22:10:03 +00:00
fix(uninstall): show full preview paths and add regression tests
This commit is contained in:
@@ -326,34 +326,19 @@ batch_uninstall_applications() {
|
|||||||
|
|
||||||
echo -e " ${GREEN}${ICON_SUCCESS}${NC} ${app_path/$HOME/~}"
|
echo -e " ${GREEN}${ICON_SUCCESS}${NC} ${app_path/$HOME/~}"
|
||||||
|
|
||||||
# Show related files (limit to 5).
|
# Show all related files so users can fully review before deletion.
|
||||||
local file_count=0
|
|
||||||
local max_files=5
|
|
||||||
while IFS= read -r file; do
|
while IFS= read -r file; do
|
||||||
if [[ -n "$file" && -e "$file" ]]; then
|
if [[ -n "$file" && -e "$file" ]]; then
|
||||||
if [[ $file_count -lt $max_files ]]; then
|
|
||||||
echo -e " ${GREEN}${ICON_SUCCESS}${NC} ${file/$HOME/~}"
|
echo -e " ${GREEN}${ICON_SUCCESS}${NC} ${file/$HOME/~}"
|
||||||
fi
|
fi
|
||||||
((file_count++))
|
|
||||||
fi
|
|
||||||
done <<< "$related_files"
|
done <<< "$related_files"
|
||||||
|
|
||||||
# Show system files (limit to 5).
|
# Show all system files so users can fully review before deletion.
|
||||||
local sys_file_count=0
|
|
||||||
while IFS= read -r file; do
|
while IFS= read -r file; do
|
||||||
if [[ -n "$file" && -e "$file" ]]; then
|
if [[ -n "$file" && -e "$file" ]]; then
|
||||||
if [[ $sys_file_count -lt $max_files ]]; then
|
|
||||||
echo -e " ${BLUE}${ICON_WARNING}${NC} System: $file"
|
echo -e " ${BLUE}${ICON_WARNING}${NC} System: $file"
|
||||||
fi
|
fi
|
||||||
((sys_file_count++))
|
|
||||||
fi
|
|
||||||
done <<< "$system_files"
|
done <<< "$system_files"
|
||||||
|
|
||||||
local total_hidden=$((file_count > max_files ? file_count - max_files : 0))
|
|
||||||
((total_hidden += sys_file_count > max_files ? sys_file_count - max_files : 0))
|
|
||||||
if [[ $total_hidden -gt 0 ]]; then
|
|
||||||
echo -e " ${GRAY} ... and ${total_hidden} more files${NC}"
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# Confirmation before requesting sudo.
|
# Confirmation before requesting sudo.
|
||||||
|
|||||||
@@ -517,6 +517,24 @@ EOF
|
|||||||
[[ "$output" == *"App saved states optimized"* ]]
|
[[ "$output" == *"App saved states optimized"* ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "opt_cache_refresh continues on permission denied (silent exit)" {
|
||||||
|
local cache_dir="$HOME/Library/Caches/com.apple.QuickLook.thumbnailcache"
|
||||||
|
mkdir -p "$cache_dir"
|
||||||
|
touch "$cache_dir/test.db"
|
||||||
|
|
||||||
|
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/optimize/tasks.sh"
|
||||||
|
qlmanage() { return 0; }
|
||||||
|
safe_remove() { return 1; }
|
||||||
|
opt_cache_refresh
|
||||||
|
EOF
|
||||||
|
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "$output" == *"QuickLook thumbnails refreshed"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
@test "opt_cache_refresh cleans Quick Look cache" {
|
@test "opt_cache_refresh cleans Quick Look cache" {
|
||||||
mkdir -p "$HOME/Library/Caches/com.apple.QuickLook.thumbnailcache"
|
mkdir -p "$HOME/Library/Caches/com.apple.QuickLook.thumbnailcache"
|
||||||
touch "$HOME/Library/Caches/com.apple.QuickLook.thumbnailcache/test.db"
|
touch "$HOME/Library/Caches/com.apple.QuickLook.thumbnailcache/test.db"
|
||||||
|
|||||||
@@ -123,6 +123,63 @@ EOF
|
|||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "batch_uninstall_applications preview shows full related file list" {
|
||||||
|
mkdir -p "$HOME/Applications/TestApp.app"
|
||||||
|
mkdir -p "$HOME/Library/Application Support/TestApp"
|
||||||
|
mkdir -p "$HOME/Library/Caches/TestApp"
|
||||||
|
mkdir -p "$HOME/Library/Logs/TestApp"
|
||||||
|
touch "$HOME/Library/Logs/TestApp/log1.log"
|
||||||
|
touch "$HOME/Library/Logs/TestApp/log2.log"
|
||||||
|
touch "$HOME/Library/Logs/TestApp/log3.log"
|
||||||
|
touch "$HOME/Library/Logs/TestApp/log4.log"
|
||||||
|
touch "$HOME/Library/Logs/TestApp/log5.log"
|
||||||
|
touch "$HOME/Library/Logs/TestApp/log6.log"
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
|
request_sudo_access() { return 0; }
|
||||||
|
start_inline_spinner() { :; }
|
||||||
|
stop_inline_spinner() { :; }
|
||||||
|
enter_alt_screen() { :; }
|
||||||
|
leave_alt_screen() { :; }
|
||||||
|
hide_cursor() { :; }
|
||||||
|
show_cursor() { :; }
|
||||||
|
remove_apps_from_dock() { :; }
|
||||||
|
pgrep() { return 1; }
|
||||||
|
pkill() { return 0; }
|
||||||
|
sudo() { return 0; }
|
||||||
|
has_sensitive_data() { return 1; }
|
||||||
|
find_app_system_files() { return 0; }
|
||||||
|
find_app_files() {
|
||||||
|
cat << LIST
|
||||||
|
$HOME/Library/Application Support/TestApp
|
||||||
|
$HOME/Library/Caches/TestApp
|
||||||
|
$HOME/Library/Logs/TestApp/log1.log
|
||||||
|
$HOME/Library/Logs/TestApp/log2.log
|
||||||
|
$HOME/Library/Logs/TestApp/log3.log
|
||||||
|
$HOME/Library/Logs/TestApp/log4.log
|
||||||
|
$HOME/Library/Logs/TestApp/log5.log
|
||||||
|
$HOME/Library/Logs/TestApp/log6.log
|
||||||
|
LIST
|
||||||
|
}
|
||||||
|
|
||||||
|
selected_apps=()
|
||||||
|
selected_apps+=("0|$HOME/Applications/TestApp.app|TestApp|com.example.TestApp|0|Never")
|
||||||
|
files_cleaned=0
|
||||||
|
total_items=0
|
||||||
|
total_size_cleaned=0
|
||||||
|
|
||||||
|
printf 'q' | batch_uninstall_applications
|
||||||
|
EOF
|
||||||
|
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "$output" == *"~/Library/Logs/TestApp/log6.log"* ]]
|
||||||
|
[[ "$output" != *"more files"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
@test "safe_remove can remove a simple directory" {
|
@test "safe_remove can remove a simple directory" {
|
||||||
mkdir -p "$HOME/test_dir"
|
mkdir -p "$HOME/test_dir"
|
||||||
touch "$HOME/test_dir/file.txt"
|
touch "$HOME/test_dir/file.txt"
|
||||||
|
|||||||
Reference in New Issue
Block a user