hermes-agent/tests/hermes_cli/test_uninstall_gateway_service.py
ethernet 92686159d1 fix(pm): integrate audited runtime and lifecycle repairs
Prepare dependency generations before selecting them. Keep shipped tool
bytes separate from writable additions, and store facts beside their entries.
Validate proposed plugin sets before config publication. Restore the previous
config if the facts write fails.

Consolidate duplicate updater, backup, setup, and voice helpers. Repair
launcher selection, dependency consumers, download ownership, update feeds,
and native Windows process and file handling.

Verification: 206 changed/prior-failing Python files reported 4630 passed,
one failed, and 330 skipped. Fix the remaining Hindsight fixture boundary.
The final targeted rerun reported 234 passed and two skipped. The store
review regression batch reported 83 passed and one skipped. Desktop
TypeScript checks, 56 selected Electron tests, 24 release tests, and the
removed-import/compatibility guards passed.

This is an integration checkpoint, not full audit acceptance. The complete
Python suite has not run on this fixed tree. Crash-atomic plugin publication,
generation cleanup, receipt correlation, and packaged lifecycle acceptance
remain open in docs/pm-audit-status.md.
2026-09-05 22:36:48 -04:00

70 lines
2.6 KiB
Python

"""Tests for ``uninstall_gateway_service`` — the per-platform service dispatch.
The dispatch is table-driven (``_GATEWAY_SERVICE_REMOVERS``, keyed by
``platform.system()``): exactly the current host's remover runs, a remover
failure is reported with the table's warning label, and a platform with no
entry (tested here via an empty table) cleans up nothing. The tests run on the
actual host — no OS faking — and all removers plus the standalone-process kill
are stubbed, so no real service is stopped and no real gateway process is
killed.
"""
from __future__ import annotations
import platform
import pytest
import hermes_cli.gateway as gateway
import hermes_cli.uninstall as uninstall
@pytest.fixture
def no_live_gateways(monkeypatch: pytest.MonkeyPatch) -> None:
"""The standalone-process sweep finds nothing (and must not kill)."""
monkeypatch.setattr(gateway, "find_gateway_pids", lambda *a, **k: [])
monkeypatch.setattr(
gateway, "kill_gateway_processes",
lambda *a, **k: pytest.fail("kill_gateway_processes must not run without live pids"))
# Neutral env in case the CI runner exports Termux variables; this host
# always reaches the dispatch table.
monkeypatch.delenv("TERMUX_VERSION", raising=False)
monkeypatch.setenv("PREFIX", "")
def _dispatch_table(calls: list) -> dict:
"""A remover table that records which platform's remover ran."""
def remover(name):
def run():
calls.append(name)
return True
return run
return {
"Linux": (remover("Linux"), "linux label"),
"Darwin": (remover("Darwin"), "darwin label"),
"Windows": (remover("Windows"), "windows label"),
}
def test_current_platform_remover_runs_and_others_do_not(monkeypatch, no_live_gateways):
calls: list = []
monkeypatch.setattr(uninstall, "_GATEWAY_SERVICE_REMOVERS", _dispatch_table(calls))
assert uninstall.uninstall_gateway_service() is True
assert calls == [platform.system()]
def test_remover_failure_reports_the_table_label(monkeypatch, no_live_gateways, capsys):
table = _dispatch_table([])
def boom():
raise RuntimeError("no service manager here")
table[platform.system()] = (boom, "remover blew up")
monkeypatch.setattr(uninstall, "_GATEWAY_SERVICE_REMOVERS", table)
assert uninstall.uninstall_gateway_service() is False
assert "remover blew up" in capsys.readouterr().out
def test_unknown_platform_runs_no_remover(monkeypatch, no_live_gateways):
monkeypatch.setattr(uninstall, "_GATEWAY_SERVICE_REMOVERS", {})
assert uninstall.uninstall_gateway_service() is False