mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-26 01:01:40 +00:00
simplify docstrings, fix some bugs
This commit is contained in:
parent
861202b56c
commit
9001b34146
6 changed files with 37 additions and 196 deletions
|
|
@ -1,10 +1,4 @@
|
|||
"""Tests for the local persistent shell backend.
|
||||
|
||||
Unit tests cover config plumbing (no real shell needed).
|
||||
Integration tests run real commands — no external dependencies required.
|
||||
|
||||
pytest tests/tools/test_local_persistent.py -v
|
||||
"""
|
||||
"""Tests for the local persistent shell backend."""
|
||||
|
||||
import glob as glob_mod
|
||||
|
||||
|
|
@ -14,10 +8,6 @@ from tools.environments.local import LocalEnvironment
|
|||
from tools.environments.persistent_shell import PersistentShellMixin
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Unit tests — config plumbing
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
class TestLocalConfig:
|
||||
def test_local_persistent_default_false(self, monkeypatch):
|
||||
monkeypatch.delenv("TERMINAL_LOCAL_PERSISTENT", raising=False)
|
||||
|
|
@ -36,8 +26,6 @@ class TestLocalConfig:
|
|||
|
||||
|
||||
class TestMergeOutput:
|
||||
"""Test the shared _merge_output static method."""
|
||||
|
||||
def test_stdout_only(self):
|
||||
assert PersistentShellMixin._merge_output("out", "") == "out"
|
||||
|
||||
|
|
@ -54,13 +42,7 @@ class TestMergeOutput:
|
|||
assert PersistentShellMixin._merge_output("out\n\n", "err\n") == "out\nerr"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# One-shot regression tests — ensure refactor didn't break anything
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
class TestLocalOneShotRegression:
|
||||
"""Verify one-shot mode still works after adding the mixin."""
|
||||
|
||||
def test_echo(self):
|
||||
env = LocalEnvironment(persistent=False)
|
||||
r = env.execute("echo hello")
|
||||
|
|
@ -75,22 +57,14 @@ class TestLocalOneShotRegression:
|
|||
env.cleanup()
|
||||
|
||||
def test_state_does_not_persist(self):
|
||||
"""Env vars set in one command should NOT survive in one-shot mode."""
|
||||
env = LocalEnvironment(persistent=False)
|
||||
env.execute("export HERMES_ONESHOT_LOCAL=yes")
|
||||
r = env.execute("echo $HERMES_ONESHOT_LOCAL")
|
||||
# In one-shot mode, env var should not persist
|
||||
assert r["output"].strip() == ""
|
||||
env.cleanup()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Persistent shell integration tests
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
class TestLocalPersistent:
|
||||
"""Persistent mode: state persists across execute() calls."""
|
||||
|
||||
@pytest.fixture
|
||||
def env(self):
|
||||
e = LocalEnvironment(persistent=True)
|
||||
|
|
@ -128,8 +102,7 @@ class TestLocalPersistent:
|
|||
|
||||
def test_timeout_then_recovery(self, env):
|
||||
r = env.execute("sleep 999", timeout=2)
|
||||
assert r["returncode"] in (124, 130) # timeout or interrupted
|
||||
# Shell should survive — next command works
|
||||
assert r["returncode"] in (124, 130)
|
||||
r = env.execute("echo alive")
|
||||
assert r["returncode"] == 0
|
||||
assert "alive" in r["output"]
|
||||
|
|
@ -143,7 +116,6 @@ class TestLocalPersistent:
|
|||
assert lines[-1] == "1000"
|
||||
|
||||
def test_shell_variable_persists(self, env):
|
||||
"""Shell variables (not exported) should also persist."""
|
||||
env.execute("MY_LOCAL_VAR=hello123")
|
||||
r = env.execute("echo $MY_LOCAL_VAR")
|
||||
assert r["output"].strip() == "hello123"
|
||||
|
|
@ -151,14 +123,12 @@ class TestLocalPersistent:
|
|||
def test_cleanup_removes_temp_files(self, env):
|
||||
env.execute("echo warmup")
|
||||
prefix = env._temp_prefix
|
||||
# Temp files should exist
|
||||
assert len(glob_mod.glob(f"{prefix}-*")) > 0
|
||||
env.cleanup()
|
||||
remaining = glob_mod.glob(f"{prefix}-*")
|
||||
assert remaining == []
|
||||
|
||||
def test_state_does_not_leak_between_instances(self):
|
||||
"""Two separate persistent instances don't share state."""
|
||||
env1 = LocalEnvironment(persistent=True)
|
||||
env2 = LocalEnvironment(persistent=True)
|
||||
try:
|
||||
|
|
@ -170,7 +140,6 @@ class TestLocalPersistent:
|
|||
env2.cleanup()
|
||||
|
||||
def test_special_characters_in_command(self, env):
|
||||
"""Commands with quotes and special chars should work."""
|
||||
r = env.execute("echo 'hello world'")
|
||||
assert r["output"].strip() == "hello world"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue