Files
DeepTutor/tests/knowledge/test_document_adder_provider.py
Bingxi Zhao (Frank) 7ac3a3ba79 release: v1.4.6
A broad consolidation release across four product surfaces.

- Learning Space: Space becomes a learning dashboard; My Agents imports
  local Claude Code / Codex chat history into resumable agents (with an
  objective explore_context briefing so the tutor never role-plays the
  user); Memory is promoted to a top-level /memory route; Partner
  conversations flow into Memory; EduHub skills install inline.
- Knowledge Center: /knowledge rebuilt as a console with per-engine
  detail pages; GraphRAG / PageIndex / LightRAG engines join LlamaIndex;
  linked-KB read-only mounts; Obsidian live-vault capability.
- Settings: pluggable document parsing (MinerU / Docling / MarkItDown)
  with a content-addressed cache and MinerU cloud/local backends; voice
  TTS/STT; image & video generation; rebuilt settings navigation.
- Platform: per-user capability gating by assigned model; Solve rebuilt
  on the chat loop with a per-step gate and mid-run failure fallback;
  username login + inline errors; CLI skill publish/update; picker
  polish; math-before-citation render fix.

Docs were split out to a standalone site, so site/ is now landing-page
only. Bumps __version__ to 1.4.6 and adds assets/releases/ver1-4-6.md.

Folds in mypy fixes surfaced by pre-commit (mineru/local Path typing,
knowledge/manager no-redef, explore_context token kwargs, CLI
set_dist_tag capability probe) plus prettier reformatting of
previously-committed web files.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-17 10:50:44 +08:00

98 lines
2.9 KiB
Python

from __future__ import annotations
import asyncio
import json
from pathlib import Path
from deeptutor.knowledge.add_documents import DocumentAdder
def _write_provider_version(kb_dir: Path, provider: str) -> None:
version_dir = kb_dir / "version-1"
version_dir.mkdir(parents=True)
if provider == "pageindex":
(version_dir / "pageindex_docs.json").write_text(
json.dumps({"provider": "pageindex", "docs": {"doc.pdf": {"doc_id": "doc-1"}}}),
encoding="utf-8",
)
elif provider == "graphrag":
output_dir = version_dir / "output"
output_dir.mkdir()
(output_dir / "entities.parquet").write_bytes(b"placeholder")
else:
(version_dir / "docstore.json").write_text("{}", encoding="utf-8")
(version_dir / "index_store.json").write_text("{}", encoding="utf-8")
(version_dir / "meta.json").write_text(
json.dumps(
{
"provider": provider,
"signature": provider,
"version": "version-1",
}
),
encoding="utf-8",
)
def test_document_adder_reads_provider_from_kb_config_when_metadata_missing(
tmp_path: Path,
) -> None:
kb_dir = tmp_path / "page-kb"
(kb_dir / "raw").mkdir(parents=True)
_write_provider_version(kb_dir, "pageindex")
(tmp_path / "kb_config.json").write_text(
json.dumps(
{"knowledge_bases": {"page-kb": {"path": "page-kb", "rag_provider": "pageindex"}}}
),
encoding="utf-8",
)
adder = DocumentAdder(kb_name="page-kb", base_dir=str(tmp_path))
assert adder.rag_provider == "pageindex"
def test_document_adder_preserves_explicit_bound_provider(tmp_path: Path) -> None:
kb_dir = tmp_path / "graph-kb"
(kb_dir / "raw").mkdir(parents=True)
_write_provider_version(kb_dir, "graphrag")
adder = DocumentAdder(
kb_name="graph-kb",
base_dir=str(tmp_path),
rag_provider="graphrag",
)
assert adder.rag_provider == "graphrag"
def test_process_new_documents_returns_failures_without_marking_processed(
monkeypatch, tmp_path: Path
) -> None:
kb_dir = tmp_path / "kb"
raw_dir = kb_dir / "raw"
raw_dir.mkdir(parents=True)
_write_provider_version(kb_dir, "llamaindex")
doc = raw_dir / "bad.txt"
doc.write_text("hello", encoding="utf-8")
class _FailingRagService:
def __init__(self, *_args, **_kwargs) -> None:
pass
async def add_documents(self, *_args, **_kwargs) -> bool:
raise RuntimeError("provider exploded")
monkeypatch.setattr(
"deeptutor.knowledge.add_documents.RAGService",
_FailingRagService,
)
adder = DocumentAdder(kb_name="kb", base_dir=str(tmp_path))
result = asyncio.run(adder.process_new_documents([doc]))
assert result.processed_files == []
assert result.failed_count == 1
assert "provider exploded" in result.failure_summary()
assert adder.get_ingested_hashes() == {}