@@ -120,4 +120,54 @@ async fn test_user_prompt_hook_single() {
120120 let req = test. requests ( ) . first ( ) . expect ( "should have one request" ) ;
121121 let first_msg = req. messages ( ) . first ( ) . expect ( "first message should exist" ) . text ( ) ;
122122 assert_contains ( & first_msg, "submitted!" ) ;
123- }
123+ }
124+
125+ #[ tokio:: test]
126+ async fn test_user_prompt_hook_persistence ( ) {
127+ let _ = tracing_subscriber:: fmt:: try_init ( ) ;
128+
129+ let hooks = HashMap :: from ( [
130+ (
131+ HookTrigger :: UserPromptSubmit ,
132+ vec ! [ HookConfig :: ShellCommand ( CommandHook {
133+ command: "printf 'a' >> turns.txt; printf \" char count: $(wc -c < turns.txt | tr -d ' ')\" " . to_string( ) ,
134+ opts: BaseHookConfig {
135+ timeout_ms: 5000 ,
136+ max_output_size: 1024 ,
137+ cache_ttl_seconds: 0 ,
138+ matcher: None ,
139+ } ,
140+ } ) ] ,
141+ ) ,
142+ ] ) ;
143+
144+ let agent_config = AgentConfig :: V2025_08_22 ( AgentConfigV2025_08_22 {
145+ hooks,
146+ ..Default :: default ( )
147+ } ) ;
148+ let mut test: TestCase = TestCase :: builder ( )
149+ . test_name ( "user prompt submit hook behavior for single shell command and one turn" )
150+ . with_agent_config ( agent_config)
151+ . with_test_perprompt_hook ( )
152+ . with_file ( ( "turns.txt" , "" ) )
153+ . with_responses (
154+ parse_response_streams ( include_str ! ( "./mock_responses/simple_two_turn.jsonl" ) )
155+ . await
156+ . unwrap ( ) ,
157+ )
158+ . build ( )
159+ . await
160+ . unwrap ( ) ;
161+
162+ test. wait_until_agent_initializes ( Duration :: from_millis ( 100 ) ) . await ;
163+ test. send_prompt ( "hello" . to_string ( ) ) . await ;
164+ test. wait_until_agent_stop ( Duration :: from_millis ( 100 ) ) . await ;
165+ test. send_prompt ( "bye" . to_string ( ) ) . await ;
166+ test. wait_until_agent_stop ( Duration :: from_millis ( 100 ) ) . await ;
167+ let req = test. requests ( ) . first ( ) . expect ( "first request should exist" ) ;
168+ let first_msg = req. messages ( ) . first ( ) . expect ( "first message should exist" ) . text ( ) ;
169+ assert_contains ( & first_msg, "char count: 1" ) ;
170+ let req = test. requests ( ) . get ( 1 ) . expect ( "second request should exist" ) ;
171+ let first_msg = req. messages ( ) . first ( ) . expect ( "first message should exist" ) . text ( ) ;
172+ assert_contains ( & first_msg, "char count: 2" ) ;
173+ }
0 commit comments