from fastapi.testclient import TestClient
from gal_fingerprint_i.web import app


def test_status_and_validation_endpoints():
    client = TestClient(app)
    status = client.get("/api/status")
    assert status.status_code == 200
    data = status.json()
    assert data["chamber"] == "GAL-FINGERPRINT-I"
    assert data["version"] == "0.2.2"
    assert data["engine"]["mc_runs"] == 2000
    assert data["gate_b"]["gate_b_pass"] is True
    validation = client.post("/api/validate")
    assert validation.status_code == 200
    payload = validation.json()
    assert payload["validation_pass"] is True
    assert payload["controller_provenance_correct"] is True
    assert payload["deterministic_random_thinning_split"] is True


def test_only_four_gate_c_primary_modes_are_authorized():
    client = TestClient(app)
    for mode in ["REPEAT", "THINNING_N10_RANDOM", "NULL_GAP_ORDER", "NULL_UNIFORM_RANGE", "THINNING_N10"]:
        result = client.post("/api/runs", json={"mode": mode, "execution_scope": "REGISTERED_EXECUTION"})
        assert result.status_code == 403, (mode, result.text)
