@@ -121,7 +121,7 @@ pub(crate) fn map_response_item_to_event_messages(
121121 show_raw_agent_reasoning : bool ,
122122) -> Vec < EventMsg > {
123123 if let Some ( turn_item) = parse_turn_item ( item) {
124- return turn_item. legacy_events ( show_raw_agent_reasoning) ;
124+ return turn_item. as_legacy_events ( show_raw_agent_reasoning) ;
125125 }
126126
127127 // Variants that require side effects are handled by higher layers and do not emit events here.
@@ -130,19 +130,18 @@ pub(crate) fn map_response_item_to_event_messages(
130130
131131#[ cfg( test) ]
132132mod tests {
133- use super :: map_response_item_to_event_messages;
134- use crate :: protocol:: EventMsg ;
135- use crate :: protocol:: WebSearchEndEvent ;
136-
133+ use super :: parse_turn_item;
134+ use codex_protocol:: items:: TurnItem ;
137135 use codex_protocol:: models:: ContentItem ;
138136 use codex_protocol:: models:: ReasoningItemContent ;
139137 use codex_protocol:: models:: ReasoningItemReasoningSummary ;
140138 use codex_protocol:: models:: ResponseItem ;
141139 use codex_protocol:: models:: WebSearchAction ;
140+ use codex_protocol:: user_input:: UserInput ;
142141 use pretty_assertions:: assert_eq;
143142
144143 #[ test]
145- fn maps_user_message_with_text_and_two_images ( ) {
144+ fn parses_user_message_with_text_and_two_images ( ) {
146145 let img1 = "https://example.com/one.png" . to_string ( ) ;
147146 let img2 = "https://example.com/two.jpg" . to_string ( ) ;
148147
@@ -162,20 +161,25 @@ mod tests {
162161 ] ,
163162 } ;
164163
165- let events = map_response_item_to_event_messages ( & item, false ) ;
166- assert_eq ! ( events. len( ) , 1 , "expected a single user message event" ) ;
164+ let turn_item = parse_turn_item ( & item) . expect ( "expected user message turn item" ) ;
167165
168- match & events[ 0 ] {
169- EventMsg :: UserMessage ( user) => {
170- assert_eq ! ( user. message, "Hello world" ) ;
171- assert_eq ! ( user. images, Some ( vec![ img1, img2] ) ) ;
166+ match turn_item {
167+ TurnItem :: UserMessage ( user) => {
168+ let expected_content = vec ! [
169+ UserInput :: Text {
170+ text: "Hello world" . to_string( ) ,
171+ } ,
172+ UserInput :: Image { image_url: img1 } ,
173+ UserInput :: Image { image_url: img2 } ,
174+ ] ;
175+ assert_eq ! ( user. content, expected_content) ;
172176 }
173- other => panic ! ( "expected UserMessage, got {other:?}" ) ,
177+ other => panic ! ( "expected TurnItem:: UserMessage, got {other:?}" ) ,
174178 }
175179 }
176180
177181 #[ test]
178- fn maps_reasoning_summary_without_raw_content ( ) {
182+ fn parses_reasoning_summary_and_raw_content ( ) {
179183 let item = ResponseItem :: Reasoning {
180184 id : "reasoning_1" . to_string ( ) ,
181185 summary : vec ! [
@@ -192,18 +196,23 @@ mod tests {
192196 encrypted_content : None ,
193197 } ;
194198
195- let events = map_response_item_to_event_messages ( & item, false ) ;
199+ let turn_item = parse_turn_item ( & item) . expect ( "expected reasoning turn item" ) ;
196200
197- assert_eq ! ( events. len( ) , 2 , "expected only reasoning summaries" ) ;
198- assert ! (
199- events
200- . iter( )
201- . all( |event| matches!( event, EventMsg :: AgentReasoning ( _) ) )
202- ) ;
201+ match turn_item {
202+ TurnItem :: Reasoning ( reasoning) => {
203+ assert_eq ! (
204+ reasoning. summary_text,
205+ vec![ "Step 1" . to_string( ) , "Step 2" . to_string( ) ]
206+ ) ;
207+ assert_eq ! ( reasoning. raw_content, vec![ "raw details" . to_string( ) ] ) ;
208+ assert_eq ! ( reasoning. encrypted_content, None ) ;
209+ }
210+ other => panic ! ( "expected TurnItem::Reasoning, got {other:?}" ) ,
211+ }
203212 }
204213
205214 #[ test]
206- fn maps_reasoning_including_raw_content_when_enabled ( ) {
215+ fn parses_reasoning_including_raw_content ( ) {
207216 let item = ResponseItem :: Reasoning {
208217 id : "reasoning_2" . to_string ( ) ,
209218 summary : vec ! [ ReasoningItemReasoningSummary :: SummaryText {
@@ -220,20 +229,23 @@ mod tests {
220229 encrypted_content : None ,
221230 } ;
222231
223- let events = map_response_item_to_event_messages ( & item, true ) ;
232+ let turn_item = parse_turn_item ( & item) . expect ( "expected reasoning turn item" ) ;
224233
225- assert_eq ! (
226- events. len( ) ,
227- 3 ,
228- "expected summary and raw reasoning content events"
229- ) ;
230- assert ! ( matches!( events[ 0 ] , EventMsg :: AgentReasoning ( _) ) ) ;
231- assert ! ( matches!( events[ 1 ] , EventMsg :: AgentReasoningRawContent ( _) ) ) ;
232- assert ! ( matches!( events[ 2 ] , EventMsg :: AgentReasoningRawContent ( _) ) ) ;
234+ match turn_item {
235+ TurnItem :: Reasoning ( reasoning) => {
236+ assert_eq ! ( reasoning. summary_text, vec![ "Summarized step" . to_string( ) ] ) ;
237+ assert_eq ! (
238+ reasoning. raw_content,
239+ vec![ "raw step" . to_string( ) , "final thought" . to_string( ) ]
240+ ) ;
241+ assert_eq ! ( reasoning. encrypted_content, None ) ;
242+ }
243+ other => panic ! ( "expected TurnItem::Reasoning, got {other:?}" ) ,
244+ }
233245 }
234246
235247 #[ test]
236- fn maps_web_search_call ( ) {
248+ fn parses_web_search_call ( ) {
237249 let item = ResponseItem :: WebSearchCall {
238250 id : Some ( "ws_1" . to_string ( ) ) ,
239251 status : Some ( "completed" . to_string ( ) ) ,
@@ -242,15 +254,14 @@ mod tests {
242254 } ,
243255 } ;
244256
245- let events = map_response_item_to_event_messages ( & item, false ) ;
246- assert_eq ! ( events. len( ) , 1 , "expected a single web search event" ) ;
257+ let turn_item = parse_turn_item ( & item) . expect ( "expected web search turn item" ) ;
247258
248- match & events [ 0 ] {
249- EventMsg :: WebSearchEnd ( WebSearchEndEvent { call_id , query } ) => {
250- assert_eq ! ( call_id , "ws_1" ) ;
251- assert_eq ! ( query, "weather" ) ;
259+ match turn_item {
260+ TurnItem :: WebSearch ( search ) => {
261+ assert_eq ! ( search . id , "ws_1" ) ;
262+ assert_eq ! ( search . query, "weather" ) ;
252263 }
253- other => panic ! ( "expected WebSearchEnd , got {other:?}" ) ,
264+ other => panic ! ( "expected TurnItem::WebSearch , got {other:?}" ) ,
254265 }
255266 }
256267}
0 commit comments