From 5003ed5efe73a3772fa6fef9a8aad6b85df9f731 Mon Sep 17 00:00:00 2001 From: Justice Sidhu Date: Fri, 26 Apr 2024 15:04:17 -0700 Subject: [PATCH 1/2] fix: pass unpatched runtime to lambda builder --- samcli/lib/build/app_builder.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/samcli/lib/build/app_builder.py b/samcli/lib/build/app_builder.py index d4fa45ac27..a256c4627d 100644 --- a/samcli/lib/build/app_builder.py +++ b/samcli/lib/build/app_builder.py @@ -866,7 +866,7 @@ def _build_function_in_process( application_framework=config.application_framework, ) - runtime = patch_runtime(runtime) + runtime_patched = patch_runtime(runtime) try: builder.build( @@ -874,7 +874,8 @@ def _build_function_in_process( artifacts_dir, scratch_dir, manifest_path, - runtime=runtime, + runtime=runtime_patched, + unpatched_runtime=runtime, executable_search_paths=config.executable_search_paths, mode=self._mode, options=options, From ffe65e0a2ac708f25e8d05ab6236fc7ed4b18e70 Mon Sep 17 00:00:00 2001 From: Justice Sidhu Date: Fri, 26 Apr 2024 15:43:33 -0700 Subject: [PATCH 2/2] add unit test --- .../unit/lib/build_module/test_app_builder.py | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/tests/unit/lib/build_module/test_app_builder.py b/tests/unit/lib/build_module/test_app_builder.py index 92c584ba30..f621effe40 100644 --- a/tests/unit/lib/build_module/test_app_builder.py +++ b/tests/unit/lib/build_module/test_app_builder.py @@ -2559,6 +2559,7 @@ def test_must_use_lambda_builder( "scratch_dir", "manifest_path", runtime="runtime", + unpatched_runtime="runtime", executable_search_paths=config_mock.executable_search_paths, mode="mode", options=None, @@ -2573,6 +2574,63 @@ def test_must_use_lambda_builder( patch_runtime_mock.assert_called_with("runtime") + @parameterized.expand([("provided.al2",), ("provided.al2023",)]) + @patch("samcli.lib.telemetry.event.EventType.get_accepted_values") + @patch("samcli.lib.build.app_builder.LambdaBuilder") + @patch("samcli.lib.build.app_builder.get_enabled_experimental_flags") + def test_pass_unpatched_runtime_to_lambda_builder( + self, + runtime, + experimental_flags_mock, + lambda_builder_mock, + event_mock, + ): + experimental_flags_mock.return_value = ["experimental_flags"] + config_mock = Mock() + builder_instance_mock = lambda_builder_mock.return_value = Mock() + event_mock.return_value = [runtime] + + result = self.builder._build_function_in_process( + config_mock, + "source_dir", + "artifacts_dir", + "scratch_dir", + "manifest_path", + runtime, + X86_64, + None, + None, + True, + True, + is_building_layer=False, + ) + self.assertEqual(result, "artifacts_dir") + + lambda_builder_mock.assert_called_with( + language=config_mock.language, + dependency_manager=config_mock.dependency_manager, + application_framework=config_mock.application_framework, + ) + + builder_instance_mock.build.assert_called_with( + "source_dir", + "artifacts_dir", + "scratch_dir", + "manifest_path", + runtime="provided", + unpatched_runtime=runtime, + executable_search_paths=config_mock.executable_search_paths, + mode="mode", + options=None, + architecture=X86_64, + dependencies_dir=None, + download_dependencies=True, + combine_dependencies=True, + is_building_layer=False, + experimental_flags=["experimental_flags"], + build_in_source=False, + ) + @patch("samcli.lib.build.app_builder.LambdaBuilder") def test_must_raise_on_error(self, lambda_builder_mock): config_mock = Mock() @@ -2626,6 +2684,7 @@ def test_building_with_experimental_flags( "scratch_dir", "manifest_path", runtime="runtime", + unpatched_runtime="runtime", executable_search_paths=ANY, mode="mode", options=None,