From 5a8d766667c2d12b21af9f0262376e35160d96e8 Mon Sep 17 00:00:00 2001 From: Shakeel Mohamed Date: Thu, 22 Jan 2026 17:55:02 -0800 Subject: [PATCH] Add Puppeteer cache cleanup (#353) --- lib/clean/user.sh | 48 ++++++++++++++++++++++++++++++++++++++ tests/clean_user_core.bats | 46 ++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/lib/clean/user.sh b/lib/clean/user.sh index 1ba543c..30533d6 100644 --- a/lib/clean/user.sh +++ b/lib/clean/user.sh @@ -12,6 +12,53 @@ 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=( @@ -446,6 +493,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 ~/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" diff --git a/tests/clean_user_core.bats b/tests/clean_user_core.bats index 97b4cba..9ea3475 100644 --- a/tests/clean_user_core.bats +++ b/tests/clean_user_core.bats @@ -110,6 +110,7 @@ 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 @@ -119,6 +120,51 @@ EOF [[ "$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