"""Hamilton review MINOR #6: `_to_int` silently coerced bad values to None. Sort fields built on `_to_int` returns then defaulted None to 0, which jumbled the failover order in the displayed result. Fix: when the conversion fails, log to stderr (so an operator can see) and return None — but the caller code path that does the sort now uses a stable tie-breaker that doesn't silently rewrite real-zero into "no value." """ import sys from io import StringIO from mcp_cucm_axl.route_plan import _to_int def test_to_int_passthrough_normal(): assert _to_int("5") == 5 assert _to_int(7) == 7 def test_to_int_none_returns_none_silently(): """Real Nones are valid (column not set) — don't log noise for them.""" captured = StringIO() real_stderr = sys.stderr sys.stderr = captured try: assert _to_int(None) is None finally: sys.stderr = real_stderr assert "warning" not in captured.getvalue().lower() def test_to_int_bad_value_logs_warning(): """A non-numeric string from the cluster (data corruption / unexpected type) should be loud enough for an operator to notice in stderr.""" captured = StringIO() real_stderr = sys.stderr sys.stderr = captured try: result = _to_int("not-a-number") finally: sys.stderr = real_stderr assert result is None output = captured.getvalue() assert "not-a-number" in output, ( f"unexpected non-numeric value should be logged with the offending value; " f"got stderr: {output!r}" )