-
Notifications
You must be signed in to change notification settings - Fork 57
Add tests to verify forward compatibility for unknown session event types #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
SteveSandersonMS
merged 7 commits into
main
from
copilot/fix-valueerror-session-usage-info
Jan 19, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
014f926
Initial plan
Copilot c4f5944
Add graceful error handling for unknown/malformed session events in P…
Copilot 32d554e
Add unit tests for unknown/malformed session event handling
Copilot 5b1c175
Improve test specificity for exception types
Copilot 39d47dc
Revert broad error suppression - let parsing errors surface for visib…
Copilot e1cc9a7
Use specific exception types in test instead of broad Exception
Copilot dc88aef
Run Python formatter (ruff format)
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)): | ||
| session_event_from_dict(malformed_event) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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: