mirror of
https://github.com/openai/codex.git
synced 2026-04-24 14:45:27 +00:00
clippy
This commit is contained in:
@@ -2401,6 +2401,7 @@ mod tests {
|
||||
use crate::tasks::SessionTask;
|
||||
use crate::tasks::SessionTaskContext;
|
||||
use crate::tools::ExecResponseFormat;
|
||||
use crate::tools::HandleExecRequest;
|
||||
use crate::tools::MODEL_FORMAT_HEAD_LINES;
|
||||
use crate::tools::MODEL_FORMAT_MAX_BYTES;
|
||||
use crate::tools::MODEL_FORMAT_MAX_LINES;
|
||||
@@ -3082,16 +3083,16 @@ mod tests {
|
||||
let sub_id = "test-sub".to_string();
|
||||
let call_id = "test-call".to_string();
|
||||
|
||||
let resp = handle_container_exec_with_params(
|
||||
let resp = handle_container_exec_with_params(HandleExecRequest {
|
||||
tool_name,
|
||||
params,
|
||||
&session,
|
||||
&turn_context,
|
||||
&mut turn_diff_tracker,
|
||||
sess: &session,
|
||||
turn_context: &turn_context,
|
||||
turn_diff_tracker: &mut turn_diff_tracker,
|
||||
sub_id,
|
||||
call_id,
|
||||
ExecResponseFormat::LegacyJson,
|
||||
)
|
||||
response_format: ExecResponseFormat::LegacyJson,
|
||||
})
|
||||
.await;
|
||||
|
||||
let Err(FunctionCallError::RespondToModel(output)) = resp else {
|
||||
@@ -3109,16 +3110,16 @@ mod tests {
|
||||
// Force DangerFullAccess to avoid platform sandbox dependencies in tests.
|
||||
turn_context.sandbox_policy = SandboxPolicy::DangerFullAccess;
|
||||
|
||||
let resp2 = handle_container_exec_with_params(
|
||||
let resp2 = handle_container_exec_with_params(HandleExecRequest {
|
||||
tool_name,
|
||||
params2,
|
||||
&session,
|
||||
&turn_context,
|
||||
&mut turn_diff_tracker,
|
||||
"test-sub".to_string(),
|
||||
"test-call-2".to_string(),
|
||||
ExecResponseFormat::LegacyJson,
|
||||
)
|
||||
params: params2,
|
||||
sess: &session,
|
||||
turn_context: &turn_context,
|
||||
turn_diff_tracker: &mut turn_diff_tracker,
|
||||
sub_id: "test-sub".to_string(),
|
||||
call_id: "test-call-2".to_string(),
|
||||
response_format: ExecResponseFormat::LegacyJson,
|
||||
})
|
||||
.await;
|
||||
|
||||
let output = resp2.expect("expected Ok result");
|
||||
|
||||
@@ -9,6 +9,7 @@ use crate::exec::ExecParams;
|
||||
use crate::function_tool::FunctionCallError;
|
||||
use crate::openai_tools::JsonSchema;
|
||||
use crate::tools::ExecResponseFormat;
|
||||
use crate::tools::HandleExecRequest;
|
||||
use crate::tools::context::ToolInvocation;
|
||||
use crate::tools::context::ToolOutput;
|
||||
use crate::tools::context::ToolPayload;
|
||||
@@ -77,16 +78,16 @@ impl ToolHandler for ApplyPatchHandler {
|
||||
justification: None,
|
||||
};
|
||||
|
||||
let content = handle_container_exec_with_params(
|
||||
tool_name.as_str(),
|
||||
exec_params,
|
||||
session,
|
||||
turn,
|
||||
tracker,
|
||||
sub_id.to_string(),
|
||||
call_id.clone(),
|
||||
let content = handle_container_exec_with_params(HandleExecRequest {
|
||||
tool_name: tool_name.as_str(),
|
||||
params: exec_params,
|
||||
sess: session,
|
||||
turn_context: turn,
|
||||
turn_diff_tracker: tracker,
|
||||
sub_id: sub_id.to_string(),
|
||||
call_id: call_id.clone(),
|
||||
response_format,
|
||||
)
|
||||
})
|
||||
.await?;
|
||||
|
||||
Ok(ToolOutput::Function {
|
||||
|
||||
@@ -6,6 +6,7 @@ use crate::exec::ExecParams;
|
||||
use crate::exec_env::create_env;
|
||||
use crate::function_tool::FunctionCallError;
|
||||
use crate::tools::ExecResponseFormat;
|
||||
use crate::tools::HandleExecRequest;
|
||||
use crate::tools::context::ToolInvocation;
|
||||
use crate::tools::context::ToolOutput;
|
||||
use crate::tools::context::ToolPayload;
|
||||
@@ -73,16 +74,16 @@ impl ToolHandler for ShellHandler {
|
||||
))
|
||||
})?;
|
||||
let exec_params = Self::to_exec_params(params, turn);
|
||||
let content = handle_container_exec_with_params(
|
||||
tool_name.as_str(),
|
||||
exec_params,
|
||||
session,
|
||||
turn,
|
||||
tracker,
|
||||
sub_id.to_string(),
|
||||
call_id.clone(),
|
||||
let content = handle_container_exec_with_params(HandleExecRequest {
|
||||
tool_name: tool_name.as_str(),
|
||||
params: exec_params,
|
||||
sess: session,
|
||||
turn_context: turn,
|
||||
turn_diff_tracker: tracker,
|
||||
sub_id: sub_id.to_string(),
|
||||
call_id: call_id.clone(),
|
||||
response_format,
|
||||
)
|
||||
})
|
||||
.await?;
|
||||
Ok(ToolOutput::Function {
|
||||
content,
|
||||
@@ -91,16 +92,16 @@ impl ToolHandler for ShellHandler {
|
||||
}
|
||||
ToolPayload::LocalShell { params } => {
|
||||
let exec_params = Self::to_exec_params(params, turn);
|
||||
let content = handle_container_exec_with_params(
|
||||
tool_name.as_str(),
|
||||
exec_params,
|
||||
session,
|
||||
turn,
|
||||
tracker,
|
||||
sub_id.to_string(),
|
||||
call_id.clone(),
|
||||
let content = handle_container_exec_with_params(HandleExecRequest {
|
||||
tool_name: tool_name.as_str(),
|
||||
params: exec_params,
|
||||
sess: session,
|
||||
turn_context: turn,
|
||||
turn_diff_tracker: tracker,
|
||||
sub_id: sub_id.to_string(),
|
||||
call_id: call_id.clone(),
|
||||
response_format,
|
||||
)
|
||||
})
|
||||
.await?;
|
||||
Ok(ToolOutput::Function {
|
||||
content,
|
||||
|
||||
@@ -51,16 +51,30 @@ pub(crate) enum ExecResponseFormat {
|
||||
}
|
||||
|
||||
// TODO(jif) break this down
|
||||
pub(crate) struct HandleExecRequest<'a> {
|
||||
pub tool_name: &'a str,
|
||||
pub params: ExecParams,
|
||||
pub sess: &'a Session,
|
||||
pub turn_context: &'a TurnContext,
|
||||
pub turn_diff_tracker: &'a mut TurnDiffTracker,
|
||||
pub sub_id: String,
|
||||
pub call_id: String,
|
||||
pub response_format: ExecResponseFormat,
|
||||
}
|
||||
|
||||
pub(crate) async fn handle_container_exec_with_params(
|
||||
tool_name: &str,
|
||||
params: ExecParams,
|
||||
sess: &Session,
|
||||
turn_context: &TurnContext,
|
||||
turn_diff_tracker: &mut TurnDiffTracker,
|
||||
sub_id: String,
|
||||
call_id: String,
|
||||
response_format: ExecResponseFormat,
|
||||
request: HandleExecRequest<'_>,
|
||||
) -> Result<String, FunctionCallError> {
|
||||
let HandleExecRequest {
|
||||
tool_name,
|
||||
params,
|
||||
sess,
|
||||
turn_context,
|
||||
turn_diff_tracker,
|
||||
sub_id,
|
||||
call_id,
|
||||
response_format,
|
||||
} = request;
|
||||
let otel_event_manager = turn_context.client.get_otel_event_manager();
|
||||
|
||||
if params.with_escalated_permissions.unwrap_or(false)
|
||||
@@ -228,7 +242,7 @@ fn format_unexpected_exec_error(err: CodexErr, response_format: ExecResponseForm
|
||||
}
|
||||
|
||||
fn format_structured_error(message: &str) -> String {
|
||||
let lines = vec![
|
||||
let lines = [
|
||||
"Exit code: N/A".to_string(),
|
||||
"Wall time: N/A seconds".to_string(),
|
||||
format!("Error: {message}"),
|
||||
|
||||
Reference in New Issue
Block a user