from unittest.mock import MagicMock

from GramAddict.core.goap import GoalPlanner, ScreenType


def test_goal_planner_uses_hd_map_over_linguistic_match():
    """
    Tests that the GoalPlanner uses the HD Map (ScreenTopology) as its
    primary routing strategy, even during Blank Start discovery.
    The HD Map returns canonical action intents that the TelepathicEngine
    interprets — not just available_actions from the XML dump.
    """
    planner = GoalPlanner("test_user")

    # Mock the internal structures
    planner.knowledge = MagicMock()
    planner.knowledge.is_trap.return_value = False
    planner.knowledge.get_requirements.return_value = None  # Force Blank Start

    # Simulate current screen
    screen = {
        "screen_type": ScreenType.HOME_FEED,
        "available_actions": ["tap explore grid", "tap messages"],
        "context": {},
    }

    goal = "open explore feed"

    result = planner.plan_next_step(goal, screen, explored_nav_actions=set())

    # HD Map routes HOME_FEED → EXPLORE_GRID via "tap explore tab"
    assert result == "tap explore tab", (
        f"Expected HD Map to route via 'tap explore tab', got '{result}'. "
        "The HD Map should override linguistic matching as the primary strategy."
    )
