Skip to content

The agent that grows with you

fix(environments): route heredoc stdin to compound commands

josh snidera781ff257a7f
diff --git a/tests/tools/test_base_environment.py b/tests/tools/test_base_environment.py
index ec33b48d58f..2d7631362b0 100644
--- a/tests/tools/test_base_environment.py
+++ b/tests/tools/test_base_environment.py
@@ -252,6 +252,31 @@ class TestEmbedStdinHeredoc:
d2 = r2.split("'")[1]
assert d1 != d2 # UUID-based, should be unique
+ def test_compound_command_receives_stdin_as_a_group(self):
+ import shutil
+ import subprocess
+
+ import pytest
+
+ bash = shutil.which("bash")
+ if bash is None:
+ pytest.skip("bash required")
+
+ command = BaseEnvironment._embed_stdin_heredoc(
+ 'IFS= read -r first; IFS= read -r second; '
+ 'printf \'<%s|%s>\' "$first" "$second"',
+ "alpha\nbeta",
+ )
+
+ result = subprocess.run(
+ [bash, "-c", command],
+ check=True,
+ capture_output=True,
+ text=True,
+ )
+
+ assert result.stdout == "<alpha|beta>"
+
class TestInitSessionFailure:
def test_snapshot_ready_false_on_failure(self):
diff --git a/tools/environments/base.py b/tools/environments/base.py
index 3e3d54bc773..8e314b2f6f2 100644
--- a/tools/environments/base.py
+++ b/tools/environments/base.py
@@ -421,9 +421,9 @@ class BaseEnvironment(ABC):
@staticmethod
def _embed_stdin_heredoc(command: str, stdin_data: str) -> str:
- """Append stdin_data as a shell heredoc to the command string (SDK backends)."""
+ """Redirect stdin_data to the complete command with a shell heredoc (SDK backends)."""
delimiter = f"HERMES_STDIN_{uuid.uuid4().hex[:12]}"
- return f"{command} << '{delimiter}'\n{stdin_data}\n{delimiter}"
+ return f"{{\n{command}\n}} << '{delimiter}'\n{stdin_data}\n{delimiter}"
# --- Process lifecycle ---
def _wait_for_process(