"""Unit tests for RosettaStone terminology translation and violation detection.""" import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).parent.parent.parent / "backend")) from rosetta import translate, client_terms, check_terminology class TestTranslate: def test_known_key_returns_client_term(self) -> None: assert translate("STOCK_CHECK", "novamart") == "availability scan" def test_same_key_different_clients_differ(self) -> None: novamart = translate("STOCK_CHECK", "novamart") shelfwise = translate("STOCK_CHECK", "shelfwise") assert novamart != shelfwise def test_unknown_key_returns_none(self) -> None: assert translate("NONEXISTENT_KEY", "novamart") is None def test_pharma_client_returns_correct_term(self) -> None: assert translate("DRUG_APPROVAL", "pharmalink") == "formulary pre-approval" assert translate("DRUG_APPROVAL", "clinixone") == "prior authorization" class TestClientTerms: def test_returns_full_mapping(self) -> None: terms = client_terms("novamart") assert isinstance(terms, dict) assert "STOCK_CHECK" in terms assert terms["STOCK_CHECK"] == "availability scan" def test_different_clients_have_different_mappings(self) -> None: nm = client_terms("novamart") sw = client_terms("shelfwise") assert nm["STOCK_CHECK"] != sw["STOCK_CHECK"] class TestCheckTerminology: def test_correct_term_no_violation(self) -> None: result = check_terminology("Please run an availability scan.", "novamart") assert result["pass"] is True assert result["violations"] == [] def test_rival_term_triggers_violation(self) -> None: result = check_terminology("Please run a stock check.", "novamart") assert result["pass"] is False assert len(result["violations"]) >= 1 def test_violation_contains_expected_and_found(self) -> None: result = check_terminology("Use a feature toggle to enable this.", "novamart") violation = next( (v for v in result["violations"] if v["found"] == "feature toggle"), None ) assert violation is not None assert violation["expected"] == "capability switch" def test_checked_count_matches_catalog(self) -> None: terms = client_terms("novamart") result = check_terminology("Neutral response with no domain terms.", "novamart") assert result["checked"] == len(terms) def test_case_insensitive_matching(self) -> None: result = check_terminology("Run a STOCK CHECK now.", "novamart") assert result["pass"] is False