diff --git a/tests/test_cli/test_display.py b/tests/test_cli/test_display.py index 408e266..b0c00e8 100644 --- a/tests/test_cli/test_display.py +++ b/tests/test_cli/test_display.py @@ -801,7 +801,7 @@ async def test_pretty_pty_write_and_keys(capsys: pytest.CaptureFixture[str]) -> status = "session_id=3\nalive=true\nexit_code=\nwrote=5" await render_events(_aiter([_pretty_call("write_pty", '{"session_id": 3, "data": "ls -la"}'), _result(status)])) out = capsys.readouterr().out - assert "* PTY Write 3 (5 chars)" in out + assert "* PTY Write 3 'ls -la' (5 chars)" in out await render_events( _aiter( @@ -815,6 +815,21 @@ async def test_pretty_pty_write_and_keys(capsys: pytest.CaptureFixture[str]) -> assert "* PTY Keys 3 '' (2 chars)" in out +async def test_pretty_pty_write_escapes_and_shortens_the_payload(capsys: pytest.CaptureFixture[str]) -> None: + """A newline or an ESC must not break the line, and a long payload is cut.""" + status = "session_id=3\nalive=true\nexit_code=\nwrote=4" + await render_events(_aiter([_pretty_call("write_pty", '{"session_id": 3, "data": "a\\nb"}'), _result(status)])) + out = capsys.readouterr().out + assert "* PTY Write 3 'a\\nb' (4 chars)" in out + + long = "x" * 60 + call = _pretty_call("write_pty", f'{{"session_id": 3, "data": "{long}"}}') + await render_events(_aiter([call, _result(status)])) + out = capsys.readouterr().out + assert "* PTY Write 3 '" + "x" * 40 + "…'" in out + assert "x" * 41 not in out + + async def test_pretty_ask_into_pty_never_shows_the_answer(capsys: pytest.CaptureFixture[str]) -> None: """The result only says the answer was written; the payload stays local.""" status = "session_id=3\nalive=true\nexit_code=\nwrote=true\nsecret=true\nsubmit=true\nsource=human"