88use amalthea:: fixtures:: dummy_frontend:: ExecuteRequestOptions ;
99use ark_test:: DummyArkPositronNotebook ;
1010
11- /// Drain the UI comm messages that arrive during execution (busy=true,
12- /// busy=false, prompt_state). These are CommMsg messages on the UI comm's
13- /// channel that interleave with the execute result on IOPub.
14- fn drain_ui_comm_msgs ( frontend : & DummyArkPositronNotebook , ui_comm_id : & str ) {
15- // busy=true
16- let msg = frontend. recv_iopub_comm_msg ( ) ;
17- assert_eq ! ( msg. comm_id, ui_comm_id) ;
18- assert_eq ! ( msg. data[ "method" ] , "busy" ) ;
19- assert_eq ! ( msg. data[ "params" ] [ "busy" ] , true ) ;
20-
21- // busy=false
22- let msg = frontend. recv_iopub_comm_msg ( ) ;
23- assert_eq ! ( msg. comm_id, ui_comm_id) ;
24- assert_eq ! ( msg. data[ "method" ] , "busy" ) ;
25- assert_eq ! ( msg. data[ "params" ] [ "busy" ] , false ) ;
26- }
27-
28- fn drain_ui_comm_prompt_state ( frontend : & DummyArkPositronNotebook , ui_comm_id : & str ) {
29- let msg = frontend. recv_iopub_comm_msg ( ) ;
30- assert_eq ! ( msg. comm_id, ui_comm_id) ;
31- assert_eq ! ( msg. data[ "method" ] , "prompt_state" ) ;
32- }
33-
3411#[ test]
3512fn test_notebook_inline_data_explorer ( ) {
3613 let frontend = DummyArkPositronNotebook :: lock ( ) ;
@@ -43,8 +20,12 @@ fn test_notebook_inline_data_explorer() {
4320 frontend. recv_iopub_busy ( ) ;
4421 frontend. recv_iopub_execute_input ( ) ;
4522
46- // Drain UI comm busy events
47- drain_ui_comm_msgs ( & frontend, & ui_comm_id) ;
23+ // The comm_open for the inline data explorer now arrives during execution
24+ // (before the execute result) because comm_open_backend blocks until Shell
25+ // has published it on IOPub.
26+ let comm_open = frontend. recv_iopub_comm_open ( ) ;
27+ assert_eq ! ( comm_open. target_name, "positron.dataExplorer" ) ;
28+ assert_eq ! ( comm_open. data[ "inline_only" ] , true ) ;
4829
4930 let result_data = frontend. recv_iopub_execute_result_data ( ) ;
5031
@@ -63,18 +44,14 @@ fn test_notebook_inline_data_explorer() {
6344 assert ! ( de_data[ "comm_id" ] . as_str( ) . is_some( ) ) ;
6445 assert ! ( de_data[ "title" ] . as_str( ) . is_some( ) ) ;
6546
47+ // The comm_id in the MIME payload must match the comm_open
48+ assert_eq ! ( comm_open. comm_id, de_data[ "comm_id" ] . as_str( ) . unwrap( ) ) ;
49+
6650 // prompt_state arrives after execute_result
67- drain_ui_comm_prompt_state ( & frontend, & ui_comm_id) ;
51+ frontend. recv_ui_prompt_state ( & ui_comm_id) ;
6852
6953 frontend. recv_iopub_idle ( ) ;
7054 frontend. recv_shell_execute_reply ( ) ;
71-
72- // The comm_open for the inline data explorer arrives after Idle
73- // (it goes through Shell's comm event channel)
74- let comm_open = frontend. recv_iopub_comm_open ( ) ;
75- assert_eq ! ( comm_open. target_name, "positron.dataExplorer" ) ;
76- assert_eq ! ( comm_open. data[ "inline_only" ] , true ) ;
77- assert_eq ! ( comm_open. comm_id, de_data[ "comm_id" ] . as_str( ) . unwrap( ) ) ;
7855}
7956
8057#[ test]
@@ -86,15 +63,13 @@ fn test_notebook_no_inline_data_explorer_for_non_data_frame() {
8663 frontend. recv_iopub_busy ( ) ;
8764 frontend. recv_iopub_execute_input ( ) ;
8865
89- drain_ui_comm_msgs ( & frontend, & ui_comm_id) ;
90-
9166 let result_data = frontend. recv_iopub_execute_result_data ( ) ;
9267
9368 // Should have text/plain but NOT the data explorer MIME type
9469 assert ! ( result_data. contains_key( "text/plain" ) ) ;
9570 assert ! ( !result_data. contains_key( "application/vnd.positron.dataExplorer+json" ) ) ;
9671
97- drain_ui_comm_prompt_state ( & frontend, & ui_comm_id) ;
72+ frontend. recv_ui_prompt_state ( & ui_comm_id) ;
9873
9974 frontend. recv_iopub_idle ( ) ;
10075 frontend. recv_shell_execute_reply ( ) ;
0 commit comments