Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.
Python ai4sciencedocument-analysisdocxextract-datalayout-analysisocrparserpdfpdf-converterpdf-extractor-llmpdf-extractor-pretrainpdf-extractor-ragpdf-parserpptxpythonxlsx
fix(ci): preserve parse error parameters and align protocol fixtures
myhloli9d959fd9d825
diff --git a/mineru/kit/commands/parse.py b/mineru/kit/commands/parse.pyindex d0e638e0..3d8c21e5 100644--- a/mineru/kit/commands/parse.py+++ b/mineru/kit/commands/parse.py@@ -11,6 +11,7 @@ from ...errors import MineruErrorfrom ...filetypes import ensure_tier_supported_for_parse_extension, is_flash_only_parse_extensionfrom ...parser import MinerUApiParserfrom ...parser import parse as local_parse+from ...parser.api_client import _V1APIErrorfrom ...parser.base import ParseResultfrom ...parser.page_range import normalize_page_range_inputfrom ...types import Tier, validate_tier@@ -115,7 +116,9 @@ def parse_cmd(except Exception as exc:disposition, code, message = classify_parse_error(exc)if not is_batch:- exit_with_message(code, t("Failed to parse {path}: {error}", path=path, error=message))+ # 单文件错误保留本地或远程协议中的参数定位,方便调用方修正请求。+ param = exc.param if isinstance(exc, (MineruError, _V1APIError)) else None+ exit_with_message(code, t("Failed to parse {path}: {error}", path=path, error=message), param)if disposition == "skipped":summary.skipped += 1print_info(t("Skipped {path}: [{code}] {error}", path=path, code=code, error=message))diff --git a/tests/unittest/test_flash_csv.py b/tests/unittest/test_flash_csv.pyindex 8e65b742..1dc79629 100644--- a/tests/unittest/test_flash_csv.py+++ b/tests/unittest/test_flash_csv.py@@ -11,6 +11,7 @@ import pytestfrom docvortex.document.detection import guess_suffix_by_bytes, guess_suffix_by_pathfrom mineru.backend.analyze import aio_doc_analyze, doc_analyze+from mineru.errors import InvalidRequestErrorfrom mineru.parser import api_server, parse, parse_asyncfrom mineru.parser.api_server import FileStorefrom mineru.render.html import render_html@@ -55,8 +56,10 @@ def test_csv_path_parsing_and_signatureless_detection(tmp_path: Path) -> None:async_result = asyncio.run(parse_async(csv_path))assert result.middle_json.metadata.file_suffix == async_result.middle_json.metadata.file_suffix == "csv"assert result.markdown() == async_result.markdown()- with pytest.raises(ValueError, match="Unsupported file type: txt"):+ with pytest.raises(InvalidRequestError, match="Unsupported file type: txt") as caught:parse(text_path)+ assert caught.value.code == "file_type_unsupported"+ assert caught.value.param == "input"def test_tsv_doc_analyze_records_independent_suffix_and_reuses_csv_engine() -> None:diff --git a/tests/unittest/test_flash_epub.py b/tests/unittest/test_flash_epub.pyindex f026e127..9228454d 100644--- a/tests/unittest/test_flash_epub.py+++ b/tests/unittest/test_flash_epub.py@@ -139,8 +139,10 @@ def test_epub_content_detection_precedes_extension_and_rejects_fake_packages(tmpfake = tmp_path / "fake.epub"fake.write_text("not an epub", encoding="utf-8")assert guess_suffix_by_path(fake) != "epub"- with pytest.raises(ValueError, match="Unsupported file type"):+ with pytest.raises(InvalidRequestError, match="Unsupported file type") as caught:parse(fake)+ assert caught.value.code == "file_type_unsupported"+ assert caught.value.param == "input"def test_doclib_extracts_epub_metadata(tmp_path: Path) -> None:diff --git a/tests/unittest/test_flash_odf.py b/tests/unittest/test_flash_odf.pyindex d015ccbd..439ae6c6 100644--- a/tests/unittest/test_flash_odf.py+++ b/tests/unittest/test_flash_odf.py@@ -63,8 +63,10 @@ def test_plain_text_renamed_to_odf_is_not_accepted(tmp_path: Path) -> None:source = tmp_path / "fake.odt"source.write_text("a,b\n1,2\n", encoding="utf-8")assert guess_suffix_by_path(source) not in {"odt", "ods", "odp"}- with pytest.raises(ValueError, match="Unsupported file type"):+ with pytest.raises(InvalidRequestError, match="Unsupported file type") as caught:parse(source)+ assert caught.value.code == "file_type_unsupported"+ assert caught.value.param == "input"@pytest.mark.parametrize(diff --git a/tests/unittest/test_transformers5_runtime.py b/tests/unittest/test_transformers5_runtime.pyindex 2e0bc763..797b7c31 100644--- a/tests/unittest/test_transformers5_runtime.py+++ b/tests/unittest/test_transformers5_runtime.py@@ -8,8 +8,10 @@ import sysfrom pathlib import Pathfrom types import ModuleType, SimpleNamespacefrom typing import Any+from unittest.mock import Mockimport pytest+from mineru_vl_utils.vlm_client.base_client import EngineHealthdef test_public_imports_keep_optional_model_dependencies_lazy() -> None:@@ -40,6 +42,12 @@ def test_runtime_constructs_caches_and_closes_pipeline(monkeypatch: pytest.Monkefrom mineru.model.vlm import runtimecalls: list[dict[str, Any]] = []+ # 保留已发布客户端的健康探测接口,验证探测排空先于 Pipeline 释放。+ backend_client = SimpleNamespace(+ health_probe_mode="sync",+ probe_health=Mock(return_value=EngineHealth("healthy")),+ close_health_probe=Mock(),+ )class Pipeline:"""记录工厂参数和关闭次数的引擎替身。"""@@ -51,6 +59,7 @@ def test_runtime_constructs_caches_and_closes_pipeline(monkeypatch: pytest.Monkedef close(self) -> None:"""模拟公开的资源释放接口。"""+ backend_client.close_health_probe.assert_called_once_with(timeout=None)self.closed += 1module = ModuleType("lmdeploy")@@ -61,7 +70,7 @@ def test_runtime_constructs_caches_and_closes_pipeline(monkeypatch: pytest.Monkeutilities.get_logger = logging.getLoggermonkeypatch.setitem(sys.modules, "lmdeploy", module)monkeypatch.setitem(sys.modules, "lmdeploy.utils", utilities)- monkeypatch.setattr(runtime, "MinerUClient", lambda **kwargs: SimpleNamespace(**kwargs))+ monkeypatch.setattr(runtime, "MinerUClient", lambda **kwargs: SimpleNamespace(client=backend_client, **kwargs))monkeypatch.setattr(runtime.ModelSingleton, "_models", {})singleton = runtime.ModelSingleton()kwargs = {"lmdeploy_backend": "pytorch", "lmdeploy_device": "cuda", "cache_max_entry_count": 0.2}@@ -71,6 +80,9 @@ def test_runtime_constructs_caches_and_closes_pipeline(monkeypatch: pytest.Monkeassert calls[0]["backend_config"].device_type == "cuda"assert calls[0]["backend_config"].cache_max_entry_count == 0.2assert calls[0]["log_level"] == "ERROR"+ assert client.supports_health_probe+ client.probe_health()+ backend_client.probe_health.assert_called_once()engine = client.predictor.lmdeploy_enginesingleton.shutdown()assert engine.closed == 1diff --git a/tests/unittest/test_vlm_config.py b/tests/unittest/test_vlm_config.pyindex 285185b1..be6c932b 100644--- a/tests/unittest/test_vlm_config.py+++ b/tests/unittest/test_vlm_config.py@@ -6,6 +6,7 @@ from typing import Anyimport pytestfrom click.testing import CliRunner+from fastapi import FastAPIfrom fastapi.testclient import TestClientfrom pydantic import ValidationErrorfrom typer.testing import CliRunner as TyperRunner@@ -136,13 +137,13 @@ def test_api_cli_merges_vlm_without_mutating_global(monkeypatch: pytest.MonkeyPamonkeypatch.setattr(api_server.get_config().model, "vlm", settings)seen: dict[str, Any] = {}- def capture_app(**kwargs: Any) -> object:+ def capture_app(**kwargs: Any) -> FastAPI:"""记录应用构造参数,用于核验 CLI 覆盖而不创建文件。"""seen.update(kwargs)- return object()+ return FastAPI()monkeypatch.setattr(api_server, "create_app", capture_app)- monkeypatch.setattr(api_server.uvicorn.Server, "run", lambda self: None)+ monkeypatch.setattr(api_server.ServerWithDocs, "run", lambda self: None)previous_env = dict(os.environ)result = CliRunner().invoke(api_server.main, ["--vlm-server-url", url, "--vlm-api-key", "", "--vlm-http-timeout", "9", "--api-key", "inbound-key"]