From 98c42ca7c1c9d21cf1bd895a0995ef06b6abfffc Mon Sep 17 00:00:00 2001 From: ruihan Date: Mon, 6 Jul 2026 01:32:02 +0000 Subject: [PATCH 1/2] fix: redirect low-level logging functions to STDERR --- lib/colors.sh | 4 ++-- unleash-standalone.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/colors.sh b/lib/colors.sh index c08d231..54c27a2 100644 --- a/lib/colors.sh +++ b/lib/colors.sh @@ -32,7 +32,7 @@ log() { local ts ts=$(date '+%H:%M:%S') - echo -e "${color}[${label}]${NC} ${msg}" + echo -e "${color}[${label}]${NC} ${msg}" >&2 if [ -n "$LOG_FILE" ]; then echo "[${ts}] [${label}] ${msg}" >> "$LOG_FILE" 2>/dev/null || true @@ -40,7 +40,7 @@ log() { } error_exit() { - log "ERROR" "$1" >&2 + log "ERROR" "$1" exit 1 } diff --git a/unleash-standalone.sh b/unleash-standalone.sh index 347311c..1e0d4d8 100755 --- a/unleash-standalone.sh +++ b/unleash-standalone.sh @@ -35,7 +35,7 @@ log() { local ts ts=$(date '+%H:%M:%S') - echo -e "${color}[${label}]${NC} ${msg}" + echo -e "${color}[${label}]${NC} ${msg}" >&2 if [ -n "$LOG_FILE" ]; then echo "[${ts}] [${label}] ${msg}" >> "$LOG_FILE" 2>/dev/null || true @@ -43,7 +43,7 @@ log() { } error_exit() { - log "ERROR" "$1" >&2 + log "ERROR" "$1" exit 1 } From d0a797db619e83b40807a668988446dfd695acaf Mon Sep 17 00:00:00 2001 From: ruihan Date: Fri, 30 Oct 2026 03:51:08 -0300 Subject: [PATCH 2/2] test(logging): keep helper output free of diagnostics --- tests/test_colors.bats | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/test_colors.bats b/tests/test_colors.bats index 424b12f..e61000a 100644 --- a/tests/test_colors.bats +++ b/tests/test_colors.bats @@ -2,6 +2,7 @@ # Tests for colors.sh - run with: bats tests/test_colors.bats setup() { + bats_require_minimum_version 1.5.0 load '../lib/colors.sh' TEST_LOG=$(mktemp) } @@ -39,3 +40,33 @@ teardown() { [ "$status" -eq 0 ] echo "$output" | grep -q "Test Title" } + +@test "diagnostics use stderr without contaminating helper return values" { + local source_file + for source_file in lib/colors.sh unleash-standalone.sh; do + run --separate-stderr bash -u -c ' + source <(sed "/^error_exit()/,\$d" "$1") + volume_path() { + log INFO "Locating Data volume" + log OK "Data volume found" + printf "%s\n" "/Volumes/Work Data" + } + result=$(volume_path) + printf "%s\n" "$result" + ' bash "$BATS_TEST_DIRNAME/../$source_file" + + [ "$status" -eq 0 ] + [ "$output" = "/Volumes/Work Data" ] + [[ "$stderr" == *"Locating Data volume"* ]] + [[ "$stderr" == *"Data volume found"* ]] + done +} + +@test "diagnostics still reach the log file when stdout is captured" { + LOG_FILE="$TEST_LOG" + local result + result=$(log WARN "Review the selected volume" 2>/dev/null) + + [ -z "$result" ] + grep -q 'Review the selected volume' "$TEST_LOG" +}