fix(ocr): ensure Tesseract language data for embed_text_layer regardless of active OCR provider

Root cause: ensure_ocr_languages_from_settings() only downloaded tessdata
when the 'tesseract' provider was active, but embed_text_layer() uses
ocrmypdf (which needs tessdata) as a fallback for ALL OCR providers.

- embed_text_layer(): call ensure_tesseract_languages(language) after
  confirming ocrmypdf is on PATH, so language data is present before
  ocrmypdf is invoked (prevents exit code 3 for fra/deu/etc.)
- ensure_ocr_languages_from_settings(): extend the condition from
  'tesseract' in active_providers to also trigger when ocrmypdf is
  on PATH, enabling proactive pre-download at startup for any config
- Tests: mock shutil.which and ensure_tesseract_languages in affected
  test cases; rename azure-only test and add new test for ocrmypdf case

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-24 18:02:19 +00:00
parent 8f3b554b0d
commit 2b2a97c2fa
4 changed files with 59 additions and 4 deletions
+5
View File
@@ -1075,6 +1075,7 @@ class TestEmbedTextLayer:
with (
patch("shutil.which", return_value="/usr/bin/ocrmypdf"),
patch("app.utils.ocr_language_manager.ensure_tesseract_languages", return_value=[]),
patch("subprocess.run", return_value=mock_proc) as mock_run,
):
result = embed_text_layer(pdf, output, language="eng")
@@ -1097,6 +1098,7 @@ class TestEmbedTextLayer:
with (
patch("shutil.which", return_value="/usr/bin/ocrmypdf"),
patch("app.utils.ocr_language_manager.ensure_tesseract_languages", return_value=[]),
patch("subprocess.run", return_value=mock_proc),
):
result = embed_text_layer(pdf, str(tmp_path / "out.pdf"))
@@ -1113,6 +1115,7 @@ class TestEmbedTextLayer:
with (
patch("shutil.which", return_value="/usr/bin/ocrmypdf"),
patch("app.utils.ocr_language_manager.ensure_tesseract_languages", return_value=[]),
patch("subprocess.run", side_effect=subprocess.TimeoutExpired(cmd="ocrmypdf", timeout=600)),
):
result = embed_text_layer(pdf, str(tmp_path / "out.pdf"))
@@ -1140,6 +1143,7 @@ class TestEmbedTextLayer:
with (
patch("shutil.which", return_value="/usr/bin/ocrmypdf"),
patch("app.utils.ocr_language_manager.ensure_tesseract_languages", return_value=[]),
patch("subprocess.run", side_effect=fake_run),
):
result = embed_text_layer(pdf, pdf)
@@ -1172,6 +1176,7 @@ class TestEmbedTextLayer:
with (
patch("shutil.which", return_value="/usr/bin/ocrmypdf"),
patch("app.utils.ocr_language_manager.ensure_tesseract_languages", return_value=[]),
patch("subprocess.run", return_value=mock_proc),
patch("tempfile.mkstemp", side_effect=fake_mkstemp),
):