diff --git a/lib/clean/caches.sh b/lib/clean/caches.sh index 72892ce..463996b 100644 --- a/lib/clean/caches.sh +++ b/lib/clean/caches.sh @@ -212,7 +212,9 @@ clean_project_caches() { [[ -d "$cache_dir/cache" ]] && safe_clean "$cache_dir/cache"/* "Next.js build cache" || true ;; "__pycache__") - [[ -d "$cache_dir" ]] && safe_clean "$cache_dir"/* "Python bytecode cache" || true + # Remove the cache directory itself so we avoid expanding every + # .pyc file into a separate safe_clean target. + [[ -d "$cache_dir" ]] && safe_clean "$cache_dir" "Python bytecode cache" || true ;; ".dart_tool") if [[ -d "$cache_dir" ]]; then diff --git a/tests/clean_system_caches.bats b/tests/clean_system_caches.bats index 0275c70..bfd2930 100644 --- a/tests/clean_system_caches.bats +++ b/tests/clean_system_caches.bats @@ -138,6 +138,25 @@ setup() { rm -rf "$HOME/Projects" } +@test "clean_project_caches removes pycache directories as single targets" { + mkdir -p "$HOME/Projects/python-app/__pycache__" + touch "$HOME/Projects/python-app/pyproject.toml" + touch "$HOME/Projects/python-app/__pycache__/module.pyc" + + 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/caches.sh" +safe_clean() { echo "$2|$1"; } +clean_project_caches +EOF + [ "$status" -eq 0 ] + [[ "$output" == *"Python bytecode cache|$HOME/Projects/python-app/__pycache__"* ]] + [[ "$output" != *"module.pyc"* ]] + + rm -rf "$HOME/Projects" +} + @test "clean_project_caches scans configured roots instead of HOME" { mkdir -p "$HOME/.config/mole" mkdir -p "$HOME/CustomProjects/app/.next/cache"