Skip to content

Commit 8dcd060

Browse files
authored
Merge pull request #126 from copilot-community-sdk/copilot/fix-quota-snapshots-null-value
Return empty map instead of null from AssistantUsageData.quotaSnapshots()
2 parents 39d55fa + 4e903fa commit 8dcd060

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/main/java/com/github/copilot/sdk/events/AssistantUsageEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public record AssistantUsageData(@JsonProperty("model") String model,
4747
/** Returns a defensive copy of the quota snapshots map. */
4848
@Override
4949
public Map<String, Object> quotaSnapshots() {
50-
return quotaSnapshots == null ? null : Collections.unmodifiableMap(quotaSnapshots);
50+
return quotaSnapshots == null ? Collections.emptyMap() : Collections.unmodifiableMap(quotaSnapshots);
5151
}
5252
}
5353
}

src/test/java/com/github/copilot/sdk/SessionEventParserTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,30 @@ void testAssistantUsageEventAllFields() throws Exception {
13811381
assertEquals(2, data.quotaSnapshots().size());
13821382
}
13831383

1384+
@Test
1385+
void testAssistantUsageEventWithNullQuotaSnapshots() throws Exception {
1386+
String json = """
1387+
{
1388+
"type": "assistant.usage",
1389+
"data": {
1390+
"model": "gpt-4-turbo",
1391+
"inputTokens": 500,
1392+
"outputTokens": 200
1393+
}
1394+
}
1395+
""";
1396+
1397+
var event = (AssistantUsageEvent) parseJson(json);
1398+
assertNotNull(event);
1399+
var data = event.getData();
1400+
assertEquals("gpt-4-turbo", data.model());
1401+
assertEquals(500.0, data.inputTokens());
1402+
assertEquals(200.0, data.outputTokens());
1403+
// quotaSnapshots should return an empty map, not null
1404+
assertNotNull(data.quotaSnapshots());
1405+
assertTrue(data.quotaSnapshots().isEmpty());
1406+
}
1407+
13841408
@Test
13851409
void testAssistantReasoningDeltaEventAllFields() throws Exception {
13861410
String json = """

0 commit comments

Comments
 (0)