@@ -216,7 +216,7 @@ impl TaskExecutor {
216216 }
217217 } ) ;
218218 } ,
219- HookConfig :: Tool ( tool ) => ( ) ,
219+ HookConfig :: Tool ( _ ) => ( ) ,
220220 } ;
221221
222222 let start_time = Utc :: now ( ) ;
@@ -282,6 +282,12 @@ impl TaskExecutor {
282282 }
283283}
284284
285+ impl Default for TaskExecutor {
286+ fn default ( ) -> Self {
287+ Self :: new ( )
288+ }
289+ }
290+
285291#[ derive( Debug ) ]
286292pub enum ExecuteRequest {
287293 Tool ( StartToolExecution ) ,
@@ -336,6 +342,7 @@ struct ExecutingHook {
336342}
337343
338344#[ derive( Debug , Clone , Serialize , Deserialize ) ]
345+ #[ allow( clippy:: large_enum_variant) ]
339346pub enum TaskExecutorEvent {
340347 /// A tool has started executing
341348 ToolExecutionStart ( ToolExecutionStartEvent ) ,
@@ -406,6 +413,7 @@ impl ToolExecutionId {
406413}
407414
408415#[ derive( Debug , Clone , Serialize , Deserialize ) ]
416+ #[ allow( clippy:: large_enum_variant) ]
409417pub enum ExecutorResult {
410418 Tool ( ToolExecutorResult ) ,
411419 Hook ( HookExecutorResult ) ,
@@ -505,7 +513,7 @@ impl HookResult {
505513 pub fn is_success ( & self ) -> bool {
506514 match self {
507515 HookResult :: Command ( res) => res. as_ref ( ) . is_ok_and ( |r| r. exit_code == 0 ) ,
508- HookResult :: Tool { .. } => todo ! ( ) ,
516+ HookResult :: Tool { .. } => panic ! ( "unimplemented" ) ,
509517 }
510518 }
511519
@@ -516,7 +524,6 @@ impl HookResult {
516524 pub fn output ( & self ) -> Option < & str > {
517525 match self {
518526 HookResult :: Command ( Ok ( CommandResult { output, .. } ) ) => Some ( output) ,
519- HookResult :: Tool { output } => todo ! ( ) ,
520527 _ => None ,
521528 }
522529 }
@@ -668,44 +675,42 @@ fn sanitize_user_prompt(input: &str) -> String {
668675#[ cfg( test) ]
669676mod tests {
670677 use super :: * ;
671- use crate :: agent:: types:: AgentId ;
672-
673- const TEST_AGENT_NAME : & str = "test_agent" ;
674678
675679 const TEST_COMMAND_HOOK : & str = r#"
676680{
677681 "command": "echo hello world"
678682}
679683"# ;
680684
681- async fn run_with_timeout < T : Future > ( fut : T ) {
682- match tokio:: time:: timeout ( std :: time :: Duration :: from_millis ( 500 ) , fut) . await {
685+ async fn run_with_timeout < T : Future > ( timeout : Duration , fut : T ) {
686+ match tokio:: time:: timeout ( timeout , fut) . await {
683687 Ok ( _) => ( ) ,
684688 Err ( e) => panic ! ( "Future failed to resolve within timeout: {}" , e) ,
685689 }
686690 }
687691
688692 #[ tokio:: test]
689693 async fn test_hook_execution ( ) {
690- let mut bg = TaskExecutor :: new ( ) ;
691-
692- let agent_id = AgentId :: new ( TEST_AGENT_NAME . to_string ( ) ) ;
693- bg. start_hook_execution ( StartHookExecution {
694- id : HookExecutionId {
695- hook : Hook {
696- trigger : HookTrigger :: UserPromptSubmit ,
697- config : serde_json:: from_str ( TEST_COMMAND_HOOK ) . unwrap ( ) ,
694+ let mut executor = TaskExecutor :: new ( ) ;
695+
696+ executor
697+ . start_hook_execution ( StartHookExecution {
698+ id : HookExecutionId {
699+ hook : Hook {
700+ trigger : HookTrigger :: UserPromptSubmit ,
701+ config : serde_json:: from_str ( TEST_COMMAND_HOOK ) . unwrap ( ) ,
702+ } ,
703+ tool_context : None ,
698704 } ,
699- tool_context : None ,
700- } ,
701- prompt : None ,
702- } )
703- . await ;
705+ prompt : None ,
706+ } )
707+ . await ;
704708
705- run_with_timeout ( async move {
709+ run_with_timeout ( Duration :: from_millis ( 100 ) , async move {
706710 let mut event_buf = Vec :: new ( ) ;
707711 loop {
708- bg. recv_next ( & mut event_buf) . await ;
712+ executor. recv_next ( & mut event_buf) . await ;
713+ // Check if we get a "hello world" successful hook execution.
709714 if event_buf. iter ( ) . any ( |ev| match ev {
710715 TaskExecutorEvent :: HookExecutionEnd ( HookExecutionEndEvent { result, .. } ) => {
711716 let HookExecutorResult :: Completed { result, .. } = result else {
@@ -720,9 +725,9 @@ mod tests {
720725 } ,
721726 _ => false ,
722727 } ) {
728+ // Hook succeeded with expected output, break.
723729 break ;
724730 }
725- println ! ( "{:?}" , event_buf) ;
726731 event_buf. drain ( ..) ;
727732 }
728733 } )
0 commit comments