Skip to content

Commit 9353950

Browse files
committed
test(sessions): tighten v0 error_message truncation assertions per review
- Replace <= with == in the truncation test: the guard is deterministic so the result should be exactly 255 chars, not merely at most 255 - Assert the concrete expected string ("x" * 241 + "...[truncated]") rather than importing private module symbols, reducing coupling to internal implementation details - Add test_from_event_with_none_error_message to cover the falsy branch of the truncation condition and document that None passes through unchanged
1 parent 43675ab commit 9353950

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

tests/unittests/sessions/test_v0_storage_event.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
from google.adk.events.event_actions import EventActions
2020
from google.adk.events.event_actions import EventCompaction
2121
from google.adk.sessions.schemas.v0 import StorageEvent
22-
from google.adk.sessions.schemas.v0 import _LEGACY_ERROR_MSG_MAX_LEN
23-
from google.adk.sessions.schemas.v0 import _TRUNCATION_SUFFIX
2422
from google.adk.sessions.session import Session
2523
from google.genai import types
2624

@@ -67,8 +65,7 @@ def test_from_event_truncates_error_message_exceeding_varchar255():
6765

6866
storage_event = StorageEvent.from_event(session, event)
6967

70-
assert len(storage_event.error_message) <= _LEGACY_ERROR_MSG_MAX_LEN
71-
assert storage_event.error_message.endswith(_TRUNCATION_SUFFIX)
68+
assert storage_event.error_message == "x" * 241 + "...[truncated]"
7269

7370

7471
def test_from_event_preserves_short_error_message():
@@ -86,3 +83,17 @@ def test_from_event_preserves_short_error_message():
8683
storage_event = StorageEvent.from_event(session, event)
8784

8885
assert storage_event.error_message == short_message
86+
87+
88+
def test_from_event_with_none_error_message():
89+
session = Session(app_name="app", user_id="user", id="session_id")
90+
event = Event(
91+
id="event_id",
92+
invocation_id="invocation_id",
93+
author="author",
94+
timestamp=1.0,
95+
)
96+
97+
storage_event = StorageEvent.from_event(session, event)
98+
99+
assert storage_event.error_message is None

0 commit comments

Comments
 (0)