|
23 | 23 |
|
24 | 24 | import com.github.copilot.sdk.events.AbstractSessionEvent; |
25 | 25 | import com.github.copilot.sdk.events.AbortEvent; |
26 | | -import com.github.copilot.sdk.events.AssistantMessageDeltaEvent; |
27 | 26 | import com.github.copilot.sdk.events.AssistantMessageEvent; |
28 | 27 | import com.github.copilot.sdk.events.SessionIdleEvent; |
29 | 28 | import com.github.copilot.sdk.events.SessionStartEvent; |
@@ -286,6 +285,14 @@ void testShouldResumeSessionUsingTheSameClient() throws Exception { |
286 | 285 | .map(m -> (AssistantMessageEvent) m).anyMatch(m -> m.getData().content().contains("2")); |
287 | 286 | assertTrue(hasAssistantMessage, "Should find previous assistant message containing 2"); |
288 | 287 |
|
| 288 | + // Can continue the conversation statefully |
| 289 | + AssistantMessageEvent answer2 = session2 |
| 290 | + .sendAndWait(new MessageOptions().setPrompt("Now if you double that, what do you get?")) |
| 291 | + .get(60, TimeUnit.SECONDS); |
| 292 | + assertNotNull(answer2); |
| 293 | + assertTrue(answer2.getData().content().contains("4"), |
| 294 | + "Follow-up response should contain 4: " + answer2.getData().content()); |
| 295 | + |
289 | 296 | session2.close(); |
290 | 297 | } |
291 | 298 | } |
@@ -327,6 +334,14 @@ void testShouldResumeSessionUsingNewClient() throws Exception { |
327 | 334 | assertTrue(messages.stream().anyMatch(m -> "session.resume".equals(m.getType())), |
328 | 335 | "Should contain session.resume event"); |
329 | 336 |
|
| 337 | + // Can continue the conversation statefully |
| 338 | + AssistantMessageEvent answer2 = session2 |
| 339 | + .sendAndWait(new MessageOptions().setPrompt("Now if you double that, what do you get?")) |
| 340 | + .get(60, TimeUnit.SECONDS); |
| 341 | + assertNotNull(answer2); |
| 342 | + assertTrue(answer2.getData().content().contains("4"), |
| 343 | + "Follow-up response should contain 4: " + answer2.getData().content()); |
| 344 | + |
330 | 345 | session2.close(); |
331 | 346 | } |
332 | 347 | } |
@@ -394,44 +409,6 @@ void testShouldCreateSessionWithReplacedSystemMessageConfig() throws Exception { |
394 | 409 | } |
395 | 410 | } |
396 | 411 |
|
397 | | - /** |
398 | | - * Verifies that streaming delta events are received when streaming is enabled. |
399 | | - * |
400 | | - * @see Snapshot: |
401 | | - * session/should_receive_streaming_delta_events_when_streaming_is_enabled |
402 | | - */ |
403 | | - @Test |
404 | | - void testShouldReceiveStreamingDeltaEventsWhenStreamingIsEnabled() throws Exception { |
405 | | - ctx.configureForTest("session", "should_receive_streaming_delta_events_when_streaming_is_enabled"); |
406 | | - |
407 | | - try (CopilotClient client = ctx.createClient()) { |
408 | | - SessionConfig config = new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL) |
409 | | - .setStreaming(true); |
410 | | - |
411 | | - CopilotSession session = client.createSession(config).get(); |
412 | | - |
413 | | - var receivedEvents = new ArrayList<AbstractSessionEvent>(); |
414 | | - var idleReceived = new CompletableFuture<Void>(); |
415 | | - |
416 | | - session.on(evt -> { |
417 | | - receivedEvents.add(evt); |
418 | | - if (evt instanceof SessionIdleEvent) { |
419 | | - idleReceived.complete(null); |
420 | | - } |
421 | | - }); |
422 | | - |
423 | | - session.send(new MessageOptions().setPrompt("What is 2+2?")).get(); |
424 | | - |
425 | | - idleReceived.get(60, TimeUnit.SECONDS); |
426 | | - |
427 | | - // Should have received delta events when streaming is enabled |
428 | | - boolean hasDeltaEvents = receivedEvents.stream().anyMatch(e -> e instanceof AssistantMessageDeltaEvent); |
429 | | - assertTrue(hasDeltaEvents, "Should receive streaming delta events when streaming is enabled"); |
430 | | - |
431 | | - session.close(); |
432 | | - } |
433 | | - } |
434 | | - |
435 | 412 | /** |
436 | 413 | * Verifies that a session can be aborted during tool execution. |
437 | 414 | * |
@@ -764,29 +741,24 @@ void testShouldCreateSessionWithCustomTool() throws Exception { |
764 | 741 | } |
765 | 742 |
|
766 | 743 | /** |
767 | | - * Verifies that streaming option is passed to session creation. |
| 744 | + * Verifies that getLastSessionId returns the ID of the most recently used |
| 745 | + * session. |
768 | 746 | * |
769 | | - * @see Snapshot: session/should_pass_streaming_option_to_session_creation |
| 747 | + * @see Snapshot: session/should_get_last_session_id |
770 | 748 | */ |
771 | 749 | @Test |
772 | | - void testShouldPassStreamingOptionToSessionCreation() throws Exception { |
773 | | - ctx.configureForTest("session", "should_pass_streaming_option_to_session_creation"); |
| 750 | + void testShouldGetLastSessionId() throws Exception { |
| 751 | + ctx.configureForTest("session", "should_get_last_session_id"); |
774 | 752 |
|
775 | 753 | try (CopilotClient client = ctx.createClient()) { |
776 | | - // Verify that the streaming option is accepted without errors |
777 | | - CopilotSession session = client.createSession( |
778 | | - new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL).setStreaming(true)).get(); |
779 | | - |
780 | | - assertNotNull(session.getSessionId()); |
781 | | - assertTrue(session.getSessionId().matches("^[a-f0-9-]+$")); |
| 754 | + CopilotSession session = client |
| 755 | + .createSession(new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)).get(); |
782 | 756 |
|
783 | | - // Session should still work normally |
784 | | - AssistantMessageEvent response = session.sendAndWait(new MessageOptions().setPrompt("What is 1+1?")).get(60, |
785 | | - TimeUnit.SECONDS); |
| 757 | + session.sendAndWait(new MessageOptions().setPrompt("Say hello")).get(60, TimeUnit.SECONDS); |
786 | 758 |
|
787 | | - assertNotNull(response); |
788 | | - assertTrue(response.getData().content().contains("2"), |
789 | | - "Response should contain 2: " + response.getData().content()); |
| 759 | + String lastId = client.getLastSessionId().get(30, TimeUnit.SECONDS); |
| 760 | + assertNotNull(lastId, "Last session ID should not be null"); |
| 761 | + assertEquals(session.getSessionId(), lastId, "Last session ID should match the current session ID"); |
790 | 762 |
|
791 | 763 | session.close(); |
792 | 764 | } |
|
0 commit comments