"""cine i2i 제공자에 MAI 를 더한다 (2026-09-08 사용자 지시).

fal 의 Reve 중계가 08-29 이후 죽어 있어(실측: 잔액 정상 · 같은 키로 다른 모델
200 · fal 자기 예제도 500) grok 으로 임시 전환해 3편을 완주했다. 그 뒤
`microsoft/mai-image-2.6` 이 OpenRouter 에 올라와 1화 24샷을 같은 프롬프트로
돌려 전부 성공했고, 사용자가 이것을 쓰기로 정했다.

★운반층이 Grok 과 같다(OpenRouter chat/completions · `modalities:["image"]`).
 그래서 client 를 새로 쓰지 않고 **모델만 갈아 끼운다** — 새 운반 코드는
 새 결함을 들여온다.
★신원에는 alias 가 아니라 **물리 모델 문자열**이 들어가야 한다. 안 그러면
 판을 갈아도 지문이 안 움직여 옛 산출이 재사용된다.
"""
from __future__ import annotations

import pytest

from app.modules.pipeline import cine_provider as cp


def test_mai_가_아는_제공자다():
    assert "mai" in cp.KNOWN_PROVIDERS


def test_모르는_제공자는_조용히_안_되돌린다(monkeypatch):
    """★기본값으로 되돌리면 운영자는 딴 모델로 도는 줄 안다."""
    monkeypatch.setattr("app.core.config.settings.still_cine_provider", "nope")
    with pytest.raises(ValueError):
        cp.resolve_cine_provider()


def test_mai_신원에_물리_모델이_실린다():
    ident = cp.cine_provider_identity("mai")
    assert ident["provider"] == "mai"
    assert ident["endpoint"] == cp.GROK_ENDPOINT
    from app.core.config import settings
    assert ident["model"] == settings.mai_image_model
    assert ident["model"], "물리 모델 문자열이 비었다 — 지문이 판을 못 가른다"


def test_mai_신원은_grok_과_다르다():
    """★같으면 제공자를 갈아도 옛 산출이 그대로 재사용된다."""
    assert cp.cine_provider_identity("mai") != cp.cine_provider_identity("grok")
    assert not cp.is_legacy_identity(cp.cine_provider_identity("mai"))


def test_mai_는_grok_운반층을_모델만_바꿔_쓴다():
    from app.core.config import settings
    from app.modules.llm.grok_image_client import GrokImageClient

    c = cp.build_cine_client("mai")
    assert isinstance(c, GrokImageClient), "새 운반 코드를 들이지 않는다"
    assert c._model == settings.mai_image_model


def test_설정_검증이_mai_를_받는다():
    """startup 검증이 막으면 `.env` 에 적어도 안 뜬다."""
    from app.core.config import Settings

    v = Settings._still_cine_provider_known.__func__(Settings, "mai")
    assert v == "mai"
