From fb4cef5fa728699a0d53fa133e8bc3593f4f8dc3 Mon Sep 17 00:00:00 2001 From: tw93 Date: Mon, 26 Jan 2026 10:10:46 +0800 Subject: [PATCH] docs: add help text and test for 'mo update --force' --- mole | 1 + tests/update.bats | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/mole b/mole index 7d14b41..f8ae12c 100755 --- a/mole +++ b/mole @@ -223,6 +223,7 @@ show_help() { printf " %s%-28s%s %s\n" "$GREEN" "mo optimize --dry-run" "$NC" "Preview optimization" printf " %s%-28s%s %s\n" "$GREEN" "mo optimize --whitelist" "$NC" "Manage protected items" printf " %s%-28s%s %s\n" "$GREEN" "mo purge --paths" "$NC" "Configure scan directories" + printf " %s%-28s%s %s\n" "$GREEN" "mo update --force" "$NC" "Force reinstall latest version" echo printf "%s%s%s\n" "$BLUE" "OPTIONS" "$NC" printf " %s%-28s%s %s\n" "$GREEN" "--debug" "$NC" "Show detailed operation logs" diff --git a/tests/update.bats b/tests/update.bats index be95475..055603a 100644 --- a/tests/update.bats +++ b/tests/update.bats @@ -392,3 +392,52 @@ EOF [[ "$output" == *"Updated to latest version (1.23.1)"* ]] [[ "$output" != *"progress: 100%"* ]] || [[ "$output" == *"Downloading (progress: 100%)"* ]] } + +@test "update_mole with --force reinstalls even when on latest version" { + run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" CURRENT_VERSION="$CURRENT_VERSION" PATH="$HOME/fake-bin:/usr/bin:/bin" TERM="dumb" bash --noprofile --norc << 'EOF' +set -euo pipefail +curl() { + local out="" + local url="" + while [[ $# -gt 0 ]]; do + case "$1" in + -o) + out="$2" + shift 2 + ;; + http*://*) + url="$1" + shift + ;; + *) + shift + ;; + esac + done + + if [[ -n "$out" ]]; then + cat > "$out" << 'INSTALLER' +#!/usr/bin/env bash +echo "Mole installed successfully (version $CURRENT_VERSION)" +INSTALLER + return 0 + fi + + if [[ "$url" == *"api.github.com"* ]]; then + echo "{\"tag_name\":\"$CURRENT_VERSION\"}" + else + echo "VERSION=\"$CURRENT_VERSION\"" + fi +} +export -f curl + +brew() { exit 1; } +export -f brew + +"$PROJECT_ROOT/mole" update --force +EOF + + [ "$status" -eq 0 ] + [[ "$output" != *"Already on latest version"* ]] + [[ "$output" == *"Downloading"* ]] || [[ "$output" == *"Installing"* ]] || [[ "$output" == *"Updated"* ]] +}