From deb5dfdfa65f73dc27fca036ddbc8c448e8d7a3b Mon Sep 17 00:00:00 2001 From: Liang-Ting Jiang Date: Sat, 25 Apr 2026 10:27:10 -0700 Subject: [PATCH] Default missing download status to success --- codex-rs/codex-api/src/files.rs | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/codex-rs/codex-api/src/files.rs b/codex-rs/codex-api/src/files.rs index b747d6809f..a03cde8370 100644 --- a/codex-rs/codex-api/src/files.rs +++ b/codex-rs/codex-api/src/files.rs @@ -110,6 +110,7 @@ struct CreateFileResponse { #[derive(Deserialize)] #[serde(rename_all = "snake_case")] struct DownloadLinkResponse { + #[serde(default = "download_link_success_status")] status: String, download_url: Option, file_name: Option, @@ -117,6 +118,10 @@ struct DownloadLinkResponse { error_message: Option, } +fn download_link_success_status() -> String { + "success".to_string() +} + #[derive(Deserialize)] struct ProcessUploadStreamStatus { event: Option, @@ -794,6 +799,35 @@ mod tests { assert!(!path.exists()); } + #[tokio::test] + async fn get_openai_file_download_info_defaults_missing_status_to_success() { + let server = MockServer::start().await; + Mock::given(method("GET")) + .and(path("/backend-api/files/file_123/download")) + .and(header("authorization", "Bearer token")) + .and(header("chatgpt-account-id", "account_id")) + .respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({ + "download_url": format!("{}/download/file_123", server.uri()), + "file_name": "hello.txt", + "mime_type": "text/plain", + }))) + .mount(&server) + .await; + + let info = get_openai_file_download_info(&base_url_for(&server), &chatgpt_auth(), "file_123") + .await + .expect("download info should resolve"); + + assert_eq!( + info, + OpenAiFileDownloadInfo { + download_url: format!("{}/download/file_123", server.uri()), + file_name: Some("hello.txt".to_string()), + mime_type: Some("text/plain".to_string()), + } + ); + } + #[tokio::test] async fn authenticated_download_does_not_follow_redirects() { let server = MockServer::start().await;