The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(tools): keep submit_stdin within the file cap; move its tests to a sibling file
Teknium6558a2eff2d9
diff --git a/tests/tools/test_process_registry.py b/tests/tools/test_process_registry.pyindex a8ead5db6c7..7b2518e73a7 100644--- a/tests/tools/test_process_registry.py+++ b/tests/tools/test_process_registry.py@@ -622,34 +622,6 @@ class TestStdinHelpers:proc.stdin.close.assert_called_once()assert result["status"] == "ok"- @pytest.mark.platforms("posix")- def test_submit_stdin_pty_mode_sends_cr(self, 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(self, 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"-def test_close_stdin_allows_eof_driven_process_to_finish(self, registry, tmp_path):"""PTY mode: writing data + sending EOF lets an EOF-driven child finish.diff --git a/tests/tools/test_process_registry_submit.py b/tests/tools/test_process_registry_submit.pynew file mode 100644index 00000000000..9a979d414b2--- /dev/null+++ b/tests/tools/test_process_registry_submit.py@@ -0,0 +1,47 @@+"""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+++def registry():+ return ProcessRegistry()+++def _make_session() -> ProcessSession:+ return ProcessSession(id="proc_submit", command="cat", task_id="t1", started_at=time.time())++[email protected]("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"diff --git a/tools/process_registry.py b/tools/process_registry.pyindex ff93bd5d40f..451dd566049 100644--- a/tools/process_registry.py+++ b/tools/process_registry.py@@ -2321,17 +2321,12 @@ class ProcessRegistry(ProcessTerminationMixin, ProcessCheckpointMixin, ProcessOureturn self._stdin_op(session_id, via_pty, via_pipe, {"status": "ok", "bytes_written": len(data)})def submit_stdin(self, session_id: str, data: str = "") -> dict:- """Send data + Enter to stdin (like pressing Enter).- On a PTY, Enter is a carriage return, the byte a keyboard sends: raw-mode TUIs- (prompt_toolkit, Ink, vim) read ``\\n`` as Ctrl+J (a newline in Hermes's own prompt),- and canonical-mode children still get ``\\n`` through the tty's ICRNL mapping. On a- Windows PTY ConPTY treats ``\\r`` as end-of-line and a bare ``\\n`` through pywinpty- is NOT a line terminator, so a blocking line read (``readline()``, Go- ``bufio.Scanner``) would hang; ``\\r\\n`` gives it both. Pipes keep ``\\n``."""+ """Send data + Enter. On a PTY Enter is the CR a keyboard sends: raw-mode TUIs (prompt_toolkit,+ Ink) read ``\\n`` as Ctrl+J and canonical children still get ``\\n`` via ICRNL; a Windows PTY+ gets ``\\r\\n`` (a bare ``\\n`` through pywinpty never ends a ConPTY line read). Pipes keep ``\\n``."""session = self.get(session_id)- if session is not None and session._pty:- return self.write_stdin(session_id, data + ("\r\n" if _IS_WINDOWS else "\r"))- return self.write_stdin(session_id, data + "\n")+ pty_enter = "\r\n" if _IS_WINDOWS else "\r"+ return self.write_stdin(session_id, data + (pty_enter if session is not None and session._pty else "\n"))def request_close_terminal(self, session_id: str) -> dict:"""Ask the desktop GUI to close this process's read-only terminal tab. Does NOT