mirror of
https://github.com/openai/codex.git
synced 2026-08-23 13:09:46 +00:00
Consolidate code mode output helper tests (#39969)
## What changed - Cover object serialization through the `text()` helper directly in the code mode runtime suite. - Remove redundant core integration coverage for serialized text and rejected image outputs. GitOrigin-RevId: f465b8361e9d725a7246994d9c41e9d01c969011
This commit is contained in:
@@ -1055,6 +1055,32 @@ text(JSON.stringify(returnsUndefined));
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn text_helper_serializes_objects() {
|
||||
let service = InProcessCodeModeSession::new();
|
||||
|
||||
let response = execute(
|
||||
&service,
|
||||
ExecuteRequest {
|
||||
source: "text({ json: true });".to_string(),
|
||||
yield_time_ms: None,
|
||||
..execute_request("")
|
||||
},
|
||||
)
|
||||
.await;
|
||||
|
||||
assert_eq!(
|
||||
response,
|
||||
RuntimeResponse::Result {
|
||||
cell_id: cell_id("1"),
|
||||
content_items: vec![FunctionCallOutputContentItem::InputText {
|
||||
text: r#"{"json":true}"#.to_string(),
|
||||
}],
|
||||
error_text: None,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn text_helper_surfaces_stringify_errors() {
|
||||
let service = InProcessCodeModeSession::new();
|
||||
|
||||
@@ -3553,36 +3553,6 @@ Total\ output\ lines:\ 1\n
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn code_mode_can_output_serialized_text_via_global_helper() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let server = responses::start_mock_server().await;
|
||||
let (_test, second_mock) = run_code_mode_turn(
|
||||
&server,
|
||||
"use exec to return structured text",
|
||||
r#"
|
||||
text({ json: true });
|
||||
"#,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let req = second_mock.single_request();
|
||||
let (output, success) = custom_tool_output_body_and_success(&req, "call-1");
|
||||
eprintln!(
|
||||
"hidden dynamic tool raw output: {}",
|
||||
req.custom_tool_call_output("call-1")
|
||||
);
|
||||
assert_ne!(
|
||||
success,
|
||||
Some(false),
|
||||
"exec call failed unexpectedly: {output}"
|
||||
);
|
||||
assert_eq!(output, r#"{"json":true}"#);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn code_mode_can_resume_after_set_timeout() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
@@ -3870,89 +3840,6 @@ async fn code_mode_unified_image_budget_preserves_legacy_contract_for_unsupporte
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn code_mode_image_helper_rejects_remote_url() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let server = responses::start_mock_server().await;
|
||||
let (_test, second_mock) = run_code_mode_turn(
|
||||
&server,
|
||||
"use exec to return a remote image",
|
||||
r#"image("https://example.com/image.jpg");"#,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let req = second_mock.single_request();
|
||||
let items = custom_tool_output_items(&req, "call-1");
|
||||
let (_, success) = custom_tool_output_body_and_success(&req, "call-1");
|
||||
assert_ne!(
|
||||
success,
|
||||
Some(true),
|
||||
"code_mode remote image URL unexpectedly succeeded"
|
||||
);
|
||||
assert_eq!(items.len(), 2);
|
||||
assert_regex_match(
|
||||
concat!(
|
||||
r"(?s)\A",
|
||||
r"Script failed\nWall time \d+\.\d seconds\nOutput:\n\z"
|
||||
),
|
||||
text_item(&items, /*index*/ 0),
|
||||
);
|
||||
assert_eq!(
|
||||
text_item(&items, /*index*/ 1),
|
||||
concat!(
|
||||
"Script error:\n",
|
||||
"Tool call failed: remote image URLs are not supported in tool outputs. ",
|
||||
"Pass a base64 data URI instead"
|
||||
)
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn code_mode_image_helper_rejects_invalid_image_output() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let server = responses::start_mock_server().await;
|
||||
let (_test, second_mock) = run_code_mode_turn(
|
||||
&server,
|
||||
"use exec to return an image",
|
||||
r#"
|
||||
const s = "Error executing tool exec: Expected at least one message to convert to CallToolResult";
|
||||
image(s.trim(), "original");
|
||||
"#,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let req = second_mock.single_request();
|
||||
let items = custom_tool_output_items(&req, "call-1");
|
||||
let (_, success) = custom_tool_output_body_and_success(&req, "call-1");
|
||||
assert_ne!(
|
||||
success,
|
||||
Some(true),
|
||||
"code_mode invalid image output unexpectedly succeeded"
|
||||
);
|
||||
assert_eq!(items.len(), 2);
|
||||
assert_regex_match(
|
||||
concat!(
|
||||
r"(?s)\A",
|
||||
r"Script failed\nWall time \d+\.\d seconds\nOutput:\n\z"
|
||||
),
|
||||
text_item(&items, /*index*/ 0),
|
||||
);
|
||||
assert_eq!(
|
||||
text_item(&items, /*index*/ 1),
|
||||
concat!(
|
||||
"Script error:\n",
|
||||
"Tool call failed: invalid image output. ",
|
||||
"Pass a base64 data URI instead"
|
||||
)
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn code_mode_view_image_rejects_invalid_file_without_exposing_contents() -> Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
Reference in New Issue
Block a user