From 4e25fb27df72d8c165f0b515b6df14a3c9cf1296 Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Sat, 6 Jun 2026 17:30:48 +0200 Subject: [PATCH] fix(sync_run): check stdin not stdout for TTY guard The --select TTY guard used sys.stdout.isatty(), but interactive prompts read from stdin. This caused two failure modes: - Redirecting stdout (e.g. | tee log.txt) blocked --select even though the keyboard was available - With stdin piped in CI, stdout could still be a TTY, allowing the prompt to proceed and block forever on absent input --- librofm_downloader/sync_run.py | 2 +- tests/test_sync_run.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/librofm_downloader/sync_run.py b/librofm_downloader/sync_run.py index 1ae160a..0ac6f26 100644 --- a/librofm_downloader/sync_run.py +++ b/librofm_downloader/sync_run.py @@ -216,7 +216,7 @@ def sync_run( # 5. Select mode pipeline (ADR #6) if select_mode: - if not sys.stdout.isatty(): + if not sys.stdin.isatty(): console.print("[red]--select requires an interactive terminal.[/red]") return SyncRunResult(fatal_error="--select requires an interactive terminal") diff --git a/tests/test_sync_run.py b/tests/test_sync_run.py index abd78b3..419ebd4 100644 --- a/tests/test_sync_run.py +++ b/tests/test_sync_run.py @@ -75,7 +75,7 @@ class TestSyncRunSelectModeTTYGuard: patch("librofm_downloader.sync_run.load_config") as mock_config, patch("librofm_downloader.sync_run.LibroFmSession") as mock_client_cls, patch("librofm_downloader.sync_run.DownloadHistory") as mock_history_cls, - patch("sys.stdout.isatty", return_value=False), + patch("sys.stdin.isatty", return_value=False), ): mock_config.return_value.username = "alice" mock_config.return_value.password = "secret" @@ -139,7 +139,7 @@ class TestSyncRunSelectModeEmptySelection: patch("librofm_downloader.sync_run.LibroFmSession") as mock_client_cls, patch("librofm_downloader.sync_run.DownloadHistory") as mock_history_cls, patch("librofm_downloader.selector.select_books", return_value=[]), - patch("sys.stdout.isatty", return_value=True), + patch("sys.stdin.isatty", return_value=True), ): mock_config.return_value.username = "alice" mock_config.return_value.password = "secret" @@ -184,7 +184,7 @@ class TestSyncRunSelectModeSelectedFlow: patch("librofm_downloader.selector.select_books", return_value=selected), patch("librofm_downloader.sync_run.download_all_books") as mock_download, patch("librofm_downloader.sync_run.DownloadReporter") as mock_reporter_cls, - patch("sys.stdout.isatty", return_value=True), + patch("sys.stdin.isatty", return_value=True), ): mock_config.return_value.username = "alice" mock_config.return_value.password = "secret" @@ -241,7 +241,7 @@ class TestSyncRunSelectModeLimitIgnored: patch("librofm_downloader.selector.select_books", return_value=selected), patch("librofm_downloader.sync_run.download_all_books") as mock_download, patch("librofm_downloader.sync_run.DownloadReporter") as mock_reporter_cls, - patch("sys.stdout.isatty", return_value=True), + patch("sys.stdin.isatty", return_value=True), ): mock_config.return_value.username = "alice" mock_config.return_value.password = "secret"