From 13ee1735c0063463ec1d2e00cd8a8733cd09366f Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Sat, 7 Mar 2026 23:01:15 -0500 Subject: [PATCH] Consolidate duplicate test backends in prompt handler tests Hoist OneShotCapturingBackend to module scope and remove two identical CapturingBackend definitions that duplicated its functionality. Co-Authored-By: Claude Opus 4.6 (1M context) --- crates/arc-workflows/src/handler/prompt.rs | 160 ++++++--------------- 1 file changed, 42 insertions(+), 118 deletions(-) diff --git a/crates/arc-workflows/src/handler/prompt.rs b/crates/arc-workflows/src/handler/prompt.rs index 7c3f07c0f..f02037cfb 100644 --- a/crates/arc-workflows/src/handler/prompt.rs +++ b/crates/arc-workflows/src/handler/prompt.rs @@ -251,50 +251,48 @@ mod tests { assert_eq!(response_content, "one-shot response"); } + struct OneShotCapturingBackend { + captured_prompt: Arc>>, + captured_system_prompt: Arc>>>, + } + + #[async_trait] + impl CodergenBackend for OneShotCapturingBackend { + async fn run( + &self, + _node: &Node, + _prompt: &str, + _context: &Context, + _thread_id: Option<&str>, + _emitter: &Arc, + _stage_dir: &Path, + _sandbox: &Arc, + ) -> Result { + panic!("run() should not be called for prompt handler"); + } + + async fn one_shot( + &self, + _node: &Node, + prompt: &str, + system_prompt: Option<&str>, + _stage_dir: &Path, + ) -> Result { + *self.captured_prompt.lock().unwrap() = Some(prompt.to_string()); + *self.captured_system_prompt.lock().unwrap() = + Some(system_prompt.map(String::from)); + Ok(CodergenResult::Text { + text: "classified".to_string(), + usage: None, + files_touched: Vec::new(), + }) + } + } + #[tokio::test] async fn prompt_handler_prepends_preamble() { use std::sync::Mutex; - use arc_agent::Sandbox; - - struct OneShotCapturingBackend { - captured_prompt: Arc>>, - captured_system_prompt: Arc>>>, - } - - #[async_trait] - impl CodergenBackend for OneShotCapturingBackend { - async fn run( - &self, - _node: &Node, - _prompt: &str, - _context: &Context, - _thread_id: Option<&str>, - _emitter: &Arc, - _stage_dir: &Path, - _sandbox: &Arc, - ) -> Result { - panic!("run() should not be called for prompt handler"); - } - - async fn one_shot( - &self, - _node: &Node, - prompt: &str, - system_prompt: Option<&str>, - _stage_dir: &Path, - ) -> Result { - *self.captured_prompt.lock().unwrap() = Some(prompt.to_string()); - *self.captured_system_prompt.lock().unwrap() = - Some(system_prompt.map(String::from)); - Ok(CodergenResult::Text { - text: "classified".to_string(), - usage: None, - files_touched: Vec::new(), - }) - } - } - let captured = Arc::new(Mutex::new(None)); let backend = OneShotCapturingBackend { captured_prompt: captured.clone(), @@ -329,46 +327,9 @@ mod tests { async fn prompt_handler_passes_system_prompt_when_project_memory_enabled() { use std::sync::Mutex; - use arc_agent::Sandbox; - - struct CapturingBackend { - captured_system_prompt: Arc>>>, - } - - #[async_trait] - impl CodergenBackend for CapturingBackend { - async fn run( - &self, - _node: &Node, - _prompt: &str, - _context: &Context, - _thread_id: Option<&str>, - _emitter: &Arc, - _stage_dir: &Path, - _sandbox: &Arc, - ) -> Result { - panic!("run() should not be called for prompt handler"); - } - - async fn one_shot( - &self, - _node: &Node, - _prompt: &str, - system_prompt: Option<&str>, - _stage_dir: &Path, - ) -> Result { - *self.captured_system_prompt.lock().unwrap() = - Some(system_prompt.map(String::from)); - Ok(CodergenResult::Text { - text: "ok".to_string(), - usage: None, - files_touched: Vec::new(), - }) - } - } - let captured_sys = Arc::new(Mutex::new(None)); - let backend = CapturingBackend { + let backend = OneShotCapturingBackend { + captured_prompt: Arc::new(Mutex::new(None)), captured_system_prompt: captured_sys.clone(), }; let handler = PromptHandler::new(Some(Box::new(backend))); @@ -398,46 +359,9 @@ mod tests { async fn prompt_handler_passes_none_system_prompt_when_project_memory_false() { use std::sync::Mutex; - use arc_agent::Sandbox; - - struct CapturingBackend { - captured_system_prompt: Arc>>>, - } - - #[async_trait] - impl CodergenBackend for CapturingBackend { - async fn run( - &self, - _node: &Node, - _prompt: &str, - _context: &Context, - _thread_id: Option<&str>, - _emitter: &Arc, - _stage_dir: &Path, - _sandbox: &Arc, - ) -> Result { - panic!("run() should not be called for prompt handler"); - } - - async fn one_shot( - &self, - _node: &Node, - _prompt: &str, - system_prompt: Option<&str>, - _stage_dir: &Path, - ) -> Result { - *self.captured_system_prompt.lock().unwrap() = - Some(system_prompt.map(String::from)); - Ok(CodergenResult::Text { - text: "ok".to_string(), - usage: None, - files_touched: Vec::new(), - }) - } - } - let captured_sys = Arc::new(Mutex::new(None)); - let backend = CapturingBackend { + let backend = OneShotCapturingBackend { + captured_prompt: Arc::new(Mutex::new(None)), captured_system_prompt: captured_sys.clone(), }; let handler = PromptHandler::new(Some(Box::new(backend)));