@@ -512,31 +512,16 @@ def test_step_with_original_name(mock_handler):
512512
513513
514514# region invoke
515- @pytest .mark .parametrize (
516- ("lambda_tenant_id" , "expected_tenant_id" ),
517- [
518- (None , None ),
519- ("test-tenant" , "test-tenant" ),
520- ],
521- )
522515@patch ("aws_durable_execution_sdk_python.context.invoke_handler" )
523- def test_invoke_basic (mock_handler , lambda_tenant_id , expected_tenant_id ):
524- """Test invoke with basic parameters and tenant_id inheritance ."""
516+ def test_invoke_basic (mock_handler ):
517+ """Test invoke with basic parameters."""
525518 mock_handler .return_value = "invoke_result"
526519 mock_state = Mock (spec = ExecutionState )
527520 mock_state .durable_execution_arn = (
528521 "arn:aws:durable:us-east-1:123456789012:execution/test"
529522 )
530523
531- # Create mock lambda context with tenant_id
532- mock_lambda_context = Mock ()
533- if lambda_tenant_id :
534- mock_lambda_context .tenant_id = lambda_tenant_id
535- else :
536- # Remove tenant_id attribute entirely when None
537- del mock_lambda_context .tenant_id
538-
539- context = DurableContext (state = mock_state , lambda_context = mock_lambda_context )
524+ context = DurableContext (state = mock_state )
540525 operation_ids = operation_id_sequence ()
541526 expected_operation_id = next (operation_ids )
542527
@@ -549,7 +534,7 @@ def test_invoke_basic(mock_handler, lambda_tenant_id, expected_tenant_id):
549534 payload = "test_payload" ,
550535 state = mock_state ,
551536 operation_identifier = OperationIdentifier (expected_operation_id , None , None ),
552- config = InvokeConfig ( tenant_id = expected_tenant_id ) ,
537+ config = None ,
553538 )
554539
555540
@@ -576,15 +561,12 @@ def test_invoke_with_name_and_config(mock_handler):
576561 expected_id = next (seq ) # 6th
577562
578563 assert result == "configured_result"
579- expected_config = InvokeConfig [str , str ](
580- timeout = Duration .from_seconds (30 ), tenant_id = None
581- )
582564 mock_handler .assert_called_once_with (
583565 function_name = "test_function" ,
584566 payload = {"key" : "value" },
585567 state = mock_state ,
586568 operation_identifier = OperationIdentifier (expected_id , None , "named_invoke" ),
587- config = expected_config ,
569+ config = config ,
588570 )
589571
590572
@@ -611,7 +593,7 @@ def test_invoke_with_parent_id(mock_handler):
611593 payload = None ,
612594 state = mock_state ,
613595 operation_identifier = OperationIdentifier (expected_id , "parent123" , None ),
614- config = InvokeConfig ( tenant_id = None ) ,
596+ config = None ,
615597 )
616598
617599
@@ -667,7 +649,7 @@ def test_invoke_with_none_payload(mock_handler):
667649 payload = None ,
668650 state = mock_state ,
669651 operation_identifier = OperationIdentifier (expected_id , None , None ),
670- config = InvokeConfig ( tenant_id = None ) ,
652+ config = None ,
671653 )
672654
673655
@@ -701,20 +683,14 @@ def test_invoke_with_custom_serdes(mock_handler):
701683 expected_id = next (seq )
702684
703685 assert result == {"transformed" : "data" }
704- expected_config = InvokeConfig [dict , dict ](
705- serdes_payload = payload_serdes ,
706- serdes_result = result_serdes ,
707- timeout = Duration .from_minutes (1 ),
708- tenant_id = None ,
709- )
710686 mock_handler .assert_called_once_with (
711687 function_name = "test_function" ,
712688 payload = {"original" : "data" },
713689 state = mock_state ,
714690 operation_identifier = OperationIdentifier (
715691 expected_id , None , "custom_serdes_invoke"
716692 ),
717- config = expected_config ,
693+ config = config ,
718694 )
719695
720696
@@ -1022,45 +998,6 @@ def test_run_in_child_context_resolves_name_from_callable(mock_handler):
1022998 assert call_args [1 ]["operation_identifier" ].name == "original_function_name"
1023999
10241000
1025- @pytest .mark .parametrize (
1026- ("parent_tenant_id" , "expected_tenant_id" ),
1027- [
1028- (None , None ),
1029- ("parent-tenant" , "parent-tenant" ),
1030- ],
1031- )
1032- def test_run_in_child_context_inherits_tenant_id (parent_tenant_id , expected_tenant_id ):
1033- """Test that child context inherits tenant_id from parent."""
1034- mock_state = Mock (spec = ExecutionState )
1035- mock_state .durable_execution_arn = (
1036- "arn:aws:durable:us-east-1:123456789012:execution/test"
1037- )
1038-
1039- # Create mock lambda context with tenant_id
1040- mock_lambda_context = Mock ()
1041- if parent_tenant_id :
1042- mock_lambda_context .tenant_id = parent_tenant_id
1043- else :
1044- del mock_lambda_context .tenant_id
1045-
1046- parent_context = DurableContext (
1047- state = mock_state , lambda_context = mock_lambda_context
1048- )
1049-
1050- def check_child_tenant_id (child_context ):
1051- # Verify child context has same tenant_id as parent
1052- assert child_context .tenant_id == expected_tenant_id
1053- return "result"
1054-
1055- with patch (
1056- "aws_durable_execution_sdk_python.context.child_handler"
1057- ) as mock_handler :
1058- # Make child_handler execute the function with a child context
1059- mock_handler .side_effect = lambda func , ** kwargs : func ()
1060-
1061- parent_context .run_in_child_context (check_child_tenant_id , "test_child" )
1062-
1063-
10641001# endregion run_in_child_context
10651002
10661003
@@ -1745,3 +1682,43 @@ def test_operation_id_generation_unique():
17451682
17461683 for i in range (len (ids ) - 1 ):
17471684 assert ids [i ] != ids [i + 1 ]
1685+
1686+
1687+ @patch ("aws_durable_execution_sdk_python.context.invoke_handler" )
1688+ def test_invoke_with_explicit_tenant_id (mock_handler ):
1689+ """Test invoke with explicit tenant_id in config."""
1690+ mock_handler .return_value = "result"
1691+ mock_state = Mock (spec = ExecutionState )
1692+ mock_state .durable_execution_arn = (
1693+ "arn:aws:durable:us-east-1:123456789012:execution/test"
1694+ )
1695+
1696+ config = InvokeConfig (tenant_id = "explicit-tenant" )
1697+ context = DurableContext (state = mock_state )
1698+
1699+ result = context .invoke ("test_function" , "payload" , config = config )
1700+
1701+ assert result == "result"
1702+ call_args = mock_handler .call_args [1 ]
1703+ assert call_args ["config" ].tenant_id == "explicit-tenant"
1704+
1705+
1706+ @patch ("aws_durable_execution_sdk_python.context.invoke_handler" )
1707+ def test_invoke_without_tenant_id_defaults_to_none (mock_handler ):
1708+ """Test invoke without tenant_id defaults to None."""
1709+ mock_handler .return_value = "result"
1710+ mock_state = Mock (spec = ExecutionState )
1711+ mock_state .durable_execution_arn = (
1712+ "arn:aws:durable:us-east-1:123456789012:execution/test"
1713+ )
1714+
1715+ context = DurableContext (state = mock_state )
1716+
1717+ result = context .invoke ("test_function" , "payload" )
1718+
1719+ assert result == "result"
1720+ # Config should be None when not provided
1721+ call_args = mock_handler .call_args [1 ]
1722+ assert call_args ["config" ] is None
1723+
1724+
0 commit comments