from pathlib import Path
from mcp_data_server.loaders import list_docs, read_doc
from mcp_data_server.index import build_index, search
def test_list_and_read():
# temporarily point at tests/fixtures
root = Path(__file__).parent / "fixtures"
docs = list_docs(root)
assert docs, "should find at least one fixture"
txt = read_doc(docs[0])
assert isinstance(txt, str) and len(txt) > 0
def test_index_and_search(tmp_path, monkeypatch):
# point DATA_DIR and INDEX_DIR to test paths
monkeypatch.setenv("DATA_DIR", str(Path(__file__).parent / "fixtures"))
monkeypatch.setenv("INDEX_DIR", str(tmp_path / ".index"))
monkeypatch.setenv("USE_FAISS", "false") # keep CI light
build_index()
results = search("apples", k=3)
assert isinstance(results, list)
assert len(results) > 0