@@ -417,11 +417,13 @@ fn process_remote_followups_auto_submits_staged_startup_prompt() {
417417}
418418
419419#[ test]
420- fn process_remote_followups_sends_startup_prompt_before_history_arrives ( ) {
420+ fn process_remote_followups_waits_for_history_before_sending_startup_image ( ) {
421421 let mut app = create_test_app ( ) ;
422422 app. is_remote = true ;
423423 app. runtime_mode = crate :: tui:: app:: AppRuntimeMode :: RemoteClient ;
424424 app. input = "Start the fork immediately" . to_string ( ) ;
425+ let images = vec ! [ ( "image/png" . to_string( ) , "aW1hZ2U=" . to_string( ) ) ] ;
426+ app. pending_images = images. clone ( ) ;
425427 app. cursor_pos = app. input . len ( ) ;
426428 app. submit_input_on_startup = true ;
427429
@@ -430,57 +432,56 @@ fn process_remote_followups_sends_startup_prompt_before_history_arrives() {
430432 let mut remote = crate :: tui:: backend:: RemoteConnection :: dummy ( ) ;
431433 assert ! ( !remote. has_loaded_history( ) ) ;
432434
435+ let next_request_id = remote. next_request_id_for_test ( ) ;
433436 rt. block_on ( process_remote_followups ( & mut app, & mut remote) ) ;
434437
435- assert ! ( !app. submit_input_on_startup) ;
436- assert ! ( app. input. is_empty( ) ) ;
437- assert ! (
438- app. is_processing,
439- "the ordered startup request should start immediately"
440- ) ;
438+ assert ! ( app. submit_input_on_startup) ;
439+ assert_eq ! ( app. input, "Start the fork immediately" ) ;
440+ assert_eq ! ( app. pending_images, images) ;
441+ assert ! ( !app. is_processing) ;
442+ assert ! ( app. current_message_id. is_none( ) ) ;
443+ assert ! ( app. pending_startup_prompt_echo. is_none( ) ) ;
444+ assert_eq ! ( remote. next_request_id_for_test( ) , next_request_id) ;
441445 assert ! (
442- app. pending_startup_prompt_echo. as_deref( ) == Some ( "Start the fork immediately" ) ,
443- "the user echo must be retained until bootstrap History is applied"
446+ !app. display_messages( )
447+ . iter( )
448+ . any( |message| message. role == "user" )
444449 ) ;
445450
446- let startup_id = app. current_message_id . expect ( "startup request was sent" ) ;
447- let next_request_id = remote. next_request_id_for_test ( ) ;
448- let processing_started = app. processing_started ;
449- let visible_turn_started = app. visible_turn_started ;
450- // A queued recovery continuation must not dispatch behind the already-sent
451- // startup turn when Subscribe's earlier, idle History snapshot arrives.
452- app. hidden_queued_system_messages
453- . push ( "Continue after reload" . to_string ( ) ) ;
454451 handle_server_event ( & mut app, startup_history ( "startup-session" ) , & mut remote) ;
455452 assert ! ( remote. has_loaded_history( ) ) ;
456453 assert_eq ! ( app. remote_session_id. as_deref( ) , Some ( "startup-session" ) ) ;
454+ assert ! ( !app. is_processing) ;
455+ assert_eq ! ( remote. next_request_id_for_test( ) , next_request_id) ;
456+
457+ rt. block_on ( process_remote_followups ( & mut app, & mut remote) ) ;
458+ assert ! ( !app. submit_input_on_startup) ;
459+ assert ! ( app. input. is_empty( ) ) ;
460+ assert ! ( app. pending_images. is_empty( ) ) ;
457461 assert ! ( app. is_processing) ;
458462 assert ! ( matches!( app. status, crate :: tui:: ProcessingStatus :: Sending ) ) ;
459- assert_eq ! ( app. current_message_id, Some ( startup_id) ) ;
460- assert_eq ! ( app. processing_started, processing_started) ;
461- assert_eq ! ( app. visible_turn_started, visible_turn_started) ;
462- assert_eq ! (
463- app. rate_limit_pending_message
464- . as_ref( )
465- . map( |pending| pending. content. as_str( ) ) ,
466- Some ( "Start the fork immediately" )
467- ) ;
463+ let startup_id = app. current_message_id . expect ( "startup request was sent" ) ;
464+ assert_eq ! ( startup_id, next_request_id) ;
465+ let sent = app
466+ . rate_limit_pending_message
467+ . as_ref ( )
468+ . expect ( "sent payload" ) ;
469+ assert_eq ! ( sent. content, "Start the fork immediately" ) ;
470+ assert_eq ! ( sent. images, images) ;
468471
472+ let next_request_id = remote. next_request_id_for_test ( ) ;
469473 rt. block_on ( process_remote_followups ( & mut app, & mut remote) ) ;
470- assert_eq ! (
471- remote. next_request_id_for_test( ) ,
472- next_request_id,
473- "History must not enable a second send"
474- ) ;
474+ assert_eq ! ( remote. next_request_id_for_test( ) , next_request_id) ;
475475 assert_eq ! ( app. current_message_id, Some ( startup_id) ) ;
476- assert ! ( app. is_processing) ;
477476 assert_eq ! (
478- app. hidden_queued_system_messages,
479- vec![ "Continue after reload" ]
477+ app. display_messages( )
478+ . iter( )
479+ . filter( |message| {
480+ message. role == "user" && message. content == "Start the fork immediately"
481+ } )
482+ . count( ) ,
483+ 1
480484 ) ;
481- assert ! ( app. display_messages( ) . iter( ) . any( |message| {
482- message. role == "user" && message. content == "Start the fork immediately"
483- } ) ) ;
484485 assert ! ( app. pending_startup_prompt_echo. is_none( ) ) ;
485486}
486487
@@ -628,9 +629,10 @@ fn startup_send_state_is_not_preserved_for_real_session_switch() {
628629 let rt = tokio:: runtime:: Runtime :: new ( ) . expect ( "runtime" ) ;
629630 let _guard = rt. enter ( ) ;
630631 let mut remote = crate :: tui:: backend:: RemoteConnection :: dummy ( ) ;
632+ remote. mark_history_loaded ( ) ;
631633 rt. block_on ( process_remote_followups ( & mut app, & mut remote) ) ;
632634 assert ! ( app. current_message_id. is_some( ) ) ;
633- assert ! ( app. pending_startup_prompt_echo . is_some ( ) ) ;
635+ assert ! ( app. is_processing ) ;
634636
635637 handle_server_event ( & mut app, startup_history ( "different-session" ) , & mut remote) ;
636638
0 commit comments