from GramAddict.core.perception.spatial_parser import SpatialNode
from GramAddict.core.telepathic_engine import TelepathicEngine


def test_telepathic_engine_global_trap_guard():
    """
    TDD Test: Proves that the TelepathicEngine structurally blocks dangerous UI
    elements (like 'audio', 'trending', 'save') regardless of the intent,
    unless explicitly requested.
    """
    engine = TelepathicEngine()
    screen_height = 2400

    # 1. Setup mock nodes for traps
    node_audio = SpatialNode(
        bounds=(0, 0, 100, 100),
        resource_id="com.instagram.android:id/audio_icon",
        class_name="android.widget.ImageView",
    )

    node_save = SpatialNode(
        bounds=(0, 100, 100, 200),
        resource_id="com.instagram.android:id/save_button",
        class_name="android.widget.ImageView",
    )

    node_normal = SpatialNode(
        bounds=(0, 200, 100, 300),
        resource_id="com.instagram.android:id/zoomable_view_container",
        class_name="android.widget.FrameLayout",
    )

    # 2. Test Intents that SHOULD NOT trigger the traps
    intent_media = "post media content"

    assert (
        engine._structural_sanity_check(node_audio, intent_media, screen_height) is False
    ), "Guard failed: Audio icon allowed for 'post media content'."
    assert (
        engine._structural_sanity_check(node_save, intent_media, screen_height) is False
    ), "Guard failed: Save button allowed for 'post media content'."
    assert (
        engine._structural_sanity_check(node_normal, intent_media, screen_height) is True
    ), "Guard failed: Normal node was blocked incorrectly."

    # 3. Test Intents that SHOULD trigger the traps
    intent_audio = "trending audio"
    intent_save = "save button"

    assert (
        engine._structural_sanity_check(node_audio, intent_audio, screen_height) is True
    ), "Guard failed: Audio icon blocked for 'trending audio'."
    assert (
        engine._structural_sanity_check(node_save, intent_save, screen_height) is True
    ), "Guard failed: Save button blocked for 'save button'."
