fix(document): apply OCR timeout to Mistral backend + review/Sonar fixes (#892)

Round-1 review on PR #892:
- Wire DOCUMENT_OCR_TIMEOUT_SECONDS into _MistralOcrBackend too (was
  gateway-only): wrap process_async in anyio.fail_after so the SDK-managed
  client honours the setting; on expiry it fails fast as a clean parse error.
  Test added.
- Tighten the misleading "honoured without a restart" comment — per-call
  get_settings() is for test monkeypatching; a live change still needs a
  restart since the backend is cached for the pod lifetime.
- Comment the size guard's two intentional gaps: an explicit processor_name
  override bypasses it, and the early return skips the parse-duration histogram.

SonarCloud (new-code smells in the added tests):
- S1244 float-equality asserts → pytest.approx (test_config.py, test_ocr_processor.py).
- S1186/S7503: rewrite the gateway-timeout test with mocker AsyncMock/MagicMock
  instead of a hand-rolled fake client (no empty method, no async-without-await).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Chris Coutinho
2026-06-11 05:36:47 +02:00
co-authored by Claude Opus 4.8
parent 523e4cb7b5
commit 64ea5c8631
4 changed files with 63 additions and 34 deletions
+4 -4
View File
@@ -219,17 +219,17 @@ class TestChunkConfigValidation:
Guards the _DEFAULTS-key-must-match-env-var footgun: a mismatch would
leave the override silently ignored.
"""
assert Settings().document_ocr_timeout_seconds == 180.0
assert Settings().document_ocr_timeout_seconds == pytest.approx(180.0)
with patch.dict(os.environ, {"DOCUMENT_OCR_TIMEOUT_SECONDS": "45"}, clear=True):
_reload_config()
assert get_settings().document_ocr_timeout_seconds == 45.0
assert get_settings().document_ocr_timeout_seconds == pytest.approx(45.0)
def test_max_pdf_size_default_and_env_override(self):
"""document_max_pdf_size_mb defaults to 50 and reads its env var."""
assert Settings().document_max_pdf_size_mb == 50.0
assert Settings().document_max_pdf_size_mb == pytest.approx(50.0)
with patch.dict(os.environ, {"DOCUMENT_MAX_PDF_SIZE_MB": "12.5"}, clear=True):
_reload_config()
assert get_settings().document_max_pdf_size_mb == 12.5
assert get_settings().document_max_pdf_size_mb == pytest.approx(12.5)
def test_valid_chunk_settings(self):
"""Test valid chunk size and overlap configuration."""