- 스윙 체결가 확인 전 executed_price NULL + fill_sweep, 진입가 resolve(ActiveTrade↔Portfolio), 0체결/부분체결 매수 장부 원복 - DT 고아 감지(근거 한정)·0체결 매도 복원·stale 점검 확대, 시간손절 -0.3% 원복 - 폴백 손절 ATR 캐시, 거래량부족-차단 신호 매수 차단, 현금 5% 유보 재적용, MDD peak/reset 수정 - KIS 서킷브레이커 청산 우회·경보, db_worker 재큐잉 순서, heartbeat·health-watch 사이드카 - 실시간 WS 재구독·41건 우선순위·다건 프레임 분할, 차트 샘플 제거·당일봉 합성, WS 서브프로토콜 인증 - 프론트: 미관리 그룹·확인 모달·차트 실시간 반영·예수금 표시 정정 - 전문가 에이전트 6종 추가(.claude/agents) - 유닛 스위트 2667 passed (소켓 차단 하), tsc OK Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y83Za98XsNw9zuA4FTUytN
60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
"""하드닝 R4 — MDD 단계 전이 텔레그램 재시도/참조 보관 회귀 테스트."""
|
|
import asyncio
|
|
from unittest.mock import AsyncMock
|
|
|
|
import pytest
|
|
|
|
|
|
async def _drain():
|
|
import app.services.mdd_manager as m
|
|
while m._alert_tasks:
|
|
await asyncio.gather(*list(m._alert_tasks), return_exceptions=True)
|
|
|
|
|
|
@pytest.fixture
|
|
def env(monkeypatch):
|
|
import app.services.mdd_manager as m
|
|
import app.services.telegram_notifier as tn
|
|
monkeypatch.setattr(m, "_alert_backoff_v2", lambda: 0.0)
|
|
monkeypatch.setattr(m, "_alert_retries_v2", lambda: 2)
|
|
mgr = m.MDDManager()
|
|
monkeypatch.setattr(mgr, "_write_state_v2", AsyncMock())
|
|
return m, tn, mgr
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_retries_on_exception_then_succeeds(env, monkeypatch):
|
|
m, tn, mgr = env
|
|
mock = AsyncMock(side_effect=[RuntimeError("boom"), False, None])
|
|
monkeypatch.setattr(tn.telegram_notifier, "notify_mdd_warning", mock)
|
|
await mgr.update(100.0)
|
|
r = await mgr.update(100.0 * (1 + (-10.5) / 100))
|
|
assert r["action"] == "REDUCE_AND_PAUSE"
|
|
assert m._alert_tasks # 참조 보관
|
|
await _drain()
|
|
assert mock.await_count == 3
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_final_failure_logged_error(env, monkeypatch, caplog):
|
|
m, tn, mgr = env
|
|
mock = AsyncMock(return_value=False)
|
|
monkeypatch.setattr(tn.telegram_notifier, "notify_mdd_warning", mock)
|
|
await mgr.update(100.0)
|
|
r = await mgr.update(79.0)
|
|
assert r["action"] == "FORCE_REDUCE"
|
|
with caplog.at_level("ERROR"):
|
|
await _drain()
|
|
assert mock.await_count == m._alert_retries_v2() + 1
|
|
assert any("최종 실패" in rec.message for rec in caplog.records)
|
|
assert not m._alert_tasks
|
|
|
|
|
|
def test_no_running_loop_logs_error_not_raise(env, caplog):
|
|
m, tn, mgr = env
|
|
mgr.peak_balance = 100.0
|
|
with caplog.at_level("ERROR"):
|
|
r = mgr._update_locked_v2(79.0)
|
|
assert r["action"] == "FORCE_REDUCE"
|
|
assert any("예약 실패" in rec.message for rec in caplog.records)
|