Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Consolidate code mode output helper tests (#39969)

felixxia-oai16e2722c50b7
diff --git a/codex-rs/code-mode-runtime/src/service_tests.rs b/codex-rs/code-mode-runtime/src/service_tests.rs
index 96c692da7d..2f97e1c3de 100644
--- a/codex-rs/code-mode-runtime/src/service_tests.rs
+++ b/codex-rs/code-mode-runtime/src/service_tests.rs
@@ -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();
diff --git a/codex-rs/core/tests/suite/code_mode.rs b/codex-rs/core/tests/suite/code_mode.rs
index 39c82af9f6..e2e2a81dd8 100644
--- a/codex-rs/core/tests/suite/code_mode.rs
+++ b/codex-rs/core/tests/suite/code_mode.rs
@@ -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(()));