from pathlib import Path import pytest # Skip cleanly where the pinned engine is not installed (e.g. light-deps CI); # see app/ingestion/ENGINE_SOURCE.md for the focused verification command. pytest.importorskip("teamhub_document_recognition_engine") def test_legacy_ocr_adapter_reexports_engine_model_and_settings(monkeypatch, tmp_path: Path) -> None: from teamhub_document_recognition_engine import OcrResult as EngineOcrResult import app.ingestion.ocr as legacy_ocr calls = {} def fake_run_ocr(input_pdf, output_pdf, **kwargs): calls.update(kwargs) return EngineOcrResult(output_path=output_pdf, skipped=True, reason="fake", languages=kwargs["languages"]) monkeypatch.setattr(legacy_ocr, "_engine_run_ocr", fake_run_ocr) monkeypatch.setattr(legacy_ocr.settings, "ocr_enabled", False) monkeypatch.setattr(legacy_ocr.settings, "ocr_deskew", False) monkeypatch.setattr(legacy_ocr.settings, "ocr_clean", False) monkeypatch.setattr(legacy_ocr.settings, "ocr_optimize", 0) result = legacy_ocr.run_ocr(tmp_path / "in.pdf", tmp_path / "out.pdf", languages="eng") assert legacy_ocr.OcrResult is EngineOcrResult assert isinstance(result, EngineOcrResult) assert calls == { "languages": "eng", "enabled": False, "deskew": False, "clean": False, "optimize": 0, } def test_legacy_docling_adapter_reexports_engine_models_and_settings(monkeypatch, tmp_path: Path) -> None: from teamhub_document_recognition_engine import ( ExtractedBlock as EngineExtractedBlock, ) from teamhub_document_recognition_engine import ( ExtractionResult as EngineExtractionResult, ) import app.ingestion.docling_extractor as legacy_docling calls = {} def fake_extract(pdf_path, **kwargs): calls.update(kwargs) return EngineExtractionResult( markdown="", json_payload={}, blocks=[], tables=[], figures=[], pages=[], ) monkeypatch.setattr(legacy_docling, "_engine_extract", fake_extract) monkeypatch.setattr(legacy_docling.settings, "docling_ocr_enabled", True) result = legacy_docling.extract(tmp_path / "ocr.pdf") assert legacy_docling.ExtractedBlock is EngineExtractedBlock assert legacy_docling.ExtractionResult is EngineExtractionResult assert isinstance(result, EngineExtractionResult) assert calls == {"docling_ocr_enabled": True}