mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-07 02:51:50 +00:00
fix(env): pass -- to cd for hyphen-prefixed workdirs
This commit is contained in:
parent
ae40fca955
commit
edf9c75621
2 changed files with 16 additions and 8 deletions
|
|
@ -30,7 +30,7 @@ class TestWrapCommand:
|
||||||
wrapped = env._wrap_command("echo hello", "/tmp")
|
wrapped = env._wrap_command("echo hello", "/tmp")
|
||||||
|
|
||||||
assert "source" in wrapped
|
assert "source" in wrapped
|
||||||
assert "cd /tmp" in wrapped or "cd '/tmp'" in wrapped
|
assert "cd -- /tmp" in wrapped or "cd -- '/tmp'" in wrapped
|
||||||
assert "eval 'echo hello'" in wrapped
|
assert "eval 'echo hello'" in wrapped
|
||||||
assert "__hermes_ec=$?" in wrapped
|
assert "__hermes_ec=$?" in wrapped
|
||||||
assert "export -p >" in wrapped
|
assert "export -p >" in wrapped
|
||||||
|
|
@ -57,24 +57,31 @@ class TestWrapCommand:
|
||||||
env._snapshot_ready = True
|
env._snapshot_ready = True
|
||||||
wrapped = env._wrap_command("ls", "~")
|
wrapped = env._wrap_command("ls", "~")
|
||||||
|
|
||||||
assert "cd ~" in wrapped
|
assert "cd -- ~" in wrapped
|
||||||
assert "cd '~'" not in wrapped
|
assert "cd -- '~'" not in wrapped
|
||||||
|
|
||||||
def test_tilde_subpath_with_spaces_uses_home_and_quotes_suffix(self):
|
def test_tilde_subpath_with_spaces_uses_home_and_quotes_suffix(self):
|
||||||
env = _TestableEnv()
|
env = _TestableEnv()
|
||||||
env._snapshot_ready = True
|
env._snapshot_ready = True
|
||||||
wrapped = env._wrap_command("ls", "~/my repo")
|
wrapped = env._wrap_command("ls", "~/my repo")
|
||||||
|
|
||||||
assert "cd $HOME/'my repo'" in wrapped
|
assert "cd -- $HOME/'my repo'" in wrapped
|
||||||
assert "cd ~/my repo" not in wrapped
|
assert "cd -- ~/my repo" not in wrapped
|
||||||
|
|
||||||
def test_tilde_slash_maps_to_home(self):
|
def test_tilde_slash_maps_to_home(self):
|
||||||
env = _TestableEnv()
|
env = _TestableEnv()
|
||||||
env._snapshot_ready = True
|
env._snapshot_ready = True
|
||||||
wrapped = env._wrap_command("ls", "~/")
|
wrapped = env._wrap_command("ls", "~/")
|
||||||
|
|
||||||
assert "cd $HOME" in wrapped
|
assert "cd -- $HOME" in wrapped
|
||||||
assert "cd ~/" not in wrapped
|
assert "cd -- ~/" not in wrapped
|
||||||
|
|
||||||
|
def test_hyphen_prefixed_workdir_is_passed_after_double_dash(self):
|
||||||
|
env = _TestableEnv()
|
||||||
|
env._snapshot_ready = True
|
||||||
|
wrapped = env._wrap_command("pwd", "-demo")
|
||||||
|
|
||||||
|
assert "builtin cd -- -demo || exit 126" in wrapped
|
||||||
|
|
||||||
def test_cd_failure_exit_126(self):
|
def test_cd_failure_exit_126(self):
|
||||||
env = _TestableEnv()
|
env = _TestableEnv()
|
||||||
|
|
|
||||||
|
|
@ -405,7 +405,8 @@ class BaseEnvironment(ABC):
|
||||||
# Preserve bare ``~`` expansion, but rewrite ``~/...`` through
|
# Preserve bare ``~`` expansion, but rewrite ``~/...`` through
|
||||||
# ``$HOME`` so suffixes with spaces remain a single shell word.
|
# ``$HOME`` so suffixes with spaces remain a single shell word.
|
||||||
quoted_cwd = self._quote_cwd_for_cd(cwd)
|
quoted_cwd = self._quote_cwd_for_cd(cwd)
|
||||||
parts.append(f"builtin cd {quoted_cwd} || exit 126")
|
# ``--`` keeps hyphen-prefixed directory names from being parsed as options.
|
||||||
|
parts.append(f"builtin cd -- {quoted_cwd} || exit 126")
|
||||||
|
|
||||||
# Run the actual command
|
# Run the actual command
|
||||||
parts.append(f"eval '{escaped}'")
|
parts.append(f"eval '{escaped}'")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue