Update agent orchestration and knowledge flow
Add sub-commander orchestration updates, align frontend integrations, and refine knowledge view behavior without including local data artifacts. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import json
|
||||
from io import BytesIO
|
||||
import builtins
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import types
|
||||
|
||||
@@ -351,6 +352,73 @@ async def test_get_document_content_returns_normalized_pdf_content(document_test
|
||||
assert content == '# PDF Title\n\nNormalized pdf body.'
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_upload_document_uses_mineru_cli_do_parse_fallback_for_pdf(document_test_env, monkeypatch, tmp_path):
|
||||
session, user = document_test_env
|
||||
service = DocumentService(session)
|
||||
|
||||
fake_mineru = types.SimpleNamespace()
|
||||
fake_common = types.SimpleNamespace()
|
||||
|
||||
def fake_do_parse(output_dir, pdf_file_names, pdf_bytes_list, p_lang_list, **kwargs):
|
||||
output_path = Path(output_dir) / pdf_file_names[0] / 'pipeline'
|
||||
output_path.mkdir(parents=True, exist_ok=True)
|
||||
(output_path / f'{pdf_file_names[0]}.md').write_text('# PDF Title\n\nCLI fallback content.', encoding='utf-8')
|
||||
|
||||
fake_common.do_parse = fake_do_parse
|
||||
monkeypatch.setitem(sys.modules, 'mineru', fake_mineru)
|
||||
monkeypatch.setitem(sys.modules, 'mineru.cli', types.SimpleNamespace(common=fake_common))
|
||||
monkeypatch.setitem(sys.modules, 'mineru.cli.common', fake_common)
|
||||
monkeypatch.setattr('app.services.document_service.settings.UPLOAD_DIR', str(tmp_path / 'uploads'))
|
||||
|
||||
upload = UploadFile(filename='fallback.pdf', file=BytesIO(b'%PDF-1.4 fake'))
|
||||
document = await service.upload_document(user.id, upload)
|
||||
|
||||
assert document.normalized_format == 'structured_markdown'
|
||||
assert '# PDF Title' in document.normalized_content
|
||||
assert 'CLI fallback content.' in document.normalized_content
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_upload_document_raises_clear_error_when_mineru_cli_runtime_dependency_is_missing(document_test_env, monkeypatch):
|
||||
session, user = document_test_env
|
||||
service = DocumentService(session)
|
||||
|
||||
fake_mineru = types.SimpleNamespace()
|
||||
fake_common = types.SimpleNamespace()
|
||||
fake_enum_class = types.SimpleNamespace(MakeMode=types.SimpleNamespace(MM_MD='mm_markdown'))
|
||||
|
||||
def fake_do_parse(*args, **kwargs):
|
||||
raise ModuleNotFoundError("No module named 'torch'")
|
||||
|
||||
fake_common.do_parse = fake_do_parse
|
||||
fake_common.read_fn = lambda path: b'%PDF-1.4 fake'
|
||||
monkeypatch.setitem(sys.modules, 'mineru', fake_mineru)
|
||||
monkeypatch.setitem(sys.modules, 'mineru.cli', types.SimpleNamespace(common=fake_common))
|
||||
monkeypatch.setitem(sys.modules, 'mineru.cli.common', fake_common)
|
||||
monkeypatch.setitem(sys.modules, 'mineru.utils', types.SimpleNamespace(enum_class=fake_enum_class))
|
||||
monkeypatch.setitem(sys.modules, 'mineru.utils.enum_class', fake_enum_class)
|
||||
|
||||
upload = UploadFile(filename='runtime-missing.pdf', file=BytesIO(b'%PDF-1.4 fake'))
|
||||
|
||||
with pytest.raises(ValueError, match="PDF 解析依赖缺失: MinerU 运行时依赖 torch"):
|
||||
await service.upload_document(user.id, upload)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_upload_document_raises_clear_error_when_mineru_interface_is_unsupported(document_test_env, monkeypatch):
|
||||
session, user = document_test_env
|
||||
service = DocumentService(session)
|
||||
|
||||
fake_mineru = types.SimpleNamespace()
|
||||
monkeypatch.setitem(sys.modules, 'mineru', fake_mineru)
|
||||
|
||||
upload = UploadFile(filename='unsupported.pdf', file=BytesIO(b'%PDF-1.4 fake'))
|
||||
|
||||
with pytest.raises(ValueError, match='PDF 解析失败: 当前安装的 MinerU 版本接口不兼容'):
|
||||
await service.upload_document(user.id, upload)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_upload_document_raises_clear_error_when_pdf_dependency_is_missing(document_test_env, monkeypatch):
|
||||
session, user = document_test_env
|
||||
|
||||
Reference in New Issue
Block a user