import pytest from src.rag.scope_guardian import ScopeGuardian @pytest.mark.parametrize( "message", [ "Can you recommend a restaurant?", "Can you recommend restaurants?", "Welche Restaurants können Sie empfehlen?", "What is the weather today?", "Who won the sports match?", "Where should I travel between locations in Switzerland?", ], ) def test_off_topic_queries_are_detected(message): assert ScopeGuardian.check_scope(message) == "off_topic" def test_german_off_topic_redirect_acknowledges_restaurant_subject(): message = ScopeGuardian.get_redirect_message("off_topic", "de") assert "Restaurants" in message assert "kann ich leider nicht beraten" in message assert "HSG Executive MBA" in message @pytest.mark.parametrize( "message", [ "Any good movies near St. Gallen?", "Welche Filme laufen heute?", ], ) def test_movie_queries_are_detected_as_off_topic(message): assert ScopeGuardian.check_scope(message) == "off_topic" @pytest.mark.parametrize( "message", [ "What are the admission requirements for EMBA?", "How much does the programme cost?", "I work in healthcare and want to strengthen my leadership skills.", ], ) def test_on_topic_queries_remain_allowed(message): assert ScopeGuardian.check_scope(message) == "on_topic" @pytest.mark.parametrize( "message", [ "Is public transport included between modules?", "How do participants travel between module locations?", "Gibt es Transport zwischen den Modulen?", ], ) def test_programme_travel_context_remains_allowed(message): assert ScopeGuardian.check_scope(message) == "on_topic" def test_financial_planning_queries_keep_their_classification(): assert ScopeGuardian.check_scope("Can you create a payment plan?") == "financial_planning" def test_aggressive_queries_keep_their_classification(): assert ScopeGuardian.check_scope("This chatbot is useless") == "aggressive" def test_redirect_language_fallback_preserves_scope_type(): message = ScopeGuardian.get_redirect_message("aggressive", "fr") assert "remain respectful" in message assert "restaurants" not in message