diff --git a/tests/api/test_routes.py b/tests/api/test_routes.py index 7a5a9ed..02c00c1 100644 --- a/tests/api/test_routes.py +++ b/tests/api/test_routes.py @@ -509,8 +509,11 @@ def test_benchmark_curve_endpoint(): assert len(data["benchmark"]) == 2 -def test_benchmark_curve_endpoint_not_found(): - """Test GET /api/v1/task/:id/benchmark-curve returns 404 when file not found""" +def test_benchmark_curve_endpoint_degrades_gracefully(): + """Test GET /api/v1/task/:id/benchmark-curve returns 200 + empty series when file not found + + 基准缺失走降级(前端画单序列),不再 404 —— 与 cta_engine 降级行为对齐。 + """ from sanguo_api.app import create_app from sanguo_api.auth import set_jwt_config, create_token import tempfile @@ -526,7 +529,9 @@ def test_benchmark_curve_endpoint_not_found(): client = TestClient(app) response = client.get("/api/v1/task/unknown_task/benchmark-curve", headers={"Authorization": f"Bearer {token}"}) - assert response.status_code == 404 + assert response.status_code == 200 + data = response.json() + assert data == {"dates": [], "strategy": [], "benchmark": []} def test_risk_series_endpoint(): @@ -578,8 +583,11 @@ def test_risk_series_endpoint(): assert len(data["dates"]) == 2 -def test_risk_series_endpoint_not_found(): - """Test GET /api/v1/task/:id/risk-series returns 404 when file not found""" +def test_risk_series_endpoint_degrades_gracefully(): + """Test GET /api/v1/task/:id/risk-series returns 200 + empty series when file not found + + 数据缺失走降级空序列,不再 404 —— 前端据此隐藏图而非报错。 + """ from sanguo_api.app import create_app from sanguo_api.auth import set_jwt_config, create_token import tempfile @@ -595,7 +603,9 @@ def test_risk_series_endpoint_not_found(): client = TestClient(app) response = client.get("/api/v1/task/unknown_task/risk-series", headers={"Authorization": f"Bearer {token}"}) - assert response.status_code == 404 + assert response.status_code == 200 + data = response.json() + assert data == {"dates": [], "alpha": [], "beta": [], "drawdown": [], "strategy_vol": [], "benchmark_vol": []} def test_daily_holdings_endpoint():