from cancontech_tracing.init_tracing import _build_exporter_headers


def test_build_exporter_headers_adds_phoenix_auth_from_env(monkeypatch):
    monkeypatch.setenv("PHOENIX_API_KEY", "my-secret-key")

    headers = _build_exporter_headers(headers=None)

    assert headers == {"authorization": "Bearer my-secret-key"}


def test_build_exporter_headers_keeps_existing_authorization(monkeypatch):
    monkeypatch.setenv("PHOENIX_API_KEY", "my-secret-key")

    headers = _build_exporter_headers(headers={"Authorization": "Basic already-set"})

    assert headers == {"Authorization": "Basic already-set"}


def test_build_exporter_headers_preserves_bearer_prefix_from_env(monkeypatch):
    monkeypatch.setenv("PHOENIX_API_KEY", "Bearer token-from-env")

    headers = _build_exporter_headers(headers={"x-extra": "value"})

    assert headers == {"x-extra": "value", "authorization": "Bearer token-from-env"}
