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

refactor(clean): merge app cache/user essentials flow

- reorganize perform_cleanup sections and naming

- merge macOS + sandbox caches into clean_app_caches

- move recent items and mail downloads into user essentials

- update core/user tests for renamed internal helpers
This commit is contained in:
tw93
2026-02-21 23:35:53 +08:00
parent 30fe312c22
commit dc8d1bd948
4 changed files with 200 additions and 191 deletions

View File

@@ -107,7 +107,7 @@ EOF
[ -f "$HOME/Documents/.DS_Store" ]
}
@test "clean_recent_items removes shared file lists" {
@test "_clean_recent_items removes shared file lists" {
local shared_dir="$HOME/Library/Application Support/com.apple.sharedfilelist"
mkdir -p "$shared_dir"
touch "$shared_dir/com.apple.LSSharedFileList.RecentApplications.sfl2"
@@ -120,14 +120,14 @@ source "$PROJECT_ROOT/lib/clean/user.sh"
safe_clean() {
echo "safe_clean $1"
}
clean_recent_items
_clean_recent_items
EOF
[ "$status" -eq 0 ]
[[ "$output" == *"Recent"* ]]
}
@test "clean_recent_items handles missing shared directory" {
@test "_clean_recent_items handles missing shared directory" {
rm -rf "$HOME/Library/Application Support/com.apple.sharedfilelist"
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc << 'EOF'
@@ -137,13 +137,13 @@ source "$PROJECT_ROOT/lib/clean/user.sh"
safe_clean() {
echo "safe_clean $1"
}
clean_recent_items
_clean_recent_items
EOF
[ "$status" -eq 0 ]
}
@test "clean_mail_downloads skips cleanup when size below threshold" {
@test "_clean_mail_downloads skips cleanup when size below threshold" {
mkdir -p "$HOME/Library/Mail Downloads"
echo "test" > "$HOME/Library/Mail Downloads/small.txt"
@@ -151,14 +151,14 @@ EOF
set -euo pipefail
source "$PROJECT_ROOT/lib/core/common.sh"
source "$PROJECT_ROOT/lib/clean/user.sh"
clean_mail_downloads
_clean_mail_downloads
EOF
[ "$status" -eq 0 ]
[ -f "$HOME/Library/Mail Downloads/small.txt" ]
}
@test "clean_mail_downloads removes old attachments" {
@test "_clean_mail_downloads removes old attachments" {
mkdir -p "$HOME/Library/Mail Downloads"
touch "$HOME/Library/Mail Downloads/old.pdf"
touch -t 202301010000 "$HOME/Library/Mail Downloads/old.pdf"
@@ -171,7 +171,7 @@ EOF
set -euo pipefail
source "$PROJECT_ROOT/lib/core/common.sh"
source "$PROJECT_ROOT/lib/clean/user.sh"
clean_mail_downloads
_clean_mail_downloads
EOF
[ "$status" -eq 0 ]

View File

@@ -38,22 +38,27 @@ EOF
[[ "$output" != *"Trash"* ]]
}
@test "clean_macos_system_caches calls safe_clean for core paths" {
@test "clean_app_caches includes macOS system caches" {
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/clean/user.sh"
stop_section_spinner() { :; }
start_section_spinner() { :; }
safe_clean() { echo "$2"; }
clean_macos_system_caches
bytes_to_human() { echo "0B"; }
note_activity() { :; }
files_cleaned=0
total_size_cleaned=0
total_items=0
clean_app_caches
EOF
[ "$status" -eq 0 ]
[[ "$output" == *"Saved application states"* ]]
[[ "$output" == *"QuickLook"* ]]
[[ "$output" == *"Saved application states"* ]] || [[ "$output" == *"App caches"* ]]
}
@test "clean_sandboxed_app_caches skips protected containers" {
@test "clean_app_caches skips protected containers" {
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" DRY_RUN=true /bin/bash --noprofile --norc <<'EOF'
set -euo pipefail
source "$PROJECT_ROOT/lib/core/common.sh"
@@ -69,12 +74,12 @@ files_cleaned=0
total_size_cleaned=0
total_items=0
mkdir -p "$HOME/Library/Containers/com.example.app/Data/Library/Caches"
process_container_cache "$HOME/Library/Containers/com.example.app"
clean_sandboxed_app_caches
touch "$HOME/Library/Containers/com.example.app/Data/Library/Caches/test.cache"
clean_app_caches
EOF
[ "$status" -eq 0 ]
[[ "$output" != *"Sandboxed app caches"* ]]
[[ "$output" != *"App caches"* ]] || [[ "$output" == *"already clean"* ]]
}
@test "clean_group_container_caches keeps protected caches and cleans non-protected caches" {