The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test: retain startup exit contracts with real authority stores
Tekniuma126b4cc0a81
diff --git a/tests/gateway/test_normal_runtime_boot.py b/tests/gateway/test_normal_runtime_boot.pyindex 4189cb51da2..4d5098dea04 100644--- a/tests/gateway/test_normal_runtime_boot.py+++ b/tests/gateway/test_normal_runtime_boot.py@@ -96,3 +96,27 @@ def test_normal_entrypoint_earns_authenticated_authority_readiness(tmp_path):except subprocess.TimeoutExpired:process.kill()process.wait(timeout=5)+++async def test_api_bind_failure_unwinds_control_db_and_reservation(tmp_path, monkeypatch):+ from functools import partial+ from gateway import run_api+ from gateway.run import start_gateway+ from gateway.config import GatewayConfig+ from gateway.runtime_ownership import process_ownership+ from hermes_cli import web_server as web+ from hermes_constants import get_hermes_home++ home = get_hermes_home()+ with socket.socket() as blocker:+ blocker.bind(('127.0.0.1', 0))+ blocker.listen()+ monkeypatch.setattr(run_api, 'start_gateway_api', partial(+ run_api.start_gateway_api, port=blocker.getsockname()[1]))+ with pytest.raises(OSError):+ await start_gateway(GatewayConfig(), verbosity=None)+ assert getattr(web.app.state, 'gateway_runner', None) is None+ assert not (home / 'gateway.pid').exists()+ assert not (home / 'gateway.sock').exists()+ assert not process_ownership.owns(home)diff --git a/tests/gateway/test_replace_child_reap.py b/tests/gateway/test_replace_child_reap.pyindex 6409ea2d22d..818552fd357 100644--- a/tests/gateway/test_replace_child_reap.py+++ b/tests/gateway/test_replace_child_reap.py@@ -177,6 +177,10 @@ async def test_start_gateway_replace_reaps_old_gateway_children_posix(class _CleanExitRunner:def __init__(self, config):+ from hermes_state import SessionDB+ from hermes_constants import get_hermes_home+ self._session_db = SessionDB(get_hermes_home() / 'state.db')+ self._draining = Falseself.config = configself.should_exit_cleanly = Trueself.exit_reason = None@@ -188,7 +192,7 @@ async def test_start_gateway_replace_reaps_old_gateway_children_posix(return Trueasync def stop(self):- return None+ self._session_db.close()_pid_state = {"alive": True}monkeypatch.setattr(diff --git a/tests/gateway/test_runner_startup_failures.py b/tests/gateway/test_runner_startup_failures.pyindex c3f906f1717..8a6c2341fb3 100644--- a/tests/gateway/test_runner_startup_failures.py+++ b/tests/gateway/test_runner_startup_failures.py@@ -91,6 +91,10 @@ async def test_start_gateway_verbosity_imports_redacting_formatter(monkeypatch,class _CleanExitRunner:def __init__(self, config):+ from hermes_state import SessionDB+ from hermes_constants import get_hermes_home+ self._session_db = SessionDB(get_hermes_home() / 'state.db')+ self._draining = Falseself.config = configself.should_exit_cleanly = Trueself.exit_reason = None@@ -102,7 +106,7 @@ async def test_start_gateway_verbosity_imports_redacting_formatter(monkeypatch,return Trueasync def stop(self):- return None+ self._session_db.close()monkeypatch.setattr("gateway.status.get_running_pid", lambda: None)monkeypatch.setattr("tools.skills_sync.sync_skills", lambda quiet=True: None)@@ -231,6 +235,10 @@ async def test_start_gateway_replace_writes_takeover_marker_before_sigterm(class _CleanExitRunner:def __init__(self, config):+ from hermes_state import SessionDB+ from hermes_constants import get_hermes_home+ self._session_db = SessionDB(get_hermes_home() / 'state.db')+ self._draining = Falseself.config = configself.should_exit_cleanly = Trueself.exit_reason = None@@ -241,7 +249,7 @@ async def test_start_gateway_replace_writes_takeover_marker_before_sigterm(return Trueasync def stop(self):- return None+ self._session_db.close()_pid_state = {"alive": True}def _mock_get_running_pid():@@ -439,6 +447,10 @@ async def test_start_gateway_propagates_fatal_config_exit_code(monkeypatch, tmp_class _FatalConfigRunner:def __init__(self, config):+ from hermes_state import SessionDB+ from hermes_constants import get_hermes_home+ self._session_db = SessionDB(get_hermes_home() / 'state.db')+ self._draining = Falseself.config = configself.should_exit_cleanly = Trueself.exit_reason = "discord: Discord bot token already in use"@@ -449,7 +461,7 @@ async def test_start_gateway_propagates_fatal_config_exit_code(monkeypatch, tmp_return Trueasync def stop(self):- return None+ self._session_db.close()monkeypatch.setattr("gateway.status.get_running_pid", lambda: None)monkeypatch.setattr("tools.skills_sync.sync_skills", lambda quiet=True: None)diff --git a/tests/gateway/test_startup_restart_race.py b/tests/gateway/test_startup_restart_race.pyindex d0dc53754a0..3e53a0b55c5 100644--- a/tests/gateway/test_startup_restart_race.py+++ b/tests/gateway/test_startup_restart_race.py@@ -192,6 +192,10 @@ async def test_start_gateway_does_not_start_cron_after_aborted_startup(tmp_path,class AbortedStartupRunner:def __init__(self, config):+ from hermes_state import SessionDB+ from hermes_constants import get_hermes_home+ self._session_db = SessionDB(get_hermes_home() / 'state.db')+ self._draining = Falseself.config = configself.adapters = {}self._running = False@@ -207,6 +211,9 @@ async def test_start_gateway_does_not_start_cron_after_aborted_startup(tmp_path,async def wait_for_shutdown(self):return None+ async def stop(self):+ self._session_db.close()+def fail_if_cron_starts(*args, **kwargs):nonlocal cron_startedcron_started = True@@ -233,6 +240,10 @@ async def test_start_gateway_preserves_service_restart_fallback_after_aborted_stclass AbortedStartupRunner:def __init__(self, config):+ from hermes_state import SessionDB+ from hermes_constants import get_hermes_home+ self._session_db = SessionDB(get_hermes_home() / 'state.db')+ self._draining = Falseself.config = configself.adapters = {}self._running = False@@ -249,6 +260,9 @@ async def test_start_gateway_preserves_service_restart_fallback_after_aborted_stasync def wait_for_shutdown(self):return None+ async def stop(self):+ self._session_db.close()+def fail_if_cron_starts(*args, **kwargs):nonlocal cron_startedcron_started = True@@ -282,6 +296,10 @@ async def test_start_gateway_classifies_startup_signal_exit(class AbortedStartupRunner:def __init__(self, config):+ from hermes_state import SessionDB+ from hermes_constants import get_hermes_home+ self._session_db = SessionDB(get_hermes_home() / 'state.db')+ self._draining = Falseself.config = configself.adapters = {}self._running = False@@ -300,6 +318,9 @@ async def test_start_gateway_classifies_startup_signal_exit(async def wait_for_shutdown(self):return None+ async def stop(self):+ self._session_db.close()+def capture_signal_state(runner, state):nonlocal signal_statesignal_state = state