1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-04 16:14:44 +00:00

refactor: simplify Puppeteer cache cleanup to match browser cache pattern

- Replace 48-line custom function with one-line safe_clean call
- Remove unnecessary interactive confirmation (consistent with other browser caches)
- Simplify tests to verify Puppeteer cache is in clean_browsers output
- Net: -93 lines of code for same functionality
This commit is contained in:
Tw93
2026-01-23 09:56:14 +08:00
parent 5a8d766667
commit 1ad7d7e79b
2 changed files with 1 additions and 93 deletions

View File

@@ -12,53 +12,6 @@ clean_user_essentials() {
fi
}
clean_puppeteer_cache() {
local puppeteer_cache="$HOME/.cache/puppeteer"
[[ -d "$puppeteer_cache" ]] || return 0
local size_kb
size_kb=$(get_path_size_kb "$puppeteer_cache" || echo 0)
size_kb="${size_kb:-0}"
if [[ $size_kb -le 0 ]]; then
return 0
fi
local size_human
size_human=$(bytes_to_human "$((size_kb * 1024))")
if [[ "$DRY_RUN" == "true" ]]; then
echo -e " ${YELLOW}${ICON_DRY_RUN}${NC} Puppeteer browser cache ${YELLOW}($size_human dry)${NC}"
note_activity
return 0
fi
if [[ -t 0 ]]; then
echo ""
echo -ne "${PURPLE}${ICON_ARROW}${NC} Remove Puppeteer cache ($size_human)? ${GREEN}Enter${NC} yes, ${GRAY}Space${NC} skip: "
local choice
choice=$(read_key)
if [[ "$choice" == "QUIT" ]]; then
echo -e " ${GRAY}Skipped${NC}"
return 0
fi
if [[ "$choice" == "SPACE" ]]; then
echo -e " ${GRAY}Skipped${NC}"
return 0
elif [[ "$choice" == "ENTER" ]]; then
printf "\r\033[K"
else
echo -e " ${GRAY}Skipped${NC}"
return 0
fi
fi
safe_clean "$puppeteer_cache" "Puppeteer browser cache"
}
# Remove old Google Chrome versions while keeping Current.
clean_chrome_old_versions() {
local -a app_paths=(
@@ -493,7 +446,7 @@ clean_browsers() {
safe_clean ~/Library/Application\ Support/Google/Chrome/*/Application\ Cache/* "Chrome app cache"
safe_clean ~/Library/Application\ Support/Google/Chrome/*/GPUCache/* "Chrome GPU cache"
safe_clean ~/Library/Caches/Chromium/* "Chromium cache"
clean_puppeteer_cache
safe_clean ~/.cache/puppeteer/* "Puppeteer browser cache"
safe_clean ~/Library/Caches/com.microsoft.edgemac/* "Edge cache"
safe_clean ~/Library/Caches/company.thebrowser.Browser/* "Arc cache"
safe_clean ~/Library/Caches/company.thebrowser.dia/* "Dia cache"

View File

@@ -110,7 +110,6 @@ EOF
set -euo pipefail
source "$PROJECT_ROOT/lib/core/common.sh"
source "$PROJECT_ROOT/lib/clean/user.sh"
mkdir -p "$HOME/.cache/puppeteer"
safe_clean() { echo "$2"; }
clean_browsers
EOF
@@ -118,53 +117,9 @@ EOF
[ "$status" -eq 0 ]
[[ "$output" == *"Safari cache"* ]]
[[ "$output" == *"Firefox cache"* ]]
}
@test "clean_puppeteer_cache cleans when cache exists in non-interactive mode" {
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" DRY_RUN=false bash --noprofile --norc <<'EOF'
set -euo pipefail
source "$PROJECT_ROOT/lib/core/common.sh"
source "$PROJECT_ROOT/lib/clean/user.sh"
mkdir -p "$HOME/.cache/puppeteer"
echo "test" > "$HOME/.cache/puppeteer/chrome-1234.zip"
safe_clean() { echo "$2"; }
clean_puppeteer_cache
EOF
[ "$status" -eq 0 ]
[[ "$output" == *"Puppeteer browser cache"* ]]
}
@test "clean_puppeteer_cache skips when cache does not exist" {
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" DRY_RUN=false bash --noprofile --norc <<'EOF'
set -euo pipefail
source "$PROJECT_ROOT/lib/core/common.sh"
source "$PROJECT_ROOT/lib/clean/user.sh"
safe_clean() { echo "$2"; }
rm -rf "$HOME/.cache/puppeteer"
clean_puppeteer_cache
EOF
[ "$status" -eq 0 ]
[[ -z "${output//[[:space:]]/}" ]]
}
@test "clean_puppeteer_cache respects DRY_RUN mode" {
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" DRY_RUN=true bash --noprofile --norc <<'EOF'
set -euo pipefail
source "$PROJECT_ROOT/lib/core/common.sh"
source "$PROJECT_ROOT/lib/clean/user.sh"
mkdir -p "$HOME/.cache/puppeteer"
echo "test" > "$HOME/.cache/puppeteer/chrome-1234.zip"
note_activity() { :; }
clean_puppeteer_cache
EOF
[ "$status" -eq 0 ]
[[ "$output" == *"Puppeteer browser cache"* ]]
[[ "$output" == *"dry"* ]]
}
@test "clean_application_support_logs skips when no access" {
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc <<'EOF'
set -euo pipefail