from scripts.quant.serve import health_url, parse_listening_pid


def test_health_url_from_port():
    assert health_url(8001) == "http://127.0.0.1:8001/health"


def test_parse_listening_pid_extracts_from_ss_line():
    ss_output = (
        'LISTEN 0 4096 127.0.0.1:8001 0.0.0.0:* users:(("python",pid=12345,fd=7))\n'
    )
    assert parse_listening_pid(ss_output, 8001) == 12345


def test_parse_listening_pid_returns_none_when_absent():
    assert parse_listening_pid("LISTEN 0 4096 127.0.0.1:9999 0.0.0.0:*\n", 8001) is None
