fix(env): pass -- to cd for hyphen-prefixed workdirs

This commit is contained in:
Yoimex 2026-04-25 07:56:29 +03:00 committed by Teknium
parent ae40fca955
commit edf9c75621
2 changed files with 16 additions and 8 deletions

View file

@ -30,7 +30,7 @@ class TestWrapCommand:
wrapped = env._wrap_command("echo hello", "/tmp")
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 "__hermes_ec=$?" in wrapped
assert "export -p >" in wrapped
@ -57,24 +57,31 @@ class TestWrapCommand:
env._snapshot_ready = True
wrapped = env._wrap_command("ls", "~")
assert "cd ~" in wrapped
assert "cd '~'" not in wrapped
assert "cd -- ~" in wrapped
assert "cd -- '~'" not in wrapped
def test_tilde_subpath_with_spaces_uses_home_and_quotes_suffix(self):
env = _TestableEnv()
env._snapshot_ready = True
wrapped = env._wrap_command("ls", "~/my repo")
assert "cd $HOME/'my repo'" in wrapped
assert "cd ~/my repo" not in wrapped
assert "cd -- $HOME/'my repo'" in wrapped
assert "cd -- ~/my repo" not in wrapped
def test_tilde_slash_maps_to_home(self):
env = _TestableEnv()
env._snapshot_ready = True
wrapped = env._wrap_command("ls", "~/")
assert "cd $HOME" in wrapped
assert "cd ~/" not in wrapped
assert "cd -- $HOME" 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):
env = _TestableEnv()