@@ -6,31 +6,60 @@ use std::collections::HashMap;
66use std:: time:: Duration ;
77use tracing:: info;
88
9- #[ tokio:: test]
10- async fn test_agent_spawn_hook ( ) {
11- let _ = tracing_subscriber:: fmt:: try_init ( ) ;
12- // creates the agent config with the agent spawn hook
13- let mut hooks = HashMap :: new ( ) ;
14- hooks. insert (
15- HookTrigger :: AgentSpawn ,
16- vec ! [ HookConfig :: ShellCommand ( CommandHook {
17- command: "echo 'Agent initialized'" . to_string( ) ,
18- opts: BaseHookConfig {
19- timeout_ms: 5000 ,
20- max_output_size: 1024 ,
21- cache_ttl_seconds: 0 ,
22- matcher: None ,
23- } ,
24- } ) ] ,
25- ) ;
9+ fn create_spawn_hook_single_shell_config ( ) -> AgentConfig {
10+ let hooks = HashMap :: from ( [
11+ (
12+ HookTrigger :: AgentSpawn ,
13+ vec ! [ HookConfig :: ShellCommand ( CommandHook {
14+ command: "echo 'Agent initialized'" . to_string( ) ,
15+ opts: BaseHookConfig {
16+ timeout_ms: 5000 ,
17+ max_output_size: 1024 ,
18+ cache_ttl_seconds: 0 ,
19+ matcher: None ,
20+ } ,
21+ } ) ] ,
22+ ) ,
23+ ] ) ;
2624
27- let agent_config = AgentConfig :: V2025_08_22 ( AgentConfigV2025_08_22 {
25+ AgentConfig :: V2025_08_22 ( AgentConfigV2025_08_22 {
2826 hooks,
2927 ..Default :: default ( )
30- } ) ;
28+ } )
29+ }
30+
31+
32+ #[ tokio:: test]
33+ async fn test_agent_spawn_hook_single ( ) {
34+ let _ = tracing_subscriber:: fmt:: try_init ( ) ;
35+
36+ let mut test: TestCase = TestCase :: builder ( )
37+ . test_name ( "agent spawn hook behavior" )
38+ . with_agent_config ( create_spawn_hook_single_shell_config ( ) )
39+ . with_responses (
40+ parse_response_streams ( include_str ! ( "./mock_responses/simple_two_turn.jsonl" ) )
41+ . await
42+ . unwrap ( ) ,
43+ )
44+ . build ( )
45+ . await
46+ . unwrap ( ) ;
47+
48+ test. wait_until_agent_initializes ( Duration :: from_millis ( 100 ) ) . await ;
49+ test. send_prompt ( "hello" . to_string ( ) ) . await ;
50+ test. wait_until_agent_stop ( Duration :: from_millis ( 100 ) ) . await ;
51+ let req = test. requests ( ) . first ( ) . expect ( "should have one request" ) ;
52+ let first_msg = req. messages ( ) . first ( ) . expect ( "first message should exist" ) . text ( ) ;
53+ assert_contains ( & first_msg, "Agent initialized" ) ;
54+ }
55+
56+ #[ tokio:: test]
57+ async fn test_agent_spawn_hook_persistence ( ) {
58+ let _ = tracing_subscriber:: fmt:: try_init ( ) ;
59+
3160 let mut test: TestCase = TestCase :: builder ( )
3261 . test_name ( "agent spawn hook behavior" )
33- . with_agent_config ( agent_config )
62+ . with_agent_config ( create_spawn_hook_single_shell_config ( ) )
3463 . with_responses (
3564 parse_response_streams ( include_str ! ( "./mock_responses/simple_two_turn.jsonl" ) )
3665 . await
@@ -40,11 +69,11 @@ async fn test_agent_spawn_hook() {
4069 . await
4170 . unwrap ( ) ;
4271
43- test. wait_until_agent_initializes ( Duration :: from_millis ( 500 ) ) . await ;
72+ test. wait_until_agent_initializes ( Duration :: from_millis ( 100 ) ) . await ;
4473 test. send_prompt ( "hello" . to_string ( ) ) . await ;
45- info ! ( "before stop" ) ;
46- test. wait_until_agent_stop ( Duration :: from_secs ( 10 ) ) . await ;
47- info ! ( "after stop" ) ;
74+ test . wait_until_agent_stop ( Duration :: from_millis ( 100 ) ) . await ;
75+ test. send_prompt ( "bye" . to_string ( ) ) . await ;
76+ test . wait_until_agent_stop ( Duration :: from_millis ( 100 ) ) . await ;
4877 for req in test. requests ( ) {
4978 let first_msg = req. messages ( ) . first ( ) . expect ( "first message should exist" ) . text ( ) ;
5079 assert_contains ( & first_msg, "Agent initialized" ) ;
0 commit comments