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
Update v1 parse image output handling
jinzhenj98ced4b87a11
diff --git a/docs/next/api/examples.md b/docs/next/api/examples.mdindex afe7c18d..b3ffcdfc 100644--- a/docs/next/api/examples.md+++ b/docs/next/api/examples.md@@ -43,7 +43,7 @@ RESP=$(curl -s -X POST https://mineru.net/api/v1/parse/jobs \\"source\": {\"type\":\"file_id\",\"file_id\":\"$FILE_ID\"}}],\"tier\": \"high\",- \"output_formats\": [\"markdown\",\"middle_json\",\"images\"]+ \"output_formats\": [\"markdown\",\"middle_json\",\"zip\"]}")```diff --git a/docs/next/api/parse-jobs.md b/docs/next/api/parse-jobs.mdindex 0d826a74..bd3d092a 100644--- a/docs/next/api/parse-jobs.md+++ b/docs/next/api/parse-jobs.md@@ -38,7 +38,7 @@ Job 状态:}],"tier": null,- "output_formats": ["markdown", "middle_json", "structured_content", "images"],+ "output_formats": ["markdown", "middle_json", "structured_content", "zip"],"wait": 30,"callback": {"url": "https://your.app/mineru-webhook",@@ -128,14 +128,15 @@ OCR 策略和图片分析能力由 `tier` 与服务端实际引擎自动决定| `middle_json` | 文本 | 完整 Middle JSON,中间结构和高级调试。 | 否 || `content_list` | 文本 | 扁平内容列表。 | 否 || `structured_content` | 文本 | 面向 Agent 和新客户端的结构化内容 JSON。 | 否 |-| `images` | 二进制集合 | 切片图片。 | 否 || `html` | 文本 | HTML 导出。 | 是 || `latex` | 文本 | LaTeX 导出。 | 是 || `docx` | 二进制 | Word 文档导出。 | 是 |-| `zip` | 二进制 | 打包请求中的其他产物。 | 否 |+| `zip` | 二进制 | 自包含解析包;图片 sidecar 只通过 zip 返回。 | 否 |所有产物都以 `purpose:"parse_output"` 的 File 对象存储。Job 响应只返回产物 File 引用;所有产物内容都通过 `GET /v1/files/{file_id}/content` 获取。+`images` 不是可请求的 `output_formats` 值。需要图片 sidecar 的客户端应请求 `zip`,并从 zip 包内读取 `middle_json` 引用的图片路径。+`json`、`content_list_v2` 不是 NEXT 版正式格式名,不进入公开格式集合。命名决策见 [ADR-0001](../decisions/0001-json-output-formats.md)。### `wait`@@ -161,7 +162,7 @@ OCR 策略和图片分析能力由 `tier` 与服务端实际引擎自动决定"status": "queued","created_at": "2026-05-21T08:30:00Z","tier": "high",- "output_formats": ["markdown", "middle_json", "structured_content", "images"],+ "output_formats": ["markdown", "middle_json", "structured_content", "zip"],"access_level": "registered","files": [{@@ -206,7 +207,7 @@ OCR 策略和图片分析能力由 `tier` 与服务端实际引擎自动决定"started_at": "2026-05-21T08:30:02Z","finished_at": "2026-05-21T08:30:48Z","tier": "high",- "output_formats": ["markdown", "middle_json", "images"],+ "output_formats": ["markdown", "middle_json", "zip"],"access_level": "registered","progress": {"completed": 1,@@ -233,13 +234,10 @@ OCR 策略和图片分析能力由 `tier` 与服务端实际引擎自动决定"file_id": "file-01HXYZJSON000002","bytes": 184320},- "images": [- {- "path": "images/0.jpg",- "file_id": "file-01HXYZIM000004",- "bytes": 102400- }- ]+ "zip": {+ "file_id": "file-01HXYZZIP000004",+ "bytes": 286720+ }}}]diff --git a/docs/next/api/uploads-files.md b/docs/next/api/uploads-files.mdindex 98dd22cb..9235f55d 100644--- a/docs/next/api/uploads-files.md+++ b/docs/next/api/uploads-files.md@@ -58,7 +58,7 @@ Upload 状态机:| `purpose` | string | 是 | `"parse"`、`"input_image"` 或 `"parse_output"`。 || `sha256sum` | string 或 null | 是 | 64 位小写 hex;未知时为 `null`。 |-`purpose:"parse"` 表示待解析源文件。`purpose:"input_image"` 表示 Chat/Responses 输入图片。`purpose:"parse_output"` 表示解析产物,如 markdown、middle_json、content_list、structured_content、images、docx、zip。+`purpose:"parse"` 表示待解析源文件。`purpose:"input_image"` 表示 Chat/Responses 输入图片。`purpose:"parse_output"` 表示解析产物,如 markdown、middle_json、content_list、structured_content、docx、zip。解析图片 sidecar 不作为独立 parse output;需要图片时从 zip 中读取。## POST `/v1/uploads`diff --git a/docs/next/sdk/api-parser.md b/docs/next/sdk/api-parser.mdindex 9b11dead..006c8806 100644--- a/docs/next/sdk/api-parser.md+++ b/docs/next/sdk/api-parser.md@@ -48,8 +48,8 @@ class MinerUApiParser(DocumentParser):api_url: str | None = None,api_key: str | None = None,tier: str | None = None,+ include_images: bool = False,include_model_output: bool = False,- zip_output_only: bool = False,) -> None: ...```@@ -60,8 +60,8 @@ class MinerUApiParser(DocumentParser):| `api_url` | v1 API base URL,如 `https://mineru.net/api` 或 `http://127.0.0.1:16580/api`。省略时读取 `MINERU_API_URL`,再退回默认官方 API。 || `api_key` | Bearer token。省略时读取 `MINERU_API_KEY`;Local Parse Server 未启用鉴权时可为空。 || `tier` | `flash`、`medium`、`high`、`extra_high` 或 `None`。`None` 表示 SDK 在 HTTP 请求中省略 `tier`,让 v1 API 使用默认选择策略。 |-| `include_model_output` | 是否额外请求模型输出 zip。 |-| `zip_output_only` | 是否只请求 zip 产物。 |+| `include_images` | 是否从 zip 产物读取图片 sidecar,并挂载到 `ParseResult` 图片缓存。 |+| `include_model_output` | 是否请求并保留模型原始输出;开启时通过 zip 产物读取。 |## 行为流程@@ -71,10 +71,11 @@ class MinerUApiParser(DocumentParser):2. 判断 `api_url` 是否是本地地址。3. 本地地址优先使用 `local` source。4. 非本地地址使用 Uploads API: create upload -> PUT upload_url -> complete upload。-5. 调用 `POST /v1/parse/jobs`,默认请求 `output_formats:["middle_json","images"]`。+5. 调用 `POST /v1/parse/jobs`;默认请求 `output_formats:["middle_json"]`,需要模型输出或图片缓存时请求 `["zip"]`。6. 如果 job 未完成,则轮询 `GET /v1/parse/jobs/{job_id}`。-7. 下载 `middle_json` output file。-8. 将返回的 middle JSON 转为 `ParseResult`。+7. 普通模式下载 `middle_json` output file;zip 模式下载 `zip` output file。+8. zip 模式从 zip 中读取 middle JSON,并在 `include_images=True` 时读取 middle JSON 引用的图片 sidecar。+9. 将 middle JSON 转为 `ParseResult`。本地 source:@@ -114,14 +115,14 @@ class MinerUApiParser(DocumentParser):## 输出格式-默认请求 `middle_json` 和 `images`,因为 `ParseResult` 需要 pages 构造结构化结果,并需要 sidecar 图片供 `images()` / `save()` 使用。+默认只请求 `middle_json`。如果 `include_images=True` 或 `include_model_output=True`,则请求 `zip`,并从 zip 中恢复 `ParseResult` 所需的 middle JSON。API 不支持把 `images` 作为独立 `output_formats` 请求值。目标可选参数:| 参数 | 说明 ||------|------|+| `include_images` | 请求 `zip` 并从其中读取图片 sidecar 到 `ParseResult` 图片缓存。 || `include_model_output` | 请求 `zip` 并尝试保留模型输出。 |-| `zip_output_only` | 只请求 `zip`。 |## 错误映射diff --git a/mineru/cli_old/gradio_app.py b/mineru/cli_old/gradio_app.pyindex 04b77687..15b559c0 100644--- a/mineru/cli_old/gradio_app.py+++ b/mineru/cli_old/gradio_app.py@@ -1302,8 +1302,8 @@ async def _run_to_markdown_job(parser = MinerUApiParser(api_url=server_health.base_url,tier=runtime.tier,+ include_images=True,include_model_output=True,- zip_output_only=True,)parse_result = await parser.parse_async(file_path,diff --git a/mineru/doclib/services/parse_svc.py b/mineru/doclib/services/parse_svc.pyindex 1a30f6c3..3940bb1e 100644--- a/mineru/doclib/services/parse_svc.py+++ b/mineru/doclib/services/parse_svc.py@@ -20,6 +20,7 @@ from ...types import TIER_ORDER, PageInfo, Tierfrom ..constants import (IMAGE_EXTENSIONS,LEGACY_OFFICE_EXTENSION_UPGRADES,+ OFFICE_EXTENSIONS,PARSEABLE_EXTENSIONS,TEXT_EXTENSIONS,is_office_temp_lock_file,@@ -1063,6 +1064,7 @@ class ParseService:api_url=base_url,api_key=api_key,tier=resolved_tier,+ include_images=Path(file_row["path"]).suffix.lower().lstrip(".") in OFFICE_EXTENSIONS,)result = await parser.parse_async(file_row["path"], page_range=page_range)_remap_api_result_pages_to_page_range(result, page_range)diff --git a/mineru/kit/commands/parse.py b/mineru/kit/commands/parse.pyindex 9740009a..d69bc651 100644--- a/mineru/kit/commands/parse.py+++ b/mineru/kit/commands/parse.py@@ -64,7 +64,7 @@ def parse_cmd(exit_with_message("invalid_request", str(exc))if api_url:- parser = MinerUApiParser(api_url=api_url, api_key=api_key, tier=tier)+ parser = MinerUApiParser(api_url=api_url, api_key=api_key, tier=tier, include_images=True)parse_one = partial(parser.parse, page_range=pages or "")else:try:diff --git a/mineru/parser/api_client.py b/mineru/parser/api_client.pyindex 742b2099..b3c146f2 100644--- a/mineru/parser/api_client.py+++ b/mineru/parser/api_client.py@@ -62,16 +62,16 @@ class MinerUApiParser(DocumentParser):api_url: str | None = None,api_key: str | None = None,tier: Tier | None = None,+ include_images: bool = False,include_model_output: bool = False,- zip_output_only: bool = False,) -> None:self._base_url = (api_url or os.environ.get("MINERU_API_URL") or self.DEFAULT_API_URL).rstrip("/")self._api_key = (api_key if api_key is not None else os.environ.get("MINERU_API_KEY")) or Noneself._local = _is_local_network_url(self._base_url)self._trust_env = should_trust_env_for_url(self._base_url)self.tier = validate_tier(tier) if tier is not None else None+ self.include_images = include_imagesself.include_model_output = include_model_output- self.zip_output_only = zip_output_only# ── DocumentParser interface ─────────────────────────────────────@@ -117,15 +117,9 @@ class MinerUApiParser(DocumentParser):return payloaddef _output_formats(self) -> list[str]:- if "staging" in self._base_url:- # Staging still exposes the non-official "json" output instead of middle_json/images.- return ["json"]- if self.zip_output_only:+ if self.include_model_output or self.include_images:return ["zip"]- formats = ["middle_json", "images"]- if self.include_model_output:- formats.append("zip")- return formats+ return ["middle_json"]# ── HTTP helpers ─────────────────────────────────────────────────@@ -321,17 +315,11 @@ def _parse_result_from_job(job: dict[str, Any], file_name: str, parser: MinerUApif files and files[0].get("output_files"):outputs = files[0]["output_files"]- if parser.zip_output_only and "staging" not in parser._base_url:+ if _uses_zip_output(parser):return _parse_result_from_zip_output(parser, outputs, file_name)mid_json = _download_json(parser, outputs)result = _parse_result_from_middle_json(mid_json)- images = _download_image_sidecars(parser, outputs)- if images or "images" in outputs:- result.attach_export_images(images)- model_output = _download_model_output_from_zip(parser, outputs, file_name)- if model_output is not None:- result._model_output = model_outputreturn result@@ -342,55 +330,21 @@ async def _async_parse_result_from_job(job: dict[str, Any], file_name: str, parsif files and files[0].get("output_files"):outputs = files[0]["output_files"]- if parser.zip_output_only and "staging" not in parser._base_url:+ if _uses_zip_output(parser):return _parse_result_from_zip_bytes(await _async_download_zip_output(parser, outputs),file_name,+ include_images=parser.include_images,include_model_output=parser.include_model_output,)mid_json = await _async_download_json(parser, outputs)result = _parse_result_from_middle_json(mid_json)- images = await _async_download_image_sidecars(parser, outputs)- if images or "images" in outputs:- result.attach_export_images(images)- model_output = await _async_download_model_output_from_zip(parser, outputs, file_name)- if model_output is not None:- result._model_output = model_outputreturn result-def _download_model_output_from_zip(parser: MinerUApiParser, outputs: dict[str, Any], file_name: str) -> Any | None:- """按需从 v1 zip 输出中提取原始模型输出;缺少目标文件时保持兼容返回 None。"""- if not parser.include_model_output:- return None- zip_ref = outputs.get("zip")- if not isinstance(zip_ref, dict):- return None- return _extract_model_output_from_zip(_download_bytes(parser, zip_ref), file_name)---async def _async_download_model_output_from_zip(- parser: MinerUApiParser,- outputs: dict[str, Any],- file_name: str,-) -> Any | None:- """异步按需下载 v1 zip 并提取原始模型输出;缺少目标文件时保持兼容返回 None。"""- if not parser.include_model_output:- return None- zip_ref = outputs.get("zip")- if not isinstance(zip_ref, dict):- return None- return _extract_model_output_from_zip(await _async_download_bytes(parser, zip_ref), file_name)---def _extract_model_output_from_zip(zip_bytes: bytes, file_name: str) -> Any | None:- """从 API server zip 中读取 `{stem}_model_output.json`,没有该文件则不影响普通解析。"""- try:- with zipfile.ZipFile(io.BytesIO(zip_bytes)) as archive:- return _extract_model_output_from_archive(archive, file_name)- except zipfile.BadZipFile as exc:- raise _V1APIError("invalid_model_output", "model output zip is not a valid ZIP archive") from exc+def _uses_zip_output(parser: MinerUApiParser) -> bool:+ return parser.include_model_output or parser.include_imagesdef _extract_model_output_from_archive(archive: zipfile.ZipFile, file_name: str) -> Any | None:@@ -428,19 +382,27 @@ def _parse_result_from_zip_output(parser: MinerUApiParser, outputs: dict[str, Anreturn _parse_result_from_zip_bytes(_download_zip_output(parser, outputs),file_name,+ include_images=parser.include_images,include_model_output=parser.include_model_output,)-def _parse_result_from_zip_bytes(zip_bytes: bytes, file_name: str, *, include_model_output: bool) -> ParseResult:+def _parse_result_from_zip_bytes(+ zip_bytes: bytes,+ file_name: str,+ *,+ include_images: bool,+ include_model_output: bool,+) -> ParseResult:"""解析自包含 zip 包:读取 middle_json、图片 sidecar 和可选 model_output。"""try:with zipfile.ZipFile(io.BytesIO(zip_bytes)) as archive:mid_json = _read_middle_json_from_zip(archive, file_name)result = _parse_result_from_middle_json(mid_json)- images = _read_image_sidecars_from_zip(archive, mid_json)- if images:- result.attach_export_images(images)+ if include_images:+ images = _read_image_sidecars_from_zip(archive, mid_json)+ if images:+ result.attach_export_images(images)if include_model_output:model_output = _extract_model_output_from_archive(archive, file_name)if model_output is not None:@@ -508,40 +470,6 @@ def _read_image_sidecars_from_zip(archive: zipfile.ZipFile, mid_json: dict[str,return images-def _download_image_sidecars(parser: MinerUApiParser, outputs: dict[str, Any]) -> dict[str, bytes]:- """下载 API 返回的图片 sidecar,并按 middle_json 中的 image_path 建立字节映射。"""- images: dict[str, bytes] = {}- image_refs = outputs.get("images")- if not isinstance(image_refs, list):- return images- for ref in image_refs:- if not isinstance(ref, dict):- continue- img_path = ref.get("path")- if not isinstance(img_path, str) or not img_path:- continue- safe_img_path = validate_image_sidecar_path(img_path)- images[safe_img_path] = _download_bytes(parser, ref)- return images---async def _async_download_image_sidecars(parser: MinerUApiParser, outputs: dict[str, Any]) -> dict[str, bytes]:- """异步下载 API 返回的图片 sidecar,并按 image_path 建立字节映射。"""- images: dict[str, bytes] = {}- image_refs = outputs.get("images")- if not isinstance(image_refs, list):- return images- for ref in image_refs:- if not isinstance(ref, dict):- continue- img_path = ref.get("path")- if not isinstance(img_path, str) or not img_path:- continue- safe_img_path = validate_image_sidecar_path(img_path)- images[safe_img_path] = await _async_download_bytes(parser, ref)- return images--def _download_json(parser: MinerUApiParser, outputs: dict[str, Any]) -> dict[str, Any]:# Staging returns output_files.json; official v1 API returns output_files.middle_json.ref = outputs.get("middle_json") or outputs.get("json")diff --git a/mineru/parser/api_server.py b/mineru/parser/api_server.pyindex 860ec755..99a78ba1 100644--- a/mineru/parser/api_server.py+++ b/mineru/parser/api_server.py@@ -102,7 +102,6 @@ OutputFormat = Literal["middle_json","content_list","structured_content",- "images","html","latex","docx",@@ -491,13 +490,6 @@ class OutputFileRef(BaseModel):bytes: int-class ImageOutputRef(BaseModel):- model_config = _PYDANTIC_CONFIG- path: str- file_id: str- bytes: int--class OutputFiles(BaseModel):"""Per-file output artifacts. Content is downloaded via the Files API."""@@ -510,7 +502,6 @@ class OutputFiles(BaseModel):latex: OutputFileRef | None = Nonedocx: OutputFileRef | None = Nonezip: OutputFileRef | None = None- images: list[ImageOutputRef] | None = Noneclass JobFileResult(BaseModel):@@ -954,17 +945,6 @@ class FileStore:app_state.file_store = self-def _store_image_outputs(file_store: FileStore, images: dict[str, bytes]) -> list[ImageOutputRef]:- """将最终导出的图片字节写入 FileStore,并返回可下载的图片引用。"""- img_refs: list[ImageOutputRef] = []- for img_path, img_bytes in images.items():- sha = hashlib.sha256(img_bytes).hexdigest()- file_store.store_blob(img_bytes, sha256hex=sha)- img_fid = file_store.create_file_for_output(pathlib.Path(img_path).name, img_bytes, sha256hex=sha)- img_refs.append(ImageOutputRef(path=img_path, file_id=img_fid, bytes=len(img_bytes)))- return img_refs--def _build_self_contained_zip_output(result: Any, output_stem: str) -> bytes:"""构建自包含解析 zip,确保只请求 zip 时也能恢复 middle_json、图片和 model_output。"""buf = io.BytesIO()@@ -1039,26 +1019,9 @@ _OUTPUT_FORMATS_LOCAL = {"middle_json","content_list","structured_content",- "images","zip",}-_IMAGE_SIDECAR_FORMATS = frozenset(- {- "markdown",- "middle_json",- "content_list",- "structured_content",- "images",- }-)---def _needs_image_outputs(out_formats: set[OutputFormat] | set[str]) -> bool:- """判断请求的输出格式是否会暴露 image_path,从而需要返回图片 sidecar。"""- return bool(out_formats.intersection(_IMAGE_SIDECAR_FORMATS))--@dataclassclass _JobRecord:id: str@@ -1360,18 +1323,12 @@ async def _run_job(# collect outputsout_formats = set(rec.output_formats)output_files = OutputFiles()- image_output_refs = (- _store_image_outputs(file_store, result.images()) if _needs_image_outputs(out_formats) else None- )- if image_output_refs is not None:- output_files.images = image_output_refsfor fmt in ("markdown","middle_json","content_list","structured_content",- "images",):if fmt not in out_formats:continue@@ -1400,8 +1357,6 @@ async def _run_job(file_store.store_blob(cl2, sha256hex=sha)fid = file_store.create_file_for_output(f"{fr.name}.structured_content.json", cl2, sha256hex=sha)output_files.structured_content = OutputFileRef(file_id=fid, bytes=len(cl2))- elif fmt == "images":- continue# zipif "zip" in out_formats:diff --git a/tests/unittest/test_doclib_cache_semantics.py b/tests/unittest/test_doclib_cache_semantics.pyindex 12871251..71f6cdb3 100644--- a/tests/unittest/test_doclib_cache_semantics.py+++ b/tests/unittest/test_doclib_cache_semantics.py@@ -3520,6 +3520,68 @@ def test_process_doc_preserves_remote_api_error_code(tmp_path: Path) -> None:assert parses[0]["error_msg"] == "Remote authentication failed: user authenticate failed"+ ("path", "expected_include_images"),+ [+ ("/tmp/doc.docx", True),+ ("/tmp/doc.pdf", False),+ ],+)+def test_parse_via_api_requests_image_cache_only_for_office(+ monkeypatch: pytest.MonkeyPatch,+ tmp_path: Path,+ path: str,+ expected_include_images: bool,+) -> None:+ calls: list[bool] = []+ service = ParseService(+ db=_FakeDB(parses=[], file_row=None),+ fts=_FakeFTS(),+ config_svc=None,+ data_dir=str(tmp_path),+ parse_lock_timeout_sec=1800,+ )++ async def _resolve_api_target(_privacy: str, _tier: Tier) -> tuple[str, str | None, str]:+ return "http://localhost:8000/api", "test-key", "local"++ class _FakeApiParser:+ def __init__(+ self,+ *,+ api_url: str,+ api_key: str | None,+ tier: Tier,+ include_images: bool = False,+ ) -> None:+ assert api_url == "http://localhost:8000/api"+ assert api_key == "test-key"+ assert tier == "high"+ calls.append(include_images)++ async def parse_async(self, _path: str, *, page_range: str = "") -> ParseResult:+ assert _path == path+ assert page_range == "1"+ return ParseResult(pages=[])++ service._resolve_api_target = _resolve_api_target # type: ignore[method-assign]+ service._resolve_tier = lambda tier, _via: tier # type: ignore[method-assign]+ monkeypatch.setattr("mineru.parser.api_client.MinerUApiParser", _FakeApiParser)++ result, via = asyncio.run(+ service._parse_via_api(+ {"path": path},+ "high",+ "1",+ "local",+ )+ )++ assert result.pages == []+ assert via == "local"+ assert calls == [expected_include_images]++def test_process_doc_fails_when_batch_json_cannot_be_written(tmp_path: Path) -> None:sha256 = "b" * 64task = {diff --git a/tests/unittest/test_kit_commands.py b/tests/unittest/test_kit_commands.pyindex 0bb074c3..c7a5be48 100644--- a/tests/unittest/test_kit_commands.py+++ b/tests/unittest/test_kit_commands.py@@ -782,6 +782,70 @@ def test_parse_forwards_backend_alias_and_effort(monkeypatch: Any, tmp_path: Patassert seen["effort"] == "high"+def test_parse_remote_requests_image_cache(monkeypatch: Any, tmp_path: Path) -> None:+ source = tmp_path / "demo.pdf"+ output = tmp_path / "out.md"+ source.write_bytes(b"%PDF-1.7\n")+ seen: dict[str, Any] = {}++ class _Result:+ def markdown(self) -> str:+ return "# demo\n"++ def images(self) -> dict[str, bytes]:+ return {}++ class _FakeApiParser:+ def __init__(+ self,+ *,+ api_url: str,+ api_key: str | None,+ tier: str | None,+ include_images: bool,+ ) -> None:+ seen["api_url"] = api_url+ seen["api_key"] = api_key+ seen["tier"] = tier+ seen["include_images"] = include_images++ def parse(self, path: Path, *, page_range: str) -> _Result:+ seen["path"] = path+ seen["page_range"] = page_range+ return _Result()++ monkeypatch.setattr(parse, "MinerUApiParser", _FakeApiParser)++ result = runner.invoke(+ app,+ [+ "parse",+ str(source),+ "-o",+ str(output),+ "--remote-url",+ "http://localhost:8000/api",+ "--api-key",+ "test-key",+ "--tier",+ "high",+ "--pages",+ "1",+ ],+ )++ assert result.exit_code == 0+ assert output.read_text(encoding="utf-8") == "# demo\n"+ assert seen == {+ "api_url": "http://localhost:8000/api",+ "api_key": "test-key",+ "tier": "high",+ "include_images": True,+ "path": source,+ "page_range": "1",+ }++def test_parse_normalizes_hidden_language_alias(monkeypatch: Any, tmp_path: Path) -> None:source = tmp_path / "demo.pdf"output = tmp_path / "out.md"@@ -1046,11 +1110,11 @@ def test_gradio_v1_job_reuses_page_range_for_api_and_origin_pdf(calls: dict[str, Any] = {}class _FakeParser:- def __init__(self, *, api_url: str, tier: str, include_model_output: bool, zip_output_only: bool) -> None:+ def __init__(self, *, api_url: str, tier: str, include_images: bool, include_model_output: bool) -> None:calls["parser_api_url"] = api_urlcalls["parser_tier"] = tier+ calls["include_images"] = include_imagescalls["include_model_output"] = include_model_output- calls["zip_output_only"] = zip_output_onlyasync def parse_async(self, file_path: str, *, page_range: str) -> ParseResult:calls["api_page_range"] = page_range@@ -1084,7 +1148,7 @@ def test_gradio_v1_job_reuses_page_range_for_api_and_origin_pdf(assert calls["api_page_range"] == "1~2"assert calls["include_model_output"] is True- assert calls["zip_output_only"] is True+ assert calls["include_images"] is Trueassert calls["persist_page_range"] == "1~2"diff --git a/tests/unittest/test_parser_api_contract.py b/tests/unittest/test_parser_api_contract.pyindex 0244e105..46ef1f7d 100644--- a/tests/unittest/test_parser_api_contract.py+++ b/tests/unittest/test_parser_api_contract.py@@ -28,7 +28,6 @@ from mineru.parser.api_server import (FileParseInfo,FileStore,HealthResponse,- ImageOutputRef,JobListItem,OutputFileRef,OutputFiles,@@ -181,7 +180,7 @@ def test_api_client_builds_file_page_range_without_options(tmp_path: Path) -> Noparser = MinerUApiParser(api_url="http://localhost:8000", tier="high")payload = parser._build_payload(pdf, "1,3~5")- assert payload["output_formats"] == ["middle_json", "images"]+ assert payload["output_formats"] == ["middle_json"]assert payload["files"] == [{"source": {"type": "local", "path": str(pdf)}, "page_range": "1,3~5"}]assert "options" not in payload["files"][0]@@ -193,43 +192,41 @@ def test_api_client_can_request_zip_for_model_output(tmp_path: Path) -> None:parser = MinerUApiParser(api_url="http://localhost:8000", tier="high", include_model_output=True)payload = parser._build_payload(pdf, "")- assert payload["output_formats"] == ["middle_json", "images", "zip"]+ assert payload["output_formats"] == ["zip"]-def test_api_client_can_request_zip_output_only(tmp_path: Path) -> None:+def test_api_client_can_request_zip_for_image_cache(tmp_path: Path) -> None:pdf = tmp_path / "demo.pdf"pdf.write_bytes(b"%PDF-1.7\n")parser = MinerUApiParser(api_url="http://localhost:8000",tier="high",- include_model_output=True,- zip_output_only=True,+ include_images=True,)payload = parser._build_payload(pdf, "")assert payload["output_formats"] == ["zip"]-def test_api_client_keeps_staging_json_format_when_model_output_requested() -> None:+def test_api_client_uses_zip_for_staging_when_model_output_requested() -> None:parser = MinerUApiParser(api_url="https://staging.mineru.org.cn/api",tier="extra_high",include_model_output=True,)- assert parser._output_formats() == ["json"]+ assert parser._output_formats() == ["zip"]-def test_api_client_keeps_staging_json_format_when_zip_output_only_requested() -> None:+def test_api_client_uses_zip_for_staging_when_image_cache_requested() -> None:parser = MinerUApiParser(api_url="https://staging.mineru.org.cn/api",tier="extra_high",- include_model_output=True,- zip_output_only=True,+ include_images=True,)- assert parser._output_formats() == ["json"]+ assert parser._output_formats() == ["zip"]def test_api_client_uses_tier_without_backend_semantics(tmp_path: Path) -> None:@@ -249,16 +246,16 @@ def test_api_client_rejects_old_tier_names(tier: str) -> None:MinerUApiParser(api_url="http://localhost:8000", tier=tier) # type: ignore[arg-type]-def test_api_client_uses_json_format_for_staging_compat() -> None:+def test_api_client_uses_middle_json_format_for_staging() -> None:parser = MinerUApiParser(api_url="https://staging.mineru.org.cn/api", tier="extra_high")- assert parser._output_formats() == ["json"]+ assert parser._output_formats() == ["middle_json"]def test_api_client_uses_env_api_key_when_no_api_key_argument(monkeypatch: pytest.MonkeyPatch) -> None:monkeypatch.setenv("MINERU_API_KEY", "env-key")- parser = MinerUApiParser(api_url="https://mineru.net/api", tier="pro")+ parser = MinerUApiParser(api_url="https://mineru.net/api", tier="high")assert parser._headers()["Authorization"] == "Bearer env-key"@@ -339,24 +336,51 @@ def test_api_client_ignores_legacy_detail_error_envelope() -> None:assert exc_info.value.message.startswith("HTTP 400:")-def test_api_client_downloads_image_sidecars_and_preserves_pdf_mapping(monkeypatch: pytest.MonkeyPatch) -> None:- parser = MinerUApiParser(api_url="http://localhost:8000", tier="high")+def test_api_client_reads_image_cache_from_zip_and_preserves_pdf_mapping(monkeypatch: pytest.MonkeyPatch) -> None:+ parser = MinerUApiParser(api_url="http://localhost:8000", tier="high", include_images=True)middle_json = {"schema_version": "1.0.0","_pdf_retained_page_indices": [0, 2],"_pdf_broken_page_indices": [1],- "pages": [{"page_idx": 0, "page_size": [100, 200]}],+ "pages": [+ {+ "page_idx": 0,+ "page_size": [100, 200],+ "para_blocks": [+ {+ "index": 0,+ "type": "image",+ "bbox": [0, 0, 10, 10],+ "lines": [+ {+ "bbox": [0, 0, 10, 10],+ "spans": [+ {+ "type": "image",+ "bbox": [0, 0, 10, 10],+ "image_path": "images/chart.png",+ }+ ],+ }+ ],+ }+ ],+ }+ ],}- image_ref = {"path": "images/chart.png", "file_id": "file-image", "bytes": 11}+ zip_ref = {"file_id": "file-zip", "bytes": 10}+ zip_buffer = io.BytesIO()+ with zipfile.ZipFile(zip_buffer, "w", zipfile.ZIP_DEFLATED) as archive:+ archive.writestr("demo.middle_json", json.dumps(middle_json, ensure_ascii=False))+ archive.writestr("images/chart.png", b"chart-bytes")- monkeypatch.setattr(api_client, "_download_json", lambda _parser, _outputs: middle_json)- monkeypatch.setattr(api_client, "_download_bytes", lambda _parser, ref: b"chart-bytes" if ref is image_ref else b"")+ monkeypatch.setattr(api_client, "_download_bytes", lambda _parser, ref: zip_buffer.getvalue() if ref is zip_ref else b"")result = _parse_result_from_job({"job_id": "job_1","status": "completed",- "files": [{"output_files": {"middle_json": {"file_id": "file-middle", "bytes": 10}, "images": [image_ref]}}],+ "files": [{"output_files": {"zip": zip_ref}}],},"demo.pdf",parser,@@ -376,12 +400,12 @@ def test_api_client_downloads_model_output_from_zip(monkeypatch: pytest.MonkeyPazip_ref = {"file_id": "file-zip", "bytes": 10}zip_buffer = io.BytesIO()with zipfile.ZipFile(zip_buffer, "w", zipfile.ZIP_DEFLATED) as archive:+ archive.writestr("demo.middle_json", json.dumps(middle_json, ensure_ascii=False))archive.writestr("demo_model_output.json",json.dumps([[{"raw": "model"}]], ensure_ascii=False, indent=4),)- monkeypatch.setattr(api_client, "_download_json", lambda _parser, _outputs: middle_json)monkeypatch.setattr(api_client,"_download_bytes",@@ -392,7 +416,7 @@ def test_api_client_downloads_model_output_from_zip(monkeypatch: pytest.MonkeyPa{"job_id": "job_1","status": "completed",- "files": [{"output_files": {"middle_json": {"file_id": "file-middle", "bytes": 10}, "zip": zip_ref}}],+ "files": [{"output_files": {"zip": zip_ref}}],},"demo.pdf",parser,@@ -410,18 +434,15 @@ def test_api_client_async_downloads_model_output_from_zip(monkeypatch: pytest.Mozip_ref = {"file_id": "file-zip", "bytes": 10}zip_buffer = io.BytesIO()with zipfile.ZipFile(zip_buffer, "w", zipfile.ZIP_DEFLATED) as archive:+ archive.writestr("demo.middle_json", json.dumps(middle_json, ensure_ascii=False))archive.writestr("demo_model_output.json",json.dumps([[{"raw": "model"}]], ensure_ascii=False, indent=4),)- async def fake_download_json(_parser: object, _outputs: object) -> dict[str, object]:- return middle_json-async def fake_download_bytes(_parser: object, ref: dict[str, object]) -> bytes:return zip_buffer.getvalue() if ref is zip_ref else b""- monkeypatch.setattr(api_client, "_async_download_json", fake_download_json)monkeypatch.setattr(api_client, "_async_download_bytes", fake_download_bytes)result = asyncio.run(@@ -429,7 +450,7 @@ def test_api_client_async_downloads_model_output_from_zip(monkeypatch: pytest.Mo{"job_id": "job_1","status": "completed",- "files": [{"output_files": {"middle_json": {"file_id": "file-middle", "bytes": 10}, "zip": zip_ref}}],+ "files": [{"output_files": {"zip": zip_ref}}],},"demo.pdf",parser,@@ -439,12 +460,12 @@ def test_api_client_async_downloads_model_output_from_zip(monkeypatch: pytest.Moassert result._model_output == [[{"raw": "model"}]]-def test_api_client_zip_output_only_downloads_single_zip(monkeypatch: pytest.MonkeyPatch) -> None:+def test_api_client_include_images_downloads_single_zip(monkeypatch: pytest.MonkeyPatch) -> None:parser = MinerUApiParser(api_url="http://localhost:8000",tier="high",+ include_images=True,include_model_output=True,- zip_output_only=True,)zip_ref = {"file_id": "file-zip", "bytes": 10}image_cache = ImagePayloadCache()@@ -471,7 +492,7 @@ def test_api_client_zip_output_only_downloads_single_zip(monkeypatch: pytest.Monmonkeypatch.setattr(api_client,"_download_json",- lambda *_args, **_kwargs: (_ for _ in ()).throw(AssertionError("zip-only must not download middle_json separately")),+ lambda *_args, **_kwargs: (_ for _ in ()).throw(AssertionError("zip result must not download middle_json separately")),)result = _parse_result_from_job(@@ -490,12 +511,59 @@ def test_api_client_zip_output_only_downloads_single_zip(monkeypatch: pytest.Monassert result._model_output == [[{"raw": "model"}]]-def test_api_client_async_zip_output_only_downloads_single_zip(monkeypatch: pytest.MonkeyPatch) -> None:+def test_api_client_does_not_read_image_cache_from_zip_unless_requested(monkeypatch: pytest.MonkeyPatch) -> None:+ parser = MinerUApiParser(api_url="http://localhost:8000", tier="high", include_model_output=True)+ zip_ref = {"file_id": "file-zip", "bytes": 10}+ middle_json = {+ "schema_version": "1.0.0",+ "pages": [+ {+ "page_idx": 0,+ "page_size": [100, 200],+ "para_blocks": [+ {+ "index": 0,+ "type": "image",+ "bbox": [0, 0, 10, 10],+ "lines": [+ {+ "bbox": [0, 0, 10, 10],+ "spans": [{"type": "image", "bbox": [0, 0, 10, 10], "image_path": "images/chart.png"}],+ }+ ],+ }+ ],+ }+ ],+ }+ zip_buffer = io.BytesIO()+ with zipfile.ZipFile(zip_buffer, "w", zipfile.ZIP_DEFLATED) as archive:+ archive.writestr("demo.middle_json", json.dumps(middle_json, ensure_ascii=False))+ archive.writestr("images/chart.png", b"chart-bytes")+ archive.writestr("demo_model_output.json", json.dumps([[{"raw": "model"}]], ensure_ascii=False, indent=4))++ monkeypatch.setattr(api_client, "_download_bytes", lambda _parser, ref: zip_buffer.getvalue() if ref is zip_ref else b"")++ result = _parse_result_from_job(+ {+ "job_id": "job_1",+ "status": "completed",+ "files": [{"output_files": {"zip": zip_ref}}],+ },+ "demo.pdf",+ parser,+ )++ assert result.images() == {}+ assert result._model_output == [[{"raw": "model"}]]+++def test_api_client_async_include_images_downloads_single_zip(monkeypatch: pytest.MonkeyPatch) -> None:parser = MinerUApiParser(api_url="http://localhost:8000",tier="high",+ include_images=True,include_model_output=True,- zip_output_only=True,)zip_ref = {"file_id": "file-zip", "bytes": 10}zip_buffer = io.BytesIO()@@ -512,7 +580,7 @@ def test_api_client_async_zip_output_only_downloads_single_zip(monkeypatch: pytereturn zip_buffer.getvalue() if ref is zip_ref else b""async def fail_download_json(*_args: object, **_kwargs: object) -> dict[str, object]:- raise AssertionError("zip-only must not download middle_json separately")+ raise AssertionError("zip result must not download middle_json separately")monkeypatch.setattr(api_client, "_async_download_bytes", fake_download_bytes)monkeypatch.setattr(api_client, "_async_download_json", fail_download_json)@@ -534,8 +602,8 @@ def test_api_client_async_zip_output_only_downloads_single_zip(monkeypatch: pyteassert result._model_output == [[{"raw": "model"}]]-def test_api_client_zip_output_only_rejects_unsafe_image_entries(monkeypatch: pytest.MonkeyPatch) -> None:- parser = MinerUApiParser(api_url="http://localhost:8000", tier="high", zip_output_only=True)+def test_api_client_include_images_rejects_unsafe_image_entries(monkeypatch: pytest.MonkeyPatch) -> None:+ parser = MinerUApiParser(api_url="http://localhost:8000", tier="high", include_images=True)zip_ref = {"file_id": "file-zip", "bytes": 10}middle_json = {"schema_version": "1.0.0",@@ -547,7 +615,12 @@ def test_api_client_zip_output_only_rejects_unsafe_image_entries(monkeypatch: py"index": 0,"type": "image","bbox": [0, 0, 10, 10],- "lines": [{"bbox": [0, 0, 10, 10], "spans": [{"type": "image", "bbox": [0, 0, 10, 10], "image_path": "../escape.png"}]}],+ "lines": [+ {+ "bbox": [0, 0, 10, 10],+ "spans": [{"type": "image", "bbox": [0, 0, 10, 10], "image_path": "../escape.png"}],+ }+ ],}],}@@ -580,7 +653,6 @@ def test_api_client_accepts_remote_pdf_info_json(monkeypatch: pytest.MonkeyPatch}monkeypatch.setattr(api_client, "_download_json", lambda _parser, _outputs: middle_json)- monkeypatch.setattr(api_client, "_download_image_sidecars", lambda _parser, _outputs: {})result = _parse_result_from_job({@@ -608,11 +680,7 @@ def test_async_api_client_accepts_remote_pdf_info_json(monkeypatch: pytest.Monkeasync def _download_json(*_args: object, **_kwargs: object) -> dict[str, object]:return middle_json- async def _download_image_sidecars(*_args: object, **_kwargs: object) -> dict[str, bytes]:- return {}-monkeypatch.setattr(api_client, "_async_download_json", _download_json)- monkeypatch.setattr(api_client, "_async_download_image_sidecars", _download_image_sidecars)result = asyncio.run(api_client._async_parse_result_from_job(@@ -633,7 +701,7 @@ def test_async_api_client_accepts_remote_pdf_info_json(monkeypatch: pytest.Monkedef test_api_client_rejects_output_reference_without_file_id() -> None:- parser = MinerUApiParser(api_url="https://staging.mineru.org.cn/api", tier="standard")+ parser = MinerUApiParser(api_url="https://staging.mineru.org.cn/api", tier="high")with pytest.raises(api_client._V1APIError) as exc_info:api_client._download_bytes(parser, {"url": "https://example.invalid/output.json", "bytes": 10})@@ -643,7 +711,7 @@ def test_api_client_rejects_output_reference_without_file_id() -> None:def test_async_api_client_rejects_output_reference_without_file_id() -> None:- parser = MinerUApiParser(api_url="https://staging.mineru.org.cn/api", tier="standard")+ parser = MinerUApiParser(api_url="https://staging.mineru.org.cn/api", tier="high")async def _run() -> None:await api_client._async_download_bytes(parser, {"url": "https://example.invalid/output.json", "bytes": 10})@@ -656,49 +724,83 @@ def test_async_api_client_rejects_output_reference_without_file_id() -> None:@pytest.mark.parametrize("image_path", ["../escape.png", "/tmp/escape.png", "\\escape.png", "C:\\escape.png"])-def test_api_client_rejects_unsafe_image_sidecar_paths(+def test_api_client_include_images_rejects_unsafe_zip_image_sidecar_paths(monkeypatch: pytest.MonkeyPatch,image_path: str,) -> None:- parser = MinerUApiParser(api_url="http://localhost:8000", tier="high")- middle_json = {"schema_version": "1.0.0", "pages": [{"page_idx": 0}]}- image_ref = {"path": image_path, "file_id": "file-image", "bytes": 11}-- monkeypatch.setattr(api_client, "_download_json", lambda _parser, _outputs: middle_json)-- def _fail_download(*_args: object, **_kwargs: object) -> bytes:- """危险 sidecar 路径必须在下载图片字节前被拒绝。"""- raise AssertionError("unsafe sidecar path should be rejected before download")+ parser = MinerUApiParser(api_url="http://localhost:8000", tier="high", include_images=True)+ zip_ref = {"file_id": "file-zip", "bytes": 10}+ middle_json = {+ "schema_version": "1.0.0",+ "pages": [+ {+ "page_idx": 0,+ "para_blocks": [+ {+ "index": 0,+ "type": "image",+ "bbox": [0, 0, 10, 10],+ "lines": [+ {+ "bbox": [0, 0, 10, 10],+ "spans": [{"type": "image", "bbox": [0, 0, 10, 10], "image_path": image_path}],+ }+ ],+ }+ ],+ }+ ],+ }+ zip_buffer = io.BytesIO()+ with zipfile.ZipFile(zip_buffer, "w", zipfile.ZIP_DEFLATED) as archive:+ archive.writestr("demo.middle_json", json.dumps(middle_json, ensure_ascii=False))- monkeypatch.setattr(api_client, "_download_bytes", _fail_download)+ monkeypatch.setattr(api_client, "_download_bytes", lambda _parser, ref: zip_buffer.getvalue() if ref is zip_ref else b"")with pytest.raises(ValueError, match="Unsafe image sidecar path"):_parse_result_from_job({"job_id": "job_1","status": "completed",- "files": [{"output_files": {"middle_json": {"file_id": "file-middle", "bytes": 10}, "images": [image_ref]}}],+ "files": [{"output_files": {"zip": zip_ref}}],},"demo.pdf",parser,)-def test_async_api_client_rejects_unsafe_image_sidecar_paths(monkeypatch: pytest.MonkeyPatch) -> None:- parser = MinerUApiParser(api_url="http://localhost:8000", tier="high")- middle_json = {"schema_version": "1.0.0", "pages": [{"page_idx": 0}]}- image_ref = {"path": "../escape.png", "file_id": "file-image", "bytes": 11}-- async def _download_json(*_args: object, **_kwargs: object) -> dict[str, object]:- """返回最小 middle_json,聚焦验证 sidecar 路径校验。"""- return middle_json+def test_async_api_client_include_images_rejects_unsafe_zip_image_sidecar_paths(monkeypatch: pytest.MonkeyPatch) -> None:+ parser = MinerUApiParser(api_url="http://localhost:8000", tier="high", include_images=True)+ zip_ref = {"file_id": "file-zip", "bytes": 10}+ middle_json = {+ "schema_version": "1.0.0",+ "pages": [+ {+ "page_idx": 0,+ "para_blocks": [+ {+ "index": 0,+ "type": "image",+ "bbox": [0, 0, 10, 10],+ "lines": [+ {+ "bbox": [0, 0, 10, 10],+ "spans": [{"type": "image", "bbox": [0, 0, 10, 10], "image_path": "../escape.png"}],+ }+ ],+ }+ ],+ }+ ],+ }+ zip_buffer = io.BytesIO()+ with zipfile.ZipFile(zip_buffer, "w", zipfile.ZIP_DEFLATED) as archive:+ archive.writestr("demo.middle_json", json.dumps(middle_json, ensure_ascii=False))- async def _fail_download(*_args: object, **_kwargs: object) -> bytes:- """异步路径同样必须在下载图片字节前拒绝危险 sidecar。"""- raise AssertionError("unsafe sidecar path should be rejected before download")+ async def _download_bytes(_parser: object, ref: dict[str, object]) -> bytes:+ return zip_buffer.getvalue() if ref is zip_ref else b""- monkeypatch.setattr(api_client, "_async_download_json", _download_json)- monkeypatch.setattr(api_client, "_async_download_bytes", _fail_download)+ monkeypatch.setattr(api_client, "_async_download_bytes", _download_bytes)with pytest.raises(ValueError, match="Unsafe image sidecar path"):asyncio.run(@@ -706,9 +808,7 @@ def test_async_api_client_rejects_unsafe_image_sidecar_paths(monkeypatch: pytest{"job_id": "job_1","status": "completed",- "files": [- {"output_files": {"middle_json": {"file_id": "file-middle", "bytes": 10}, "images": [image_ref]}}- ],+ "files": [{"output_files": {"zip": zip_ref}}],},"demo.pdf",parser,@@ -927,7 +1027,7 @@ def test_api_client_rejects_missing_middle_json_output() -> None:def test_api_client_rejects_json_underscore_output_alias() -> None:- parser = MinerUApiParser(api_url="http://localhost:8000", tier="standard")+ parser = MinerUApiParser(api_url="http://localhost:8000", tier="high")with pytest.raises(api_client._V1APIError) as exc_info:api_client._download_json(parser, {"json_": {"file_id": "file-json", "bytes": 10}})@@ -973,6 +1073,14 @@ def test_create_job_request_accepts_new_format_names_and_rejects_options() -> Noassert req.files[0].page_range is Noneassert req.output_formats == ["middle_json", "structured_content"]+ with pytest.raises(ValidationError):+ CreateJobRequest.model_validate(+ {+ "files": [{"source": {"type": "local", "path": "/tmp/demo.pdf"}}],+ "output_formats": ["images"],+ }+ )+with pytest.raises(ValidationError):CreateJobRequest.model_validate({@@ -1117,16 +1225,6 @@ def test_output_files_expose_new_names_without_inline_content() -> None:OutputFileRef.model_validate({"file_id": "file-1", "bytes": 12, "content": "inline"})-def test_store_image_outputs_creates_downloadable_image_refs(tmp_path: Path) -> None:- file_store = FileStore(tmp_path / "api-files")-- assert hasattr(api_server, "_store_image_outputs")- refs = api_server._store_image_outputs(file_store, {"images/chart.png": b"chart-bytes"})-- assert refs == [ImageOutputRef(path="images/chart.png", file_id=refs[0].file_id, bytes=len(b"chart-bytes"))]- assert file_store.read_file_data(refs[0].file_id) == b"chart-bytes"--@pytest.mark.parametrize(("output_format", "output_attr"),[@@ -1135,7 +1233,7 @@ def test_store_image_outputs_creates_downloadable_image_refs(tmp_path: Path) ->("structured_content", "structured_content"),],)-def test_api_server_rendered_outputs_store_image_sidecars(+def test_api_server_rendered_outputs_do_not_return_image_sidecars(monkeypatch: pytest.MonkeyPatch,tmp_path: Path,output_format: str,@@ -1191,14 +1289,7 @@ def test_api_server_rendered_outputs_store_image_sidecars(output_files = rec.files[0].output_filesassert getattr(output_files, output_attr) is not None- assert output_files.images == [- ImageOutputRef(- path=output_files.images[0].path,- file_id=output_files.images[0].file_id,- bytes=len(img_bytes),- )- ]- assert file_store.read_file_data(output_files.images[0].file_id) == img_bytes+ assert "images" not in output_files.model_dump(by_alias=True, exclude_none=True)def test_api_server_middle_json_preserves_backend_for_client_rendering(@@ -1366,7 +1457,6 @@ def test_api_server_zip_is_self_contained_when_only_zip_requested(output_files = rec.files[0].output_filesassert output_files.middle_json is None- assert output_files.images is Noneassert output_files.zip is not Nonewith zipfile.ZipFile(io.BytesIO(file_store.read_file_data(output_files.zip.file_id))) as archive:names = set(archive.namelist())@@ -1725,9 +1815,7 @@ def test_api_server_multi_tier_http_metadata(tmp_path: Path, monkeypatch: pytest]-def test_api_server_multi_tier_jobs_use_requested_tier_runtime(- tmp_path: Path, monkeypatch: pytest.MonkeyPatch-) -> None:+def test_api_server_multi_tier_jobs_use_requested_tier_runtime(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:"""校验多 tier server 按每个 job 的 tier 选择 backend/effort,而不是复用全局默认值。"""_stub_api_server_dependency_preflight(monkeypatch)calls: list[dict[str, object]] = []@@ -1771,9 +1859,7 @@ def test_api_server_multi_tier_jobs_use_requested_tier_runtime(]-def test_api_server_single_tier_rejects_unavailable_tier(- tmp_path: Path, monkeypatch: pytest.MonkeyPatch-) -> None:+def test_api_server_single_tier_rejects_unavailable_tier(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:"""校验单 tier server 不接受未启动的 tier,避免请求绕过启动能力边界。"""_stub_api_server_dependency_preflight(monkeypatch)source = tmp_path / "demo.pdf"