Add opt-in debug logging across the CLI pipeline
Thread RP_DEBUG-driven logging through input, detection, rendering, and pager decisions so CLI behavior is inspectable without polluting stdout. Add focused coverage for debug wiring, env parsing, and stderr-only output.
This commit is contained in:
@@ -75,6 +75,7 @@ class TestFileInput:
|
||||
content="x = 1\n",
|
||||
explicit_type=None,
|
||||
guess_content=False,
|
||||
debug=None,
|
||||
)
|
||||
|
||||
def test_render_called_with_correct_options(self, tmp_file) -> None:
|
||||
@@ -182,8 +183,41 @@ class TestStdinInput:
|
||||
content="hello\n",
|
||||
explicit_type=None,
|
||||
guess_content=False,
|
||||
debug=None,
|
||||
)
|
||||
|
||||
def test_debug_env_enables_debug_logger(self) -> None:
|
||||
with patch("rp.cli.detect_type") as mock_detect_type:
|
||||
mock_detect_type.return_value = "text"
|
||||
with patch("rp.cli.render"):
|
||||
runner.invoke(
|
||||
app, ["--no-pager"], input="hello\n", env={"RP_DEBUG": "1"}
|
||||
)
|
||||
|
||||
_, kwargs = mock_detect_type.call_args
|
||||
assert kwargs["debug"] is not None
|
||||
|
||||
def test_debug_output_stays_on_stderr(self, tmp_file) -> None:
|
||||
file = tmp_file("# Hello\n", suffix=".md")
|
||||
|
||||
result = runner.invoke(app, [str(file), "--no-pager"], env={"RP_DEBUG": "1"})
|
||||
normalized_stderr = result.stderr.replace("\n", "")
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert "[rp debug]" not in result.stdout
|
||||
assert "Hello" in result.stdout
|
||||
assert "[rp debug] input: reading file" in result.stderr
|
||||
assert repr(str(file)) in normalized_stderr
|
||||
assert (
|
||||
"[rp debug] type: inferred 'markdown' from extension '.md'" in result.stderr
|
||||
)
|
||||
assert (
|
||||
"[rp debug] render: auto-set line_numbers=False for 'markdown'"
|
||||
in result.stderr
|
||||
)
|
||||
assert "[rp debug] pager: explicitly disabled" in result.stderr
|
||||
assert "[rp debug] pager: writing directly to the console" in result.stderr
|
||||
|
||||
def test_stdin_shows_tty_prompt(self) -> None:
|
||||
"""When stdin is a TTY and no input is piped, show the reading hint."""
|
||||
with patch("rp.cli.sys.stdin.isatty", return_value=True):
|
||||
|
||||
Reference in New Issue
Block a user