Skip to content
Merged
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
64 changes: 64 additions & 0 deletions python/test_event_forward_compatibility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""
Test that unknown event types are handled gracefully for forward compatibility.

This test verifies that:
1. The session.usage_info event type is recognized
2. Unknown future event types map to UNKNOWN enum value
3. Real parsing errors (malformed data) are NOT suppressed and surface for visibility
"""

from datetime import datetime
from uuid import uuid4

import pytest

from copilot.generated.session_events import SessionEventType, session_event_from_dict


class TestEventForwardCompatibility:
"""Test forward compatibility for unknown event types."""

def test_session_usage_info_is_recognized(self):
"""The session.usage_info event type should be in the enum."""
assert SessionEventType.SESSION_USAGE_INFO.value == "session.usage_info"

def test_unknown_event_type_maps_to_unknown(self):
"""Unknown event types should map to UNKNOWN enum value for forward compatibility."""
unknown_event = {
"id": str(uuid4()),
"timestamp": datetime.now().isoformat(),
"parentId": None,
"type": "session.future_feature_from_server",
"data": {},
}

event = session_event_from_dict(unknown_event)
assert event.type == SessionEventType.UNKNOWN, f"Expected UNKNOWN, got {event.type}"

def test_malformed_uuid_raises_error(self):
"""Malformed UUIDs should raise ValueError for visibility, not be suppressed."""
malformed_event = {
"id": "not-a-valid-uuid",
"timestamp": datetime.now().isoformat(),
"parentId": None,
"type": "session.start",
"data": {},
}

# This should raise an error and NOT be silently suppressed
with pytest.raises(ValueError):
session_event_from_dict(malformed_event)

def test_malformed_timestamp_raises_error(self):
"""Malformed timestamps should raise an error for visibility."""
malformed_event = {
"id": str(uuid4()),
"timestamp": "not-a-valid-timestamp",
"parentId": None,
"type": "session.start",
"data": {},
}

# This should raise an error and NOT be silently suppressed
with pytest.raises((ValueError, TypeError)):
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The expected exceptions should include ParserError from dateutil.parser, as the from_datetime function uses dateutil.parser.parse() which raises ParserError for invalid timestamps, not just ValueError or TypeError. Consider adding: with pytest.raises((ValueError, TypeError, dateutil.parser.ParserError))

This issue also appears in the following locations of the same file:

  • line 14

Copilot uses AI. Check for mistakes.
session_event_from_dict(malformed_event)
Loading