Assistant: codex Assistant-Model: gpt-5.6-sol Assistant-Session: 01a03397-4d51-7fd1-8ff2-946eb22ea2bc
This commit is contained in:
parent
9000640b2e
commit
9fcfba3c17
16 changed files with 415 additions and 80 deletions
45
tests/test_terminal_output.py
Normal file
45
tests/test_terminal_output.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import os
|
||||
import pty
|
||||
import select
|
||||
|
||||
import pytest
|
||||
|
||||
from tamq.terminal import (
|
||||
TerminalOutputError,
|
||||
format_comment,
|
||||
terminal_frame,
|
||||
write_terminal_output,
|
||||
)
|
||||
|
||||
|
||||
def test_comment_format_escapes_controls_and_prefixes_every_line():
|
||||
assert format_comment("repo-a", "first\nsecond\x1b[31m", "m-1") == (
|
||||
"#repo-a: first\n# second\\x1b[31m [m-1]"
|
||||
)
|
||||
assert terminal_frame("repo-a", "hello", "m-1") == (
|
||||
"\r\n#repo-a: hello [m-1]\r\n"
|
||||
)
|
||||
|
||||
|
||||
def test_terminal_output_reaches_pty_output_but_not_input():
|
||||
master, slave = pty.openpty()
|
||||
try:
|
||||
tty_path = os.ttyname(slave)
|
||||
write_terminal_output(tty_path, terminal_frame("repo-a", "hello", "m-1"))
|
||||
|
||||
readable, _, _ = select.select([master], [], [], 1)
|
||||
assert readable == [master]
|
||||
assert b"#repo-a: hello [m-1]" in os.read(master, 4096)
|
||||
readable_input, _, _ = select.select([slave], [], [], 0)
|
||||
assert readable_input == []
|
||||
finally:
|
||||
os.close(master)
|
||||
os.close(slave)
|
||||
|
||||
|
||||
def test_terminal_output_rejects_non_pty_paths(tmp_path):
|
||||
target = tmp_path / "ordinary-file"
|
||||
target.write_text("untouched", encoding="utf-8")
|
||||
with pytest.raises(TerminalOutputError, match="non-PTY"):
|
||||
write_terminal_output(target, "message")
|
||||
assert target.read_text(encoding="utf-8") == "untouched"
|
||||
Loading…
Add table
Add a link
Reference in a new issue