From 5f5f4979de0ef1876470038868617554cd2e4af1 Mon Sep 17 00:00:00 2001 From: lucarlig Date: Fri, 21 Aug 2026 17:40:10 +0100 Subject: [PATCH] fix: avoid unused async trait handlers Signed-off-by: lucarlig --- .../src/handle.rs | 8 +++---- .../tests/support/paginating_mock.rs | 8 +++---- .../tests/support/plugin.rs | 22 ++++++++--------- .../tests/support/plugin_gateway.rs | 24 ++++++++++++------- .../plugins/cpex-secrets-detection/src/lib.rs | 10 ++++---- 5 files changed, 39 insertions(+), 33 deletions(-) diff --git a/crates/contextforge-data-plane-cpex/src/handle.rs b/crates/contextforge-data-plane-cpex/src/handle.rs index eae5f182..5251758d 100644 --- a/crates/contextforge-data-plane-cpex/src/handle.rs +++ b/crates/contextforge-data-plane-cpex/src/handle.rs @@ -510,12 +510,12 @@ mod tests { } impl HookHandler for TestPlugin { - async fn handle( + fn handle( &self, payload: &MessagePayload, _extensions: &Extensions, ctx: &mut PluginContext, - ) -> PluginResult { + ) -> impl std::future::Future> { let is_post = payload.message.role == Role::Tool; let mut observations = self.observations.lock().expect("observations lock poisoned"); if is_post { @@ -529,7 +529,7 @@ mod tests { } drop(observations); - if is_post { + std::future::ready(if is_post { match self.post_behavior { PostBehavior::Allow => PluginResult::allow(), PostBehavior::Rewrite => PluginResult::modify_payload(payload.clone()), @@ -604,7 +604,7 @@ mod tests { PluginResult::allow() }, } - } + }) } } diff --git a/crates/contextforge-data-plane-lib/tests/support/paginating_mock.rs b/crates/contextforge-data-plane-lib/tests/support/paginating_mock.rs index 0e8b2066..e3a91cf6 100755 --- a/crates/contextforge-data-plane-lib/tests/support/paginating_mock.rs +++ b/crates/contextforge-data-plane-lib/tests/support/paginating_mock.rs @@ -36,17 +36,17 @@ impl ServerHandler for PaginatingServer { .with_protocol_version(ProtocolVersion::V_2024_11_05) } - async fn list_tools( + fn list_tools( &self, request: Option, _: RequestContext, - ) -> Result { - if request.as_ref().and_then(|r| r.cursor.as_deref()) == Some(PAGE2_CURSOR) { + ) -> impl std::future::Future> { + std::future::ready(if request.as_ref().and_then(|r| r.cursor.as_deref()) == Some(PAGE2_CURSOR) { Ok(ListToolsResult::with_all_items(Self::page2_tools())) } else { let mut result = ListToolsResult::with_all_items(Self::page1_tools()); result.next_cursor = Some(PAGE2_CURSOR.to_owned()); Ok(result) - } + }) } } diff --git a/crates/contextforge-data-plane-lib/tests/support/plugin.rs b/crates/contextforge-data-plane-lib/tests/support/plugin.rs index 788bfe9f..294dc300 100644 --- a/crates/contextforge-data-plane-lib/tests/support/plugin.rs +++ b/crates/contextforge-data-plane-lib/tests/support/plugin.rs @@ -154,12 +154,12 @@ impl Plugin for TestPlugin { } impl HookHandler for TestPlugin { - async fn handle( + fn handle( &self, payload: &MessagePayload, _extensions: &Extensions, ctx: &mut PluginContext, - ) -> PluginResult { + ) -> impl std::future::Future> { let is_post = payload.message.role == Role::Tool; let mut observations = self.observations.lock().expect("observations lock poisoned"); if is_post { @@ -180,7 +180,7 @@ impl HookHandler for TestPlugin { } drop(observations); - if is_post { + std::future::ready(if is_post { match self.post_behavior { PostBehavior::Allow => PluginResult::allow(), PostBehavior::Rewrite => { @@ -190,7 +190,7 @@ impl HookHandler for TestPlugin { modified.message.content.iter_mut().find(|part| matches!(part, ContentPart::ToolResult { .. })) { if !is_tool_result_content(&content.content) { - return PluginResult::allow(); + return std::future::ready(PluginResult::allow()); } content.content = serde_json::to_value(CallToolResult::success(vec![ContentBlock::text( format!("post:{result_text}"), @@ -205,7 +205,7 @@ impl HookHandler for TestPlugin { modified.message.content.iter_mut().find(|part| matches!(part, ContentPart::ToolResult { .. })) { if !is_tool_result_content(&content.content) { - return PluginResult::allow(); + return std::future::ready(PluginResult::allow()); } content.content = json!("raw-post"); } @@ -220,7 +220,7 @@ impl HookHandler for TestPlugin { { progress.message = progress.message.map(|message| format!("plugin:{message}")); content.content = serde_json::to_value(progress).expect("progress serializes"); - return PluginResult::modify_payload(modified); + return std::future::ready(PluginResult::modify_payload(modified)); } PluginResult::allow() }, @@ -279,7 +279,7 @@ impl HookHandler for TestPlugin { PluginResult::allow() }, } - } + }) } } @@ -492,17 +492,17 @@ impl Plugin for PromptTestPlugin { } impl HookHandler for PromptTestPlugin { - async fn handle( + fn handle( &self, payload: &MessagePayload, _extensions: &Extensions, ctx: &mut PluginContext, - ) -> PluginResult { - if payload.message.get_prompt_results().is_empty() { + ) -> impl std::future::Future> { + std::future::ready(if payload.message.get_prompt_results().is_empty() { self.handle_pre(payload, ctx) } else { self.handle_post(payload, ctx) - } + }) } } diff --git a/crates/contextforge-data-plane-lib/tests/support/plugin_gateway.rs b/crates/contextforge-data-plane-lib/tests/support/plugin_gateway.rs index a118e25a..32d88fa5 100644 --- a/crates/contextforge-data-plane-lib/tests/support/plugin_gateway.rs +++ b/crates/contextforge-data-plane-lib/tests/support/plugin_gateway.rs @@ -59,20 +59,22 @@ struct TestBackend { } impl ServerHandler for TestBackend { - async fn initialize( + fn initialize( &self, _request: InitializeRequestParams, _cx: RequestContext, - ) -> Result { - Ok(InitializeResult::new(ServerCapabilities::builder().enable_tools().enable_prompts().build()) - .with_server_info(Implementation::new("test-backend", "0.1.0"))) + ) -> impl std::future::Future> { + std::future::ready(Ok(InitializeResult::new( + ServerCapabilities::builder().enable_tools().enable_prompts().build(), + ) + .with_server_info(Implementation::new("test-backend", "0.1.0")))) } - async fn get_prompt( + fn get_prompt( &self, request: GetPromptRequestParams, _cx: RequestContext, - ) -> Result { + ) -> impl std::future::Future> { self.state .prompts .lock() @@ -87,7 +89,7 @@ impl ServerHandler for TestBackend { .and_then(Value::as_str) .unwrap_or("nothing"); if request.name == "review_bundle" { - return Ok(GetPromptResult::new(vec![ + return std::future::ready(Ok(GetPromptResult::new(vec![ PromptMessage::new_text(Role::User, format!("review of {topic}")), PromptMessage::new( Role::User, @@ -95,10 +97,14 @@ impl ServerHandler for TestBackend { ), PromptMessage::new(Role::Assistant, ContentBlock::image(BACKEND_PROMPT_IMAGE, "image/png")), ]) - .into()); + .into())); } - Ok(GetPromptResult::new(vec![PromptMessage::new_text(Role::User, format!("review of {topic}"))]).into()) + std::future::ready(Ok(GetPromptResult::new(vec![PromptMessage::new_text( + Role::User, + format!("review of {topic}"), + )]) + .into())) } async fn call_tool( diff --git a/crates/plugins/cpex-secrets-detection/src/lib.rs b/crates/plugins/cpex-secrets-detection/src/lib.rs index 09f0e26e..ba74c68d 100644 --- a/crates/plugins/cpex-secrets-detection/src/lib.rs +++ b/crates/plugins/cpex-secrets-detection/src/lib.rs @@ -80,12 +80,12 @@ impl Plugin for StageHandler { } impl HookHandler for StageHandler { - async fn handle( + fn handle( &self, payload: &MessagePayload, extensions: &Extensions, _ctx: &mut PluginContext, - ) -> PluginResult { + ) -> impl std::future::Future> { let scan = self.scan_payload(payload); if self.core.should_block(scan.count) { @@ -93,20 +93,20 @@ impl HookHandler for StageHandler { let mut result = PluginResult::deny(violation); result.modified_payload = scan.modified_payload.or_else(|| Some(payload.clone())); attach_metrics(&mut result, extensions, scan.count, &scan.findings, DetectionOutcome::Blocked); - return result; + return std::future::ready(result); } if let Some(modified_payload) = scan.modified_payload { let mut result = PluginResult::modify_payload(modified_payload); attach_metrics(&mut result, extensions, scan.count, &scan.findings, DetectionOutcome::Masked); - return result; + return std::future::ready(result); } let mut result = PluginResult::allow(); if scan.count > 0 { attach_metrics(&mut result, extensions, scan.count, &scan.findings, DetectionOutcome::None); } - result + std::future::ready(result) } }