1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-22 19:40:07 +00:00

fix(log): preserve Mole runtime logs during clean

This commit is contained in:
Tw93
2026-03-19 09:52:27 +08:00
parent 3b46b4ade6
commit 584e10cdc4
6 changed files with 107 additions and 26 deletions

View File

@@ -80,6 +80,41 @@ EOF
[[ "$output" == *"Trash · emptied, 2 items"* ]]
}
@test "clean_user_essentials keeps Mole runtime logs while cleaning other user logs" {
mkdir -p "$HOME/Library/Logs/mole"
mkdir -p "$HOME/Library/Logs/OtherApp"
touch "$HOME/Library/Logs/mole/operations.log"
touch "$HOME/Library/Logs/OtherApp/old.log"
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc <<'EOF'
set -euo pipefail
source "$PROJECT_ROOT/lib/core/common.sh"
source "$PROJECT_ROOT/lib/clean/user.sh"
DRY_RUN=false
start_section_spinner() { :; }
stop_section_spinner() { :; }
note_activity() { :; }
is_path_whitelisted() { return 1; }
safe_clean() {
local path=""
for path in "${@:1:$#-1}"; do
if should_protect_path "$path"; then
continue
fi
/bin/rm -rf "$path"
done
}
clean_user_essentials
[[ -d "$HOME/Library/Logs/mole" ]]
[[ -f "$HOME/Library/Logs/mole/operations.log" ]]
[[ ! -e "$HOME/Library/Logs/OtherApp/old.log" ]]
EOF
[ "$status" -eq 0 ]
}
@test "clean_app_caches includes macOS system caches" {
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc <<'EOF'
set -euo pipefail

View File

@@ -69,6 +69,25 @@ setup() {
grep -q "ERROR: $message" "$log_file"
}
@test "log_operation recreates operations log if the log directory disappears mid-session" {
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc <<'EOF'
set -euo pipefail
source "$PROJECT_ROOT/lib/core/common.sh"
rm -rf "$HOME/Library/Logs/mole"
log_operation "clean" "REMOVED" "/tmp/example" "1KB"
EOF
[ "$status" -eq 0 ]
local oplog="$HOME/Library/Logs/mole/operations.log"
[[ -f "$oplog" ]]
grep -Fq "[clean] REMOVED /tmp/example (1KB)" "$oplog"
}
@test "should_protect_path protects Mole runtime logs" {
result="$(HOME="$HOME" bash --noprofile --norc -c "source '$PROJECT_ROOT/lib/core/common.sh'; should_protect_path '$HOME/Library/Logs/mole/operations.log' && echo protected || echo not-protected")"
[ "$result" = "protected" ]
}
@test "rotate_log_once only checks log size once per session" {
local log_file="$HOME/Library/Logs/mole/mole.log"
mkdir -p "$(dirname "$log_file")"