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
This commit is contained in:
AlexKucera committed 2026-06-06 17:30:48 +02:00
1 parent 77712951d0
commit 4e25fb27df
2 files changed
+5 -5

No files matched your search

+1 -1
View File
@@ -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")
+4 -4
View File
@@ -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"