fix: 대시보드 mode 배지 os.getenv 대신 settings.MODE 사용 (#237)
Some checks failed
CI / test (pull_request) Has been cancelled
Some checks failed
CI / test (pull_request) Has been cancelled
os.getenv("MODE")는 .env 파일을 읽지 못해 항상 paper를 반환함.
create_dashboard_app에 mode 파라미터 추가 후 main.py에서
settings.MODE를 직접 전달하도록 수정.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -13,10 +13,11 @@ from fastapi import FastAPI, HTTPException, Query
|
|||||||
from fastapi.responses import FileResponse
|
from fastapi.responses import FileResponse
|
||||||
|
|
||||||
|
|
||||||
def create_dashboard_app(db_path: str) -> FastAPI:
|
def create_dashboard_app(db_path: str, mode: str = "paper") -> FastAPI:
|
||||||
"""Create dashboard FastAPI app bound to a SQLite database path."""
|
"""Create dashboard FastAPI app bound to a SQLite database path."""
|
||||||
app = FastAPI(title="The Ouroboros Dashboard", version="1.0.0")
|
app = FastAPI(title="The Ouroboros Dashboard", version="1.0.0")
|
||||||
app.state.db_path = db_path
|
app.state.db_path = db_path
|
||||||
|
app.state.mode = mode
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
def index() -> FileResponse:
|
def index() -> FileResponse:
|
||||||
@@ -111,7 +112,7 @@ def create_dashboard_app(db_path: str) -> FastAPI:
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
"date": today,
|
"date": today,
|
||||||
"mode": os.getenv("MODE", "paper"),
|
"mode": mode,
|
||||||
"markets": market_status,
|
"markets": market_status,
|
||||||
"totals": {
|
"totals": {
|
||||||
"trade_count": total_trades,
|
"trade_count": total_trades,
|
||||||
|
|||||||
@@ -2045,7 +2045,7 @@ def _start_dashboard_server(settings: Settings) -> threading.Thread | None:
|
|||||||
import uvicorn
|
import uvicorn
|
||||||
from src.dashboard import create_dashboard_app
|
from src.dashboard import create_dashboard_app
|
||||||
|
|
||||||
app = create_dashboard_app(settings.DB_PATH)
|
app = create_dashboard_app(settings.DB_PATH, mode=settings.MODE)
|
||||||
uvicorn.run(
|
uvicorn.run(
|
||||||
app,
|
app,
|
||||||
host=settings.DASHBOARD_HOST,
|
host=settings.DASHBOARD_HOST,
|
||||||
|
|||||||
@@ -415,28 +415,37 @@ def test_status_circuit_breaker_unknown_when_no_data(tmp_path: Path) -> None:
|
|||||||
assert cb["current_pnl_pct"] is None
|
assert cb["current_pnl_pct"] is None
|
||||||
|
|
||||||
|
|
||||||
def test_status_mode_paper(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
def test_status_mode_paper(tmp_path: Path) -> None:
|
||||||
"""MODE=paper일 때 status 응답에 mode=paper가 포함돼야 한다."""
|
"""mode=paper로 생성하면 status 응답에 mode=paper가 포함돼야 한다."""
|
||||||
monkeypatch.setenv("MODE", "paper")
|
db_path = tmp_path / "dashboard_test.db"
|
||||||
app = _app(tmp_path)
|
conn = init_db(str(db_path))
|
||||||
|
_seed_db(conn)
|
||||||
|
conn.close()
|
||||||
|
app = create_dashboard_app(str(db_path), mode="paper")
|
||||||
get_status = _endpoint(app, "/api/status")
|
get_status = _endpoint(app, "/api/status")
|
||||||
body = get_status()
|
body = get_status()
|
||||||
assert body["mode"] == "paper"
|
assert body["mode"] == "paper"
|
||||||
|
|
||||||
|
|
||||||
def test_status_mode_live(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
def test_status_mode_live(tmp_path: Path) -> None:
|
||||||
"""MODE=live일 때 status 응답에 mode=live가 포함돼야 한다."""
|
"""mode=live로 생성하면 status 응답에 mode=live가 포함돼야 한다."""
|
||||||
monkeypatch.setenv("MODE", "live")
|
db_path = tmp_path / "dashboard_test.db"
|
||||||
app = _app(tmp_path)
|
conn = init_db(str(db_path))
|
||||||
|
_seed_db(conn)
|
||||||
|
conn.close()
|
||||||
|
app = create_dashboard_app(str(db_path), mode="live")
|
||||||
get_status = _endpoint(app, "/api/status")
|
get_status = _endpoint(app, "/api/status")
|
||||||
body = get_status()
|
body = get_status()
|
||||||
assert body["mode"] == "live"
|
assert body["mode"] == "live"
|
||||||
|
|
||||||
|
|
||||||
def test_status_mode_default_paper(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
def test_status_mode_default_paper(tmp_path: Path) -> None:
|
||||||
"""MODE 환경변수가 없으면 mode 기본값은 paper여야 한다."""
|
"""mode 파라미터 미전달 시 기본값은 paper여야 한다."""
|
||||||
monkeypatch.delenv("MODE", raising=False)
|
db_path = tmp_path / "dashboard_test.db"
|
||||||
app = _app(tmp_path)
|
conn = init_db(str(db_path))
|
||||||
|
_seed_db(conn)
|
||||||
|
conn.close()
|
||||||
|
app = create_dashboard_app(str(db_path))
|
||||||
get_status = _endpoint(app, "/api/status")
|
get_status = _endpoint(app, "/api/status")
|
||||||
body = get_status()
|
body = get_status()
|
||||||
assert body["mode"] == "paper"
|
assert body["mode"] == "paper"
|
||||||
|
|||||||
Reference in New Issue
Block a user