The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
Fix tests
IAvecilla9d5745d0a072
diff --git a/tests/gateway/test_scale_to_zero_watcher.py b/tests/gateway/test_scale_to_zero_watcher.pyindex f4fc4fdb23b..0e5d2f2e081 100644--- a/tests/gateway/test_scale_to_zero_watcher.py+++ b/tests/gateway/test_scale_to_zero_watcher.py@@ -27,13 +27,20 @@ class _FakeRelayAdapter:return True-def _runner_with(monkeypatch, *, idle, armed_adapter=True):+def _runner_with(monkeypatch, *, idle, armed_adapter=True, can_self_suspend=True):"""Build a GatewayRunner without booting it, stubbing just what the watchertouches. Real methods (_scale_to_zero_is_idle composition, the watcher body)- run; only their dependencies are stubbed."""+ run; only their dependencies are stubbed.++ `can_self_suspend` stands in for the platform: True is Fly (an in-machine+ suspend API exists, so quiescing is followed by a freeze), False is anywhere+ the platform suspends on its own timer. The watcher only quiesces in the+ first case, so this defaults True to keep the existing cases on that path.+ """r = GatewayRunner.__new__(GatewayRunner)r._running = Truer._scale_to_zero_cooldown_until = 0.0+ r._scale_to_zero_no_suspend_logged = Falser._last_inbound_at = time.time()r._running_agents = {}r._background_tasks = set()@@ -43,9 +50,46 @@ def _runner_with(monkeypatch, *, idle, armed_adapter=True):monkeypatch.setattr(r, "_relay_adapter_for_dormancy", lambda: adapter, raising=False)monkeypatch.setattr(r, "_scale_to_zero_idle_timeout_seconds", lambda: 300.0, raising=False)monkeypatch.setattr(r, "_update_runtime_status", lambda *a, **k: None, raising=False)+ monkeypatch.setattr(+ "gateway.scale_to_zero.self_suspend_available",+ lambda *a, **k: can_self_suspend,+ )return r, adapter+async def test_watcher_does_not_quiesce_when_the_platform_owns_the_suspend(+ monkeypatch,+):+ """Off-Fly the platform freezes on its own timer and cannot see the relay WS,+ so quiescing does not bring the freeze closer -- it only flips the relay+ destination and closes the socket, which the reconnect supervisor undoes+ ~1.4s later. Repeated every cooldown, that leaves the destination unflipped+ when the freeze finally lands, and inbound is dropped instead of buffered.+ Staying connected lets the connector's orphan detection adopt the+ destination after the freeze instead.+ """+ r, adapter = _runner_with(monkeypatch, idle=True, can_self_suspend=False)+ suspends = []+ monkeypatch.setattr(+ r,+ "_scale_to_zero_self_suspend",+ lambda *a, **k: suspends.append(1),+ raising=False,+ )++ task = asyncio.create_task(r._scale_to_zero_watcher(interval=0.01))+ await asyncio.sleep(0.1)+ r._running = False+ await asyncio.wait_for(task, timeout=2)++ assert adapter.go_dormant_calls == 0, "must not flip/close on a platform-timed suspend"+ assert suspends == []+ # No cooldown either: nothing was driven, so the next tick is free to act+ # the moment the platform picture changes.+ assert r._scale_to_zero_cooldown_until == 0.0++@pytest.mark.asyncioasync def test_watcher_goes_dormant_when_idle(monkeypatch):r, adapter = _runner_with(monkeypatch, idle=True)