diff --git a/codex-rs/code-mode-runtime/src/service_tests.rs b/codex-rs/code-mode-runtime/src/service_tests.rs index 8ec8cbe15f..a40c2eb998 100644 --- a/codex-rs/code-mode-runtime/src/service_tests.rs +++ b/codex-rs/code-mode-runtime/src/service_tests.rs @@ -937,6 +937,47 @@ text(JSON.stringify(returnsUndefined)); ); } +#[tokio::test] +async fn text_helper_surfaces_stringify_errors() { + let service = InProcessCodeModeSession::new(); + + let response = execute( + &service, + ExecuteRequest { + source: r#" +const circular = {}; +circular.self = circular; +text(circular); +"# + .to_string(), + yield_time_ms: None, + ..execute_request("") + }, + ) + .await; + + let RuntimeResponse::Result { + error_text: Some(error_text), + .. + } = &response + else { + panic!("circular stringify unexpectedly succeeded: {response:?}"); + }; + assert!( + error_text.contains("Converting circular structure to JSON"), + "unexpected circular stringify error: {error_text}" + ); + let error_text = error_text.clone(); + assert_eq!( + response, + RuntimeResponse::Result { + cell_id: cell_id("1"), + content_items: Vec::new(), + error_text: Some(error_text), + } + ); +} + #[tokio::test] async fn audio_helper_accepts_audio_url_object_and_raw_mcp_audio_block() { 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 43d7537df3..452429a236 100644 --- a/codex-rs/core/tests/suite/code_mode.rs +++ b/codex-rs/core/tests/suite/code_mode.rs @@ -3686,46 +3686,6 @@ text("after"); Ok(()) } -#[tokio::test(flavor = "multi_thread", worker_threads = 2)] -async fn code_mode_surfaces_text_stringify_errors() -> 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 circular text", - r#" -const circular = {}; -circular.self = circular; -text(circular); -"#, - ) - .await?; - - let req = second_mock.single_request(); - let items = custom_tool_output_items(&req, "call-1"); - let (_, success) = req - .custom_tool_call_output_content_and_success("call-1") - .expect("custom tool output should be present"); - assert_ne!( - success, - Some(true), - "circular stringify 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!(text_item(&items, /*index*/ 1).contains("Script error:")); - assert!(text_item(&items, /*index*/ 1).contains("Converting circular structure to JSON")); - - Ok(()) -} - #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn code_mode_can_output_images_via_global_helper() -> Result<()> { skip_if_no_network!(Ok(()));