test: lock OCR phase3 renderer contract

This commit is contained in:
Research Assistant 2026-06-05 10:12:48 +08:00
parent 1963a091fc
commit 4263cb4100
2 changed files with 63 additions and 0 deletions

View file

@ -457,3 +457,29 @@ def test_postprocess_creates_object_directories(tmp_path: Path) -> None:
assert (ocr_dir / "assets" / "figures").exists()
assert (ocr_dir / "assets" / "tables").exists()
assert (ocr_dir / "assets" / "orphans").exists()
def test_postprocess_writes_render_fulltext(tmp_path: Path) -> None:
import json
from paperforge.worker.ocr import postprocess_ocr_result
vault = tmp_path / "vault"
vault.mkdir()
(vault / "paperforge.json").write_text(
json.dumps({"vault_config": {"system_dir": "System", "resources_dir": "Resources"}}),
encoding="utf-8",
)
ocr_root = vault / "System" / "PaperForge" / "ocr"
ocr_root.mkdir(parents=True)
ocr_dir = ocr_root / "RNDR001"
ocr_dir.mkdir()
(ocr_dir / "meta.json").write_text(
'{"zotero_key":"RNDR001","ocr_status":"done","ocr_model":"PaddleOCR"}',
encoding="utf-8",
)
_, _, _, _ = postprocess_ocr_result(vault, "RNDR001", [])
# Phase 3: render/fulltext.md does not exist yet -- this test will fail
assert (ocr_dir / "render" / "fulltext.md").exists()

View file

@ -0,0 +1,37 @@
from __future__ import annotations
def test_render_fulltext_uses_resolved_metadata_and_object_links(tmp_path) -> None:
from paperforge.worker.ocr_render import render_fulltext_markdown
structured_blocks = [
{"page": 1, "block_id": "p1_b1", "role": "abstract_heading", "text": "Abstract", "render_default": True},
{"page": 1, "block_id": "p1_b2", "role": "abstract_body", "text": "Background text.", "render_default": True},
{"page": 2, "block_id": "p2_b1", "role": "section_heading", "text": "1 Introduction", "render_default": True},
{"page": 2, "block_id": "p2_b2", "role": "body_paragraph", "text": "Intro body.", "render_default": True},
]
resolved_metadata = {
"title": {"value": "Paper Title"},
"authors": {"value": ["Alice", "Bob"]},
"journal": {"value": "Journal A"},
"year": {"value": 2024},
"doi": {"value": "10.1000/xyz"},
}
figure_inventory = {
"matched_figures": [{"figure_id": "figure_001", "confidence": 0.91, "flags": []}],
}
table_inventory = {
"tables": [{"table_id": "table_001", "has_asset": True}],
}
md = render_fulltext_markdown(
structured_blocks=structured_blocks,
resolved_metadata=resolved_metadata,
figure_inventory=figure_inventory,
table_inventory=table_inventory,
)
assert "# Paper Title" in md
assert "Authors:" in md
assert "## 1 Introduction" in md or "### 1 Introduction" in md
assert "![[figures/figure_001.md]]" in md or "![[render/figures/figure_001.md]]" in md