Files
codex/codex-rs/tools/src/tool_output_tests.rs
T
pakrym-oai ce0323f2f2 Support typed content in contextual prompt fragments (#54776)
## Why

Contextual fragments and extension-owned world-state sections currently return strings, limiting them to text content.

## What changed

- Return `ContentItem` from fragment bodies and rendering, preserving classification and attribution. Apply text markers only to `InputText`; pass other content through unchanged.
- Allow extension prompt and world-state contributions to carry typed content, and preserve media in context-window hints.
- Hash non-text world-state fragments by their serialized content and role while retaining the existing text hashing behavior.
- Add shared content-to-tool-output conversion that preserves image references, image detail, and audio.

## Testing

Add coverage for typed world-state hashing and preservation of image content and attribution. Expand code-mode output tests to cover input text, output text, file-backed and inline images, and audio.

GitOrigin-RevId: 2ed00d466a3f169b151202f3eef71e667ea64be1
2026-10-17 04:02:21 +00:00

47 lines
1.5 KiB
Rust

use codex_protocol::models::ContentItem;
use codex_protocol::models::ImageReference;
use codex_protocol::models::ResponseInputItem;
use pretty_assertions::assert_eq;
use super::response_input_to_code_mode_result;
#[test]
fn code_mode_text_preserves_message_content() {
let response = ResponseInputItem::Message {
role: "user".to_string(),
content: vec![
ContentItem::InputText {
text: "Input text".to_string(),
},
ContentItem::OutputText {
text: "Output text".to_string(),
annotations: Some(vec![serde_json::json!({"type": "citation"})]),
logprobs: Some(vec![serde_json::json!({"token": "Output"})]),
},
ContentItem::InputImage {
image: ImageReference::File {
file_id: "file_123".to_string(),
},
detail: None,
},
ContentItem::InputImage {
image: ImageReference::Inline {
image_url: "data:image/png;base64,abc".to_string(),
},
detail: None,
},
ContentItem::InputAudio {
audio_url: "data:audio/wav;base64,def".to_string(),
},
],
phase: None,
};
assert_eq!(
response_input_to_code_mode_result(response),
serde_json::json!(
"Input text\nOutput text\nfile_123\ndata:image/png;base64,abc\ndata:audio/wav;base64,def"
)
);
}