Files
Adriano Dal Pastro ccf5e38101 feat(dashboard): banner alert operativi del book live (SKH/posizione/equity)
Il dashboard non mostrava nessuno dei tre segnali di health introdotti nei
commit 31369b3 (skh_error) e 5670469 (pos_error/eq_fallback): finivano solo su
Telegram + log cron, invisibili a chi guarda il monitor. pos_error/eq_fallback
erano gia' in shadow_report (usato dal dashboard) ma ignorati dal template;
skh_error non era nemmeno recuperato (il dashboard usa shadow_report, non
book_report).

Fix:
- _alerts_banner(): helper puro (verde "nessun alert" se pulito, rosso con una
  riga per errore) che rispecchia i tre alert di book_execute.
- build(): raccoglie pos_error/eq_fallback dallo shadow gia' fetchato + skh_error
  da book_report(offline=True) (feed certificato, nessuna rete extra).
- html(): renderizza il banner in cima alla sezione ① LIVE.
- tests/test_dashboard.py: +4 (verde, 3 alert, parziale, chiave-ignota).

Suite 160/160. Render end-to-end verde (conto sano $598.06 flat). Chiude la
copertura: i 3 pattern di errore silenzioso ora visibili su log + Telegram + dashboard.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-01 22:47:35 +00:00

45 lines
1.8 KiB
Python

"""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