from GramAddict.core.perception.intent_resolver import IntentResolver
from GramAddict.core.perception.spatial_parser import SpatialNode


def test_reply_guard_filters_edittext(monkeypatch):
    """
    TDD: Prove that the Reply Guard filters out EditText classes
    when the intent does not imply typing/messaging.
    """
    resolver = IntentResolver()

    # Create mock candidates
    node_normal = SpatialNode(
        bounds=(0, 0, 100, 100),
        resource_id="com.instagram.android:id/button_next",
        class_name="android.widget.Button",
        text="Next",
    )

    node_edittext = SpatialNode(
        bounds=(0, 100, 100, 200),
        resource_id="com.instagram.android:id/comment_composer",
        class_name="android.widget.EditText",
        text="Add a comment...",
    )

    candidates = [node_normal, node_edittext]

    # We will capture the candidates passed to _annotate_screenshot_with_candidates
    captured_candidates = []

    def fake_annotate(device, cands):
        captured_candidates.extend(cands)
        # Return a dummy annotation output
        return (None, {0: node_normal})

    monkeypatch.setattr(resolver, "_annotate_screenshot_with_candidates", fake_annotate)

    class DummyDevice:
        pass

    dummy_device = DummyDevice()

    # Attempt to resolve an intent that shouldn't match EditText
    resolver._visual_discovery("tap the next button", candidates, dummy_device, screen_height=1000)

    assert len(captured_candidates) == 1
    assert captured_candidates[0].class_name == "android.widget.Button"
    assert node_edittext not in captured_candidates
