1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-16 06:36:13 +00:00

feat: smart vendor directory handling in purge

- Only clean PHP Composer vendor (regeneratable)
  - Protect Rails, Go, and unknown vendor directories
  - Enhanced test coverage for all scenarios

  Builds on PR #229 with improved multi-language support
This commit is contained in:
Tw93
2026-01-02 00:03:17 +08:00
parent 70f427d861
commit a671c63401
2 changed files with 90 additions and 10 deletions

View File

@@ -127,7 +127,7 @@ setup() {
[[ "$result" == "SKIPPED" ]]
}
@test "scan_purge_targets: keeps non-Rails vendor directory" {
@test "scan_purge_targets: cleans PHP Composer vendor directory" {
mkdir -p "$HOME/www/php-app/vendor"
touch "$HOME/www/php-app/composer.json"
@@ -149,6 +149,52 @@ setup() {
[[ "$result" == "FOUND" ]]
}
@test "scan_purge_targets: skips Go vendor directory" {
mkdir -p "$HOME/www/go-app/vendor"
touch "$HOME/www/go-app/go.mod"
touch "$HOME/www/go-app/go.sum"
local scan_output
scan_output="$(mktemp)"
result=$(bash -c "
source '$PROJECT_ROOT/lib/clean/project.sh'
scan_purge_targets '$HOME/www' '$scan_output'
if grep -q '$HOME/www/go-app/vendor' '$scan_output'; then
echo 'FOUND'
else
echo 'SKIPPED'
fi
")
rm -f "$scan_output"
[[ "$result" == "SKIPPED" ]]
}
@test "scan_purge_targets: skips unknown vendor directory" {
# Create a vendor directory without any project file
mkdir -p "$HOME/www/unknown-app/vendor"
local scan_output
scan_output="$(mktemp)"
result=$(bash -c "
source '$PROJECT_ROOT/lib/clean/project.sh'
scan_purge_targets '$HOME/www' '$scan_output'
if grep -q '$HOME/www/unknown-app/vendor' '$scan_output'; then
echo 'FOUND'
else
echo 'SKIPPED'
fi
")
rm -f "$scan_output"
# Unknown vendor should be protected (conservative approach)
[[ "$result" == "SKIPPED" ]]
}
@test "is_recently_modified: detects recent projects" {
mkdir -p "$HOME/www/project/node_modules"
touch "$HOME/www/project/package.json"