@@ -159,6 +159,134 @@ EOF
159159 [[ " $output " != * " (custom path)" * ]]
160160}
161161
162+ @test " clean_dev_npm cleans default bun cache when bun is unavailable" {
163+ run env HOME=" $HOME " PROJECT_ROOT=" $PROJECT_ROOT " bash --noprofile --norc << 'EOF '
164+ set -euo pipefail
165+ source "$PROJECT_ROOT/lib/core/common.sh"
166+ source "$PROJECT_ROOT/lib/clean/dev.sh"
167+ start_section_spinner() { :; }
168+ stop_section_spinner() { :; }
169+ clean_tool_cache() { echo "$1|$*"; }
170+ safe_clean() { echo "$2|$1"; }
171+ note_activity() { :; }
172+ run_with_timeout() { shift; "$@"; }
173+ npm() { return 0; }
174+ bun() { return 1; }
175+ export -f npm bun
176+ clean_dev_npm
177+ EOF
178+
179+ [ " $status " -eq 0 ]
180+ [[ " $output " == * " Bun cache|$HOME /.bun/install/cache/*" * ]]
181+ [[ " $output " != * " bun cache|bun cache bun pm cache rm" * ]]
182+ [[ " $output " != * " Orphaned bun cache" * ]]
183+ }
184+
185+ @test " clean_dev_npm uses bun cache command for default bun cache path" {
186+ run env HOME=" $HOME " PROJECT_ROOT=" $PROJECT_ROOT " bash --noprofile --norc << 'EOF '
187+ set -euo pipefail
188+ source "$PROJECT_ROOT/lib/core/common.sh"
189+ source "$PROJECT_ROOT/lib/clean/dev.sh"
190+ start_section_spinner() { :; }
191+ stop_section_spinner() { :; }
192+ clean_tool_cache() { echo "$1|$*"; }
193+ safe_clean() { echo "$2|$1"; }
194+ note_activity() { :; }
195+ run_with_timeout() { shift; "$@"; }
196+ npm() { return 0; }
197+ bun() {
198+ if [[ "$1" == "--version" ]]; then
199+ echo "1.2.0"
200+ return 0
201+ fi
202+ if [[ "$1" == "pm" && "$2" == "cache" && "${3:-}" == "rm" ]]; then
203+ return 0
204+ fi
205+ if [[ "$1" == "pm" && "$2" == "cache" ]]; then
206+ echo "$HOME/.bun/install/cache"
207+ return 0
208+ fi
209+ return 0
210+ }
211+ export -f npm bun
212+ clean_dev_npm
213+ EOF
214+
215+ [ " $status " -eq 0 ]
216+ [[ " $output " == * " bun cache|bun cache bun pm cache rm" * ]]
217+ [[ " $output " != * " Orphaned bun cache" * ]]
218+ }
219+
220+ @test " clean_dev_npm cleans orphaned default bun cache when custom path is configured" {
221+ run env HOME=" $HOME " PROJECT_ROOT=" $PROJECT_ROOT " bash --noprofile --norc << 'EOF '
222+ set -euo pipefail
223+ source "$PROJECT_ROOT/lib/core/common.sh"
224+ source "$PROJECT_ROOT/lib/clean/dev.sh"
225+ start_section_spinner() { :; }
226+ stop_section_spinner() { :; }
227+ clean_tool_cache() { echo "$1|$*"; }
228+ safe_clean() { echo "$2|$1"; }
229+ note_activity() { :; }
230+ run_with_timeout() { shift; "$@"; }
231+ npm() { return 0; }
232+ bun() {
233+ if [[ "$1" == "--version" ]]; then
234+ echo "1.2.0"
235+ return 0
236+ fi
237+ if [[ "$1" == "pm" && "$2" == "cache" && "${3:-}" == "rm" ]]; then
238+ return 0
239+ fi
240+ if [[ "$1" == "pm" && "$2" == "cache" ]]; then
241+ echo "/tmp/mole-bun-cache"
242+ return 0
243+ fi
244+ return 0
245+ }
246+ export -f npm bun
247+ clean_dev_npm
248+ EOF
249+
250+ [ " $status " -eq 0 ]
251+ [[ " $output " == * " bun cache|bun cache bun pm cache rm" * ]]
252+ [[ " $output " == * " Orphaned bun cache|$HOME /.bun/install/cache/*" * ]]
253+ }
254+
255+ @test " clean_dev_npm treats default bun cache path with trailing slash as same path" {
256+ run env HOME=" $HOME " PROJECT_ROOT=" $PROJECT_ROOT " bash --noprofile --norc << 'EOF '
257+ set -euo pipefail
258+ source "$PROJECT_ROOT/lib/core/common.sh"
259+ source "$PROJECT_ROOT/lib/clean/dev.sh"
260+ start_section_spinner() { :; }
261+ stop_section_spinner() { :; }
262+ clean_tool_cache() { echo "$1|$*"; }
263+ safe_clean() { echo "$2|$1"; }
264+ note_activity() { :; }
265+ run_with_timeout() { shift; "$@"; }
266+ npm() { return 0; }
267+ bun() {
268+ if [[ "$1" == "--version" ]]; then
269+ echo "1.2.0"
270+ return 0
271+ fi
272+ if [[ "$1" == "pm" && "$2" == "cache" && "${3:-}" == "rm" ]]; then
273+ return 0
274+ fi
275+ if [[ "$1" == "pm" && "$2" == "cache" ]]; then
276+ echo "$HOME/.bun/install/cache/"
277+ return 0
278+ fi
279+ return 0
280+ }
281+ export -f npm bun
282+ clean_dev_npm
283+ EOF
284+
285+ [ " $status " -eq 0 ]
286+ [[ " $output " == * " bun cache|bun cache bun pm cache rm" * ]]
287+ [[ " $output " != * " Orphaned bun cache" * ]]
288+ }
289+
162290@test " clean_dev_docker skips when daemon not running" {
163291 run env HOME=" $HOME " PROJECT_ROOT=" $PROJECT_ROOT " DRY_RUN=false bash --noprofile --norc << 'EOF '
164292set -euo pipefail
0 commit comments