11use insta:: assert_snapshot;
2- use std:: time:: Duration ;
32use tui_pty_e2e:: normalize_for_snapshot;
43use tui_pty_e2e:: Key ;
54use tui_pty_e2e:: SessionConfig ;
65use tui_pty_e2e:: TuiSession ;
7-
8- const TIMEOUT : Duration = Duration :: from_secs ( 10 ) ;
6+ use tui_pty_e2e :: TIMEOUT ;
7+ use tui_pty_e2e :: TIMEOUT_INPUT ;
98
109#[ test]
1110fn test_submit_prompt_default_response ( ) {
@@ -15,22 +14,23 @@ fn test_submit_prompt_default_response() {
1514
1615 // Type prompt
1716 session. send_str ( "Hello" ) . unwrap ( ) ;
18- std:: thread:: sleep ( Duration :: from_millis ( 100 ) ) ;
17+ std:: thread:: sleep ( TIMEOUT_INPUT ) ;
1918 session. wait_for_text ( "Hello" , TIMEOUT ) . unwrap ( ) ;
2019
2120 // Submit
2221 session. send_key ( Key :: Enter ) . unwrap ( ) ;
23- std:: thread:: sleep ( Duration :: from_millis ( 100 ) ) ;
22+ std:: thread:: sleep ( TIMEOUT_INPUT ) ;
2423
2524 // Wait for default mock responses
2625 // (extra long waits because the ACP can have retries, and we want the final err)
2726 session
28- . wait_for_text ( "Test message 1" , Duration :: from_secs ( 25 ) )
27+ . wait_for_text ( "Test message 1" , TIMEOUT )
2928 . expect ( "Did not receive mock response" ) ;
3029 session
3130 . wait_for_text ( "Test message 2" , TIMEOUT )
3231 . expect ( "Did not receive second mock response" ) ;
3332
33+ std:: thread:: sleep ( TIMEOUT_INPUT ) ;
3434 assert_snapshot ! (
3535 "prompt_submitted" ,
3636 normalize_for_snapshot( session. screen_contents( ) )
@@ -50,61 +50,68 @@ fn test_submit_prompt_missing_model() {
5050
5151 // Type prompt
5252 session. send_str ( "Hello" ) . unwrap ( ) ;
53- std:: thread:: sleep ( Duration :: from_millis ( 100 ) ) ;
53+ std:: thread:: sleep ( TIMEOUT_INPUT ) ;
5454 session. wait_for_text ( "Hello" , TIMEOUT ) . unwrap ( ) ;
5555
5656 // Submit
5757 session. send_key ( Key :: Enter ) . unwrap ( ) ;
58- std:: thread:: sleep ( Duration :: from_millis ( 100 ) ) ;
58+ std:: thread:: sleep ( TIMEOUT_INPUT ) ;
5959
6060 session
6161 . wait_for_text (
6262 "Model 'nonexistent' has wire_api=acp but is not registered" ,
63- Duration :: from_secs ( 10 ) ,
63+ TIMEOUT ,
6464 )
6565 . unwrap ( ) ;
6666
67+ std:: thread:: sleep ( TIMEOUT_INPUT ) ;
6768 assert_snapshot ! (
6869 "missing_model" ,
6970 normalize_for_snapshot( session. screen_contents( ) )
7071 ) ;
7172}
7273
73- // #[test]
74- // fn test_submit_prompt_custom_response() {
75- // let config = SessionConfig::new()
76- // .with_mock_response("This is a custom test response from the mock agent.");
77- //
78- // let mut session = TuiSession::spawn_with_config(18, 80, config).expect("Failed to spawn codex");
79- //
80- // session.wait_for_text("? for shortcuts", TIMEOUT).unwrap();
81- //
82- // session.send_str("test prompt").unwrap();
83- // std::thread::sleep(Duration::from_millis(100));
84- // session.send_key(Key::Enter).unwrap();
85- // std::thread::sleep(Duration::from_millis(100));
86- //
87- // session
88- // .wait_for_text("This is a custom test response", Duration::from_secs(10))
89- // .expect("Did not receive custom response");
90- //
91- // assert_snapshot!("custom_response", session.screen_contents());
92- // }
93- //
94- // #[test]
95- // fn test_multiline_input() {
96- // let mut session = TuiSession::spawn(18, 80).unwrap();
97- // session.wait_for_text("? for shortcuts", TIMEOUT).unwrap();
98- //
99- // // Type multiline prompt
100- // session.send_str("Line 1").unwrap();
101- // session.send_key(Key::Enter).unwrap();
102- // session.send_str("Line 2").unwrap();
103- // session.send_key(Key::Enter).unwrap();
104- // session.send_str("Line 3").unwrap();
105- //
106- // // Verify all lines visible
107- // session.wait_for_text("Line 1", TIMEOUT).unwrap();
108- // session.wait_for_text("Line 2", TIMEOUT).unwrap();
109- // session.wait_for_text("Line 3", TIMEOUT).unwrap();
110- // }
74+ #[ test]
75+ fn test_submit_prompt_custom_response ( ) {
76+ let config = SessionConfig :: new ( )
77+ . with_mock_response ( "This is a custom test response from the mock agent." ) ;
78+
79+ let mut session = TuiSession :: spawn_with_config ( 18 , 80 , config) . expect ( "Failed to spawn codex" ) ;
80+
81+ session. wait_for_text ( "? for shortcuts" , TIMEOUT ) . unwrap ( ) ;
82+
83+ session. send_str ( "test prompt" ) . unwrap ( ) ;
84+ std:: thread:: sleep ( TIMEOUT_INPUT ) ;
85+ session. send_key ( Key :: Enter ) . unwrap ( ) ;
86+ std:: thread:: sleep ( TIMEOUT_INPUT ) ;
87+
88+ session
89+ . wait_for_text ( "This is a custom test response" , TIMEOUT )
90+ . expect ( "Did not receive custom response" ) ;
91+
92+ std:: thread:: sleep ( TIMEOUT_INPUT ) ;
93+ assert_snapshot ! (
94+ "custom_response" ,
95+ normalize_for_snapshot( session. screen_contents( ) )
96+ ) ;
97+ }
98+
99+ #[ test]
100+ fn test_multiline_input ( ) {
101+ let mut session = TuiSession :: spawn ( 30 , 80 ) . unwrap ( ) ;
102+ session. wait_for_text ( "? for shortcuts" , TIMEOUT ) . unwrap ( ) ;
103+
104+ // Type multiline prompt
105+ session. send_str ( "Line 1\n Line 2\n Line 3" ) . unwrap ( ) ;
106+
107+ // Verify all lines visible
108+ session. wait_for_text ( "Line 1" , TIMEOUT ) . unwrap ( ) ;
109+ session. wait_for_text ( "Line 2" , TIMEOUT ) . unwrap ( ) ;
110+ session. wait_for_text ( "Line 3" , TIMEOUT ) . unwrap ( ) ;
111+
112+ std:: thread:: sleep ( TIMEOUT_INPUT ) ;
113+ assert_snapshot ! (
114+ "multiline_input" ,
115+ normalize_for_snapshot( session. screen_contents( ) )
116+ ) ;
117+ }
0 commit comments