Skip to content

Commit f1583e3

Browse files
CopilotfriggeriSteveSandersonMS
authored
Add tests to verify forward compatibility for unknown session event types (github#35)
* Initial plan * Add graceful error handling for unknown/malformed session events in Python SDK Co-authored-by: friggeri <106686+friggeri@users.noreply.github.com> * Add unit tests for unknown/malformed session event handling Co-authored-by: friggeri <106686+friggeri@users.noreply.github.com> * Improve test specificity for exception types Co-authored-by: friggeri <106686+friggeri@users.noreply.github.com> * Revert broad error suppression - let parsing errors surface for visibility Co-authored-by: SteveSandersonMS <1101362+SteveSandersonMS@users.noreply.github.com> * Use specific exception types in test instead of broad Exception Co-authored-by: SteveSandersonMS <1101362+SteveSandersonMS@users.noreply.github.com> * Run Python formatter (ruff format) Co-authored-by: SteveSandersonMS <1101362+SteveSandersonMS@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: friggeri <106686+friggeri@users.noreply.github.com> Co-authored-by: SteveSandersonMS <1101362+SteveSandersonMS@users.noreply.github.com>
1 parent 9f6b764 commit f1583e3

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""
2+
Test that unknown event types are handled gracefully for forward compatibility.
3+
4+
This test verifies that:
5+
1. The session.usage_info event type is recognized
6+
2. Unknown future event types map to UNKNOWN enum value
7+
3. Real parsing errors (malformed data) are NOT suppressed and surface for visibility
8+
"""
9+
10+
from datetime import datetime
11+
from uuid import uuid4
12+
13+
import pytest
14+
15+
from copilot.generated.session_events import SessionEventType, session_event_from_dict
16+
17+
18+
class TestEventForwardCompatibility:
19+
"""Test forward compatibility for unknown event types."""
20+
21+
def test_session_usage_info_is_recognized(self):
22+
"""The session.usage_info event type should be in the enum."""
23+
assert SessionEventType.SESSION_USAGE_INFO.value == "session.usage_info"
24+
25+
def test_unknown_event_type_maps_to_unknown(self):
26+
"""Unknown event types should map to UNKNOWN enum value for forward compatibility."""
27+
unknown_event = {
28+
"id": str(uuid4()),
29+
"timestamp": datetime.now().isoformat(),
30+
"parentId": None,
31+
"type": "session.future_feature_from_server",
32+
"data": {},
33+
}
34+
35+
event = session_event_from_dict(unknown_event)
36+
assert event.type == SessionEventType.UNKNOWN, f"Expected UNKNOWN, got {event.type}"
37+
38+
def test_malformed_uuid_raises_error(self):
39+
"""Malformed UUIDs should raise ValueError for visibility, not be suppressed."""
40+
malformed_event = {
41+
"id": "not-a-valid-uuid",
42+
"timestamp": datetime.now().isoformat(),
43+
"parentId": None,
44+
"type": "session.start",
45+
"data": {},
46+
}
47+
48+
# This should raise an error and NOT be silently suppressed
49+
with pytest.raises(ValueError):
50+
session_event_from_dict(malformed_event)
51+
52+
def test_malformed_timestamp_raises_error(self):
53+
"""Malformed timestamps should raise an error for visibility."""
54+
malformed_event = {
55+
"id": str(uuid4()),
56+
"timestamp": "not-a-valid-timestamp",
57+
"parentId": None,
58+
"type": "session.start",
59+
"data": {},
60+
}
61+
62+
# This should raise an error and NOT be silently suppressed
63+
with pytest.raises((ValueError, TypeError)):
64+
session_event_from_dict(malformed_event)

0 commit comments

Comments
 (0)