diff --git a/tests/test_app_health_connectivity.py b/tests/test_app_health_connectivity.py index 2ec1e30..955a5c2 100644 --- a/tests/test_app_health_connectivity.py +++ b/tests/test_app_health_connectivity.py @@ -62,6 +62,25 @@ class TestHealthHistoryIsDeque: assert hh[0]['n'] == 4 +# --------------------------------------------------------------------------- +# startup regenerates the Caddyfile (stale-Caddyfile restart-loop fix) +# --------------------------------------------------------------------------- + +class TestStartupCaddyRegen: + def test_startup_regenerates_caddyfile_first(self): + """_apply_startup_enforcement must regenerate the Caddyfile before + anything else, so a stale on-disk Caddyfile (e.g. missing + `admin 0.0.0.0:2019`) can't wedge the health monitor into restarting + Caddy every few minutes.""" + with patch.object(app_module, 'caddy_manager') as mock_caddy, \ + patch.object(app_module, 'peer_registry') as mock_pr: + # Raise right after the caddy regen to short-circuit the rest of + # the (heavy, docker/iptables) startup work. + mock_pr.list_peers.side_effect = RuntimeError('stop here') + app_module._apply_startup_enforcement() + mock_caddy.regenerate_with_installed.assert_called_once_with([]) + + # --------------------------------------------------------------------------- # GET /api/health/history # ---------------------------------------------------------------------------