from GramAddict.core.telepathic_engine import TelepathicEngine


def test_core_nav_rejects_generic_action_bar_right():
    # Simulate an XML where the generic container is present, but NO explicit DM icon exists
    xml_content = """<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
    <hierarchy rotation="0">
        <node index="0" text="" resource-id="com.instagram.android:id/action_bar_buttons_container_right" class="android.widget.LinearLayout" package="com.instagram.android" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" visible-to-user="true" bounds="[800,100][1080,250]" drawing-order="1" hint="" display-id="0">
        </node>
    </hierarchy>
    """

    engine = TelepathicEngine()
    engine._is_modal_active = lambda *args, **kwargs: False
    intent = "tap direct message icon inbox"

    # We mock out VLM entirely to ensure it does not fallback, so we only test fast-path
    engine._agentic_vision_fallback = lambda *args, **kwargs: None

    result = engine.find_best_node(xml_content, intent)

    # In the RED phase, this will FAIL if the fast path erroneously selects the generic container.
    # The fast path should ONLY trigger if "direct" is in the ID, so it should return None here.
    if result is not None and result.get("source") == "core_nav":
        assert (
            "action bar buttons container right" not in result["semantic"]
        ), "Fast path erroneously triggered on generic action_bar right container!"
