"""Translation acceptance gate (#1376, #155) — pure unit tests for ``_accept``, which decides whether curator stores Interpreter's translation or keeps the original. Curator does no detection of its own; it only thresholds Interpreter's reported detected language + confidence against the operator-tunable floor (Scribe rule 133). No DB, no network.""" from backend.app.tasks.translation import _DEFAULT_MIN_LATIN_CONFIDENCE, _accept def test_accept_trusts_cjk_regardless_of_confidence_or_floor(): # ja/ko/zh are script-detected — accepted even at a low reported number and # even against a high floor (pure-kanji Japanese can come back labelled zh # ~0.75, still translated). assert _accept("ja", None) is True assert _accept("ja", 0.10, 0.99) is True assert _accept("ko", 0.99) is True assert _accept("zh", 0.75) is True assert _accept("zh-CN", 0.20) is True # region suffix is still CJK def test_accept_default_floor_is_strict(): # Default floor is 0.90 (#155): the ~0.86 band — where genuine German AND # mis-flagged short English collide — is now REJECTED (the whole point of the # stricter default). Genuine high-confidence non-English (~1.0) still passes. assert _accept("de", 0.98) is True assert _accept("de", 0.86) is False # the collision band, now cut assert _accept("de", _DEFAULT_MIN_LATIN_CONFIDENCE) is True # at floor assert _accept("de", _DEFAULT_MIN_LATIN_CONFIDENCE - 0.01) is False assert _accept("fr", 0.40) is False # short mis-flag def test_accept_honors_an_explicit_floor(): # The floor is a parameter now (fed from ImportSettings). A looser floor keeps # the 0.86 band; a stricter one rejects even a fairly confident detection. assert _accept("de", 0.86, 0.80) is True assert _accept("de", 0.86, 0.95) is False assert _accept("de", 0.96, 0.95) is True def test_accept_is_case_insensitive(): assert _accept("JA", None) is True assert _accept("DE", 0.40) is False def test_accept_missing_confidence_fails_open(): # No confidence reported → don't silently drop a translation. assert _accept("de", None) is True assert _accept("", None) is True assert _accept("de", None, 0.99) is True # fail-open beats a high floor