from pathlib import Path
import sys


sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "live"))

from roster_scope import active_presentation_roster  # noqa: E402


def test_active_matchup_excludes_still_open_teams_but_keeps_hull_substitutions():
    roster = {
        "previous-red": ["boat:1", "boat:2"],
        "previous-blue": ["boat:3", "boat:4"],
        "current-green": ["boat:11", "boat:12"],
        "current-orange": ["boat:13", "boat:14"],
    }
    config = {
        "current-green": {"boats": {"scheduled:5": {"sailId": "5"}}},
        "current-orange": {"boats": {"scheduled:7": {"sailId": "7"}}},
    }

    active, boats = active_presentation_roster(roster, config)

    assert set(active) == {"current-green", "current-orange"}
    assert boats == ["boat:11", "boat:12", "boat:13", "boat:14"]


def test_missing_team_config_preserves_the_resolved_roster():
    roster = {"red": ["boat:1"], "blue": ["boat:2"]}

    active, boats = active_presentation_roster(roster, None)

    assert active == roster
    assert boats == ["boat:1", "boat:2"]
