from gal_fingerprint_i.validation import validate_profile_payload, canonical_kappa_grid, vulnerability, median
import numpy as np


def test_valid_synthetic_profile_contract():
    values = [0.0, 0.35, 0.9, 1.4]
    gaps = np.diff(values)
    med = median(gaps[gaps > 0])
    profile = []
    for kappa in canonical_kappa_grid():
        eps = float(kappa * med)
        nu, count = vulnerability(values, eps)
        profile.append({"kappa": float(kappa), "epsilon": eps, "nu": nu, "vulnCount": count, "inv": 0.0, "rho": 0.0, "Ak": 1.0})
    expected = {"item_id": "x", "ladder_name": "G", "input_sha256": "h", "values": values}
    payload = {
        "item_id": "x", "ladder_name": "G", "input_sha256": "h", "engine": "STRUC-I", "engine_version": "1.0.4",
        "settings": {"kappa_min": 0.01, "kappa_max": 1.0, "kappa_steps": 40, "mc_runs": 2000}, "profile": profile,
    }
    assert validate_profile_payload(payload, expected) == []
