diff --git a/tests/tools/test_local_persistent.py b/tests/tools/test_local_persistent.py index b20cca5be..5b9ce2e23 100644 --- a/tests/tools/test_local_persistent.py +++ b/tests/tools/test_local_persistent.py @@ -63,6 +63,18 @@ class TestLocalOneShotRegression: assert r["output"].strip() == "" env.cleanup() + def test_oneshot_heredoc_does_not_leak_fence_wrapper(self): + """Heredoc closing line must not be merged with the fence wrapper tail.""" + env = LocalEnvironment(persistent=False) + cmd = "cat <<'H_EOF'\nheredoc body line\nH_EOF" + r = env.execute(cmd) + env.cleanup() + assert r["returncode"] == 0 + assert "heredoc body line" in r["output"] + assert "__hermes_rc" not in r["output"] + assert "printf '" not in r["output"] + assert "exit $" not in r["output"] + class TestLocalPersistent: @pytest.fixture diff --git a/tools/environments/local.py b/tools/environments/local.py index 8ee794e3b..8cd416efa 100644 --- a/tools/environments/local.py +++ b/tools/environments/local.py @@ -391,12 +391,17 @@ class LocalEnvironment(PersistentShellMixin, BaseEnvironment): effective_stdin = stdin_data user_shell = _find_bash() + # Newline-separated wrapper (not `cmd; __hermes_rc=...` on one line). + # A trailing `; __hermes_rc` glued to `<