Fix tests and clippy

This commit is contained in:
jimmyfraiture
2025-09-30 21:03:35 +01:00
parent 94a66e7d8b
commit ee5f5e85cd
7 changed files with 16 additions and 54 deletions

View File

@@ -1,5 +1,4 @@
use std::borrow::Cow;
use std::collections::HashMap;
use std::fmt::Debug;
use std::path::PathBuf;
use std::sync::Arc;
@@ -75,7 +74,6 @@ use crate::protocol::EventMsg;
use crate::protocol::ExecApprovalRequestEvent;
use crate::protocol::ExecCommandBeginEvent;
use crate::protocol::ExecCommandEndEvent;
use crate::protocol::FileChange;
use crate::protocol::InputItem;
use crate::protocol::ListCustomPromptsResponseEvent;
use crate::protocol::Op;
@@ -1089,23 +1087,6 @@ impl Drop for Session {
}
}
#[derive(Clone, Debug)]
pub(crate) struct ExecCommandContext {
pub(crate) sub_id: String,
pub(crate) call_id: String,
pub(crate) command_for_display: Vec<String>,
pub(crate) cwd: PathBuf,
pub(crate) apply_patch: Option<ApplyPatchCommandContext>,
pub(crate) tool_name: String,
pub(crate) otel_event_manager: OtelEventManager,
}
#[derive(Clone, Debug)]
pub(crate) struct ApplyPatchCommandContext {
pub(crate) user_explicitly_approved_this_action: bool,
pub(crate) changes: HashMap<PathBuf, FileChange>,
}
async fn submission_loop(
sess: Arc<Session>,
turn_context: TurnContext,
@@ -2365,6 +2346,8 @@ pub(crate) async fn exit_review_mode(
use crate::executor::errors::ExecError;
use crate::executor::linkers::PreparedExec;
use crate::tools::context::ApplyPatchCommandContext;
use crate::tools::context::ExecCommandContext;
#[cfg(test)]
pub(crate) use tests::make_session_and_context;

View File

@@ -10,11 +10,11 @@ pub(crate) use runner::ExecutorConfig;
pub(crate) use runner::normalize_exec_result;
pub(crate) mod linkers {
use crate::codex::ExecCommandContext;
use crate::exec::ExecParams;
use crate::exec::StdoutStream;
use crate::executor::backends::ExecutionMode;
use crate::executor::runner::ExecutionRequest;
use crate::tools::context::ExecCommandContext;
pub struct PreparedExec {
pub(crate) context: ExecCommandContext,

View File

@@ -6,7 +6,6 @@ use std::time::Duration;
use super::backends::ExecutionMode;
use super::backends::backend_for_mode;
use super::cache::ApprovalCache;
use crate::codex::ExecCommandContext;
use crate::codex::Session;
use crate::error::CodexErr;
use crate::error::SandboxErr;
@@ -24,6 +23,7 @@ use crate::protocol::AskForApproval;
use crate::protocol::ReviewDecision;
use crate::protocol::SandboxPolicy;
use crate::shell;
use crate::tools::context::ExecCommandContext;
use codex_otel::otel_event_manager::ToolDecisionSource;
#[derive(Clone, Debug)]

View File

@@ -1,3 +1,6 @@
use crate::codex::Session;
use crate::codex::TurnContext;
use crate::turn_diff_tracker::TurnDiffTracker;
use codex_otel::otel_event_manager::OtelEventManager;
use codex_protocol::models::FunctionCallOutputPayload;
use codex_protocol::models::ResponseInputItem;
@@ -8,10 +11,6 @@ use std::borrow::Cow;
use std::collections::HashMap;
use std::path::PathBuf;
use crate::codex::Session;
use crate::codex::TurnContext;
use crate::turn_diff_tracker::TurnDiffTracker;
pub struct ToolInvocation<'a> {
pub session: &'a Session,
pub turn: &'a TurnContext,
@@ -98,7 +97,7 @@ pub(crate) struct ExecCommandContext {
pub(crate) call_id: String,
pub(crate) command_for_display: Vec<String>,
pub(crate) cwd: PathBuf,
pub(crate) apply_patch: Option<crate::codex::ApplyPatchCommandContext>,
pub(crate) apply_patch: Option<ApplyPatchCommandContext>,
pub(crate) tool_name: String,
pub(crate) otel_event_manager: OtelEventManager,
}

View File

@@ -8,8 +8,6 @@ use crate::apply_patch;
use crate::apply_patch::ApplyPatchExec;
use crate::apply_patch::InternalApplyPatchInvocation;
use crate::apply_patch::convert_apply_patch_to_protocol;
use crate::codex::ApplyPatchCommandContext;
use crate::codex::ExecCommandContext;
use crate::codex::Session;
use crate::codex::TurnContext;
use crate::error::CodexErr;
@@ -21,6 +19,8 @@ use crate::executor::ExecutionMode;
use crate::executor::errors::ExecError;
use crate::executor::linkers::PreparedExec;
use crate::function_tool::FunctionCallError;
use crate::tools::context::ApplyPatchCommandContext;
use crate::tools::context::ExecCommandContext;
use crate::turn_diff_tracker::TurnDiffTracker;
use codex_apply_patch::MaybeApplyPatchVerified;
use codex_apply_patch::maybe_parse_apply_patch_verified;

View File

@@ -13,18 +13,12 @@ use crate::tools::context::ToolPayload;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum ToolKind {
Function,
Custom,
LocalShell,
UnifiedExec,
Mcp,
}
#[async_trait]
pub trait ToolHandler: Send + Sync {
fn spec(&self) -> Option<&crate::tools::spec::ResponsesApiTool> {
None
}
fn kind(&self) -> ToolKind;
fn matches_kind(&self, payload: &ToolPayload) -> bool {
@@ -32,8 +26,6 @@ pub trait ToolHandler: Send + Sync {
(self.kind(), payload),
(ToolKind::Function, ToolPayload::Function { .. })
| (ToolKind::Function, ToolPayload::UnifiedExec { .. })
| (ToolKind::Custom, ToolPayload::Custom { .. })
| (ToolKind::LocalShell, ToolPayload::LocalShell { .. })
| (ToolKind::UnifiedExec, ToolPayload::UnifiedExec { .. })
| (ToolKind::Mcp, ToolPayload::Mcp { .. })
)
@@ -64,10 +56,6 @@ impl ToolRegistry {
// }
// }
pub fn iter_handlers(&self) -> impl Iterator<Item = (&String, &Arc<dyn ToolHandler>)> {
self.handlers.iter()
}
pub async fn dispatch<'a>(
&self,
invocation: ToolInvocation<'a>,
@@ -97,7 +85,9 @@ impl ToolRegistry {
match handler.handle(invocation).await {
Ok(output) => {
let preview = output.log_preview();
let mut guard = output_cell.lock().expect("mutex poisoned");
let mut guard = output_cell
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner);
*guard = Some(output);
Ok(preview)
}
@@ -109,7 +99,9 @@ impl ToolRegistry {
match result {
Ok(_) => {
let mut guard = output_cell.lock().expect("mutex poisoned");
let mut guard = output_cell
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner);
let output = guard.take().ok_or_else(|| {
FunctionCallError::RespondToModel("tool produced no output".to_string())
})?;
@@ -160,14 +152,6 @@ impl ToolRegistryBuilder {
// }
// }
pub fn extend(&mut self, other: ToolRegistryBuilder) {
for (name, handler) in other.handlers {
if self.handlers.insert(name.clone(), handler).is_some() {
warn!("overwriting handler for tool {name}");
}
}
}
pub fn build(self) -> ToolRegistry {
ToolRegistry::new(self.handlers)
}

View File

@@ -37,10 +37,6 @@ impl Router {
Self { registry, specs }
}
pub fn new(registry: ToolRegistry, specs: Vec<ToolSpec>) -> Self {
Self { registry, specs }
}
pub fn specs(&self) -> &[ToolSpec] {
&self.specs
}