feat(stock): /api/stock/trade-alerts 응답에 조건별 근거(reason) 문자열 추가

FE가 detail(객체)을 그대로 렌더해 React #31 크래시 → 안전한 텍스트 필드 제공.
condition_reason(조건→한줄근거), agent-office telegram_trade._COND_REASON과 동일 유지.
This commit is contained in:
2026-07-09 12:47:34 +09:00
parent 9baea3a0e2
commit b8229c0ffa
3 changed files with 34 additions and 2 deletions

View File

@@ -70,6 +70,17 @@ def test_report_refire_after_cooldown_alerts(client, monkeypatch):
assert r.json()["new_alerts"] == 1
def test_trade_alerts_history_includes_reason_string(client):
"""이력 API가 조건별 사람이 읽는 근거(reason) 문자열을 함께 반환한다(FE가 detail 객체 대신 렌더)."""
firing = [{"ticker": "005930", "name": "삼성", "kind": "sell",
"condition": "sell_ma_break", "price": 60000,
"detail": {"ma50": 1, "ma200": 2, "severity": "high"}}]
with patch("app.trade_alerts.notify_agent_office", return_value=True):
_report(client, firing)
alerts = client.get("/api/stock/trade-alerts?days=1").json()["alerts"]
assert isinstance(alerts[0]["reason"], str) and len(alerts[0]["reason"]) > 3
def test_report_resolves_stock_name_from_watchlist(client):
"""워커 firing에 name이 없어도 NAS가 종목명을 해석해 알림에 포함한다."""
from app import db