Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions src/test/java/com/github/copilot/sdk/CopilotSessionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,34 +244,34 @@ void testResumeSessionWithSameClient() throws Exception {
void testResumeSessionWithNewClient() throws Exception {
ctx.configureForTest("session", "should_resume_a_session_using_a_new_client");

String sessionId;

// First client - create session
// Use a single try-with-resources for the first client to keep it alive
// throughout the test, matching the behavior of other SDK implementations
try (CopilotClient client1 = ctx.createClient()) {
// Create initial session
CopilotSession session1 = client1.createSession().get();
sessionId = session1.getSessionId();
String sessionId = session1.getSessionId();

AssistantMessageEvent answer = session1.sendAndWait(new MessageOptions().setPrompt("What is 1+1?")).get(60,
TimeUnit.SECONDS);
assertNotNull(answer);
assertTrue(answer.getData().getContent().contains("2"),
"Response should contain 2: " + answer.getData().getContent());
}

// Second client - resume session
try (CopilotClient client2 = ctx.createClient()) {
CopilotSession session2 = client2.resumeSession(sessionId).get();
// Resume using a new client (keeping client1 alive)
try (CopilotClient client2 = ctx.createClient()) {
CopilotSession session2 = client2.resumeSession(sessionId).get();

assertEquals(sessionId, session2.getSessionId());
assertEquals(sessionId, session2.getSessionId());

// When resuming with a new client, validate messages contain expected types
List<AbstractSessionEvent> messages = session2.getMessages().get(60, TimeUnit.SECONDS);
assertTrue(messages.stream().anyMatch(m -> m instanceof UserMessageEvent),
"Should contain user.message event");
assertTrue(messages.stream().anyMatch(m -> "session.resume".equals(m.getType())),
"Should contain session.resume event");
// When resuming with a new client, validate messages contain expected types
List<AbstractSessionEvent> messages = session2.getMessages().get(60, TimeUnit.SECONDS);
assertTrue(messages.stream().anyMatch(m -> m instanceof UserMessageEvent),
"Should contain user.message event");
assertTrue(messages.stream().anyMatch(m -> "session.resume".equals(m.getType())),
"Should contain session.resume event");

session2.close();
session2.close();
}
}
}

Expand Down