"""Test offline del logger forward della vol term-structure (2026-06-26). La STORIA per-scadenza
non e' pubblica su Deribit -> calendar-vol non backtestabile ora; questo logger costruisce il dataset
in avanti. Si testa la pura interpolazione ai tenor fissi. Diario 2026-06-26-vol-termstructure-feasibility.md."""
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT))
sys.path.insert(0, str(ROOT / "scripts" / "research"))

from log_vol_termstructure import build_row, TENORS  # type: ignore


def test_build_row_interpolates_all_tenors():
    """Curva sintetica in contango -> riga con tutti i tenor + slope positivo."""
    curve = [(7, 40.0), (30, 45.0), (90, 50.0), (180, 55.0)]
    row = build_row(100000.0, curve, now_ms=1_700_000_000_000)
    assert all(f"iv_{t}d" in row for t in TENORS)
    assert abs(row["iv_30d"] - 45.0) < 1e-6           # nodo esatto
    assert 45.0 < row["iv_60d"] < 50.0                # interpolato tra 30 e 90
    assert row["slope_7_180"] > 0                      # contango -> slope positivo


def test_build_row_needs_two_points():
    assert build_row(100.0, [(30, 50.0)], now_ms=1_700_000_000_000) is None
    assert build_row(100.0, [], now_ms=1_700_000_000_000) is None
