tui3: guard against non-interactive stdin with TTY check

Add _stdin_is_tty() helper and check at start of _launch_tui3_or_exit.
When stdin is not a TTY, emit a clear error message and exit 1 instead
of propagating an EOF exception from seed setup prompts.
Add test for non-interactive stdin error path; patch _stdin_is_tty in
existing tests that expect tui3 launch to proceed.

Fixes SeedPass-6d26
This commit is contained in:
thePR0M3TH3AN committed 2026-03-09 12:45:34 -04:00
1 parent 0cf1d58c9c
commit 96f64d00bc
2 files changed
+21

No files matched your search

+11
View File
@@ -1021,6 +1021,7 @@ def test_root_tui3_forward_fingerprint(monkeypatch):
called["factory"] = kwargs.get("entry_service_factory")
return True
monkeypatch.setattr(cli, "_stdin_is_tty", lambda: True)
monkeypatch.setattr(cli, "launch_tui3", fake_launch)
result = runner.invoke(app, ["--fingerprint", "abc"])
assert result.exit_code == 0
@@ -1170,6 +1171,7 @@ def test_tui2_fallback_legacy_strips_subcommand_argv(monkeypatch):
def test_root_tui3_unavailable_returns_error(monkeypatch):
monkeypatch.setattr(cli, "_stdin_is_tty", lambda: True)
monkeypatch.setattr(cli, "launch_tui3", lambda **_: False)
result = runner.invoke(app, ["--fingerprint", "abc"])
assert result.exit_code == 1
@@ -1179,6 +1181,7 @@ def test_root_tui3_unavailable_returns_error(monkeypatch):
def test_root_tui3_does_not_preflight_entry_service(monkeypatch):
monkeypatch.setattr(cli, "_stdin_is_tty", lambda: True)
monkeypatch.setattr(
cli,
"_get_entry_service",
@@ -1189,6 +1192,14 @@ def test_root_tui3_does_not_preflight_entry_service(monkeypatch):
assert result.exit_code == 0
def test_tui3_non_interactive_stdin_exits_with_error(monkeypatch):
"""tui3 must exit cleanly with an error message when stdin is not a TTY."""
monkeypatch.setattr(cli, "_stdin_is_tty", lambda: False)
result = runner.invoke(app, ["tui3"])
assert result.exit_code == 1
assert "not a TTY" in result.stderr
def test_tui2_preflight_failure_without_fallback(monkeypatch):
monkeypatch.setattr(
cli,