"""Guard: the scores router must forward the sentiment-adjustment breakdown fields.

get_score computes base_score / sentiment_adjustment, but the router builds the
response model by hand — so it has to explicitly pass those through, or the ticker
page loses the "Composite = Base + Sentiment" caption and the ± dimension marker.
"""

from app.routers.scores import _map_composite_breakdown


def test_forwards_sentiment_fields():
    raw = {
        "weights": {"technical": 0.25},
        "available_dimensions": ["technical"],
        "missing_dimensions": ["sentiment"],
        "renormalized_weights": {"technical": 1.0},
        "formula": "x",
        "base_score": 78.0,
        "sentiment_score": 75.0,
        "sentiment_adjustment": 5.0,
        "max_sentiment_adjustment": 10.0,
    }
    model = _map_composite_breakdown(raw)
    assert model is not None
    assert model.base_score == 78.0
    assert model.sentiment_score == 75.0
    assert model.sentiment_adjustment == 5.0
    assert model.max_sentiment_adjustment == 10.0


def test_none_stays_none():
    assert _map_composite_breakdown(None) is None


def test_old_shaped_dict_defaults_new_fields_to_none():
    raw = {
        "weights": {},
        "available_dimensions": [],
        "missing_dimensions": [],
        "renormalized_weights": {},
        "formula": "x",
    }
    model = _map_composite_breakdown(raw)
    assert model.sentiment_adjustment is None
    assert model.base_score is None
