Skip to content

The agent that grows with you

refactor: move gateway service wizard into setup sibling

Tekniumf0b35a982ece
diff --git a/hermes_cli/gateway.py b/hermes_cli/gateway.py
index 5fc7314b440..090f5a7542f 100644
--- a/hermes_cli/gateway.py
+++ b/hermes_cli/gateway.py
@@ -5521,38 +5521,7 @@ def _wizard_platform_loop() -> None:
_configure_platform(platforms[choice])
-def _wizard_install_service(backend: str) -> None:
- """Fresh install from the wizard: ask start-now / start-on-login, install, then start."""
- wsl_note = " (note: services may not survive WSL restarts)" if is_wsl() else ""
- start_now = prompt_yes_no(" Start the gateway now?", True)
- start_on_login = prompt_yes_no(
- f" Start the gateway automatically on login/boot as a {_WIZARD_BACKEND_LABELS[backend]} service?"
- f"{wsl_note}",
- True,
- )
- if not (start_now or start_on_login):
- print_info(" Skipped start and auto-start setup.")
- print_info(" You can install later: hermes gateway install")
- if supports_systemd_services():
- print_info(" Or as a boot-time service: sudo hermes gateway install --system")
- print_info(" Or run in foreground: hermes gateway run")
- return
- try:
- installed_scope, did_install = None, True
- if backend == "systemd":
- installed_scope, did_install = install_linux_gateway_from_setup(
- force=False, enable_on_startup=start_on_login
- )
- elif backend == "launchd":
- launchd_install(force=False)
- else:
- _gw_windows().install(force=False)
- print()
- if did_install and start_now:
- _setup_service_action("start", failed_label="Start failed", system=installed_scope == "system")
- except subprocess.CalledProcessError as e:
- print_error(f" Install failed: {e}")
- print_info(" You can try manually: hermes gateway install")
+
def _wizard_post_setup() -> None:
@@ -5570,6 +5539,7 @@ def _wizard_post_setup() -> None:
print()
backend = _service_backend()
if backend is not None:
+ from hermes_cli.gateway_setup_service import _wizard_install_service
_wizard_install_service(backend)
return
if is_wsl():
diff --git a/hermes_cli/gateway_setup_service.py b/hermes_cli/gateway_setup_service.py
index 12dad69aa26..7aecbd36222 100644
--- a/hermes_cli/gateway_setup_service.py
+++ b/hermes_cli/gateway_setup_service.py
@@ -99,3 +99,44 @@ def ensure_gateway_service(context: str = "setup", *, interactive: bool = False,
gw.print_warning(f"Gateway service setup failed: {exc}")
gw.print_info("You can retry manually: hermes gateway install")
return False
+
+
+def _wizard_install_service(backend: str) -> None:
+ """Fresh install from the wizard: ask start-now / start-on-login, install, then start."""
+ import subprocess
+ from hermes_cli.gateway import (
+ is_wsl, prompt_yes_no, _WIZARD_BACKEND_LABELS, print_info,
+ supports_systemd_services, install_linux_gateway_from_setup,
+ launchd_install, _gw_windows, _setup_service_action, print_error,
+ )
+
+ wsl_note = " (note: services may not survive WSL restarts)" if is_wsl() else ""
+ start_now = prompt_yes_no(" Start the gateway now?", True)
+ start_on_login = prompt_yes_no(
+ f" Start the gateway automatically on login/boot as a {_WIZARD_BACKEND_LABELS[backend]} service?"
+ f"{wsl_note}",
+ True,
+ )
+ if not (start_now or start_on_login):
+ print_info(" Skipped start and auto-start setup.")
+ print_info(" You can install later: hermes gateway install")
+ if supports_systemd_services():
+ print_info(" Or as a boot-time service: sudo hermes gateway install --system")
+ print_info(" Or run in foreground: hermes gateway run")
+ return
+ try:
+ installed_scope, did_install = None, True
+ if backend == "systemd":
+ installed_scope, did_install = install_linux_gateway_from_setup(
+ force=False, enable_on_startup=start_on_login
+ )
+ elif backend == "launchd":
+ launchd_install(force=False)
+ else:
+ _gw_windows().install(force=False)
+ print()
+ if did_install and start_now:
+ _setup_service_action("start", failed_label="Start failed", system=installed_scope == "system")
+ except subprocess.CalledProcessError as e:
+ print_error(f" Install failed: {e}")
+ print_info(" You can try manually: hermes gateway install")
diff --git a/tests/hermes_cli/test_gateway_service_choice.py b/tests/hermes_cli/test_gateway_service_choice.py
index 104d2b0bb62..393576ab58f 100644
--- a/tests/hermes_cli/test_gateway_service_choice.py
+++ b/tests/hermes_cli/test_gateway_service_choice.py
@@ -102,3 +102,27 @@ def test_explicit_setup_consent_is_durable_only_after_success(supervisor, monkey
if not answer:
assert not gateway.get_systemd_unit_path().exists()
assert not any(set(op) & {"enable", "enable-linger", "start", "daemon-reload"} for op in _operations(calls))
+
+
[email protected]("start_now", [False])
+def test_wizard_declined_service_does_not_install(supervisor, monkeypatch, start_now):
+ profile, calls = supervisor
+ config_api.save_config({"gateway": {"service_install_choice": None}})
+ answers = iter([start_now, False])
+ monkeypatch.setattr(gateway, "prompt_yes_no", lambda *args: next(answers))
+ monkeypatch.setattr(gateway, "prompt_choice", lambda *args, **kwargs: 0)
+ spawned = []
+ # Popen is the unmanaged process boundary; no real gateway is launched.
+ original_popen = gateway.subprocess.Popen
+
+ def popen(argv, *args, **kwargs):
+ if "hermes_cli.main" in argv:
+ spawned.append((argv, kwargs))
+ return None
+ return original_popen(argv, *args, **kwargs)
+
+ monkeypatch.setattr(gateway.subprocess, "Popen", popen)
+ setup_service._wizard_install_service("systemd")
+ assert not gateway.get_systemd_unit_path().exists()
+ assert bool(spawned) is start_now