"""Address-selection tests (multi-homing) — the core of the reachability fix.""" from mdns_tools import _pick def test_single_routable_ip_returned(): assert _pick.pick_best(["192.168.1.17"]) == "192.168.1.17" def test_only_virtual_ip_returns_none(monkeypatch): # libvirt bridge address must be rejected so callers fall back to Tailscale. monkeypatch.setattr(_pick, "local_ipv4", lambda: "192.168.1.112") assert _pick.pick_best(["192.168.122.1"]) is None def test_docker_range_rejected(monkeypatch): monkeypatch.setattr(_pick, "local_ipv4", lambda: "192.168.1.112") assert _pick.pick_best(["172.17.0.1"]) is None def test_prefers_same_subnet(monkeypatch): monkeypatch.setattr(_pick, "local_ipv4", lambda: "192.168.1.112") got = _pick.pick_best(["10.8.0.3", "192.168.1.50"]) assert got == "192.168.1.50" def test_dedupe_preserves_order(): assert _pick.pick_best(["10.0.0.9", "10.0.0.9"]) == "10.0.0.9" def test_ipv6_prefers_global_over_link_local(): got = _pick.pick_best(["fe80::1", "2800:e2::5"], family="v6") assert got == "2800:e2::5"