()
| 187 | |
| 188 | #[tokio::test] |
| 189 | async fn test_proxy_forwards_upstream_errors() { |
| 190 | let mock_server = MockServer::start().await; |
| 191 | |
| 192 | Mock::given(method("POST")) |
| 193 | .and(path("/v1/chat/completions")) |
| 194 | .respond_with(ResponseTemplate::new(400).set_body_json(serde_json::json!({ |
| 195 | "error": {"message": "Invalid model", "type": "invalid_request_error"} |
| 196 | }))) |
| 197 | .mount(&mock_server) |
| 198 | .await; |
| 199 | |
| 200 | let app = make_app(&mock_server.uri()); |
| 201 | let body = r#"{"model":"nonexistent"}"#; |
| 202 | let req = Request::builder() |
| 203 | .method("POST") |
| 204 | .uri("/v1/chat/completions") |
| 205 | .header("authorization", "Bearer vk-test-1") |
| 206 | .header("content-type", "application/json") |
| 207 | .body(Body::from(body)) |
| 208 | .unwrap(); |
| 209 | |
| 210 | let resp = app.oneshot(req).await.unwrap(); |
| 211 | assert_eq!(resp.status(), StatusCode::BAD_REQUEST); |
| 212 | |
| 213 | let body = resp.into_body().collect().await.unwrap().to_bytes(); |
| 214 | let json: serde_json::Value = serde_json::from_slice(&body).unwrap(); |
| 215 | assert!( |
| 216 | json["error"]["message"] |
| 217 | .as_str() |
| 218 | .unwrap() |
| 219 | .contains("Invalid model") |
| 220 | ); |
| 221 | } |
| 222 | |
| 223 | #[tokio::test] |
| 224 | async fn test_real_key_injected_correctly() { |
nothing calls this directly
no test coverage detected