Video2Guide / tests /test_llm_replace_ocr.py
Claude
editor: remove summary / key-terms / self-check (round 3)
b863381
Raw History Blame Contribute Delete
2.5 kB
"""Tests for the Tesseract-skip-when-LLM-replaces-OCR decision.
The orchestrator skips the Tesseract pass when Claude is going to
overwrite every frame's on-screen text anyway, except in topic mode
where Tesseract output is still needed to pick each topic's primary
frame from its scene pool.
"""
from pathlib import Path
from app.pipeline.llm_extract import LLMToggles
from app.pipeline.orchestrator import PipelineInputs, _llm_will_replace_tesseract
def _inputs(**overrides) -> PipelineInputs:
defaults = dict(
video_path=Path("video.mp4"),
transcript_path=None,
frames_dir=Path("frames"),
title="t",
)
defaults.update(overrides)
return PipelineInputs(**defaults)
def test_skips_tesseract_when_llm_ocr_on_no_topic_seg():
inputs = _inputs(
anthropic_api_key="sk-stub",
llm_toggles=LLMToggles(ocr_text=True),
)
assert _llm_will_replace_tesseract(inputs) is True
def test_keeps_tesseract_in_topic_segmentation_mode():
"""Topic-primary picking pools scenes by OCR character count to
push talking-head shots out of the way; skipping Tesseract here
would lose that signal and regress the recent fix.
"""
inputs = _inputs(
anthropic_api_key="sk-stub",
llm_toggles=LLMToggles(ocr_text=True, topic_segmentation=True),
)
assert _llm_will_replace_tesseract(inputs) is False
def test_keeps_tesseract_when_llm_ocr_toggle_is_off():
"""When the LLM isn't going to provide on-screen text, Tesseract
is the only OCR source — never skip.
"""
inputs = _inputs(
anthropic_api_key="sk-stub",
llm_toggles=LLMToggles(ocr_text=False, alt_text=True, math_equations=True),
)
assert _llm_will_replace_tesseract(inputs) is False
def test_keeps_tesseract_when_no_api_key():
"""`llm_ocr_text` is on but no key was provided; the LLM call
would no-op, so Tesseract must still run.
"""
inputs = _inputs(
anthropic_api_key=None,
llm_toggles=LLMToggles(ocr_text=True),
)
assert _llm_will_replace_tesseract(inputs) is False
def test_skip_ocr_flag_short_circuits_the_check():
"""If the user explicitly opted out of OCR, we don't run Tesseract
OR ask the LLM for text — the flag wins regardless of toggles.
"""
inputs = _inputs(
skip_ocr=True,
anthropic_api_key="sk-stub",
llm_toggles=LLMToggles(ocr_text=True),
)
assert _llm_will_replace_tesseract(inputs) is False