mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-24 05:41:40 +00:00
fix(acp): honor task cwd for foreground terminal commands
This commit is contained in:
parent
550f6e2efc
commit
b349ae1e4c
2 changed files with 78 additions and 3 deletions
74
tests/tools/test_terminal_task_cwd.py
Normal file
74
tests/tools/test_terminal_task_cwd.py
Normal file
|
|
@ -0,0 +1,74 @@
|
||||||
|
"""Regression tests for task/session cwd propagation in terminal_tool."""
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
|
import tools.terminal_tool as terminal_tool
|
||||||
|
|
||||||
|
|
||||||
|
def _minimal_terminal_config(cwd="/default"):
|
||||||
|
return {
|
||||||
|
"env_type": "local",
|
||||||
|
"cwd": cwd,
|
||||||
|
"timeout": 60,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_foreground_command_uses_registered_task_cwd_for_existing_environment(monkeypatch):
|
||||||
|
"""ACP can update task cwd after the local env exists; foreground must honor it."""
|
||||||
|
calls = []
|
||||||
|
|
||||||
|
class FakeEnv:
|
||||||
|
env = {}
|
||||||
|
|
||||||
|
def execute(self, command, **kwargs):
|
||||||
|
calls.append((command, kwargs))
|
||||||
|
return {"output": "ok", "returncode": 0}
|
||||||
|
|
||||||
|
task_id = "acp-session-1"
|
||||||
|
monkeypatch.setattr(terminal_tool, "_active_environments", {task_id: FakeEnv()})
|
||||||
|
monkeypatch.setattr(terminal_tool, "_last_activity", {})
|
||||||
|
monkeypatch.setattr(terminal_tool, "_task_env_overrides", {task_id: {"cwd": "/workspace/acp"}})
|
||||||
|
monkeypatch.setattr(terminal_tool, "_get_env_config", lambda: _minimal_terminal_config())
|
||||||
|
monkeypatch.setattr(
|
||||||
|
terminal_tool,
|
||||||
|
"_check_all_guards",
|
||||||
|
lambda command, env_type: {"approved": True},
|
||||||
|
)
|
||||||
|
|
||||||
|
result = json.loads(terminal_tool.terminal_tool(command="pwd", task_id=task_id))
|
||||||
|
|
||||||
|
assert result["exit_code"] == 0
|
||||||
|
assert calls == [("pwd", {"timeout": 60, "cwd": "/workspace/acp"})]
|
||||||
|
|
||||||
|
|
||||||
|
def test_explicit_workdir_still_wins_over_registered_task_cwd(monkeypatch):
|
||||||
|
calls = []
|
||||||
|
|
||||||
|
class FakeEnv:
|
||||||
|
env = {}
|
||||||
|
|
||||||
|
def execute(self, command, **kwargs):
|
||||||
|
calls.append(kwargs)
|
||||||
|
return {"output": "ok", "returncode": 0}
|
||||||
|
|
||||||
|
task_id = "acp-session-1"
|
||||||
|
monkeypatch.setattr(terminal_tool, "_active_environments", {task_id: FakeEnv()})
|
||||||
|
monkeypatch.setattr(terminal_tool, "_last_activity", {})
|
||||||
|
monkeypatch.setattr(terminal_tool, "_task_env_overrides", {task_id: {"cwd": "/workspace/acp"}})
|
||||||
|
monkeypatch.setattr(terminal_tool, "_get_env_config", lambda: _minimal_terminal_config())
|
||||||
|
monkeypatch.setattr(
|
||||||
|
terminal_tool,
|
||||||
|
"_check_all_guards",
|
||||||
|
lambda command, env_type: {"approved": True},
|
||||||
|
)
|
||||||
|
|
||||||
|
result = json.loads(
|
||||||
|
terminal_tool.terminal_tool(
|
||||||
|
command="pwd",
|
||||||
|
task_id=task_id,
|
||||||
|
workdir="/explicit/workdir",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["exit_code"] == 0
|
||||||
|
assert calls == [{"timeout": 60, "cwd": "/explicit/workdir"}]
|
||||||
|
|
@ -2001,9 +2001,10 @@ def terminal_tool(
|
||||||
|
|
||||||
while retry_count <= max_retries:
|
while retry_count <= max_retries:
|
||||||
try:
|
try:
|
||||||
execute_kwargs = {"timeout": effective_timeout}
|
execute_kwargs = {
|
||||||
if workdir:
|
"timeout": effective_timeout,
|
||||||
execute_kwargs["cwd"] = workdir
|
"cwd": workdir or cwd,
|
||||||
|
}
|
||||||
result = env.execute(command, **execute_kwargs)
|
result = env.execute(command, **execute_kwargs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error_str = str(e).lower()
|
error_str = str(e).lower()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue