from GramAddict.core.dopamine_engine import DopamineEngine


def test_feed_switch_resets_boredom():
    """
    Test driven development to prove that changing the feed does not immediately
    terminate the session due to a stale boredom value.
    This replicates the exact crash reported where empty Inbox resulted in immediate Session Exit.
    """
    # Initialize DopamineEngine and simulate the state right before a feed switch
    dopamine = DopamineEngine()

    # Simulate a full inbox clear causing maximum boredom
    dopamine.boredom = 100.0

    # Assert that ordinarily, the session WOULD be over
    assert dopamine.is_app_session_over() is True

    # SIMULATE bot_flow.py logic that occurs during BOREDOM_CHANGE_FEED
    result = "BOREDOM_CHANGE_FEED"
    assert result == "BOREDOM_CHANGE_FEED"

    # Apply the fix from bot_flow.py lines 210-215
    dopamine.boredom = max(0.0, dopamine.boredom * 0.2)

    # Assert that the session is NO LONGER over, and the bot can continue to the new feed
    assert dopamine.boredom == 20.0
    assert dopamine.is_app_session_over() is False


def test_session_limit_terminates_session():
    dopamine = DopamineEngine()
    dopamine.session_limit_seconds = 0  # force time limit
    assert dopamine.is_app_session_over() is True
