"""Test del dashboard (src/live/dashboard.py) — solo la logica pura, niente rete/HTTP. Copre il banner degli ALERT operativi del book live: i tre segnali di health (feed SKH, posizione non leggibile, equity fallback) che book_execute manda su Telegram devono comparire anche sul dashboard. Verde quando pulito, rosso con le righe quando in errore. """ import sys from pathlib import Path PROJECT_ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(PROJECT_ROOT)) from src.live.dashboard import _alerts_banner def test_banner_green_when_no_alerts(): h = _alerts_banner({}) assert "nessun alert" in h assert "class=g" in h # stile verde assert "ALERT OPERATIVI" not in h # nessun banner rosso def test_banner_shows_all_three_alerts(): h = _alerts_banner({ "skh_error": "RuntimeError: feed 5m giu", "pos_error": "posizione non leggibile, assunta FLAT: BTC", "eq_fallback": "sizing su paper_cap $2,000", }) assert "ALERT OPERATIVI BOOK LIVE" in h and "class=r" in h # banner rosso # ogni alert: label descrittiva + messaggio grezzo assert "Feed SKH01 fallito" in h and "feed 5m giu" in h assert "Posizione reale non leggibile" in h and "assunta FLAT: BTC" in h assert "Equity reale non leggibile" in h and "paper_cap $2,000" in h def test_banner_partial_alert_only_shows_present(): h = _alerts_banner({"pos_error": "BTC non leggibile"}) assert "Posizione reale non leggibile" in h and "BTC non leggibile" in h assert "Feed SKH01" not in h and "Equity reale" not in h # solo quello presente def test_banner_unknown_key_falls_back_to_key_name(): h = _alerts_banner({"book_report": "ImportError: boom"}) assert "Book report non calcolabile" in h and "boom" in h