Skip to content

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

fix: update PDF fixture handling to support encrypted samples and improve geometry validation

myhloli156b70c98f21
diff --git a/scripts/review_flash_layout_geometry.py b/scripts/review_flash_layout_geometry.py
index 3dc45706..1c475f1f 100644
--- a/scripts/review_flash_layout_geometry.py
+++ b/scripts/review_flash_layout_geometry.py
@@ -35,6 +35,7 @@ PERTURBATION_NAMES = (
"latin_only",
"punctuation",
)
+_PDF_FIXTURE_XOR_KEY = b"MinerU flash layout fixture"
_IGNORED_FINGERPRINT_KEYS = {
"bbox",
"lines",
@@ -66,6 +67,16 @@ def _sha256_bytes(value: bytes) -> str:
return hashlib.sha256(value).hexdigest()
+def read_pdf_fixture(path: Path) -> bytes:
+ """读取普通 PDF,或在内存中解密以 .xor 结尾的测试样本。"""
+
+ payload = path.read_bytes()
+ if path.suffix != ".xor":
+ return payload
+ key_length = len(_PDF_FIXTURE_XOR_KEY)
+ return bytes(value ^ _PDF_FIXTURE_XOR_KEY[index % key_length] for index, value in enumerate(payload))
+
+
def _corpus_paths(manifest: dict[str, Any], source_root: Path) -> list[Path]:
"""按版本化 manifest 返回仓库相对路径语料。"""
@@ -358,8 +369,9 @@ def _run_document(
) -> dict[str, Any]:
"""解析一份语料并返回正常、扰动、overlay 和金标页面信息。"""
- pdf_bytes = path.read_bytes()
- pdf_sha = _sha256_bytes(pdf_bytes)
+ stored_bytes = path.read_bytes()
+ pdf_bytes = read_pdf_fixture(path)
+ pdf_sha = _sha256_bytes(stored_bytes)
geometry_diagnostics: list[dict[str, Any]] = []
started = time.perf_counter()
rss_before = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
diff --git a/tests/fixtures/flash_layout_geometry_manifest.json b/tests/fixtures/flash_layout_geometry_manifest.json
index bbd78dd0..5a19fc90 100644
--- a/tests/fixtures/flash_layout_geometry_manifest.json
+++ b/tests/fixtures/flash_layout_geometry_manifest.json
@@ -6962,8 +6962,8 @@
}
},
{
- "path": "tests/unittest/pdfs/flash_layout/NPU_开发环境部署_参考指南.pdf",
- "sha256": "886b6ac14de0c44387ac1b2a4f0263c258c676d5c3a6845312930d705bb18441",
+ "path": "tests/unittest/pdfs/flash_layout/mixed_text_layout_sample.pdf.xor",
+ "sha256": "fc3150c68c9f88b78d10dd2c321871f63a2e08be2099528fe00cf62d8a17e3d3",
"role": "normal",
"approved": true,
"pages": [
diff --git "a/tests/unittest/pdfs/flash_layout/NPU_\345\274\200\345\217\221\347\216\257\345\242\203\351\203\250\347\275\262_\345\217\202\350\200\203\346\214\207\345\215\227.pdf" "b/tests/unittest/pdfs/flash_layout/NPU_\345\274\200\345\217\221\347\216\257\345\242\203\351\203\250\347\275\262_\345\217\202\350\200\203\346\214\207\345\215\227.pdf"
deleted file mode 100644
index 64ca6f1e..00000000
Binary files "a/tests/unittest/pdfs/flash_layout/NPU_\345\274\200\345\217\221\347\216\257\345\242\203\351\203\250\347\275\262_\345\217\202\350\200\203\346\214\207\345\215\227.pdf" and /dev/null differ
diff --git a/tests/unittest/pdfs/flash_layout/mixed_text_layout_sample.pdf.xor b/tests/unittest/pdfs/flash_layout/mixed_text_layout_sample.pdf.xor
new file mode 100644
index 00000000..a52058ee
Binary files /dev/null and b/tests/unittest/pdfs/flash_layout/mixed_text_layout_sample.pdf.xor differ
diff --git a/tests/unittest/test_flash_pdf_char_geometry.py b/tests/unittest/test_flash_pdf_char_geometry.py
index 97ca8758..19db7a11 100644
--- a/tests/unittest/test_flash_pdf_char_geometry.py
+++ b/tests/unittest/test_flash_pdf_char_geometry.py
@@ -14,6 +14,19 @@ from mineru.model.flash.pdf.document import PDFPageTextGeometry
from mineru.model.flash.pdf.models import _LineItem
+_PDF_FIXTURE_XOR_KEY = b"MinerU flash layout fixture"
+
+
+def _read_pdf_fixture(path: Path) -> bytes:
+ """读取普通 PDF,或在内存中解密以 .xor 结尾的测试样本。"""
+
+ payload = path.read_bytes()
+ if path.suffix != ".xor":
+ return payload
+ key_length = len(_PDF_FIXTURE_XOR_KEY)
+ return bytes(value ^ _PDF_FIXTURE_XOR_KEY[index % key_length] for index, value in enumerate(payload))
+
+
def _line_fixture(
*,
source_index: int,
@@ -402,17 +415,19 @@ def test_strong_bad_font_family_propagates_to_supported_sibling_run() -> None:
assert (0, 100) in plan.char_repairs
-def test_versioned_npu_fixture_keeps_normal_geometry_identity() -> None:
- """验证提交的 NPU 中英混排与等宽字体不会误触发生产修复。"""
+def test_versioned_mixed_text_fixture_keeps_normal_geometry_identity() -> None:
+ """验证版本化中英混排与等宽字体样本不会误触发生产修复。"""
project_root = Path(__file__).parents[2]
- fixture = project_root / "tests" / "unittest" / "pdfs" / "flash_layout" / "NPU_开发环境部署_参考指南.pdf"
- assert (
- hashlib.sha256(fixture.read_bytes()).hexdigest() == "886b6ac14de0c44387ac1b2a4f0263c258c676d5c3a6845312930d705bb18441"
- )
+ fixture = project_root / "tests" / "unittest" / "pdfs" / "flash_layout" / "mixed_text_layout_sample.pdf.xor"
+ encrypted_bytes = fixture.read_bytes()
+ assert hashlib.sha256(encrypted_bytes).hexdigest() == "fc3150c68c9f88b78d10dd2c321871f63a2e08be2099528fe00cf62d8a17e3d3"
+ assert not encrypted_bytes.startswith(b"%PDF-")
+ pdf_bytes = _read_pdf_fixture(fixture)
+ assert hashlib.sha256(pdf_bytes).hexdigest() == "87d98f6f4e42152c38b0a1f8dcfefa3e5ac163cc086a6f37169cabadf77bd107"
diagnostics: list[dict[str, object]] = []
- with pipeline.PDFDocument(fixture.read_bytes()) as document:
+ with pipeline.PDFDocument(pdf_bytes) as document:
pipeline._analyze_native_document(document, geometry_diagnostics=diagnostics) # noqa: SLF001
geometry = diagnostics[0]
diff --git a/tests/unittest/test_flash_pdf_native_text.py b/tests/unittest/test_flash_pdf_native_text.py
index 6ad06c85..f30e6719 100644
--- a/tests/unittest/test_flash_pdf_native_text.py
+++ b/tests/unittest/test_flash_pdf_native_text.py
@@ -54,7 +54,7 @@ def test_mixed_footer_and_315_degree_watermark_are_split_before_filtering() -> N
pdf_line = _line(
[
_span("文档问题反馈: [email protected]", (30.0, 90.0, 80.0, 98.0), 0.0),
- _span("深圳TCL智能家庭科技有限公司raynL", (5.0, 10.0, 25.0, 95.0), 315.000019),
+ _span("通用测试文档", (5.0, 10.0, 25.0, 95.0), 315.000019),
_span("\r\n", (26.0, 20.0, 26.0, 20.0), 0.0),
],
0.0,