diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 881f9e3..b5fe6e6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,6 +22,9 @@ jobs: go-version: "1.24.6" - name: Run test script + env: + MOLE_PERF_BYTES_TO_HUMAN_LIMIT_MS: "6000" + MOLE_PERF_GET_FILE_SIZE_LIMIT_MS: "3000" run: ./scripts/test.sh compatibility: diff --git a/install.sh b/install.sh index b74820a..6b08dbc 100755 --- a/install.sh +++ b/install.sh @@ -61,7 +61,14 @@ ACTION="install" # Resolve source dir (local checkout, env override, or download). needs_sudo() { - [[ ! -w "$INSTALL_DIR" ]] + if [[ -e "$INSTALL_DIR" ]]; then + [[ ! -w "$INSTALL_DIR" ]] + return + fi + + local parent_dir + parent_dir="$(dirname "$INSTALL_DIR")" + [[ ! -w "$parent_dir" ]] } maybe_sudo() { diff --git a/scripts/test.sh b/scripts/test.sh index 992f20d..627b79e 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -10,15 +10,8 @@ PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" cd "$PROJECT_ROOT" -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -NC='\033[0m' - -readonly ICON_SUCCESS="✓" -readonly ICON_ERROR="☻" -readonly ICON_WARNING="●" -readonly ICON_LIST="•" +# shellcheck source=lib/core/file_ops.sh +source "$PROJECT_ROOT/lib/core/file_ops.sh" echo "===============================" echo "Mole Test Runner" @@ -123,7 +116,7 @@ else printf "${RED}${ICON_ERROR} Installation test failed${NC}\n" ((FAILED++)) fi -rm -rf /tmp/mole-test +safe_remove "/tmp/mole-test" true || true echo "" echo "===============================" diff --git a/tests/dev_caches.bats b/tests/dev_caches.bats index c2d7565..96377d0 100644 --- a/tests/dev_caches.bats +++ b/tests/dev_caches.bats @@ -30,6 +30,7 @@ stop_section_spinner() { :; } clean_tool_cache() { echo "$1"; } safe_clean() { echo "$2"; } note_activity() { :; } +run_with_timeout() { shift; "$@"; } pnpm() { if [[ "$1" == "store" && "$2" == "prune" ]]; then return 0 diff --git a/tests/performance.bats b/tests/performance.bats index 4ac7a64..dfc4037 100644 --- a/tests/performance.bats +++ b/tests/performance.bats @@ -18,6 +18,7 @@ setup() { @test "bytes_to_human handles large values efficiently" { local start end elapsed + local limit_ms="${MOLE_PERF_BYTES_TO_HUMAN_LIMIT_MS:-4000}" bytes_to_human 1073741824 > /dev/null @@ -29,7 +30,7 @@ setup() { elapsed=$(( (end - start) / 1000000 )) - [ "$elapsed" -lt 2000 ] + [ "$elapsed" -lt "$limit_ms" ] } @test "bytes_to_human produces correct output for GB range" { @@ -74,6 +75,7 @@ setup() { dd if=/dev/zero of="$test_file" bs=1024 count=100 2> /dev/null local start end elapsed + local limit_ms="${MOLE_PERF_GET_FILE_SIZE_LIMIT_MS:-2000}" start=$(date +%s%N) for i in {1..100}; do get_file_size "$test_file" > /dev/null @@ -82,7 +84,7 @@ setup() { elapsed=$(( (end - start) / 1000000 )) - [ "$elapsed" -lt 1000 ] + [ "$elapsed" -lt "$limit_ms" ] } @test "get_file_mtime returns valid timestamp" {