from __future__ import annotations

from infra_core.http_utils import absolute_url


def test_absolute_url_preserves_query_when_appending_segments() -> None:
    result = absolute_url("https://example.test/api/run?id=1", "status", "child")
    assert result == "https://example.test/api/run/status/child?id=1"


def test_absolute_url_handles_relative_paths() -> None:
    result = absolute_url("/api/run?debug=1", "status")
    assert result == "/api/run/status?debug=1"


def test_absolute_url_preserves_query_when_no_segments_are_added() -> None:
    result = absolute_url("https://example.test/api/run?id=1")
    assert result == "https://example.test/api/run?id=1"


def test_absolute_url_preserves_query_when_segments_are_empty() -> None:
    result = absolute_url("https://example.test/api/run?id=1", "", "/")
    assert result == "https://example.test/api/run?id=1"


def test_absolute_url_returns_root_for_empty_input() -> None:
    assert absolute_url("") == "/"
