Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,9 @@
logger = logging.getLogger(__name__)


def _is_in_var_dir(module_file: str = __file__) -> bool:
"""Return True if this SDK is installed under /var/lang/.

Lambda bundled Python runtimes install packages at
/var/lang/lib/pythonX.Y/site-packages/.
"""
return module_file.startswith("/var/lang/")
def _is_bundled(version: str = __version__) -> bool:
"""True if the managed runtime stamped a +bundled label onto this install."""
return "+bundled" in version

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex AI review · Finding arf_v1_m4vdthbymtstfubzqehpcuftc7

[P3] Match the bundled label exactly

This substring check also accepts valid, distinct local versions such as 2.0.0+bundleddebug, causing customer builds to be reported as managed-runtime -bundled installs. Compare against the exact +bundled suffix and add a negative test for a label beginning with bundled.

Suggested change
return "+bundled" in version
return version.endswith("+bundled")



# region model
Expand Down Expand Up @@ -1218,7 +1214,7 @@ def initialize_client(cls) -> LambdaClient:
config=Config(
connect_timeout=5,
read_timeout=50,
user_agent_extra=f"aws-durable-execution-sdk-python/{__version__}{'-bundled' if _is_in_var_dir() else ''}",
user_agent_extra=f"aws-durable-execution-sdk-python/{__version__.split('+')[0]}{'-bundled' if _is_bundled() else ''}",
),
)
return cls(client=cls._cached_boto_client)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
TimestampConverter,
WaitDetails,
WaitOptions,
_is_in_var_dir,
_is_bundled,
)


Expand Down Expand Up @@ -2226,14 +2226,14 @@ def test_lambda_client_initialize_client_no_endpoint(


@patch(
"aws_durable_execution_sdk_python.lambda_service._is_in_var_dir",
"aws_durable_execution_sdk_python.lambda_service._is_bundled",
return_value=True,
)
@patch("boto3.client")
def test_lambda_client_user_agent_runtime_bundled(
mock_boto_client, _mock_is_in_var_dir, reset_lambda_client_cache
mock_boto_client, _mock_is_bundled, reset_lambda_client_cache
):
"""user_agent_extra includes -bundled when SDK is in /var/lang/."""
"""user_agent_extra includes -bundled when the +bundled stamp is present."""
mock_client = Mock()
mock_boto_client.return_value = mock_client

Expand All @@ -2243,56 +2243,50 @@ def test_lambda_client_user_agent_runtime_bundled(
config = call_args[1]["config"]
assert (
config.user_agent_extra
== f"aws-durable-execution-sdk-python/{__version__}-bundled"
== f"aws-durable-execution-sdk-python/{__version__.split('+')[0]}-bundled"
)
assert isinstance(client, LambdaClient)


@patch(
"aws_durable_execution_sdk_python.lambda_service._is_in_var_dir",
"aws_durable_execution_sdk_python.lambda_service._is_bundled",
return_value=False,
)
@patch("boto3.client")
def test_lambda_client_user_agent_not_runtime_bundled(
mock_boto_client, _mock_is_in_var_dir, reset_lambda_client_cache
mock_boto_client, _mock_is_bundled, reset_lambda_client_cache
):
"""user_agent_extra omits -bundled when SDK is not in /var/lang."""
"""user_agent_extra omits -bundled when the +bundled stamp is absent."""
mock_client = Mock()
mock_boto_client.return_value = mock_client

client = LambdaClient.initialize_client()

call_args = mock_boto_client.call_args
config = call_args[1]["config"]
assert config.user_agent_extra == f"aws-durable-execution-sdk-python/{__version__}"
assert (
config.user_agent_extra
== f"aws-durable-execution-sdk-python/{__version__.split('+')[0]}"
)
assert isinstance(client, LambdaClient)


@pytest.mark.parametrize(
"path,expected",
"version,expected",
[
# Lambda bundled runtime site-packages
(
"/var/lang/lib/python3.13/site-packages/aws_durable_execution_sdk_python/lambda_service.py",
True,
),
(
"/var/lang/lib/python3.12/site-packages/aws_durable_execution_sdk_python/lambda_service.py",
True,
),
# Customer deployment package
("/var/task/aws_durable_execution_sdk_python/lambda_service.py", False),
# Lambda Layer
("/opt/python/aws_durable_execution_sdk_python/lambda_service.py", False),
# Trailing-slash guard: /var/langsurprise must not match
("/var/langsurprise/lib/python3.13/site-packages/x.py", False),
# Local dev
("/Users/me/project/.venv/lib/python3.12/site-packages/x.py", False),
# Managed-runtime stamp
("1.7.0+bundled", True),
("1.7.0.post0+bundled", True),
# Public PyPI installs never carry the local label
("1.7.0", False),
("1.7.0.post0", False),
# A different local label must not match
("1.7.0+local", False),
("", False),
],
)
def test_is_in_var_dir(path, expected):
assert _is_in_var_dir(path) is expected
def test_is_bundled(version, expected):
assert _is_bundled(version) is expected


def test_lambda_client_checkpoint_with_non_none_client_token():
Expand Down
Loading