Skip to content

Commit 7cec100

Browse files
committed
feedback
1 parent 79de526 commit 7cec100

File tree

3 files changed

+42
-53
lines changed

3 files changed

+42
-53
lines changed

codex-rs/core/src/codex.rs

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3277,11 +3277,28 @@ mod tests {
32773277
use mcp_types::ContentBlock;
32783278
use mcp_types::TextContent;
32793279
use pretty_assertions::assert_eq;
3280+
use serde::Deserialize;
32803281
use serde_json::json;
32813282
use std::path::PathBuf;
32823283
use std::sync::Arc;
32833284
use std::time::Duration as StdDuration;
32843285

3286+
fn test_echo_command() -> Vec<String> {
3287+
if cfg!(windows) {
3288+
vec![
3289+
"cmd.exe".to_string(),
3290+
"/C".to_string(),
3291+
"echo hi".to_string(),
3292+
]
3293+
} else {
3294+
vec![
3295+
"/bin/sh".to_string(),
3296+
"-c".to_string(),
3297+
"echo hi".to_string(),
3298+
]
3299+
}
3300+
}
3301+
32853302
#[test]
32863303
fn reconstruct_history_matches_live_compactions() {
32873304
let (session, turn_context) = make_session_and_context();
@@ -3678,18 +3695,19 @@ mod tests {
36783695
turn_context.approval_policy = AskForApproval::OnFailure;
36793696

36803697
let params = ExecParams {
3681-
command: vec![
3682-
"/bin/sh".to_string(),
3683-
"-c".to_string(),
3684-
"echo hi".to_string(),
3685-
],
3698+
command: test_echo_command(),
36863699
cwd: turn_context.cwd.clone(),
36873700
timeout_ms: Some(1000),
36883701
env: HashMap::new(),
36893702
with_escalated_permissions: Some(true),
36903703
justification: Some("test".to_string()),
36913704
};
36923705

3706+
let params2 = ExecParams {
3707+
with_escalated_permissions: Some(false),
3708+
..params.clone()
3709+
};
3710+
36933711
let mut turn_diff_tracker = TurnDiffTracker::new();
36943712

36953713
let sub_id = "test-sub".to_string();
@@ -3720,19 +3738,6 @@ mod tests {
37203738
// Force DangerFullAccess to avoid platform sandbox dependencies in tests.
37213739
turn_context.sandbox_policy = SandboxPolicy::DangerFullAccess;
37223740

3723-
let params2 = ExecParams {
3724-
command: vec![
3725-
"/bin/sh".to_string(),
3726-
"-c".to_string(),
3727-
"echo hi".to_string(),
3728-
],
3729-
cwd: turn_context.cwd.clone(),
3730-
timeout_ms: Some(1000),
3731-
env: HashMap::new(),
3732-
with_escalated_permissions: Some(false),
3733-
justification: Some("test".to_string()),
3734-
};
3735-
37363741
let resp2 = handle_container_exec_with_params(
37373742
params2,
37383743
&session,
@@ -3747,11 +3752,24 @@ mod tests {
37473752
panic!("expected FunctionCallOutput on retry");
37483753
};
37493754

3750-
// Parse the structured exec output and assert success without new structs
3751-
let v: serde_json::Value =
3755+
#[derive(Deserialize)]
3756+
struct ResponseExecMetadata {
3757+
exit_code: i32,
3758+
duration_seconds: f32,
3759+
}
3760+
3761+
#[derive(Deserialize)]
3762+
struct ResponseExecOutput {
3763+
output: String,
3764+
metadata: ResponseExecMetadata,
3765+
}
3766+
3767+
let exec_output: ResponseExecOutput =
37523768
serde_json::from_str(&output.content).expect("valid exec output json");
3753-
assert_eq!(v["metadata"]["exit_code"].as_i64(), Some(0));
3754-
assert!(v["output"].as_str().unwrap_or("").contains("hi"));
3769+
3770+
assert_eq!(exec_output.metadata.exit_code, 0);
3771+
assert!(exec_output.metadata.duration_seconds >= 0.0);
3772+
assert!(exec_output.output.contains("hi"));
37553773
assert_eq!(output.success, Some(true));
37563774
}
37573775
}

codex-rs/core/src/exec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const AGGREGATE_BUFFER_INITIAL_CAPACITY: usize = 8 * 1024; // 8 KiB
4444
/// Aggregation still collects full output; only the live event stream is capped.
4545
pub(crate) const MAX_EXEC_OUTPUT_DELTAS_PER_CALL: usize = 10_000;
4646

47-
#[derive(Debug, Clone)]
47+
#[derive(Clone, Debug)]
4848
pub struct ExecParams {
4949
pub command: Vec<String>,
5050
pub cwd: PathBuf,

codex-rs/core/src/openai_tools.rs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ mod tests {
10331033
}
10341034

10351035
#[test]
1036-
fn test_shell_tool_for_sandbox_workspace_write() {
1036+
fn test_shell_tool() {
10371037
let tool = super::create_shell_tool();
10381038
let OpenAiTool::Function(ResponsesApiTool {
10391039
description, name, ..
@@ -1046,33 +1046,4 @@ mod tests {
10461046
let expected = "Runs a shell command and returns its output.";
10471047
assert_eq!(description, expected);
10481048
}
1049-
1050-
#[test]
1051-
fn test_shell_tool_for_sandbox_readonly() {
1052-
let tool = super::create_shell_tool();
1053-
let OpenAiTool::Function(ResponsesApiTool {
1054-
description, name, ..
1055-
}) = &tool
1056-
else {
1057-
panic!("expected function tool");
1058-
};
1059-
assert_eq!(name, "shell");
1060-
1061-
let expected = "Runs a shell command and returns its output.";
1062-
assert_eq!(description, expected);
1063-
}
1064-
1065-
#[test]
1066-
fn test_shell_tool_for_sandbox_danger_full_access() {
1067-
let tool = super::create_shell_tool();
1068-
let OpenAiTool::Function(ResponsesApiTool {
1069-
description, name, ..
1070-
}) = &tool
1071-
else {
1072-
panic!("expected function tool");
1073-
};
1074-
assert_eq!(name, "shell");
1075-
1076-
assert_eq!(description, "Runs a shell command and returns its output.");
1077-
}
10781049
}

0 commit comments

Comments
 (0)