from __future__ import annotations

from autosana_cli import ports


def test_allocate_port_skips_reserved() -> None:
    port = ports.allocate_port(49152, reserved_ports={49152, 49153})
    assert port >= 49154


def test_allocate_port_skips_unavailable_ports(monkeypatch) -> None:
    monkeypatch.setattr(ports, "is_port_available", lambda port, host="127.0.0.1": port >= 49154)
    assert ports.allocate_port(49152) == 49154
