Skip to content

Commit af0e78c

Browse files
Copilotbrunoborges
andcommitted
Address review feedback: add parser tests for new fields, fix Javadoc @see refs
Co-authored-by: brunoborges <129743+brunoborges@users.noreply.github.com>
1 parent e2234d0 commit af0e78c

File tree

3 files changed

+90
-5
lines changed

3 files changed

+90
-5
lines changed

src/main/java/com/github/copilot/sdk/CopilotClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ public CompletableFuture<List<ModelInfo>> listModels() {
460460
*
461461
* @return a future that resolves with the last session ID, or {@code null} if
462462
* no sessions exist
463-
* @see #resumeSession(String)
463+
* @see #resumeSession(String, com.github.copilot.sdk.json.ResumeSessionConfig)
464464
*/
465465
public CompletableFuture<String> getLastSessionId() {
466466
return ensureConnected().thenCompose(
@@ -498,7 +498,7 @@ public CompletableFuture<Void> deleteSession(String sessionId) {
498498
*
499499
* @return a future that resolves with a list of session metadata
500500
* @see SessionMetadata
501-
* @see #resumeSession(String)
501+
* @see #resumeSession(String, com.github.copilot.sdk.json.ResumeSessionConfig)
502502
*/
503503
public CompletableFuture<List<SessionMetadata>> listSessions() {
504504
return listSessions(null);
@@ -528,7 +528,7 @@ public CompletableFuture<List<SessionMetadata>> listSessions() {
528528
* @return a future that resolves with a list of session metadata
529529
* @see SessionMetadata
530530
* @see SessionListFilter
531-
* @see #resumeSession(String)
531+
* @see #resumeSession(String, com.github.copilot.sdk.json.ResumeSessionConfig)
532532
*/
533533
public CompletableFuture<List<SessionMetadata>> listSessions(SessionListFilter filter) {
534534
return ensureConnected().thenCompose(connection -> {

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

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,7 @@ void testAssistantMessageEventAllFields() throws Exception {
13431343
}
13441344
],
13451345
"parentToolCallId": "parent-tc",
1346+
"interactionId": "interaction-msg-1",
13461347
"reasoningOpaque": "opaque-data",
13471348
"reasoningText": "My reasoning",
13481349
"encryptedContent": "enc123"
@@ -1356,6 +1357,7 @@ void testAssistantMessageEventAllFields() throws Exception {
13561357
assertEquals("msg-rich", data.messageId());
13571358
assertEquals("Full response", data.content());
13581359
assertEquals("parent-tc", data.parentToolCallId());
1360+
assertEquals("interaction-msg-1", data.interactionId());
13591361
assertEquals("opaque-data", data.reasoningOpaque());
13601362
assertEquals("My reasoning", data.reasoningText());
13611363
assertEquals("enc123", data.encryptedContent());
@@ -1390,6 +1392,59 @@ void testAssistantMessageDeltaEventAllFields() throws Exception {
13901392
assertEquals("ptc-1", data.parentToolCallId());
13911393
}
13921394

1395+
@Test
1396+
void testAssistantStreamingDeltaEventAllFields() throws Exception {
1397+
String json = """
1398+
{
1399+
"type": "assistant.streaming_delta",
1400+
"data": {
1401+
"totalResponseSizeBytes": 4096.0
1402+
}
1403+
}
1404+
""";
1405+
1406+
var event = (AssistantStreamingDeltaEvent) parseJson(json);
1407+
assertNotNull(event);
1408+
assertEquals("assistant.streaming_delta", event.getType());
1409+
assertEquals(4096.0, event.getData().totalResponseSizeBytes());
1410+
}
1411+
1412+
@Test
1413+
void testAssistantMessageEventIncludesInteractionId() throws Exception {
1414+
String json = """
1415+
{
1416+
"type": "assistant.message",
1417+
"data": {
1418+
"messageId": "msg-with-interaction",
1419+
"content": "Response",
1420+
"interactionId": "interaction-abc-123"
1421+
}
1422+
}
1423+
""";
1424+
1425+
var event = (AssistantMessageEvent) parseJson(json);
1426+
assertNotNull(event);
1427+
assertEquals("interaction-abc-123", event.getData().interactionId());
1428+
}
1429+
1430+
@Test
1431+
void testAssistantTurnStartEventIncludesInteractionId() throws Exception {
1432+
String json = """
1433+
{
1434+
"type": "assistant.turn_start",
1435+
"data": {
1436+
"turnId": "turn-with-interaction",
1437+
"interactionId": "interaction-xyz-456"
1438+
}
1439+
}
1440+
""";
1441+
1442+
var event = (AssistantTurnStartEvent) parseJson(json);
1443+
assertNotNull(event);
1444+
assertEquals("turn-with-interaction", event.getData().turnId());
1445+
assertEquals("interaction-xyz-456", event.getData().interactionId());
1446+
}
1447+
13931448
@Test
13941449
void testAssistantUsageEventAllFields() throws Exception {
13951450
String json = """
@@ -1410,6 +1465,23 @@ void testAssistantUsageEventAllFields() throws Exception {
14101465
"quotaSnapshots": {
14111466
"premium": 100,
14121467
"standard": 500
1468+
},
1469+
"copilotUsage": {
1470+
"totalNanoAiu": 1234567.0,
1471+
"tokenDetails": [
1472+
{
1473+
"tokenType": "input",
1474+
"tokenCount": 500.0,
1475+
"batchSize": 100.0,
1476+
"costPerBatch": 0.001
1477+
},
1478+
{
1479+
"tokenType": "output",
1480+
"tokenCount": 200.0,
1481+
"batchSize": 100.0,
1482+
"costPerBatch": 0.002
1483+
}
1484+
]
14131485
}
14141486
}
14151487
}
@@ -1431,6 +1503,15 @@ void testAssistantUsageEventAllFields() throws Exception {
14311503
assertEquals("ptc-usage", data.parentToolCallId());
14321504
assertNotNull(data.quotaSnapshots());
14331505
assertEquals(2, data.quotaSnapshots().size());
1506+
1507+
// Verify copilotUsage
1508+
assertNotNull(data.copilotUsage());
1509+
assertEquals(1234567.0, data.copilotUsage().totalNanoAiu());
1510+
assertNotNull(data.copilotUsage().tokenDetails());
1511+
assertEquals(2, data.copilotUsage().tokenDetails().size());
1512+
assertEquals("input", data.copilotUsage().tokenDetails().get(0).tokenType());
1513+
assertEquals(500.0, data.copilotUsage().tokenDetails().get(0).tokenCount());
1514+
assertEquals("output", data.copilotUsage().tokenDetails().get(1).tokenType());
14341515
}
14351516

14361517
@Test
@@ -1546,6 +1627,8 @@ void testToolExecutionCompleteEventWithError() throws Exception {
15461627
"data": {
15471628
"toolCallId": "tc-err-1",
15481629
"success": false,
1630+
"model": "claude-3-5-sonnet",
1631+
"interactionId": "interaction-tool-1",
15491632
"isUserRequested": true,
15501633
"error": {
15511634
"message": "File not found",
@@ -1565,6 +1648,8 @@ void testToolExecutionCompleteEventWithError() throws Exception {
15651648
var data = event.getData();
15661649
assertEquals("tc-err-1", data.toolCallId());
15671650
assertFalse(data.success());
1651+
assertEquals("claude-3-5-sonnet", data.model());
1652+
assertEquals("interaction-tool-1", data.interactionId());
15681653
assertTrue(data.isUserRequested());
15691654
assertEquals("ptc-complete", data.parentToolCallId());
15701655

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ void testCanReceiveAndReturnComplexTypes(TestInfo testInfo) throws Exception {
229229

230230
/**
231231
* Verifies that a custom tool is invoked with the permission handler being
232-
* called and can inspect the tool name.
232+
* called and can inspect the permission request kind.
233233
*
234234
* @see Snapshot: tools/invokes_custom_tool_with_permission_handler
235235
*/
@@ -257,7 +257,7 @@ void testInvokesCustomToolWithPermissionHandler(TestInfo testInfo) throws Except
257257
CopilotSession session = client.createSession(
258258
new SessionConfig().setTools(List.of(encryptTool)).setOnPermissionRequest((request, invocation) -> {
259259
permissionRequests.add(request);
260-
return CompletableFuture.completedFuture(new PermissionRequestResult().setKind("approved"));
260+
return PermissionHandler.APPROVE_ALL.handle(request, invocation);
261261
})).get();
262262

263263
AssistantMessageEvent response = session

0 commit comments

Comments
 (0)