"""History state behavior with shallow and deep history.

Tests exercise shallow history (remembers last direct child), deep history
(remembers exact leaf in nested compounds), default transitions on first visit,
multiple exit/reentry cycles, and the history_values dict.

Theme: Gollum's dual personality — remembers which was active.
"""

import pytest

from tests.machines.history.deep_memory_of_moria import DeepMemoryOfMoria
from tests.machines.history.gollum_personality import GollumPersonality
from tests.machines.history.gollum_personality_default_gollum import GollumPersonalityDefaultGollum
from tests.machines.history.gollum_personality_with_default import GollumPersonalityWithDefault
from tests.machines.history.shallow_moria import ShallowMoria


@pytest.mark.timeout(5)
class TestHistoryStates:
    async def test_shallow_history_remembers_last_child(self, sm_runner):
        """Exit compound, re-enter via history -> restores last active child."""
        sm = await sm_runner.start(GollumPersonality)
        await sm_runner.send(sm, "dark_side")
        assert "gollum" in sm.configuration_values

        await sm_runner.send(sm, "leave")
        assert {"outside"} == set(sm.configuration_values)

        await sm_runner.send(sm, "return_via_history")
        assert "gollum" in sm.configuration_values
        assert "personality" in sm.configuration_values

    async def test_shallow_history_default_on_first_visit(self, sm_runner):
        """No prior visit -> history uses default transition target."""
        sm = await sm_runner.start(GollumPersonalityWithDefault)
        assert {"outside"} == set(sm.configuration_values)

        await sm_runner.send(sm, "enter_via_history")
        assert "smeagol" in sm.configuration_values
=====
=====
8:from statemachine.contrib.diagram import DotGraphMachine
101:    graph = DotGraphMachine(machine)
285:def test_compound_state_diagram():
301:    graph = DotGraphMachine(SM)
308:def test_parallel_state_diagram():
326:    graph = DotGraphMachine(SM)
334:def test_nested_compound_state_diagram():
350:    graph = DotGraphMachine(SM)
368:    dot = DotGraphMachine(SM)().to_string()
385:    dot = DotGraphMachine(SM)().to_string()
