Files
codex/codex-rs/model-provider/src/models_endpoint_timeout_tests.rs
T
jif 977193486d Bound model catalog decode errors and classify request timeouts (#45928)
## Why

Model catalog decode errors can include the full response body and payload values from deserialization errors. Catalog request deadlines also report a generic timeout instead of a request timeout.

## What changed

- Report only the JSON error category, line, column, and response byte count when model catalog decoding fails.
- Return `CodexErr::RequestTimeout` when the model catalog refresh deadline expires.

## Testing

Add regression tests for invalid response shapes, large payload values, malformed and truncated JSON, and a delayed catalog response that must return `RequestTimeout`.

GitOrigin-RevId: 6fe5111a3e3b113d79942b3c213f8e94d773eb5a
2026-09-16 11:46:37 +00:00

41 lines
1.1 KiB
Rust

use super::*;
use codex_http_client::OutboundProxyPolicy;
use codex_protocol::error::CodexErrorDetails;
use wiremock::Mock;
use wiremock::MockServer;
use wiremock::ResponseTemplate;
use wiremock::matchers::method;
use wiremock::matchers::path;
#[tokio::test]
async fn catalog_deadline_returns_request_timeout() {
let server = MockServer::start().await;
Mock::given(method("GET"))
.and(path("/models"))
.respond_with(
ResponseTemplate::new(200)
.set_body_json(serde_json::json!({ "models": [] }))
.set_delay(MODELS_REFRESH_TIMEOUT * 2),
)
.expect(1)
.mount(&server)
.await;
let endpoint = OpenAiModelsEndpoint::new(
ModelProviderInfo::create_openai_provider(Some(server.uri())),
/*auth_manager*/ None,
);
let error = endpoint
.list_models(
"0.0.0",
HttpClientFactory::new(OutboundProxyPolicy::ReqwestDefault),
)
.await
.expect_err("delayed catalog request should time out");
assert!(
matches!(error.details(), CodexErrorDetails::RequestTimeout),
"{error}"
);
}