mirror of
https://github.com/tw93/Mole.git
synced 2026-03-22 21:55:08 +00:00
fix(tests): prevent permission dialogs during test runs
Add MOLE_TEST_MODE=1 checks to skip AppleScript osascript calls and sudo operations that trigger system permission dialogs during tests: - lib/check/all.sh: Skip login items listing - lib/clean/apps.sh: Skip running app detection - lib/clean/user.sh: Skip Finder trash operations and sudo test calls - lib/core/log.sh: Skip sudo status check in debug log - lib/uninstall/batch.sh: Skip login item removal Also add MOLE_TEST_MODE=1 export to all test files that load these modules to ensure consistent test isolation.
This commit is contained in:
@@ -186,26 +186,29 @@ remove_login_item() {
|
||||
|
||||
# Remove from Login Items using index-based deletion (handles broken items)
|
||||
if [[ -n "$clean_name" ]]; then
|
||||
# Escape double quotes and backslashes for AppleScript
|
||||
local escaped_name="${clean_name//\\/\\\\}"
|
||||
escaped_name="${escaped_name//\"/\\\"}"
|
||||
# Skip AppleScript during tests to avoid permission dialogs
|
||||
if [[ "${MOLE_TEST_MODE:-0}" != "1" && "${MOLE_TEST_NO_AUTH:-0}" != "1" ]]; then
|
||||
# Escape double quotes and backslashes for AppleScript
|
||||
local escaped_name="${clean_name//\\/\\\\}"
|
||||
escaped_name="${escaped_name//\"/\\\"}"
|
||||
|
||||
osascript <<- EOF > /dev/null 2>&1 || true
|
||||
tell application "System Events"
|
||||
try
|
||||
set itemCount to count of login items
|
||||
-- Delete in reverse order to avoid index shifting
|
||||
repeat with i from itemCount to 1 by -1
|
||||
try
|
||||
set itemName to name of login item i
|
||||
if itemName is "$escaped_name" then
|
||||
delete login item i
|
||||
end if
|
||||
end try
|
||||
end repeat
|
||||
end try
|
||||
end tell
|
||||
EOF
|
||||
osascript <<- EOF > /dev/null 2>&1 || true
|
||||
tell application "System Events"
|
||||
try
|
||||
set itemCount to count of login items
|
||||
-- Delete in reverse order to avoid index shifting
|
||||
repeat with i from itemCount to 1 by -1
|
||||
try
|
||||
set itemName to name of login item i
|
||||
if itemName is "$escaped_name" then
|
||||
delete login item i
|
||||
end if
|
||||
end try
|
||||
end repeat
|
||||
end try
|
||||
end tell
|
||||
EOF
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user