Skip to content

The agent that grows with you

fix: route wizard startup through canonical gateway ensure

Tekniumaf2c2c363152
diff --git a/hermes_cli/gateway_setup_service.py b/hermes_cli/gateway_setup_service.py
index c252d9415a9..27ac1c9697a 100644
--- a/hermes_cli/gateway_setup_service.py
+++ b/hermes_cli/gateway_setup_service.py
@@ -105,7 +105,7 @@ def _wizard_install_service(backend: str) -> None:
"""Choose persistence once; start-now without persistence stays unmanaged."""
import subprocess
from hermes_cli import gateway as gw
- from hermes_cli._subprocess_compat import windows_detach_popen_kwargs
+ from hermes_cli.gateway_runtime import ensure_gateway_runtime
if not sys.stdin.isatty():
return
@@ -113,19 +113,11 @@ def _wizard_install_service(backend: str) -> None:
if not wants_service_install(interactive=True):
gw.print_info("Without a service, messaging and scheduled jobs stop at logout/reboot; jobs cannot run while the host is off.")
if start_now:
- log_dir = gw.get_hermes_home() / "logs"
- log_dir.mkdir(parents=True, exist_ok=True)
- # A setup start is not a request to evict an existing runtime.
- command = [arg for arg in gw._timestamped_stderr_gateway_command(
- log_dir / "gateway.error.log"
- ) if arg != "--replace"]
- try:
- with (log_dir / "gateway.log").open("ab") as output:
- subprocess.Popen(command, stdin=subprocess.DEVNULL, stdout=output,
- stderr=subprocess.DEVNULL, **windows_detach_popen_kwargs())
- gw.print_info("Gateway launch requested without installing a service. Check: hermes gateway status")
- except OSError as exc:
- gw.print_error(f"Gateway launch failed: {exc}")
+ result = ensure_gateway_runtime(gw.get_hermes_home(), timeout=5.0)
+ if result.state == "ready":
+ gw.print_success("Gateway runtime ready; no service was installed.")
+ else:
+ gw.print_info(f"Gateway runtime: {result.state} ({result.reason_code or 'pending'}). Check: hermes gateway status")
else:
gw.print_info("Run later: hermes gateway run. Install later: hermes gateway install")
return
diff --git a/tests/hermes_cli/test_gateway_service_choice.py b/tests/hermes_cli/test_gateway_service_choice.py
index 13d990eab8a..485b8fa0719 100644
--- a/tests/hermes_cli/test_gateway_service_choice.py
+++ b/tests/hermes_cli/test_gateway_service_choice.py
@@ -45,6 +45,7 @@ def supervisor(tmp_path, monkeypatch):
"if 'start' in args: active.touch()\n"
"if 'is-active' in args: print('active' if active.exists() else 'inactive')\n"
"elif 'show-user' in args: print('yes')\n"
+ "elif 'show' in args: print('LoadState=not-found')\n"
"elif 'is-system-running' in args: print('running')\n",
encoding="utf-8",
)
@@ -162,3 +163,30 @@ def test_explicit_install_records_only_completed_install(supervisor, monkeypatch
else:
gateway._cmd_install(args)
assert config_api.load_config()["gateway"]["service_install_choice"] == ("decline" if fail else "install")
+
+
+def test_wizard_start_does_not_spawn_over_reserved_owner(supervisor, monkeypatch):
+ from gateway.runtime_ownership import ProfileOwnership
+ profile, calls = supervisor
+ profile.chmod(0o700)
+ config_api.save_config({"gateway": {"service_install_choice": "decline"}})
+ stream = io.StringIO()
+ stream.isatty = lambda: True
+ monkeypatch.setattr(sys, "stdin", stream)
+ monkeypatch.setattr(gateway, "prompt_yes_no", lambda *args: True)
+ spawned = []
+ original = gateway.subprocess.Popen
+ def boundary(argv, *args, **kwargs):
+ if "hermes_cli.main" in argv:
+ spawned.append(argv)
+ return None
+ return original(argv, *args, **kwargs)
+ monkeypatch.setattr(gateway.subprocess, "Popen", boundary)
+ owner = ProfileOwnership()
+ owner.reserve([profile])
+ try:
+ setup_service._wizard_install_service("systemd")
+ assert not spawned
+ finally:
+ owner.close()