mirror of
https://github.com/openai/codex.git
synced 2026-04-26 15:45:02 +00:00
chore(shell_command) fix freeform timeout output (#7791)
## Summary Adding an additional integration test for timeout_ms ## Testing - [x] these are tests
This commit is contained in:
@@ -13,10 +13,15 @@ use core_test_support::test_codex::TestCodexHarness;
|
||||
use core_test_support::test_codex::test_codex;
|
||||
use serde_json::json;
|
||||
|
||||
fn shell_responses(call_id: &str, command: &str, login: Option<bool>) -> Vec<String> {
|
||||
fn shell_responses_with_timeout(
|
||||
call_id: &str,
|
||||
command: &str,
|
||||
login: Option<bool>,
|
||||
timeout_ms: i64,
|
||||
) -> Vec<String> {
|
||||
let args = json!({
|
||||
"command": command,
|
||||
"timeout_ms": 2_000,
|
||||
"timeout_ms": timeout_ms,
|
||||
"login": login,
|
||||
});
|
||||
|
||||
@@ -36,6 +41,10 @@ fn shell_responses(call_id: &str, command: &str, login: Option<bool>) -> Vec<Str
|
||||
]
|
||||
}
|
||||
|
||||
fn shell_responses(call_id: &str, command: &str, login: Option<bool>) -> Vec<String> {
|
||||
shell_responses_with_timeout(call_id, command, login, 2_000)
|
||||
}
|
||||
|
||||
async fn shell_command_harness_with(
|
||||
configure: impl FnOnce(TestCodexBuilder) -> TestCodexBuilder,
|
||||
) -> Result<TestCodexHarness> {
|
||||
@@ -54,6 +63,20 @@ async fn mount_shell_responses(
|
||||
mount_sse_sequence(harness.server(), shell_responses(call_id, command, login)).await;
|
||||
}
|
||||
|
||||
async fn mount_shell_responses_with_timeout(
|
||||
harness: &TestCodexHarness,
|
||||
call_id: &str,
|
||||
command: &str,
|
||||
login: Option<bool>,
|
||||
timeout_ms: i64,
|
||||
) {
|
||||
mount_sse_sequence(
|
||||
harness.server(),
|
||||
shell_responses_with_timeout(call_id, command, login, timeout_ms),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
fn assert_shell_command_output(output: &str, expected: &str) -> Result<()> {
|
||||
let normalized_output = output
|
||||
.replace("\r\n", "\n")
|
||||
@@ -172,3 +195,32 @@ async fn pipe_output_without_login() -> anyhow::Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn shell_command_times_out_with_timeout_ms() -> anyhow::Result<()> {
|
||||
skip_if_no_network!(Ok(()));
|
||||
|
||||
let harness = shell_command_harness_with(|builder| builder.with_model("gpt-5.1")).await?;
|
||||
|
||||
let call_id = "shell-command-timeout";
|
||||
let command = if cfg!(windows) {
|
||||
"timeout /t 5"
|
||||
} else {
|
||||
"sleep 5"
|
||||
};
|
||||
mount_shell_responses_with_timeout(&harness, call_id, command, None, 200).await;
|
||||
harness
|
||||
.submit("run a long command with a short timeout")
|
||||
.await?;
|
||||
|
||||
let output = harness.function_call_stdout(call_id).await;
|
||||
let normalized_output = output
|
||||
.replace("\r\n", "\n")
|
||||
.replace('\r', "\n")
|
||||
.trim_end_matches('\n')
|
||||
.to_string();
|
||||
let expected_pattern = r"(?s)^Exit code: 124\nWall time: [0-9]+(?:\.[0-9]+)? seconds\nOutput:\ncommand timed out after [0-9]+ milliseconds\n?$";
|
||||
assert_regex_match(expected_pattern, &normalized_output);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user