diff --git a/hermes_cli/windows_ssh_runtime.py b/hermes_cli/windows_ssh_runtime.py index 427911b73fe4a..e031274583a09 100644 --- a/hermes_cli/windows_ssh_runtime.py +++ b/hermes_cli/windows_ssh_runtime.py @@ -10,7 +10,7 @@ import sys from pathlib import Path from typing import Any -from hermes_constants import get_hermes_home +from hermes_constants import get_default_hermes_root _HEX32 = re.compile(r"[0-9a-f]{32}\Z") _HEX16 = re.compile(r"[0-9a-f]{16}\Z") @@ -49,7 +49,11 @@ def _nonce(value: str) -> str: def _root() -> Path: - return get_hermes_home() / "desktop-ssh" + # The helper uploads the token before the child applies `--profile`, while + # read_token() runs after profile activation. Anchor both processes to the + # machine root so a named profile cannot move the reader away from the + # helper's token, including custom HERMES_HOME layouts. + return get_default_hermes_root() / "desktop-ssh" def _directory(ownership_id: str) -> Path: @@ -452,7 +456,7 @@ def dispatch(argv: list[str]) -> Any: operation = argv[0] if operation == "probe": import platform - return {"os": "Windows", "arch": platform.machine(), "hermesHome": str(get_hermes_home()), "python": sys.executable} + return {"os": "Windows", "arch": platform.machine(), "hermesHome": str(get_default_hermes_root()), "python": sys.executable} if operation == "upload-token" and len(argv) == 3: return upload_token(argv[1], argv[2], sys.stdin.buffer.read(65)) if operation == "read-lock" and len(argv) == 2: diff --git a/tests/hermes_cli/test_ssh_session_token_parser.py b/tests/hermes_cli/test_ssh_session_token_parser.py index de7ea87b7079f..fd50b7a373284 100644 --- a/tests/hermes_cli/test_ssh_session_token_parser.py +++ b/tests/hermes_cli/test_ssh_session_token_parser.py @@ -138,3 +138,12 @@ def test_token_file_rejects_parent_escape(tmp_path, monkeypatch): assert escaped.exists() finally: reset_hermes_home_override(override) + + +def test_windows_runtime_root_stays_at_machine_root_for_named_profile(tmp_path, monkeypatch): + from hermes_cli import windows_ssh_runtime + + machine_root = tmp_path / "custom-hermes-root" + monkeypatch.setenv("HERMES_HOME", str(machine_root / "profiles" / "writer_2")) + + assert windows_ssh_runtime._root() == machine_root / "desktop-ssh"