"""
E2E: Plugin Import Integrity
==============================
Tests that ALL production plugins can be imported and instantiated.
A single broken import (like the humanized_scroll bug) would crash here.

This is not a workflow test — it's a build-time sanity gate.
"""


def test_all_plugins_importable_and_instantiable(setup_e2e_plugin_registry):
    """
    The plugin registry must contain all production plugins.
    If any plugin has a broken import, the conftest fixture crashes.
    """
    expected_plugins = {
        "ad_guard",
        "anomaly_handler",
        "close_friends_guard",
        "obstacle_guard",
        "perfect_snapping",
        "post_data_extraction",
        "resonance_evaluator",
        "darwin_dwell",
        "likes",
        "comment",
        "repost",
        "post_interaction",
    }

    registered = {p.name for p in setup_e2e_plugin_registry.plugins}

    missing = expected_plugins - registered
    assert not missing, (
        f"Plugins failed to register (import errors): {missing}. "
        f"Registered: {registered}"
    )


def test_each_plugin_has_required_interface():
    """
    Every plugin module must import cleanly and have execute/can_activate/priority.
    """
    from GramAddict.core.behaviors.ad_guard import AdGuardPlugin
    from GramAddict.core.behaviors.anomaly_handler import AnomalyHandlerPlugin
    from GramAddict.core.behaviors.close_friends_guard import CloseFriendsGuardPlugin
    from GramAddict.core.behaviors.comment import CommentPlugin
    from GramAddict.core.behaviors.darwin_dwell import DarwinDwellPlugin
    from GramAddict.core.behaviors.like import LikePlugin
    from GramAddict.core.behaviors.obstacle_guard import ObstacleGuardPlugin
    from GramAddict.core.behaviors.perfect_snapping import PerfectSnappingPlugin
    from GramAddict.core.behaviors.post_data_extraction import PostDataExtractionPlugin
    from GramAddict.core.behaviors.post_interaction import PostInteractionPlugin
    from GramAddict.core.behaviors.resonance_evaluator import ResonanceEvaluatorPlugin

    for cls in [
        AdGuardPlugin, AnomalyHandlerPlugin, CloseFriendsGuardPlugin,
        CommentPlugin, DarwinDwellPlugin, LikePlugin, ObstacleGuardPlugin,
        PerfectSnappingPlugin, PostDataExtractionPlugin, PostInteractionPlugin,
        ResonanceEvaluatorPlugin,
    ]:
        plugin = cls()
        assert hasattr(plugin, "execute"), f"{cls.__name__} missing execute()"
        assert hasattr(plugin, "can_activate"), f"{cls.__name__} missing can_activate()"
        assert hasattr(plugin, "priority"), f"{cls.__name__} missing priority"
