File size: 3,283 Bytes
bb3fbf9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""

Tests for Phase Transitions.

Verifies that invariants hold and state is securely cleaned up when moving between phases.

"""

from engine.game.enums import Phase


class TestPhaseTransitions:
    def test_main_to_live_set_clears_looked_cards(self, validated_game_state):
        """

        Verify that transitioning from MAIN to LIVE_SET clears 'looked_cards'.

        Stale looked_cards can cause information leaks or illegal actions.

        """
        gs = validated_game_state
        p = gs.players[0]

        # Setup: MAIN phase, looked_cards populated (simulating a "Look at top 3" ability)
        # We need to simulate P2 (last player) ending turn to trigger LIVE_SET
        gs.phase = Phase.MAIN
        gs.current_player = 1  # Player 1 (2nd player)
        gs.looked_cards = [101, 102, 103]

        # Action 0 in MAIN = End Main Phase
        gs = gs.step(0)

        # Assert
        assert gs.phase == Phase.LIVE_SET
        assert gs.looked_cards == [], "looked_cards should be cleared after MAIN phase"

    def test_live_result_to_active_clears_performance_data(self, validated_game_state):
        """

        Verify that transitioning from LIVE_RESULT to ACTIVE (next turn) clears performance data.

        """
        gs = validated_game_state
        p = gs.players[0]

        # Setup: LIVE_RESULT phase
        gs.phase = Phase.LIVE_RESULT

        # Dirty state that should be cleaned
        gs.performance_results = {"p1": 5000, "p2": 4000}
        p.performance_abilities_processed = True

        # Setup: Simulate the state where we are waiting for user confirmation
        # The engine requires the user to acknowledge results ("CONTINUE_LIVE_RESULT")
        # before transitioning to ACTIVE and clearing data.
        gs.pending_choices = [("CONTINUE_LIVE_RESULT", {"player_id": 0})]
        gs.current_player = 0

        # Action 0 = Select first choice (Confirm)
        gs = gs.step(0)

        # Assert
        # Should be back to start of turn sequence (ACTIVE)
        # Note: Depending on engine logic, it might go to P2 LIVE_RESULT if multiplayer?
        # Assuming verified fixture has 2 players.
        # But if it's new turn, phase should be ACTIVE (Phase 1).

        assert gs.performance_results == {}, "performance_results should be cleared"
        assert gs.players[0].performance_abilities_processed is False, "performance processing flag should be reset"

    def test_turn_change_resets_temporary_flags(self, validated_game_state):
        """

        Verify that 'members_played_this_turn' and other turn-scoped flags are reset.

        """
        gs = validated_game_state
        p = gs.players[0]

        # Setup: P1 (next player) has dirty state that needs clearing
        gs.players[1].members_played_this_turn.fill(True)

        # Setup: Pending choice to confirm results and advance
        gs.pending_choices = [("CONTINUE_LIVE_RESULT", {"player_id": 0})]
        gs.current_player = 0

        # Transition
        gs = gs.step(0)  # Confirm -> _finish_live_result -> _do_active_phase (P1)

        # Check P1 (current player)
        assert not any(gs.players[1].members_played_this_turn), "P1's history should be cleared"