1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-04 11:31:46 +00:00

Merge branch 'main' into dev

This commit is contained in:
tw93
2026-01-31 17:37:46 +08:00
22 changed files with 1642 additions and 414 deletions

View File

@@ -160,6 +160,32 @@ EOF
[ "$result" = "protected" ]
}
@test "Apple apps from App Store can be uninstalled (Issue #386)" {
# Xcode should NOT be protected from uninstall
result=$(HOME="$HOME" bash --noprofile --norc -c "source '$PROJECT_ROOT/lib/core/common.sh'; should_protect_from_uninstall 'com.apple.dt.Xcode' && echo 'protected' || echo 'not-protected'")
[ "$result" = "not-protected" ]
# Final Cut Pro should NOT be protected from uninstall
result=$(HOME="$HOME" bash --noprofile --norc -c "source '$PROJECT_ROOT/lib/core/common.sh'; should_protect_from_uninstall 'com.apple.FinalCutPro' && echo 'protected' || echo 'not-protected'")
[ "$result" = "not-protected" ]
# GarageBand should NOT be protected from uninstall
result=$(HOME="$HOME" bash --noprofile --norc -c "source '$PROJECT_ROOT/lib/core/common.sh'; should_protect_from_uninstall 'com.apple.GarageBand' && echo 'protected' || echo 'not-protected'")
[ "$result" = "not-protected" ]
# iWork apps should NOT be protected from uninstall
result=$(HOME="$HOME" bash --noprofile --norc -c "source '$PROJECT_ROOT/lib/core/common.sh'; should_protect_from_uninstall 'com.apple.iWork.Pages' && echo 'protected' || echo 'not-protected'")
[ "$result" = "not-protected" ]
# But Safari (system app) should still be protected
result=$(HOME="$HOME" bash --noprofile --norc -c "source '$PROJECT_ROOT/lib/core/common.sh'; should_protect_from_uninstall 'com.apple.Safari' && echo 'protected' || echo 'not-protected'")
[ "$result" = "protected" ]
# And Finder should still be protected
result=$(HOME="$HOME" bash --noprofile --norc -c "source '$PROJECT_ROOT/lib/core/common.sh'; should_protect_from_uninstall 'com.apple.finder' && echo 'protected' || echo 'not-protected'")
[ "$result" = "protected" ]
}
@test "print_summary_block formats output correctly" {
result=$(HOME="$HOME" bash --noprofile --norc -c "source '$PROJECT_ROOT/lib/core/common.sh'; print_summary_block 'success' 'Test Summary' 'Detail 1' 'Detail 2'")
[[ "$result" == *"Test Summary"* ]]

View File

@@ -123,28 +123,28 @@ EOF
}
@test "check_android_ndk reports multiple NDK versions" {
run bash -c 'HOME=$(mktemp -d) && mkdir -p "$HOME/Library/Android/sdk/ndk"/{21.0.1,22.0.0,20.0.0} && source "$0" && note_activity() { :; } && NC="" && GREEN="" && GRAY="" && YELLOW="" && ICON_WARNING="" && check_android_ndk' "$PROJECT_ROOT/lib/clean/dev.sh"
run bash -c 'HOME=$(mktemp -d) && mkdir -p "$HOME/Library/Android/sdk/ndk"/{21.0.1,22.0.0,20.0.0} && source "$0" && note_activity() { :; } && NC="" && GREEN="" && GRAY="" && YELLOW="" && ICON_SUCCESS="" && check_android_ndk' "$PROJECT_ROOT/lib/clean/dev.sh"
[ "$status" -eq 0 ]
[[ "$output" == *"Android NDK versions: 3 found"* ]]
}
@test "check_android_ndk silent when only one NDK" {
run bash -c 'HOME=$(mktemp -d) && mkdir -p "$HOME/Library/Android/sdk/ndk/22.0.0" && source "$0" && note_activity() { :; } && NC="" && GREEN="" && GRAY="" && YELLOW="" && ICON_WARNING="" && check_android_ndk' "$PROJECT_ROOT/lib/clean/dev.sh"
run bash -c 'HOME=$(mktemp -d) && mkdir -p "$HOME/Library/Android/sdk/ndk/22.0.0" && source "$0" && note_activity() { :; } && NC="" && GREEN="" && GRAY="" && YELLOW="" && ICON_SUCCESS="" && check_android_ndk' "$PROJECT_ROOT/lib/clean/dev.sh"
[ "$status" -eq 0 ]
[[ "$output" != *"NDK versions"* ]]
}
@test "check_rust_toolchains reports multiple toolchains" {
run bash -c 'HOME=$(mktemp -d) && mkdir -p "$HOME/.rustup/toolchains"/{stable,nightly,1.75.0}-aarch64-apple-darwin && source "$0" && note_activity() { :; } && NC="" && GREEN="" && GRAY="" && YELLOW="" && ICON_WARNING="" && rustup() { :; } && export -f rustup && check_rust_toolchains' "$PROJECT_ROOT/lib/clean/dev.sh"
run bash -c 'HOME=$(mktemp -d) && mkdir -p "$HOME/.rustup/toolchains"/{stable,nightly,1.75.0}-aarch64-apple-darwin && source "$0" && note_activity() { :; } && NC="" && GREEN="" && GRAY="" && YELLOW="" && ICON_SUCCESS="" && rustup() { :; } && export -f rustup && check_rust_toolchains' "$PROJECT_ROOT/lib/clean/dev.sh"
[ "$status" -eq 0 ]
[[ "$output" == *"Rust toolchains: 3 found"* ]]
}
@test "check_rust_toolchains silent when only one toolchain" {
run bash -c 'HOME=$(mktemp -d) && mkdir -p "$HOME/.rustup/toolchains/stable-aarch64-apple-darwin" && source "$0" && note_activity() { :; } && NC="" && GREEN="" && GRAY="" && YELLOW="" && ICON_WARNING="" && rustup() { :; } && export -f rustup && check_rust_toolchains' "$PROJECT_ROOT/lib/clean/dev.sh"
run bash -c 'HOME=$(mktemp -d) && mkdir -p "$HOME/.rustup/toolchains/stable-aarch64-apple-darwin" && source "$0" && note_activity() { :; } && NC="" && GREEN="" && GRAY="" && YELLOW="" && ICON_SUCCESS="" && rustup() { :; } && export -f rustup && check_rust_toolchains' "$PROJECT_ROOT/lib/clean/dev.sh"
[ "$status" -eq 0 ]
[[ "$output" != *"Rust toolchains"* ]]

View File

@@ -0,0 +1,97 @@
#!/usr/bin/env bats
# Test naming variant detection for find_app_files (Issue #377)
setup_file() {
PROJECT_ROOT="$(cd "${BATS_TEST_DIRNAME}/.." && pwd)"
export PROJECT_ROOT
ORIGINAL_HOME="${HOME:-}"
export ORIGINAL_HOME
HOME="$(mktemp -d "${BATS_TEST_DIRNAME}/tmp-naming.XXXXXX")"
export HOME
source "$PROJECT_ROOT/lib/core/base.sh"
source "$PROJECT_ROOT/lib/core/log.sh"
source "$PROJECT_ROOT/lib/core/app_protection.sh"
}
teardown_file() {
if [[ -d "$HOME" && "$HOME" =~ tmp-naming ]]; then
rm -rf "$HOME"
fi
export HOME="$ORIGINAL_HOME"
}
setup() {
find "$HOME" -mindepth 1 -maxdepth 1 -exec rm -rf {} + 2>/dev/null || true
source "$PROJECT_ROOT/lib/core/base.sh"
source "$PROJECT_ROOT/lib/core/log.sh"
source "$PROJECT_ROOT/lib/core/app_protection.sh"
}
@test "find_app_files detects lowercase-hyphen variant (maestro-studio)" {
mkdir -p "$HOME/.config/maestro-studio"
echo "test" > "$HOME/.config/maestro-studio/config.json"
result=$(find_app_files "com.maestro.studio" "Maestro Studio")
[[ "$result" =~ .config/maestro-studio ]]
}
@test "find_app_files detects no-space variant (MaestroStudio)" {
mkdir -p "$HOME/Library/Application Support/MaestroStudio"
echo "test" > "$HOME/Library/Application Support/MaestroStudio/data.db"
result=$(find_app_files "com.maestro.studio" "Maestro Studio")
[[ "$result" =~ "Library/Application Support/MaestroStudio" ]]
}
@test "find_app_files extracts base name from version suffix (Zed Nightly -> zed)" {
mkdir -p "$HOME/.config/zed"
mkdir -p "$HOME/Library/Application Support/Zed"
echo "test" > "$HOME/.config/zed/settings.json"
echo "test" > "$HOME/Library/Application Support/Zed/cache.db"
result=$(find_app_files "dev.zed.Zed-Nightly" "Zed Nightly")
[[ "$result" =~ .config/zed ]]
[[ "$result" =~ "Library/Application Support/Zed" ]]
}
@test "find_app_files detects multiple naming variants simultaneously" {
mkdir -p "$HOME/.config/maestro-studio"
mkdir -p "$HOME/Library/Application Support/MaestroStudio"
mkdir -p "$HOME/Library/Application Support/Maestro-Studio"
mkdir -p "$HOME/.local/share/maestrostudio"
echo "test" > "$HOME/.config/maestro-studio/config.json"
echo "test" > "$HOME/Library/Application Support/MaestroStudio/data.db"
echo "test" > "$HOME/Library/Application Support/Maestro-Studio/prefs.json"
echo "test" > "$HOME/.local/share/maestrostudio/cache.db"
result=$(find_app_files "com.maestro.studio" "Maestro Studio")
[[ "$result" =~ .config/maestro-studio ]]
[[ "$result" =~ "Library/Application Support/MaestroStudio" ]]
[[ "$result" =~ "Library/Application Support/Maestro-Studio" ]]
[[ "$result" =~ .local/share/maestrostudio ]]
}
@test "find_app_files handles multi-word version suffix (Firefox Developer Edition)" {
mkdir -p "$HOME/.local/share/firefox"
echo "test" > "$HOME/.local/share/firefox/profiles.ini"
result=$(find_app_files "org.mozilla.firefoxdeveloperedition" "Firefox Developer Edition")
[[ "$result" =~ .local/share/firefox ]]
}
@test "find_app_files does not match empty app name" {
mkdir -p "$HOME/Library/Application Support/test"
result=$(find_app_files "com.test" "" 2>/dev/null || true)
[[ ! "$result" =~ "Library/Application Support"$ ]]
}