from pathlib import Path

import pytest

from kbqa.api.errors import AppError
from kbqa.indexing.loaders import load_document


def test_text_loader_rejects_non_utf8(tmp_path: Path) -> None:
    path = tmp_path / "bad.txt"
    path.write_bytes(b"\xff\xfe")
    with pytest.raises(AppError, match="UTF-8"):
        load_document(path, "txt")
