mirror of
https://github.com/openai/codex.git
synced 2026-11-13 06:45:07 +00:00
Preserve image transparency metadata in app-server items (#37178)
## What changed - Add `transparentBackground` to image-generation items and legacy completion events. - Map Images API backgrounds to `true` for transparent, `false` for opaque, and `null` for automatic or unavailable values. - Preserve the metadata in live notifications and persisted or resumed thread history while continuing to deserialize older items that omit it. ## Testing - Cover transparent, opaque, and automatic backgrounds, including image edits and thread read/resume flows. - Verify the stable JSON shape and optional TypeScript field. GitOrigin-RevId: 08527f37f23431df45fab1ed34eb82b2139b49d7
This commit is contained in:
1 parent
a3ebd19fa4
commit
928bda82cf
35 files changed
+407
-9
No files matched your search
@@ -1,5 +1,6 @@
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::json;
|
||||
use ts_rs::TS;
|
||||
|
||||
use super::ExtensionItem;
|
||||
use super::image_generation::ImageGenerationItem;
|
||||
@@ -13,6 +14,7 @@ fn completed_image_generation_item() -> ExtensionItem {
|
||||
status: "completed".to_string(),
|
||||
revised_prompt: Some("A blue square".to_string()),
|
||||
result: "cG5n".to_string(),
|
||||
transparent_background: None,
|
||||
saved_path: None,
|
||||
})
|
||||
}
|
||||
@@ -30,12 +32,58 @@ fn image_generation_item_preserves_stable_wire_shape() {
|
||||
"status": "completed",
|
||||
"revisedPrompt": "A blue square",
|
||||
"result": "cG5n",
|
||||
"transparentBackground": null,
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::from_value::<ExtensionItem>(value).expect("deserialize extension item"),
|
||||
item
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::from_value::<ExtensionItem>(json!({
|
||||
"kind": "image_gen.generation",
|
||||
"id": "image-1",
|
||||
"status": "completed",
|
||||
"revisedPrompt": "A blue square",
|
||||
"result": "cG5n",
|
||||
}))
|
||||
.expect("deserialize legacy image-generation item without transparency metadata"),
|
||||
item
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn image_generation_item_preserves_authoritative_transparency() {
|
||||
let ExtensionItem::ImageGeneration(mut image) = completed_image_generation_item() else {
|
||||
panic!("expected image-generation item");
|
||||
};
|
||||
image.transparent_background = Some(true);
|
||||
let item = ExtensionItem::ImageGeneration(image);
|
||||
let value = serde_json::to_value(&item).expect("serialize extension item");
|
||||
|
||||
assert_eq!(
|
||||
value,
|
||||
json!({
|
||||
"kind": "image_gen.generation",
|
||||
"id": "image-1",
|
||||
"status": "completed",
|
||||
"revisedPrompt": "A blue square",
|
||||
"result": "cG5n",
|
||||
"transparentBackground": true,
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::from_value::<ExtensionItem>(value).expect("deserialize extension item"),
|
||||
item
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn image_generation_transparency_is_optional_in_typescript() {
|
||||
assert!(
|
||||
ImageGenerationItem::inline().contains("transparentBackground?: boolean"),
|
||||
"image-generation transparency must remain optional for existing TypeScript clients"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user