import pytest
from launch_controller import BOUNDARIES, Blocked, BoundaryModel

def test_happy_order_exactly_one():
    m=BoundaryModel()
    for b in BOUNDARIES:m.cross(b)
    assert m.sent==1 and m.attempted

def test_every_order_violation_fails():
    for i in range(len(BOUNDARIES)-1):
        m=BoundaryModel()
        with pytest.raises(Blocked):m.cross(BOUNDARIES[i+1])

@pytest.mark.parametrize('where', range(len(BOUNDARIES)))
@pytest.mark.parametrize('side', ('before','after'))
def test_crash_each_boundary_never_duplicates(where,side):
    m=BoundaryModel()
    for b in BOUNDARIES[:where]:m.cross(b)
    with pytest.raises(RuntimeError):m.cross(BOUNDARIES[where],**{f'crash_{side}':True})
    assert m.sent<=1

def test_duplicate_invocation_and_unknown_outcome_are_fail_closed():
    m=BoundaryModel()
    for b in BOUNDARIES[:-2]:m.cross(b)
    m.cross('invite_intent')
    with pytest.raises(Blocked):m.cross('invite_intent')
    with pytest.raises(Blocked):m.cross('invite_result',unknown=True)
    assert m.sent==0
