@@ -81,6 +81,42 @@ 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+ # Invoke the Lambda directly to verify the handler is correct
107+ lambda_client = boto3 .client ("lambda" )
108+ response = lambda_client .invoke (
109+ FunctionName = evaluator .reference ,
110+ InvocationType = "RequestResponse" ,
111+ Payload = json .dumps ({"input" : "test" }).encode (),
112+ )
113+ assert response ["StatusCode" ] == 200
114+ assert "FunctionError" not in response , (
115+ f"Lambda invocation failed with error: { response .get ('FunctionError' )} "
116+ )
117+ result = json .loads (response ["Payload" ].read ())
118+ assert result .get ("statusCode" ) == 200
119+
84120 def test_get_evaluator (self , unique_name , sample_prompt_file , cleanup_list ):
85121 """Test retrieving evaluator by name."""
86122 try :
0 commit comments