@@ -81,6 +81,47 @@ def test_create_reward_function_from_local_code(self, unique_name, sample_lambda
8181 assert evaluator .method == EvaluatorMethod .BYOC
8282 assert evaluator .reference is not None
8383
84+ def test_create_reward_function_from_local_py_file_and_invoke (
85+ self , unique_name , sample_lambda_py_file , test_role , cleanup_list
86+ ):
87+ """End-to-end test: create evaluator from a raw .py file with non-default name and invoke it.
88+
89+ Regression test for the handler name bug where the Lambda was created with an incorrect
90+ handler derived from the source filename instead of 'lambda_function.lambda_handler'.
91+ """
92+ import json
93+ import boto3
94+
95+ evaluator = Evaluator .create (
96+ name = unique_name ,
97+ type = REWARD_FUNCTION ,
98+ source = sample_lambda_py_file ,
99+ role = test_role ,
100+ wait = True , # wait for Lambda to be active
101+ )
102+ cleanup_list .append (evaluator )
103+ assert evaluator .method == EvaluatorMethod .BYOC
104+ assert evaluator .reference is not None
105+
106+ # Wait for Lambda to become Active before invoking
107+ lambda_client = boto3 .client ("lambda" )
108+ waiter = lambda_client .get_waiter ("function_active_v2" )
109+ waiter .wait (FunctionName = evaluator .reference )
110+
111+ # Invoke the Lambda directly to verify the handler is correct
112+ lambda_client = boto3 .client ("lambda" )
113+ response = lambda_client .invoke (
114+ FunctionName = evaluator .reference ,
115+ InvocationType = "RequestResponse" ,
116+ Payload = json .dumps ({"input" : "test" }).encode (),
117+ )
118+ assert response ["StatusCode" ] == 200
119+ assert "FunctionError" not in response , (
120+ f"Lambda invocation failed with error: { response .get ('FunctionError' )} "
121+ )
122+ result = json .loads (response ["Payload" ].read ())
123+ assert result .get ("statusCode" ) == 200
124+
84125 def test_get_evaluator (self , unique_name , sample_prompt_file , cleanup_list ):
85126 """Test retrieving evaluator by name."""
86127 try :
0 commit comments