Skip to content

The agent that grows with you

fix(cli): read a POSIX launcher's interpreter the way sh does

unsupportedpastels24b9f0f8c5df
diff --git a/hermes_cli/_launchers.py b/hermes_cli/_launchers.py
index 1566933a4be..35d53d3bc24 100644
--- a/hermes_cli/_launchers.py
+++ b/hermes_cli/_launchers.py
@@ -472,7 +472,16 @@ def _launcher_python(target: Path) -> Path | None:
line = next((entry for entry in lines if entry.startswith("exec ")), None)
if line is None:
return None
- line = line.removeprefix("exec ")
+ # The writer quotes with shlex.join, which splices an apostrophe in as
+ # '"'"', so read the first token the way sh does. Only the first: the
+ # rest of the line opens a multi-line -c argument.
+ lexer = shlex.shlex(line.removeprefix("exec "), posix=True)
+ lexer.whitespace_split = True
+ try:
+ token = lexer.get_token()
+ except ValueError:
+ return None
+ return Path(token) if token else None
try:
return _first_token(line)
except (ValueError, OSError):
diff --git a/tests/hermes_cli/test_hermes_home_shared_launchers.py b/tests/hermes_cli/test_hermes_home_shared_launchers.py
index 2f5ccc1b024..5eb289da0ac 100644
--- a/tests/hermes_cli/test_hermes_home_shared_launchers.py
+++ b/tests/hermes_cli/test_hermes_home_shared_launchers.py
@@ -76,7 +76,8 @@ def _publish(repo: Path) -> dict[str, bytes]:
# Every lane: the guard reads native .exe and .cmd launchers on Windows, POSIX wrappers elsewhere.
@pytest.mark.platforms("any")
def test_temp_home_prepare_launch_relaunches_without_rebinding(tmp_path, monkeypatch):
- default_home, _ = _make_home(tmp_path, "default")
+ # An apostrophe in the owner's path: the guard must read back what the writer quoted.
+ default_home, _ = _make_home(tmp_path, "owner's home")
temp_home, temp_python = _make_home(tmp_path, "temp")
repo = _make_repo(tmp_path)