"""ORCH-036 TC-16: STAGE_TRANSITIONS for deploy are unchanged (AC-10).

ORCH-036 only changes HOW the deploy verdict is produced (a deterministic
finalizer) — it must NOT touch the state machine. The deploy edge keeps its
exact transition (deploy -> done), no in-line agent (None), and the gate
``check_deploy_status``. The deploy-staging edge is likewise untouched.
"""

import os

os.environ.setdefault("ORCH_PLANE_API_TOKEN", "test-token")
os.environ.setdefault("ORCH_GITEA_TOKEN", "test-token")

from src.stages import (  # noqa: E402
    STAGE_TRANSITIONS,
    get_agent_for_stage,
    get_next_stage,
    get_qg_for_stage,
)


def test_tc16_deploy_transition_unchanged():
    assert STAGE_TRANSITIONS["deploy"] == {
        "next": "done", "agent": None, "qg": "check_deploy_status"
    }
    assert get_next_stage("deploy") == "done"
    assert get_agent_for_stage("deploy") is None
    assert get_qg_for_stage("deploy") == "check_deploy_status"


def test_tc16_deploy_staging_transition_unchanged():
    assert STAGE_TRANSITIONS["deploy-staging"] == {
        "next": "deploy", "agent": "deployer", "qg": "check_staging_status"
    }
    assert get_next_stage("deploy-staging") == "deploy"
    assert get_agent_for_stage("deploy-staging") == "deployer"
    assert get_qg_for_stage("deploy-staging") == "check_staging_status"


def test_tc16_done_is_terminal():
    assert get_next_stage("done") is None


# ---------------------------------------------------------------------------
# ORCH-071 TC-16: the merge-verify under-gate is an EDGE sub-gate врезанный in
# advance_stage (like the merge-gate), NOT a new STAGE_TRANSITIONS edge and NOT a
# new registered QG. The state machine + QG registry must stay untouched.
# ---------------------------------------------------------------------------
def test_tc16_merge_verify_adds_no_stage_or_qg():
    # The deploy->done edge keeps its single gate (no second registered QG).
    assert STAGE_TRANSITIONS["deploy"]["qg"] == "check_deploy_status"
    # No new stage was introduced for merge verification.
    assert "merge-verify" not in STAGE_TRANSITIONS
    assert "merge_verify" not in STAGE_TRANSITIONS

    from src.qg.checks import QG_CHECKS
    # The under-gate is NOT a registered quality-gate check.
    assert "check_merged_to_main" not in QG_CHECKS
    assert "check_merge_verify" not in QG_CHECKS
