1111from bec_lib .messaging_hooks import MessagingEvent
1212from bec_lib .tests .fixtures import dm_with_devices # noqa: F401
1313from bec_lib .tests .utils import ConnectorMock
14+ from bec_lib .utils .scan_utils import compose_cli_input_from_scan_info
1415from bec_server .scan_server .instruction_handler import InstructionHandler
1516from bec_server .scan_server .scan_stubs import ScanStubStatus
1617from bec_server .scan_server .scans .scan_base import ScanBase , ScanInfo
@@ -107,6 +108,40 @@ def test_scan_info_stores_scan_report_device_objects_as_names(dm_with_devices):
107108 assert scan_info .scan_report_devices == ["samz" ]
108109
109110
111+ def test_compose_cli_input_from_scan_info_uses_named_inputs ():
112+ scan_info = ScanInfo (
113+ scan_name = "_v4_test_scan" ,
114+ scan_id = "scan-id-test" ,
115+ scan_type = None ,
116+ request_inputs = {
117+ "arg_bundle" : [],
118+ "inputs" : {"device" : "samx" , "target" : 1 },
119+ "kwargs" : {"relative" : True },
120+ },
121+ )
122+
123+ assert (
124+ compose_cli_input_from_scan_info (scan_info )
125+ == "scans._v4_test_scan(device='samx', target=1, relative=True)"
126+ )
127+
128+
129+ def test_compose_cli_input_from_scan_info_uses_arg_bundle ():
130+ scan_info = {
131+ "scan_name" : "line_scan" ,
132+ "request_inputs" : {
133+ "arg_bundle" : ["samx" , - 5 , 5 , 3 ],
134+ "inputs" : {},
135+ "kwargs" : {"exp_time" : 0.1 },
136+ },
137+ }
138+
139+ assert (
140+ compose_cli_input_from_scan_info (scan_info )
141+ == "scans.line_scan('samx', -5, 5, 3, exp_time=0.1)"
142+ )
143+
144+
110145def _last_device_instruction (ctx , action ):
111146 return _sent_device_instructions (ctx , action )[- 1 ]
112147
@@ -531,6 +566,7 @@ def test_send_scan_status_publishes_message(action_context):
531566 ctx .connector .notify = mock .MagicMock ()
532567 status_msg = messages .ScanStatusMessage (scan_id = "scan-id-test" , status = "closed" , info = {})
533568 ctx .actions ._build_scan_status_message = mock .MagicMock (return_value = status_msg )
569+ ctx .scan .scan_info .request_inputs = {"arg_bundle" : [], "inputs" : {}, "kwargs" : {}}
534570
535571 ctx .actions ._send_scan_status ("closed" , reason = "alarm" )
536572
@@ -542,7 +578,9 @@ def test_send_scan_status_publishes_message(action_context):
542578 MessageEndpoints .scan_status (), status_msg , pipe = pipe
543579 )
544580 ctx .connector .notify .assert_called_once_with (
545- MessagingEvent .SCAN_COMPLETED , "Scan completed: scan-id-test" , pipe = pipe
581+ MessagingEvent .SCAN_COMPLETED ,
582+ "Scan completed: scan_number=1 (scans._v4_test_scan(), scan_id=scan-id-test)" ,
583+ pipe = pipe ,
546584 )
547585 pipe .execute .assert_called_once_with ()
548586
@@ -556,11 +594,18 @@ def test_send_scan_status_publishes_new_scan_notification(action_context):
556594 ctx .connector .notify = mock .MagicMock ()
557595 status_msg = messages .ScanStatusMessage (scan_id = "scan-id-test" , status = "open" , info = {})
558596 ctx .actions ._build_scan_status_message = mock .MagicMock (return_value = status_msg )
597+ ctx .scan .scan_info .request_inputs = {
598+ "arg_bundle" : [],
599+ "inputs" : {"device" : "samx" },
600+ "kwargs" : {},
601+ }
559602
560603 ctx .actions ._send_scan_status ("open" )
561604
562605 ctx .connector .notify .assert_called_once_with (
563- MessagingEvent .SCAN , "Scan started: scan-id-test" , pipe = pipe
606+ MessagingEvent .SCAN ,
607+ "Scan started: scan_number=1 (scans._v4_test_scan(device='samx'), scan_id=scan-id-test)" ,
608+ pipe = pipe ,
564609 )
565610
566611
0 commit comments