"""Tier-range invariants — the selection model's load-bearing properties.

The supervisor's whole tier story rests on: tier ranges are nested
(`0-N` ⊆ `0-(N+1)`), unmarked tests fall to DEFAULT_TIER, and a
multi-marked test takes the HIGHEST tier (conservative budgeting). If any
of these silently breaks, `--tier` selection is wrong and nobody notices.
(No Hypothesis — the supervisor stays stdlib-only per TS-23.)
"""

from __future__ import annotations

from mgf.test_supervisor.tiers import (
    DEFAULT_TIER,
    MARKER_TIER,
    parse_tier_range,
    tier_for_markers,
)


def test_tier_ranges_are_nested_subsets() -> None:
    for hi in range(3):
        assert parse_tier_range(f"0-{hi}") < parse_tier_range(f"0-{hi + 1}")


def test_full_range_is_all_four_tiers() -> None:
    assert parse_tier_range("0-3") == {0, 1, 2, 3}


def test_single_tier_is_singleton() -> None:
    for t in range(4):
        assert parse_tier_range(str(t)) == {t}


def test_unmarked_test_is_default_tier() -> None:
    assert tier_for_markers(()) == DEFAULT_TIER


def test_highest_marker_wins() -> None:
    # smoke=0, stress=3 → the conservative (highest) tier is chosen.
    assert tier_for_markers(("smoke", "stress")) == 3
    assert tier_for_markers(("contract", "perf")) == MARKER_TIER["perf"]


def test_every_marker_maps_into_range() -> None:
    for marker, tier in MARKER_TIER.items():
        assert 0 <= tier <= 3, f"{marker} → out-of-range tier {tier}"
