mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-06 05:51:24 +08:00
test(lightrag): isolate role configuration in offline fixtures
This commit is contained in:
@@ -78,7 +78,26 @@ def test_document_adder_preserves_explicit_bound_provider(tmp_path: Path) -> Non
|
||||
assert adder.rag_provider == "graphrag"
|
||||
|
||||
|
||||
def test_document_adder_allows_empty_lightrag_kb_to_bootstrap(tmp_path: Path) -> None:
|
||||
def test_document_adder_allows_empty_lightrag_kb_to_bootstrap(monkeypatch, tmp_path: Path) -> None:
|
||||
from deeptutor.services import config
|
||||
from deeptutor.services.llm.config import LLMConfig
|
||||
from deeptutor.services.rag.pipelines.lightrag import roles
|
||||
|
||||
monkeypatch.setattr(
|
||||
config,
|
||||
"load_lightrag_settings",
|
||||
lambda: {
|
||||
"version": 2,
|
||||
"role_models": {"base": {"profile_id": "fixture", "model_id": "fixture"}},
|
||||
},
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
roles,
|
||||
"resolve_selection",
|
||||
lambda *_args, **_kwargs: LLMConfig(
|
||||
model="fixture", binding="openai", api_key="offline-fixture"
|
||||
),
|
||||
)
|
||||
(tmp_path / "empty-kb").mkdir()
|
||||
|
||||
adder = DocumentAdder(
|
||||
@@ -89,6 +108,8 @@ def test_document_adder_allows_empty_lightrag_kb_to_bootstrap(tmp_path: Path) ->
|
||||
|
||||
assert adder.rag_provider == "lightrag"
|
||||
assert adder.raw_dir.is_dir()
|
||||
assert adder.accepted_indexing_snapshot.extract.config.model == "fixture"
|
||||
assert adder.accepted_indexing_snapshot.vlm is None
|
||||
|
||||
|
||||
def test_process_new_documents_returns_failures_without_marking_processed(
|
||||
|
||||
@@ -177,11 +177,13 @@ def test_default_snapshot_prefers_released_lightrag_selection(monkeypatch) -> No
|
||||
|
||||
|
||||
def test_default_snapshot_rejects_unreadable_released_setting(monkeypatch) -> None:
|
||||
from deeptutor.services import config as settings_config
|
||||
from deeptutor.services.rag.pipelines.lightrag import config
|
||||
|
||||
def fail():
|
||||
raise OSError("settings unreadable")
|
||||
|
||||
monkeypatch.setattr(settings_config, "load_lightrag_settings", lambda: {"version": 1})
|
||||
monkeypatch.setattr(config, "lightrag_indexing_selection_from_settings", fail)
|
||||
|
||||
with pytest.raises(indexing_policy.IndexingPolicyError, match="could not be resolved"):
|
||||
|
||||
@@ -11,9 +11,11 @@ import pytest
|
||||
|
||||
EmbeddingFunc = pytest.importorskip("lightrag.utils").EmbeddingFunc
|
||||
|
||||
from deeptutor.services import config
|
||||
from deeptutor.services.llm.config import LLMConfig
|
||||
from deeptutor.services.parsing.types import ParsedDocument
|
||||
from deeptutor.services.rag.index_versioning import list_kb_versions
|
||||
from deeptutor.services.rag.pipelines.lightrag import engine, ingress, storage
|
||||
from deeptutor.services.rag.pipelines.lightrag import engine, ingress, roles, storage
|
||||
|
||||
|
||||
async def _fake_llm(_prompt, **_kwargs) -> str:
|
||||
@@ -28,6 +30,23 @@ async def _fake_embedding(texts: list[str]) -> np.ndarray:
|
||||
|
||||
|
||||
def _configure_real_sdk(monkeypatch, llm=_fake_llm) -> None:
|
||||
# Resolve real role settings against a synthetic model instead of depending
|
||||
# on an existing developer settings file or a configured provider.
|
||||
monkeypatch.setattr(
|
||||
config,
|
||||
"load_lightrag_settings",
|
||||
lambda: {
|
||||
"version": 2,
|
||||
"role_models": {"base": {"profile_id": "fixture", "model_id": "fixture"}},
|
||||
},
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
roles,
|
||||
"resolve_selection",
|
||||
lambda *_args, **_kwargs: LLMConfig(
|
||||
model="fixture", binding="openai", api_key="offline-fixture"
|
||||
),
|
||||
)
|
||||
monkeypatch.setattr(engine, "build_llm_model_func", lambda **_kwargs: llm)
|
||||
monkeypatch.setattr(
|
||||
engine,
|
||||
|
||||
Reference in New Issue
Block a user