forked from github/copilot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForwardCompatibilityTests.cs
More file actions
100 lines (84 loc) · 3.3 KB
/
Copy pathForwardCompatibilityTests.cs
File metadata and controls
100 lines (84 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
using Xunit;
namespace GitHub.Copilot.SDK.Test;
/// <summary>
/// Tests for forward-compatible handling of unknown session event types.
/// Verifies that the SDK gracefully handles event types introduced by newer CLI versions.
/// </summary>
public class ForwardCompatibilityTests
{
[Fact]
public void FromJson_KnownEventType_DeserializesNormally()
{
var json = """
{
"id": "00000000-0000-0000-0000-000000000001",
"timestamp": "2026-01-01T00:00:00Z",
"parentId": null,
"type": "user.message",
"data": {
"content": "Hello"
}
}
""";
var result = SessionEvent.FromJson(json);
Assert.IsType<UserMessageEvent>(result);
Assert.Equal("user.message", result.Type);
}
[Fact]
public void FromJson_UnknownEventType_ReturnsBaseSessionEvent()
{
var json = """
{
"id": "12345678-1234-1234-1234-123456789abc",
"timestamp": "2026-06-15T10:30:00Z",
"parentId": "abcdefab-abcd-abcd-abcd-abcdefabcdef",
"type": "future.feature_from_server",
"data": { "key": "value" }
}
""";
var result = SessionEvent.FromJson(json);
Assert.IsType<SessionEvent>(result);
Assert.Equal("unknown", result.Type);
}
[Fact]
public void FromJson_UnknownEventType_PreservesBaseMetadata()
{
var json = """
{
"id": "12345678-1234-1234-1234-123456789abc",
"timestamp": "2026-06-15T10:30:00Z",
"parentId": "abcdefab-abcd-abcd-abcd-abcdefabcdef",
"type": "future.feature_from_server",
"data": {}
}
""";
var result = SessionEvent.FromJson(json);
Assert.Equal(Guid.Parse("12345678-1234-1234-1234-123456789abc"), result.Id);
Assert.Equal(DateTimeOffset.Parse("2026-06-15T10:30:00Z"), result.Timestamp);
Assert.Equal(Guid.Parse("abcdefab-abcd-abcd-abcd-abcdefabcdef"), result.ParentId);
}
[Fact]
public void FromJson_MultipleEvents_MixedKnownAndUnknown()
{
var events = new[]
{
"""{"id":"00000000-0000-0000-0000-000000000001","timestamp":"2026-01-01T00:00:00Z","parentId":null,"type":"user.message","data":{"content":"Hi"}}""",
"""{"id":"00000000-0000-0000-0000-000000000002","timestamp":"2026-01-01T00:00:00Z","parentId":null,"type":"future.unknown_type","data":{}}""",
"""{"id":"00000000-0000-0000-0000-000000000003","timestamp":"2026-01-01T00:00:00Z","parentId":null,"type":"user.message","data":{"content":"Bye"}}""",
};
var results = events.Select(SessionEvent.FromJson).ToList();
Assert.Equal(3, results.Count);
Assert.IsType<UserMessageEvent>(results[0]);
Assert.IsType<SessionEvent>(results[1]);
Assert.IsType<UserMessageEvent>(results[2]);
}
[Fact]
public void SessionEvent_Type_DefaultsToUnknown()
{
var evt = new SessionEvent();
Assert.Equal("unknown", evt.Type);
}
}