From baaa45948122e130d91699022259a13cafa12bd1 Mon Sep 17 00:00:00 2001 From: claude_dev Date: Thu, 13 Aug 2026 19:57:23 +0800 Subject: [PATCH] =?UTF-8?q?test(api):=20=E4=BF=AE2=E4=B8=AAstale=E6=B5=8B?= =?UTF-8?q?=E8=AF=95(benchmark-curve/risk-series=E6=9C=AA=E7=9F=A5?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E4=BB=8E404=E6=94=B9=E6=96=AD=E8=A8=80?= =?UTF-8?q?=E9=99=8D=E7=BA=A7200=E7=A9=BA=E5=BA=8F=E5=88=97,=E5=AF=B9?= =?UTF-8?q?=E9=BD=90b2c41c7=E9=99=8D=E7=BA=A7=E8=AE=BE=E8=AE=A1)=20[nas]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/api/test_routes.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) 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():