"""Tests para parse_llm_json."""

import sys
import os
import pytest

sys.path.insert(0, os.path.dirname(__file__))

from parse_llm_json import parse_llm_json


def test_JSON_limpio_es_parseado_correctamente():
    result = parse_llm_json('{"status": "ok", "value": 42}')
    assert result == {"status": "ok", "value": 42}


def test_JSON_con_think_tags_y_codeblock_es_parseado_correctamente():
    raw = '<think>I need to return JSON.</think>\n```json\n{"status": "ok"}\n```'
    result = parse_llm_json(raw)
    assert result == {"status": "ok"}


def test_JSON_invalido_lanza_ValueError():
    with pytest.raises(ValueError, match="parse_llm_json"):
        parse_llm_json("not json at all")
