fix(coding): teach agents terminal env state persists

Tell coding agents to activate shell setup once per session instead of re-sourcing it before every command, and pin the existing LocalEnvironment env-snapshot behavior with regression tests.
This commit is contained in:
Brooklyn Nicholson
2026-06-11 19:50:08 -05:00
parent afe53708ee
commit ab06ef8ed6
5 changed files with 63 additions and 1 deletions
+6
View File
@@ -11,6 +11,12 @@ import pytest
from agent import coding_context as cc
def test_coding_guidance_advertises_persistent_terminal_state():
assert "Terminal state persists across calls" in cc.CODING_AGENT_GUIDANCE
assert "Activate a virtualenv" in cc.CODING_AGENT_GUIDANCE
assert "instead of re-sourcing it before every test command" in cc.CODING_AGENT_GUIDANCE
def _git_init(path):
env = {
"GIT_AUTHOR_NAME": "t", "GIT_AUTHOR_EMAIL": "t@t",
+43
View File
@@ -190,6 +190,49 @@ class TestSnapshotEndToEnd:
"""Spin up a real LocalEnvironment and confirm the snapshot sources
extra init files."""
def test_exported_env_changes_persist_between_commands(self, tmp_path):
env = LocalEnvironment(cwd=str(tmp_path), timeout=15)
try:
first = env.execute(
'export HERMES_SESSION_ENV_PROBE="sticky"; '
'export PATH="/tmp/hermes-session-bin:$PATH"; '
'echo "first=$HERMES_SESSION_ENV_PROBE"'
)
second = env.execute(
'echo "second=$HERMES_SESSION_ENV_PROBE"; echo "PATH=$PATH"'
)
finally:
env.cleanup()
assert first["returncode"] == 0
assert second["returncode"] == 0
assert "first=sticky" in first.get("output", "")
output = second.get("output", "")
assert "second=sticky" in output
assert "/tmp/hermes-session-bin" in output
def test_venv_style_activation_persists_between_commands(self, tmp_path):
venv_bin = tmp_path / ".venv" / "bin"
venv_bin.mkdir(parents=True)
activate = venv_bin / "activate"
activate.write_text(
f'export VIRTUAL_ENV="{tmp_path / ".venv"}"\n'
f'export PATH="{venv_bin}:$PATH"\n'
)
env = LocalEnvironment(cwd=str(tmp_path), timeout=15)
try:
first = env.execute('source .venv/bin/activate; echo "venv=$VIRTUAL_ENV"')
second = env.execute('echo "venv=$VIRTUAL_ENV"; echo "PATH=$PATH"')
finally:
env.cleanup()
assert first["returncode"] == 0
assert second["returncode"] == 0
output = second.get("output", "")
assert f"venv={tmp_path / '.venv'}" in output
assert str(venv_bin) in output
def test_snapshot_picks_up_init_file_exports(self, tmp_path, monkeypatch):
init_file = tmp_path / "custom-init.sh"
init_file.write_text(
+8
View File
@@ -22,6 +22,14 @@ def test_searching_for_sudo_does_not_trigger_rewrite(monkeypatch):
assert sudo_stdin is None
def test_terminal_schema_advertises_persistent_env_state():
description = terminal_tool.TERMINAL_TOOL_DESCRIPTION
assert "exported environment variables persist between calls" in description
assert "activate a virtualenv" in description
assert "do not re-source the same environment before every command" in description
def test_printf_literal_sudo_does_not_trigger_rewrite(monkeypatch):
monkeypatch.delenv("SUDO_PASSWORD", raising=False)
monkeypatch.delenv("HERMES_INTERACTIVE", raising=False)