mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-09 08:21:50 +00:00
test(tui): cover _terminal_task_cwd remote-backend branches
Adds regression tests for the SSH cwd fix: local backend keeps host-validated session cwd; non-local backend uses TERMINAL_CWD (or terminal.cwd config) verbatim without host isdir() validation; sentinel values fall back to session cwd.
This commit is contained in:
parent
0e0d704f2d
commit
f9ea4927f2
2 changed files with 44 additions and 0 deletions
|
|
@ -1210,6 +1210,7 @@ AUTHOR_MAP = {
|
|||
"teknium@hermes-agent": "teknium1",
|
||||
"web3blind@gmail.com": "web3blind",
|
||||
"ztzheng@163.com": "chengoak", # PR #17467
|
||||
"zwcf5200@163.com": "zwcf5200", # PR #38661 (SSH remote cwd fix)
|
||||
"24110240104@m.fudan.edu.cn": "YuShu", # co-author only
|
||||
"charliekerfoot@gmail.com": "CharlieKerfoot", # PR #18951
|
||||
# Debug share upload-time redaction (May 2026)
|
||||
|
|
|
|||
|
|
@ -60,6 +60,49 @@ def test_session_context_explicit_cwd_for_ephemeral_task(monkeypatch, tmp_path):
|
|||
server._clear_session_context(tokens)
|
||||
|
||||
|
||||
def test_terminal_task_cwd_local_backend_uses_session_cwd(monkeypatch, tmp_path):
|
||||
"""A local terminal backend must keep host-validated session cwd behaviour."""
|
||||
project = tmp_path / "project"
|
||||
project.mkdir()
|
||||
monkeypatch.setenv("TERMINAL_ENV", "local")
|
||||
monkeypatch.delenv("TERMINAL_CWD", raising=False)
|
||||
|
||||
assert server._terminal_task_cwd({"cwd": str(project)}) == str(project)
|
||||
|
||||
|
||||
def test_terminal_task_cwd_ssh_uses_remote_path_unvalidated(monkeypatch):
|
||||
"""SSH (non-local) backend: the configured remote cwd is used verbatim even
|
||||
though it does not exist on the local host. This is the jonbohz fix — host
|
||||
`isdir()` validation would otherwise discard the remote path and fall back
|
||||
to os.getcwd(), running commands against the wrong machine."""
|
||||
remote = "/home/jonboh/workspace/proj" # does not exist on this host
|
||||
assert not os.path.isdir(remote)
|
||||
monkeypatch.setenv("TERMINAL_ENV", "ssh")
|
||||
monkeypatch.setenv("TERMINAL_CWD", remote)
|
||||
|
||||
assert server._terminal_task_cwd({"cwd": "/some/host/dir"}) == remote
|
||||
|
||||
|
||||
def test_terminal_task_cwd_ssh_falls_back_to_config(monkeypatch):
|
||||
"""When TERMINAL_CWD is unset, the SSH path reads terminal.cwd from config."""
|
||||
remote = "/home/jonboh/workspace/from-config"
|
||||
monkeypatch.setenv("TERMINAL_ENV", "ssh")
|
||||
monkeypatch.delenv("TERMINAL_CWD", raising=False)
|
||||
monkeypatch.setattr(server, "_load_cfg", lambda: {"terminal": {"cwd": remote}})
|
||||
|
||||
assert server._terminal_task_cwd({"cwd": "/some/host/dir"}) == remote
|
||||
|
||||
|
||||
def test_terminal_task_cwd_ssh_sentinel_cwd_falls_back_to_session(monkeypatch):
|
||||
"""Sentinel/auto cwd values are not real remote paths, so the SSH branch
|
||||
must defer to the session cwd rather than registering a meaningless dir."""
|
||||
monkeypatch.setenv("TERMINAL_ENV", "ssh")
|
||||
monkeypatch.setenv("TERMINAL_CWD", "auto")
|
||||
monkeypatch.setattr(server, "_load_cfg", lambda: {"terminal": {"cwd": "."}})
|
||||
|
||||
assert server._terminal_task_cwd({"cwd": "/host/session/dir"}) == "/host/session/dir"
|
||||
|
||||
|
||||
class _ChunkyStdout:
|
||||
def __init__(self):
|
||||
self.parts: list[str] = []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue