Files
DeepTutor/tests/tools/test_rag_tool.py
Bingxi Zhao (Frank) 100576da69 release: v1.1.2 — schema-driven channels, secret masking, RAG simplification, KB-consistency hardening
* TutorBot Channels tab is now schema-driven across every built-in & plugin channel
  (GET /api/v1/tutorbot/channels/schema), with per-field secret reveal toggles.
* Channel secrets are masked end-to-end; raw values only surface via the explicit
  ?include_secrets=true edit-form route. PATCH validates ChannelsConfig at the API
  boundary and returns 422 on bad payloads. reload_channels is serialised by an
  asyncio.Lock and records last_reload_error for the UI.
* Collapsed services/rag/ to a single LlamaIndex pipeline: removed ~2.6k lines of
  unused components/* + pipeline.py + types.py + utils/ + parsers/. rag_provider
  is now a stub; legacy values silently coerce to llamaindex.
* Centralised file routing into services/rag/file_routing.py (FileTypeRouter /
  DocumentType / FileClassification); dropped per-provider extension helpers.
* Defensive RAG/KB consistency: deep_solve / deep_research strip rag/kb when no
  KB is attached; SolveToolRuntime + ResearchPipeline + DecomposeAgent
  short-circuit instead of falling back to non-existent default KBs (DE-all,
  ai_textbook).
* Externalised AgenticChatPipeline prompts into agentic_chat.yaml (zh + en).
* Added Thai README (#337).
* New test modules: file_routing, knowledge_base_config, channel_schema,
  channel_secrets, rag_consistency, research_pipeline_rag.

Full notes: assets/releases/ver1-1-2.md

Made-with: Cursor
2026-04-18 11:33:53 +08:00

79 lines
2.7 KiB
Python

"""Factory + tool-wrapper layer tests (llamaindex-only)."""
from __future__ import annotations
import pytest
from deeptutor.services.rag.factory import (
DEFAULT_PROVIDER,
get_pipeline,
list_pipelines,
normalize_provider_name,
)
from deeptutor.tools.rag_tool import (
RAGService,
get_available_providers,
get_current_provider,
)
class TestNormalizeProviderName:
"""`normalize_provider_name` is now a stub: every input collapses to llamaindex."""
@pytest.mark.parametrize(
"value",
[None, "", " ", "llamaindex", "LlamaIndex", "lightrag", "raganything",
"raganything_docling", "totally_unknown_xyz"],
)
def test_collapses_to_default(self, value) -> None:
assert normalize_provider_name(value) == DEFAULT_PROVIDER
class TestPipelineFactory:
def test_list_pipelines_only_default(self) -> None:
pipelines = list_pipelines()
assert isinstance(pipelines, list)
assert {p["id"] for p in pipelines} == {DEFAULT_PROVIDER}
def test_get_pipeline_returns_singleton(self) -> None:
try:
first = get_pipeline()
second = get_pipeline()
except (ValueError, ImportError) as exc:
pytest.skip(f"LlamaIndex optional dependency missing: {exc}")
assert first is second
def test_get_pipeline_ignores_provider_name(self) -> None:
"""The legacy ``name`` argument is silently ignored."""
try:
a = get_pipeline("llamaindex")
b = get_pipeline("lightrag")
c = get_pipeline("nonexistent_xyz")
except (ValueError, ImportError) as exc:
pytest.skip(f"LlamaIndex optional dependency missing: {exc}")
assert a is b is c
class TestRAGServiceClassHelpers:
def test_list_providers_only_default(self) -> None:
providers = RAGService.list_providers()
assert {p["id"] for p in providers} == {DEFAULT_PROVIDER}
def test_has_provider_default_true(self) -> None:
assert RAGService.has_provider(DEFAULT_PROVIDER) is True
def test_has_provider_unknown_false(self) -> None:
assert RAGService.has_provider("nonexistent") is False
assert RAGService.has_provider("") is False
def test_get_current_provider_ignores_env(self, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("RAG_PROVIDER", "lightrag")
assert get_current_provider() == DEFAULT_PROVIDER
monkeypatch.delenv("RAG_PROVIDER", raising=False)
assert get_current_provider() == DEFAULT_PROVIDER
class TestToolLayerExports:
def test_get_available_providers_matches_class_method(self) -> None:
assert get_available_providers() == RAGService.list_providers()