1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-17 13:15:26 +00:00

fix(clean): use sudo-safe cleanup for Xcode documentation cache

This commit is contained in:
tw93
2026-02-15 07:52:43 +08:00
parent 7d193526c3
commit 744ecec4ba
5 changed files with 102 additions and 8 deletions

View File

@@ -149,10 +149,12 @@ set -euo pipefail
source "$PROJECT_ROOT/lib/core/common.sh"
source "$PROJECT_ROOT/lib/clean/dev.sh"
note_activity() { :; }
safe_clean() {
local description="${*: -1}"
has_sudo_session() { return 0; }
is_path_whitelisted() { return 1; }
should_protect_path() { return 1; }
safe_sudo_remove() {
local target="$1"
echo "CLEAN:$target:$description"
echo "CLEAN:$target:Xcode documentation cache (old indexes)"
}
clean_xcode_documentation_cache
EOF
@@ -174,13 +176,13 @@ source "$PROJECT_ROOT/lib/core/common.sh"
source "$PROJECT_ROOT/lib/clean/dev.sh"
note_activity() { :; }
pgrep() { return 0; }
safe_clean() { echo "UNEXPECTED_SAFE_CLEAN"; }
safe_sudo_remove() { echo "UNEXPECTED_SAFE_SUDO_REMOVE"; }
clean_xcode_documentation_cache
EOF
[ "$status" -eq 0 ]
[[ "$output" == *"skipping documentation cache cleanup"* ]]
[[ "$output" != *"UNEXPECTED_SAFE_CLEAN"* ]]
[[ "$output" != *"UNEXPECTED_SAFE_SUDO_REMOVE"* ]]
}
@test "check_rust_toolchains reports multiple toolchains" {

View File

@@ -77,6 +77,8 @@ touch "$TMP_DIAG/MyApp_2025-02-10-120000_host.ips"
touch "$TMP_DIAG/MyApp.crash"
touch "$TMP_DIAG/MyApp_2025-02-10-120001_host.spin"
touch "$TMP_DIAG/OtherApp_2025-02-10.ips"
touch "$TMP_DIAG/MyAppPro_2025-02-10-120002_host.ips"
touch "$TMP_DIAG/MyAppPro.crash"
touch "$TMP_DIAG/MyApp_log.txt"
out=$(get_diagnostic_report_paths_for_app "$TMP_APP" "My App" "$TMP_DIAG" 2> /dev/null || true)
@@ -92,6 +94,13 @@ else
echo " OK does not return OtherApp"
((PASSED++))
fi
if [[ "$out" == *"MyAppPro"* ]]; then
echo " FAIL should not return MyAppPro (prefix collision)"
((FAILED++))
else
echo " OK does not return MyAppPro"
((PASSED++))
fi
if [[ "$out" == *"MyApp_log.txt"* ]]; then
echo " FAIL should not return non-diagnostic extension"
((FAILED++))

View File

@@ -60,6 +60,41 @@ EOF
[[ "$result" == *"LaunchAgents/com.example.TestApp.plist"* ]]
}
@test "get_diagnostic_report_paths_for_app avoids executable prefix collisions" {
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc << 'EOF'
set -euo pipefail
source "$PROJECT_ROOT/lib/core/common.sh"
diag_dir="$HOME/Library/Logs/DiagnosticReports"
app_dir="$HOME/Applications/Foo.app"
mkdir -p "$diag_dir" "$app_dir/Contents"
cat > "$app_dir/Contents/Info.plist" << 'PLIST'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>Foo</string>
</dict>
</plist>
PLIST
touch "$diag_dir/Foo.crash"
touch "$diag_dir/Foo_2026-01-01-120000_host.ips"
touch "$diag_dir/Foobar.crash"
touch "$diag_dir/Foobar_2026-01-01-120001_host.ips"
result=$(get_diagnostic_report_paths_for_app "$app_dir" "Foo" "$diag_dir")
[[ "$result" == *"Foo.crash"* ]] || exit 1
[[ "$result" == *"Foo_2026-01-01-120000_host.ips"* ]] || exit 1
[[ "$result" != *"Foobar.crash"* ]] || exit 1
[[ "$result" != *"Foobar_2026-01-01-120001_host.ips"* ]] || exit 1
EOF
[ "$status" -eq 0 ]
}
@test "calculate_total_size returns aggregate kilobytes" {
mkdir -p "$HOME/sized"
dd if=/dev/zero of="$HOME/sized/file1" bs=1024 count=1 > /dev/null 2>&1