From ab36fdab757ed28088479bce9680cdc539b6a869 Mon Sep 17 00:00:00 2001 From: Michael Bolin Date: Thu, 4 Sep 2025 10:14:39 -0700 Subject: [PATCH] fix: fix serde_as annotation and verify with test --- codex-rs/protocol/Cargo.toml | 2 +- codex-rs/protocol/src/protocol.rs | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/codex-rs/protocol/Cargo.toml b/codex-rs/protocol/Cargo.toml index cb403d23e4..37ab63e042 100644 --- a/codex-rs/protocol/Cargo.toml +++ b/codex-rs/protocol/Cargo.toml @@ -17,7 +17,7 @@ mime_guess = "2.0.5" serde = { version = "1", features = ["derive"] } serde_bytes = "0.11" serde_json = "1" -serde_with = "3.14.0" +serde_with = { version = "3.14.0", features = ["macros", "base64"] } strum = "0.27.2" strum_macros = "0.27.2" tracing = "0.1.41" diff --git a/codex-rs/protocol/src/protocol.rs b/codex-rs/protocol/src/protocol.rs index 0552867f8a..3c40b33c1b 100644 --- a/codex-rs/protocol/src/protocol.rs +++ b/codex-rs/protocol/src/protocol.rs @@ -774,22 +774,22 @@ pub struct ExecCommandEndEvent { pub formatted_output: String, } -#[derive(Debug, Clone, Deserialize, Serialize)] +#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)] #[serde(rename_all = "snake_case")] pub enum ExecOutputStream { Stdout, Stderr, } -#[derive(Debug, Clone, Deserialize, Serialize)] #[serde_as] +#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)] pub struct ExecCommandOutputDeltaEvent { /// Identifier for the ExecCommandBegin that produced this chunk. pub call_id: String, /// Which stream produced this chunk. pub stream: ExecOutputStream, /// Raw bytes from the stream (may not be valid UTF-8). - #[serde_as(as = "Base64")] + #[serde_as(as = "serde_with::base64::Base64")] pub chunk: Vec, } @@ -980,4 +980,21 @@ mod tests { r#"{"id":"1234","msg":{"type":"session_configured","session_id":"67e55044-10b1-426f-9247-bb680e5fe0c8","model":"codex-mini-latest","history_log_id":0,"history_entry_count":0}}"# ); } + + #[test] + fn vec_u8_as_base64_serialization_and_deserialization() { + let event = ExecCommandOutputDeltaEvent { + call_id: "call21".to_string(), + stream: ExecOutputStream::Stdout, + chunk: vec![1, 2, 3, 4, 5], + }; + let serialized = serde_json::to_string(&event).unwrap(); + assert_eq!( + r#"{"call_id":"call21","stream":"stdout","chunk":"AQIDBAU="}"#, + serialized, + ); + + let deserialized: ExecCommandOutputDeltaEvent = serde_json::from_str(&serialized).unwrap(); + assert_eq!(deserialized, event); + } }