feat(signal_v2-phase3a): main.py lifespan integrates KIS client + WS
AppContext extended with kis_client + kis_ws. lifespan: - If KIS_APP_KEY set: create KISClient + KISWebSocket, fetch portfolio, subscribe WebSocket H0STASP0 for holdings. - If unset: WARNING log, signal_v2 still serves /health (no KIS data). - Shutdown closes kis_ws → kis_client → stock client in order. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -34,3 +34,20 @@ def test_startup_warns_if_webai_api_key_missing(monkeypatch, caplog):
|
||||
with TestClient(main_mod.app) as client:
|
||||
client.get("/health")
|
||||
assert any("WEBAI_API_KEY" in rec.message for rec in caplog.records)
|
||||
|
||||
|
||||
def test_startup_warns_if_kis_app_key_missing(monkeypatch, caplog):
|
||||
"""KIS_APP_KEY 미설정 시 startup WARNING (KIS 호출 disabled)."""
|
||||
monkeypatch.setenv("STOCK_API_URL", "https://test.stock.local")
|
||||
monkeypatch.setenv("WEBAI_API_KEY", "test-secret")
|
||||
monkeypatch.delenv("KIS_APP_KEY", raising=False)
|
||||
|
||||
import importlib
|
||||
from signal_v2 import config as cfg
|
||||
importlib.reload(cfg)
|
||||
from signal_v2 import main as main_mod
|
||||
importlib.reload(main_mod)
|
||||
with caplog.at_level(logging.WARNING, logger="signal_v2.main"):
|
||||
with TestClient(main_mod.app) as client:
|
||||
client.get("/health")
|
||||
assert any("KIS_APP_KEY" in rec.message for rec in caplog.records)
|
||||
|
||||
Reference in New Issue
Block a user