@@ -74,6 +74,45 @@ run_clean_dry_run() {
7474 " $PROJECT_ROOT /mole" clean --dry-run
7575}
7676
77+ @test " safe_clean item count reflects cleaned items, not raw target count" {
78+ local base=" $HOME /safe_clean_count"
79+ mkdir -p " $base "
80+ printf ' xxxx' > " $base /a"
81+ printf ' xxxx' > " $base /b"
82+ printf ' xxxx' > " $base /keep"
83+
84+ run env HOME=" $HOME " PROJECT_ROOT=" $PROJECT_ROOT " MOLE_TEST_MODE=1 bash --noprofile --norc << EOF
85+ set -euo pipefail
86+ source "\$ PROJECT_ROOT/lib/core/common.sh"
87+ source "\$ PROJECT_ROOT/bin/clean.sh"
88+ DRY_RUN=false
89+ files_cleaned=0
90+ total_size_cleaned=0
91+ total_items=0
92+ start_section_spinner() { :; }
93+ stop_section_spinner() { :; }
94+ start_inline_spinner() { :; }
95+ stop_inline_spinner() { :; }
96+ note_activity() { :; }
97+ # One of the three targets is whitelisted, so only two are actually cleaned.
98+ is_path_whitelisted() { [[ "\$ 1" == "$base /keep" ]]; }
99+ safe_remove() { /bin/rm -rf "\$ 1"; return 0; }
100+ safe_clean "$base /a" "$base /b" "$base /keep" "Test cache"
101+ EOF
102+
103+ [ " $status " -eq 0 ] || return 1
104+ # Two items were removed, so the detail column must say "2 items", not "3".
105+ # Every assertion ends with || return 1: bare [[ ]] failures mid-test can be
106+ # swallowed and let the test pass vacuously (same shape as #886).
107+ [[ " $output " == * " 2 items" * ]] || return 1
108+ [[ " $output " != * " 3 items" * ]] || return 1
109+ [[ ! -e " $base /a" ]] || return 1
110+ [[ ! -e " $base /b" ]] || return 1
111+ [[ -e " $base /keep" ]] || return 1
112+
113+ rm -rf " $base "
114+ }
115+
77116@test " mo clean --dry-run skips system cleanup in non-interactive mode" {
78117 set_mock_sudo_uncached
79118 run_clean_dry_run
0 commit comments