From 4c60fcca73c36d400f29d5f31d5680e718c26d76 Mon Sep 17 00:00:00 2001 From: tw93 Date: Wed, 11 Feb 2026 14:22:22 +0800 Subject: [PATCH] fix(uninstall): show full preview paths and add regression tests --- lib/uninstall/batch.sh | 23 ++---------- tests/clean_system_maintenance.bats | 18 +++++++++ tests/uninstall.bats | 57 +++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 19 deletions(-) diff --git a/lib/uninstall/batch.sh b/lib/uninstall/batch.sh index 851436d..4996089 100755 --- a/lib/uninstall/batch.sh +++ b/lib/uninstall/batch.sh @@ -326,34 +326,19 @@ batch_uninstall_applications() { echo -e " ${GREEN}${ICON_SUCCESS}${NC} ${app_path/$HOME/~}" - # Show related files (limit to 5). - local file_count=0 - local max_files=5 + # Show all related files so users can fully review before deletion. while IFS= read -r file; do if [[ -n "$file" && -e "$file" ]]; then - if [[ $file_count -lt $max_files ]]; then - echo -e " ${GREEN}${ICON_SUCCESS}${NC} ${file/$HOME/~}" - fi - ((file_count++)) + echo -e " ${GREEN}${ICON_SUCCESS}${NC} ${file/$HOME/~}" fi done <<< "$related_files" - # Show system files (limit to 5). - local sys_file_count=0 + # Show all system files so users can fully review before deletion. while IFS= read -r file; do if [[ -n "$file" && -e "$file" ]]; then - if [[ $sys_file_count -lt $max_files ]]; then - echo -e " ${BLUE}${ICON_WARNING}${NC} System: $file" - fi - ((sys_file_count++)) + echo -e " ${BLUE}${ICON_WARNING}${NC} System: $file" fi 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 # Confirmation before requesting sudo. diff --git a/tests/clean_system_maintenance.bats b/tests/clean_system_maintenance.bats index bec4928..9e80560 100644 --- a/tests/clean_system_maintenance.bats +++ b/tests/clean_system_maintenance.bats @@ -517,6 +517,24 @@ EOF [[ "$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" { mkdir -p "$HOME/Library/Caches/com.apple.QuickLook.thumbnailcache" touch "$HOME/Library/Caches/com.apple.QuickLook.thumbnailcache/test.db" diff --git a/tests/uninstall.bats b/tests/uninstall.bats index cd6b24e..f1edade 100644 --- a/tests/uninstall.bats +++ b/tests/uninstall.bats @@ -123,6 +123,63 @@ EOF [ "$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" { mkdir -p "$HOME/test_dir" touch "$HOME/test_dir/file.txt"