"""Tests for ensure_finite_json."""

from __future__ import annotations

import pytest

from dr_langfuse.validation import ensure_finite_json


def test_finite_float_passes() -> None:
    ensure_finite_json(1.5, path="root")


def test_nan_raises() -> None:
    with pytest.raises(ValueError, match="NaN or infinity"):
        ensure_finite_json(float("nan"), path="root")


def test_inf_raises() -> None:
    with pytest.raises(ValueError, match="NaN or infinity"):
        ensure_finite_json(float("inf"), path="root")


def test_negative_inf_raises() -> None:
    with pytest.raises(ValueError, match="NaN or infinity"):
        ensure_finite_json(float("-inf"), path="root")


def test_nested_list_nan_raises() -> None:
    with pytest.raises(ValueError, match=r"root\[1\]"):
        ensure_finite_json([1.0, float("nan")], path="root")


def test_nested_dict_nan_raises() -> None:
    with pytest.raises(ValueError, match=r"root\.bad"):
        ensure_finite_json({"ok": 1.0, "bad": float("nan")}, path="root")


def test_strings_and_ints_pass() -> None:
    ensure_finite_json({"s": "hello", "n": 42, "nested": [1, "two"]}, path="root")
