"""The OCR guard must actually skip when there is no engine. This is a regression test for a real bug: the guard in `test_cli.py` asked `detector_available()`, whose default `auto` is `True` even with nothing installed - because the grid fallback always exists. So on a machine with no OCR engine the test *failed* instead of skipping, and the failure looked like a harness defect. The guard now asks for `ocr` specifically, and here is the proof. """ import pytest from conftest import require_ocr import tiny_computer_agent.perception as perception def test_the_guard_skips_when_no_engine_is_installed(monkeypatch): monkeypatch.setattr(perception, "detector_available", lambda name="auto": (False, "simulated: no engine")) with pytest.raises(pytest.skip.Exception): require_ocr() def test_the_guard_passes_when_an_engine_is_installed(monkeypatch): monkeypatch.setattr(perception, "detector_available", lambda name="auto": (True, "simulated: engine present")) require_ocr() # must not raise def test_the_guard_asks_for_ocr_and_not_auto(monkeypatch): """`auto` is available with nothing installed, so it would never skip.""" asked = [] def record(name="auto"): asked.append(name) return True, "recorded" monkeypatch.setattr(perception, "detector_available", record) require_ocr() assert asked == ["ocr"] def test_auto_is_available_without_any_engine(): """The reason the old guard never fired, pinned down as a test.""" available, detail = perception.detector_available("auto") assert available is True, "auto must stay usable with no OCR engine"