From 975706373644fa6ebb5c690cc583d9256d437339 Mon Sep 17 00:00:00 2001 From: Tw93 Date: Mon, 23 Mar 2026 20:18:06 +0800 Subject: [PATCH] fix(clean): align threshold colors with displayed GB units --- lib/core/base.sh | 5 +++-- tests/core_common.bats | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/core/base.sh b/lib/core/base.sh index 4c559a9..4cffa94 100644 --- a/lib/core/base.sh +++ b/lib/core/base.sh @@ -79,6 +79,7 @@ readonly MOLE_TM_BACKUP_SAFE_HOURS=48 # TM backup safety window (hours) readonly MOLE_MAX_DS_STORE_FILES=500 # Max .DS_Store files to clean per scan readonly MOLE_MAX_ORPHAN_ITERATIONS=100 # Max iterations for orphaned app data scan readonly MOLE_ONE_GIB_KB=$((1024 * 1024)) +readonly MOLE_ONE_GB_BYTES=1000000000 # ============================================================================ # Whitelist Configuration @@ -549,12 +550,12 @@ bytes_to_human_kb() { bytes_to_human "$((${1:-0} * 1024))" } -# Pick a cleanup result color using the shared 1 GiB threshold. +# Pick a cleanup result color using the displayed decimal 1 GB threshold. cleanup_result_color_kb() { local size_kb="${1:-0}" [[ "$size_kb" =~ ^[0-9]+$ ]] || size_kb=0 - if ((size_kb >= MOLE_ONE_GIB_KB)); then + if ((size_kb * 1024 >= MOLE_ONE_GB_BYTES)); then printf '%s' "$GREEN" else printf '%s' "$YELLOW" diff --git a/tests/core_common.bats b/tests/core_common.bats index b56fa52..ad75000 100644 --- a/tests/core_common.bats +++ b/tests/core_common.bats @@ -44,13 +44,16 @@ setup() { [[ -n "$result" ]] } -@test "cleanup_result_color_kb switches from yellow to green at 1 GiB" { +@test "cleanup_result_color_kb switches from yellow to green at 1 GB" { 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 +below_threshold_kb=$(((MOLE_ONE_GB_BYTES - 1) / 1024)) +at_threshold_kb=$(((MOLE_ONE_GB_BYTES + 1023) / 1024)) + +if [[ "$(cleanup_result_color_kb "$below_threshold_kb")" == "$YELLOW" ]] && + [[ "$(cleanup_result_color_kb "$at_threshold_kb")" == "$GREEN" ]]; then echo "ok" fi EOF