hermes-agent/tests/tools/test_process_registry_submit.py
Teknium 6558a2eff2 refactor(tools): keep submit_stdin within the file cap; move its tests to a sibling file
process_registry.py and its test file are over the 2,000-line target and may
only shrink: the PTY/pipe Enter choice collapses to one expression and the two
submit_stdin tests move to tests/tools/test_process_registry_submit.py.
2026-10-28 19:05:57 -07:00

48 lines
1.3 KiB
Python

"""submit_stdin presses Enter the way the child's input expects it: CR on a POSIX PTY, LF on a pipe."""
import time
from unittest.mock import MagicMock
import pytest
from tools.process_registry import ProcessRegistry, ProcessSession
@pytest.fixture()
def registry():
return ProcessRegistry()
def _make_session() -> ProcessSession:
return ProcessSession(id="proc_submit", command="cat", task_id="t1", started_at=time.time())
@pytest.mark.platforms("posix")
def test_submit_stdin_pty_mode_sends_cr(registry):
"""PTY Enter is \\r — what a real keyboard sends. Raw-mode TUIs bind
Enter to \\r and ignore \\n; canonical-mode children still see \\n via
the tty driver's ICRNL mapping.
"""
pty = MagicMock()
s = _make_session()
s._pty = pty
registry._running[s.id] = s
result = registry.submit_stdin(s.id, "hello")
pty.write.assert_called_once_with(b"hello\r")
assert result["status"] == "ok"
def test_submit_stdin_pipe_mode_sends_newline(registry):
proc = MagicMock()
proc.stdin = MagicMock()
s = _make_session()
s.process = proc
registry._running[s.id] = s
result = registry.submit_stdin(s.id, "hello")
proc.stdin.write.assert_called_once_with("hello\n")
assert result["status"] == "ok"