Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app-setup/templates/transmission-done.sh
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,12 @@ log() {
fi
local timestamp
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
# In test mode, only write to log file (don't output to stdout)
# stderr, never stdout: functions that return data by echo are captured with
# $(...), and a log line in that capture corrupts the returned value.
if [[ "${TEST_MODE}" == "true" ]]; then
printf '[%s] %s\n' "${timestamp}" "$1" >>"${LOG_FILE}"
else
printf '[%s] %s\n' "${timestamp}" "$1" | tee -a "${LOG_FILE}"
printf '[%s] %s\n' "${timestamp}" "$1" | tee -a "${LOG_FILE}" >&2
fi
}

Expand Down
28 changes: 28 additions & 0 deletions tests/transmission-filebot/unit/test_type_detection.bats
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,31 @@ load ../test_helper
run cat "${LOG_FILE}"
assert_output_contains "Pattern counts" "${output}"
}

# Production runs with TEST_MODE=false, where log() also prints to the
# terminal. That output must not reach stdout: callers capture this function
# with $(...), and on 2026-09-24 the captured log lines made media_type differ
# from "tv", so an SNW episode previewed with strict auto-detection and failed.
@test "detect_media_type_heuristic: returns only the type when TEST_MODE=false" {
local file="${TEST_TEMP_DIR}/star.trek.strange.new.worlds.s04e10.1080p.web.h264-cakes[EZTVx.to].mkv"
touch "${file}"
export TR_TORRENT_FILES="${file}"
export TEST_MODE=false

local result
result=$(detect_media_type_heuristic "${file}")

assert_equal "tv" "${result}"
}

@test "log: writes to LOG_FILE and not to stdout when TEST_MODE=false" {
export TEST_MODE=false
: >"${LOG_FILE}"

local captured
captured=$(log "probe message" 2>/dev/null)

assert_equal "" "${captured}"
run cat "${LOG_FILE}"
assert_output_contains "probe message" "${output}"
}
Loading