From a0909ea1a9648056fd9f9445144dd37db778021d Mon Sep 17 00:00:00 2001 From: Ahmed Ibrahim Date: Sun, 11 Jan 2026 16:13:27 -0800 Subject: [PATCH] strong tests --- codex-rs/core/tests/suite/abort_tasks.rs | 27 +++++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/codex-rs/core/tests/suite/abort_tasks.rs b/codex-rs/core/tests/suite/abort_tasks.rs index 578a70e8c0..51690bfb21 100644 --- a/codex-rs/core/tests/suite/abort_tasks.rs +++ b/codex-rs/core/tests/suite/abort_tasks.rs @@ -5,6 +5,7 @@ use codex_core::features::Feature; use codex_core::protocol::EventMsg; use codex_core::protocol::Op; use codex_protocol::user_input::UserInput; +use core_test_support::assert_regex_match; use core_test_support::responses::ev_completed; use core_test_support::responses::ev_function_call; use core_test_support::responses::ev_local_shell_call; @@ -58,6 +59,20 @@ fn long_running_local_shell_call_with_output() -> Vec<&'static str> { } } +fn assert_aborted_output(output: &str) { + let normalized_output = output.replace("\r\n", "\n").replace('\r', "\n"); + let normalized_output = normalized_output.trim_end_matches('\n'); + let expected_pattern = r"(?s)^Exit code: [0-9]+\nWall time: ([0-9]+(?:\.[0-9]+)?) seconds\nOutput:\npartial output\ncommand aborted by user$"; + let captures = assert_regex_match(expected_pattern, &normalized_output); + let secs: f32 = captures + .get(1) + .expect("aborted message with elapsed seconds") + .as_str() + .parse() + .expect("parse wall time seconds"); + assert!(secs >= 0.0); +} + /// Integration test: spawn a long‑running shell_command tool via a mocked Responses SSE /// function call, then interrupt the session and expect TurnAborted. #[tokio::test(flavor = "multi_thread", worker_threads = 2)] @@ -181,8 +196,7 @@ async fn interrupt_tool_records_history_entries() { let output = response_mock .function_call_output_text(call_id) .expect("missing function_call_output text"); - assert!(output.contains("partial output")); - assert!(output.contains("command aborted by user")); + assert_aborted_output(&output); } #[tokio::test(flavor = "multi_thread", worker_threads = 2)] @@ -246,8 +260,7 @@ async fn interrupt_shell_records_partial_output() { let output = response_mock .function_call_output_text(call_id) .expect("missing shell output"); - assert!(output.contains("partial output")); - assert!(output.contains("command aborted by user")); + assert_aborted_output(&output); } #[tokio::test(flavor = "multi_thread", worker_threads = 2)] @@ -306,8 +319,7 @@ async fn interrupt_local_shell_records_partial_output() { let output = response_mock .function_call_output_text(call_id) .expect("missing local shell output"); - assert!(output.contains("partial output")); - assert!(output.contains("command aborted by user")); + assert_aborted_output(&output); } #[tokio::test(flavor = "multi_thread", worker_threads = 2)] @@ -382,6 +394,5 @@ async fn interrupt_unified_exec_records_partial_output() { let output = response_mock .function_call_output_text(call_id) .expect("missing exec_command output"); - assert!(output.contains("partial output")); - assert!(output.contains("command aborted by user")); + assert_aborted_output(&output); }