from GramAddict.core.telepathic_engine import TelepathicEngine


def test_keyword_fast_path_no_feed_pollution():
    engine = TelepathicEngine()

    # A generic Feed post that used to spoof the 'home' keyword due to 'row feed photo'
    feed_post_node = {
        "x": 100,
        "y": 200,
        "area": 500,
        "semantic_string": "description: 'Profile picture of ericrubens', id context: 'row feed photo profile imageview'",
        "resource_id": "row_feed_photo_profile_imageview",
        "original_attribs": {"desc": "Profile picture of ericrubens", "text": ""},
    }

    # The actual Home Tab button
    home_tab_node = {
        "x": 100,
        "y": 2300,
        "area": 300,
        "semantic_string": "description: 'Home', id context: 'tab bar'",
        "resource_id": "tab_avatar",
        "original_attribs": {"desc": "Home", "text": ""},
    }

    nodes = [feed_post_node, home_tab_node]

    # Intention is to tap the home tab
    result = engine._keyword_match_score("tap home tab", nodes)

    assert result is not None
    # Verify it matched the actual home tab and NOT the feed post
    assert result["semantic"] == "description: 'Home', id context: 'tab bar'"
