Thicket/tests/test_graph_and_ask.py

58 lines
2.2 KiB
Python

"""Graph engines, MinIO archiver, and the ask bridge — contract tests
that run without any service or heavy dependency installed."""
from __future__ import annotations
import pytest
from thicket.graph_store import GRAPH_ENGINES, GraphUnavailable, create_graph
def test_graph_engine_registry():
assert sorted(GRAPH_ENGINES) == ["graphify", "lightrag"]
assert GRAPH_ENGINES["lightrag"]["modules"] == ("lightrag",)
assert GRAPH_ENGINES["graphify"]["modules"] == ("graphify",)
def test_unknown_graph_engine_names_choices(tmp_path):
with pytest.raises(GraphUnavailable, match="known:"):
create_graph("memgraph", working_dir=tmp_path, llm_model="m",
embed_model="e")
def test_graphify_engine_stages_documents(tmp_path):
pytest.importorskip("graphify")
store = create_graph("graphify", working_dir=tmp_path, llm_model="m",
embed_model="e")
store.ingest_document("Doc One", "alpha text")
store.ingest_document("Doc Two", "beta text")
staged = list((tmp_path / ".graphify" / "corpus").glob("*.md"))
assert len(staged) == 2
store.ingest_document("Doc One", "different content this time")
# same title + different content -> a digest sibling, not a clobber
assert len(list((tmp_path / ".graphify" / "corpus").glob("doc-one*.md"))) == 2
def test_minio_archiver_requires_package():
from thicket.minio_archive import ArchiveUnavailable, MinioArchiver
import importlib.util
if importlib.util.find_spec("minio"):
pytest.skip("minio installed — guard path covered live")
with pytest.raises(ArchiveUnavailable, match="pip install"):
MinioArchiver()
def test_ask_rejects_non_sql_targets():
from thicket.ask_vanna import AskUnavailable, SQL_TARGETS, target_ddl
assert SQL_TARGETS == ("pgvector", "mariadb")
with pytest.raises(AskUnavailable, match="no SQL corpus"):
target_ddl("chroma")
def test_ask_ddl_documents_payload_fields():
from thicket.ask_vanna import target_ddl
for target in ("pgvector", "mariadb"):
ddl = target_ddl(target, "second_brain")
assert "second_brain" in ddl
assert "document_title" in ddl and "chunk_index" in ddl