@@ -2474,3 +2474,40 @@ def test_authorize_without_pending_login_still_rejected(tmp_path):
24742474 response = client .get ("/authorize?refreshToken=RT" )
24752475 assert response .status_code == 400
24762476 assert response .json ()["error" ]["code" ] == "invalid_request"
2477+
2478+
2479+ def test_dump_request_bodies_writes_file (tmp_path ):
2480+ """诊断开关:dump_request_bodies=True 时 /v1 请求体落盘(main 291-293)。"""
2481+ import json as _json
2482+
2483+ from fastapi .testclient import TestClient
2484+
2485+ from src .config import Settings
2486+ from src .main import build_app
2487+
2488+ settings = Settings (_env_file = None , APP_SECRET = "s" , DATA_DIR = str (tmp_path ),
2489+ dump_request_bodies = True )
2490+
2491+ class P :
2492+ id = "p1"
2493+
2494+ async def list_models (self , _data ):
2495+ from src .provider .base import Model
2496+
2497+ return [Model (id = "m" )]
2498+
2499+ def import_credential (self , raw ): # pragma: no cover
2500+ return raw
2501+
2502+ app = build_app (settings , providers = {"p1" : P ()})
2503+ key = app .state .api_keys .create ("root" )["api_key" ]
2504+ with TestClient (app ) as client :
2505+ r = client .post ("/v1/chat/completions" ,
2506+ headers = {"Authorization" : f"Bearer { key } " },
2507+ json = {"model" : "m" , "stream" : False ,
2508+ "messages" : [{"role" : "user" , "content" : "hi" }]})
2509+ assert r .status_code in (200 , 400 , 503 ) # body 是否合法不影响 dump
2510+ dumps = list ((tmp_path / "dumps" ).glob ("*.json" ))
2511+ assert dumps , "应产生 dump 文件"
2512+ body = _json .loads (dumps [0 ].read_text (encoding = "utf-8" ))
2513+ assert body ["model" ] == "m"
0 commit comments