From c40d8f587b5e18c039db2a23069f0128a1bafc2e Mon Sep 17 00:00:00 2001 From: gcoinstash-cmd Date: Sun, 13 Sep 2026 18:08:49 -0700 Subject: [PATCH] test(client): add unit test suite for event tag string length bounds and truncation --- tests/test_tag_value_invariants.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/test_tag_value_invariants.py diff --git a/tests/test_tag_value_invariants.py b/tests/test_tag_value_invariants.py new file mode 100644 index 0000000000..41cc3c3d35 --- /dev/null +++ b/tests/test_tag_value_invariants.py @@ -0,0 +1,23 @@ +import pytest + +def sanitize_sentry_tag(key: str, value: str, max_len: int = 200) -> tuple[str, str] | None: + if not key or not isinstance(key, str): + return None + k = key.strip() + if not k: + return None + v = str(value) if value is not None else "" + if len(v) > max_len: + v = v[:max_len] + return k, v + +def test_valid_tag(): + assert sanitize_sentry_tag("environment", "production") == ("environment", "production") + +def test_truncated_tag(): + long_str = "x" * 250 + k, v = sanitize_sentry_tag("payload_id", long_str) + assert len(v) == 200 + +def test_invalid_key(): + assert sanitize_sentry_tag("", "production") is None