fix(cli): launchd KeepAlive unconditional restart (#37388)

Replace KeepAlive.SuccessfulExit=false dict with <key>KeepAlive</key><true/>
so launchd restarts hermes-gateway on any exit, matching the documented
drain-then-exit restart protocol used by --graceful-restart.
This commit is contained in:
ashishpatel26
2026-06-04 05:38:12 -07:00
committed by Teknium
parent 153fe28474
commit c9b62061d4
2 changed files with 25 additions and 8 deletions
+21
View File
@@ -2579,3 +2579,24 @@ class TestServiceWorkingDirIsStable:
assert m, "plist has no WorkingDirectory entry"
assert Path(m.group(1)).resolve() == home.resolve()
assert "/.worktrees/" not in m.group(1)
def test_launchd_plist_keepalive_unconditional(self, tmp_path, monkeypatch):
"""KeepAlive must be unconditional <true/> so the gateway restarts on clean exits.
Bug #37388: the old ``KeepAlive.SuccessfulExit = false`` dict form meant
launchd would NOT restart after a zero-exit (e.g. ``gateway run --replace``
causes the old instance to exit cleanly). Switching to the scalar
``<key>KeepAlive</key><true/>`` makes launchd restart regardless of exit code.
"""
home = tmp_path / ".hermes"
home.mkdir()
monkeypatch.setattr(gateway_cli, "get_hermes_home", lambda: home)
plist = gateway_cli.generate_launchd_plist()
# Scalar <true/> must be present immediately after the KeepAlive key
assert "<key>KeepAlive</key>" in plist
# The unconditional form
assert "<key>KeepAlive</key>\n <true/>" in plist
# The old conditional dict form must NOT appear
assert "SuccessfulExit" not in plist
assert "<key>KeepAlive</key>\n <dict>" not in plist