Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

fix(ci): preserve parse error parameters and align protocol fixtures

myhloli9d959fd9d825
diff --git a/mineru/kit/commands/parse.py b/mineru/kit/commands/parse.py
index d0e638e0..3d8c21e5 100644
--- a/mineru/kit/commands/parse.py
+++ b/mineru/kit/commands/parse.py
@@ -11,6 +11,7 @@ from ...errors import MineruError
from ...filetypes import ensure_tier_supported_for_parse_extension, is_flash_only_parse_extension
from ...parser import MinerUApiParser
from ...parser import parse as local_parse
+from ...parser.api_client import _V1APIError
from ...parser.base import ParseResult
from ...parser.page_range import normalize_page_range_input
from ...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 += 1
print_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.py
index 8e65b742..1dc79629 100644
--- a/tests/unittest/test_flash_csv.py
+++ b/tests/unittest/test_flash_csv.py
@@ -11,6 +11,7 @@ import pytest
from docvortex.document.detection import guess_suffix_by_bytes, guess_suffix_by_path
from mineru.backend.analyze import aio_doc_analyze, doc_analyze
+from mineru.errors import InvalidRequestError
from mineru.parser import api_server, parse, parse_async
from mineru.parser.api_server import FileStore
from 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.py
index 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(tmp
fake = 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.py
index 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.py
index 2e0bc763..797b7c31 100644
--- a/tests/unittest/test_transformers5_runtime.py
+++ b/tests/unittest/test_transformers5_runtime.py
@@ -8,8 +8,10 @@ import sys
from pathlib import Path
from types import ModuleType, SimpleNamespace
from typing import Any
+from unittest.mock import Mock
import pytest
+from mineru_vl_utils.vlm_client.base_client import EngineHealth
def test_public_imports_keep_optional_model_dependencies_lazy() -> None:
@@ -40,6 +42,12 @@ def test_runtime_constructs_caches_and_closes_pipeline(monkeypatch: pytest.Monke
from mineru.model.vlm import runtime
calls: 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.Monke
def close(self) -> None:
"""模拟公开的资源释放接口。"""
+ backend_client.close_health_probe.assert_called_once_with(timeout=None)
self.closed += 1
module = ModuleType("lmdeploy")
@@ -61,7 +70,7 @@ def test_runtime_constructs_caches_and_closes_pipeline(monkeypatch: pytest.Monke
utilities.get_logger = logging.getLogger
monkeypatch.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.Monke
assert calls[0]["backend_config"].device_type == "cuda"
assert calls[0]["backend_config"].cache_max_entry_count == 0.2
assert calls[0]["log_level"] == "ERROR"
+ assert client.supports_health_probe
+ client.probe_health()
+ backend_client.probe_health.assert_called_once()
engine = client.predictor.lmdeploy_engine
singleton.shutdown()
assert engine.closed == 1
diff --git a/tests/unittest/test_vlm_config.py b/tests/unittest/test_vlm_config.py
index 285185b1..be6c932b 100644
--- a/tests/unittest/test_vlm_config.py
+++ b/tests/unittest/test_vlm_config.py
@@ -6,6 +6,7 @@ from typing import Any
import pytest
from click.testing import CliRunner
+from fastapi import FastAPI
from fastapi.testclient import TestClient
from pydantic import ValidationError
from typer.testing import CliRunner as TyperRunner
@@ -136,13 +137,13 @@ def test_api_cli_merges_vlm_without_mutating_global(monkeypatch: pytest.MonkeyPa
monkeypatch.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"]