"""Agent heartbeat 401 / discarded stop policy (A-05).""" import sys from pathlib import Path import pytest _AGENT_DIR = Path(__file__).resolve().parents[1] / "web" / "agent" if str(_AGENT_DIR) not in sys.path: sys.path.insert(0, str(_AGENT_DIR)) from heartbeat_policy import heartbeat_should_stop # noqa: E402 from server.utils.agent_version import get_central_agent_version # noqa: E402 def test_stop_on_401(): assert heartbeat_should_stop(401) is True assert heartbeat_should_stop(401, {}) is True def test_stop_on_discarded(): assert heartbeat_should_stop(200, {"status": "discarded", "reason": "missing server_id"}) is True def test_continue_on_success(): assert heartbeat_should_stop(200, {"status": "ok"}) is False def test_continue_on_transient_errors(): assert heartbeat_should_stop(500) is False assert heartbeat_should_stop(502, None) is False def test_central_agent_version_matches_constant(): assert get_central_agent_version() == "2.0.0"