File size: 2,496 Bytes
496ac75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b863381
496ac75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""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