1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-23 21:35:06 +00:00

fix: keep dry-run yellow and align clean output colors

Keep dry-run previews yellow while reusing the 1 GiB threshold for actual cleanup results across clean modules. Add regression coverage for the shared color helper and DS_Store cleanup output.
This commit is contained in:
Tw93
2026-03-23 17:53:02 +08:00
parent 4b82b4aa70
commit 5df81a2314
8 changed files with 105 additions and 27 deletions

View File

@@ -32,8 +32,8 @@ source "$PROJECT_ROOT/lib/clean/apps.sh"
start_inline_spinner() { :; }
stop_section_spinner() { :; }
note_activity() { :; }
get_file_size() { echo 10; }
bytes_to_human() { echo "0B"; }
get_file_size() { echo $((2 * 1024 * 1024 * 1024)); }
bytes_to_human() { echo "2.15GB"; }
files_cleaned=0
total_size_cleaned=0
total_items=0
@@ -44,6 +44,30 @@ EOF
[ "$status" -eq 0 ]
[[ "$output" == *"DS test"* ]]
[[ "$output" == *$'\033[0;33m→\033[0m'* ]]
}
@test "clean_ds_store_tree uses yellow for small successful cleanups" {
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" DRY_RUN=false /bin/bash --noprofile --norc <<'EOF'
set -euo pipefail
source "$PROJECT_ROOT/lib/core/common.sh"
source "$PROJECT_ROOT/lib/clean/apps.sh"
start_inline_spinner() { :; }
stop_section_spinner() { :; }
note_activity() { :; }
get_file_size() { echo 512; }
bytes_to_human() { echo "512B"; }
files_cleaned=0
total_size_cleaned=0
total_items=0
mkdir -p "$HOME/test_ds"
touch "$HOME/test_ds/.DS_Store"
clean_ds_store_tree "$HOME/test_ds" "DS test"
EOF
[ "$status" -eq 0 ]
[[ "$output" == *"DS test"* ]]
[[ "$output" == *$'\033[0;33m✓\033[0m'* ]]
}
@test "scan_installed_apps uses cache when fresh" {

View File

@@ -44,6 +44,21 @@ setup() {
[[ -n "$result" ]]
}
@test "cleanup_result_color_kb switches from yellow to green at 1 GiB" {
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc <<'EOF'
set -euo pipefail
source "$PROJECT_ROOT/lib/core/common.sh"
if [[ "$(cleanup_result_color_kb $((MOLE_ONE_GIB_KB - 1)))" == "$YELLOW" ]] &&
[[ "$(cleanup_result_color_kb "$MOLE_ONE_GIB_KB")" == "$GREEN" ]]; then
echo "ok"
fi
EOF
[ "$status" -eq 0 ]
[ "$output" = "ok" ]
}
@test "log_info prints message and appends to log file" {
local message="Informational message from test"
local stdout_output