← Volver al índice · 60_tests_smoke

Suite de tests y smoke

72 tests unitarios + smoke prod cada hora (cron) con log en /var/log/tokenstree-smoke.log.

Reporte fase 60_tests_smoke — OK

Estado: 72 tests pass en 0.6s. Smoke prod exit 0. Cron horario instalado. Producción intacta.

Archivos (en 213.165.80.157:/opt/trading-web/)

Path md5
tests/__init__.py d41d8cd98f00b204e9800998ecf8427e
tests/_common.py 4dbbfdb44e9fae1036a05d9844e135ee
tests/test_quant_engine.py 8899984e1c6ba86f0f4411f5e4a8e916
tests/test_agents.py c237d0c4c2dc8d7c929c30a653293239
tests/test_metrics_pro.py b854599e596299a913fe5f973fd69723
tests/test_calibration.py 24b1653f0eb9a25faf9ccf1bfd378533
tests/test_backtest_engine.py 02d28a3adca578030b0a1d9257592a6a
tests/test_risk.py a1a00f812d96457ad7f17031f7382df1
run_tests.sh da71a2b367ffa02f7153aa053af572a4
scripts/smoke_prod.sh 717aeaca6b3753afd347a7bb04b378da

Todos los ficheros son nuevos — ningún módulo de producción fue editado, no hubo necesidad de backup.

Cobertura tests (72 total)

  • quant_engine: GBM (prob_up↑/≈50/↓, short-empty, keys), Merton jump-detección, GARCH vol ranking, Kalman ALCISTA/BAJISTA, HMM 2-régimen + up-bias, NaN-safety sobre serie casi-constante.
  • agents: score∈[0,100], OHLCV alcista→score≥50, bajista→score≤50, sin datos→neutral, targets consistentes con dirección; master_agent no crashea con news vacío.
  • metrics_pro: Sharpe (NaN en var=0, positivo en mean>0), Sortino (∞ con all-positive), MaxDD (0 en creciente, −0.5 conocido), ProfitFactor (∞/0/2.0 conocido), WinRate/Expectancy, Calmar, hit_rate_by_confidence_bucket (todos aciertos→1.0, todos fallos→0.0).
  • calibration: pav_fit monotonía, IsotonicCalibrator fit anti-cal produce knots no-decrecientes, round-trip save/load idéntico, clamp de salida.
  • backtest_engine: insufficient_data marker, history slice size == train_window (no-lookahead), always-up en trend alcista es positivo, always-down negativo, summarize shape.
  • risk: Kelly (edge=0→0, edge<0→0, caso conocido 0.10, cap, b≤0), VolTarget (high-vol scaled, 1x matched, low-vol levered, target=0→0), CorrCap (correlación 0.95 reduce, 0.0 preserva, hard cap), size_pipeline dict, compute_risk_score bounds + monotonía.

Cron

0 * * * * /opt/trading-web/scripts/smoke_prod.sh >> /var/log/tokenstree-smoke.log 2>&1

/var/log/tokenstree-smoke.log ya tiene entradas OK (chown vfalbor). smoke_prod.sh también emite a syslog con tag tokenstree-smoke (journalctl -t tokenstree-smoke) para alerting futuro.

Verificación final de producción

  • GET /200
  • GET /report200 (contiene "Informe Diario", 2 ocurrencias)
  • GET /analyze200
  • /api/prices → 200 + JSON válido
  • /history → 200 + contiene <tr

Caveats honestos

  • test_agents.py monkey-patcha agents._fetch_ohlcv (yfinance boundary) en lugar de golpear red; rápido y determinista pero no valida integración real de yfinance.
  • La bullish/bearish OHLCV sintética mete un pullback tardío (últimos 15 bars) — necesario porque technical_agent penaliza RSI>70 y BB>0.9; sin el pullback, una tendencia alcista monótona genera score<50 por sobrecompra (comportamiento correcto del módulo real, pero haría falso el test ingenuo). Esto revela que el score técnico es fuertemente mean-reverting en extremos — documentado por si se reinterpreta.
  • master_agent imprime a stdout ([MasterAgent] Analizando ...) durante el test — cosmético, no rompe unittest.
  • Los tests no cubren macro_agent, fundamental_agent, sentiment_agent (I/O-bound via yfinance/RSS) ni ml_ensemble_predict (requiere sklearn + BD de sentiment); quedan fuera por el alcance "suite mínima".
  • Suite no valida la BD productiva en ningún test (todo pasa por tempfile o datos sintéticos).