Some checks failed
tamq-ci / test (push) Failing after 7s
Assistant: codex Assistant-Model: gpt-5.6-sol Assistant-Session: 01a03397-4d51-7fd1-8ff2-946eb22ea2bc
45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
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"
|