@@ -204,3 +204,40 @@ def orchestrator(ctx: task.OrchestrationContext, _):
204204 assert action .sendEvent .name == "event1"
205205 expected_data = json .dumps ({"key" : "value" , "number" : 42 })
206206 assert action .sendEvent .data .value == expected_data
207+
208+
209+ def test_send_event_validation ():
210+ """Test send_event input validation"""
211+
212+ def orchestrator_empty_instance (ctx : task .OrchestrationContext , _ ):
213+ yield ctx .send_event ("" , "event1" , data = "test" )
214+ return "completed"
215+
216+ registry = worker ._Registry ()
217+
218+ # Test empty instance_id
219+ name1 = registry .add_orchestrator (orchestrator_empty_instance )
220+ new_events = [
221+ helpers .new_orchestrator_started_event (),
222+ helpers .new_execution_started_event (name1 , TEST_INSTANCE_ID , encoded_input = None ),
223+ ]
224+ executor = worker ._OrchestrationExecutor (registry , TEST_LOGGER )
225+
226+ result = executor .execute (TEST_INSTANCE_ID , [], new_events )
227+
228+ # Check if the orchestration failed due to validation error
229+ actions = result .actions
230+ if len (actions ) > 0 :
231+ action = actions [0 ]
232+ if action .WhichOneof ("orchestratorActionType" ) == "completeOrchestration" :
233+ complete_action = action .completeOrchestration
234+ if complete_action .orchestrationStatus == pb .ORCHESTRATION_STATUS_FAILED :
235+ # The orchestration should have failed with the validation error
236+ failure_details = complete_action .failureDetails
237+ assert "instance_id cannot be None or empty" in failure_details .errorMessage
238+ else :
239+ assert False , "Expected orchestration to fail with validation error"
240+ else :
241+ assert False , "Expected failure completion action, got different action type"
242+ else :
243+ assert False , "Expected at least one action (failure completion)"
0 commit comments