"""
P2-9 & P2-10: ScreenTopology Completeness

TDD RED: These tests enforce that:
1. COMMENTS and SEARCH_RESULTS screens are reachable in the graph.
2. OTHER_PROFILE transitions are deterministic (no "press back" to HOME_FEED).
3. The pathfinder can find routes to these critical screens.
"""

import pytest
from GramAddict.core.screen_topology import ScreenTopology
from GramAddict.core.goap import ScreenType

class TestTopologyCompleteness:
    def test_comments_reachability(self):
        """RED: Pathfinder should find a route FROM COMMENTS back to HOME_FEED."""
        # This requires COMMENTS to have a transition back to somewhere reachable
        route = ScreenTopology.find_route(ScreenType.COMMENTS, ScreenType.HOME_FEED)
        assert route is not None
        assert "press back" in [step[0] for step in route]

    def test_search_results_reachability(self):
        """RED: Pathfinder should find a route FROM SEARCH_RESULTS back to HOME_FEED."""
        route = ScreenTopology.find_route(ScreenType.SEARCH_RESULTS, ScreenType.HOME_FEED)
        assert route is not None

    def test_other_profile_to_home_is_not_back(self):
        """RED: Moving from OTHER_PROFILE to HOME_FEED should NOT use 'press back'."""
        route = ScreenTopology.find_route(ScreenType.OTHER_PROFILE, ScreenType.HOME_FEED)
        assert route is not None
        steps = [step[0] for step in route]
        # 'press back' is forbidden for this transition because it's non-deterministic
        assert "press back" not in steps
        assert "tap home tab" in steps

    def test_goal_map_contains_missing_screens(self):
        """RED: Goals like 'open search' should map to SEARCH_RESULTS."""
        # Note: SEARCH_RESULTS might be reached via 'tap explore tab' + 'tap search bar'
        # but the goal should still be valid.
        assert ScreenTopology.goal_to_target_screen("open search") == ScreenType.SEARCH_RESULTS
