Skip to content

Commit 1cd3849

Browse files
Copilotedburns
andauthored
Port SetForegroundSessionRequest bug fix and add COPILOT_HOME to test harness
Agent-Logs-Url: https://github.com/github/copilot-sdk-java/sessions/a61a1c47-9550-486c-800b-6deeeadaadbf Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
1 parent b04ed27 commit 1cd3849

4 files changed

Lines changed: 39 additions & 12 deletions

File tree

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -744,18 +744,15 @@ public CompletableFuture<String> getForegroundSessionId() {
744744
* if the operation fails
745745
*/
746746
public CompletableFuture<Void> setForegroundSessionId(String sessionId) {
747-
return ensureConnected()
748-
.thenCompose(
749-
connection -> connection.rpc
750-
.invoke("session.setForeground", Map.of("sessionId", sessionId),
751-
com.github.copilot.sdk.json.SetForegroundSessionResponse.class)
752-
.thenAccept(response -> {
753-
if (!response.success()) {
754-
throw new RuntimeException(response.error() != null
755-
? response.error()
756-
: "Failed to set foreground session");
757-
}
758-
}));
747+
return ensureConnected().thenCompose(connection -> connection.rpc
748+
.invoke("session.setForeground", new com.github.copilot.sdk.json.SetForegroundSessionRequest(sessionId),
749+
com.github.copilot.sdk.json.SetForegroundSessionResponse.class)
750+
.thenAccept(response -> {
751+
if (!response.success()) {
752+
throw new RuntimeException(
753+
response.error() != null ? response.error() : "Failed to set foreground session");
754+
}
755+
}));
759756
}
760757

761758
/**
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
*--------------------------------------------------------------------------------------------*/
4+
5+
package com.github.copilot.sdk.json;
6+
7+
import com.fasterxml.jackson.annotation.JsonProperty;
8+
9+
/**
10+
* Request body for session.setForeground RPC call.
11+
* <p>
12+
* Using an explicit record type (rather than an ad-hoc map) ensures correct
13+
* JSON serialization in all execution environments.
14+
*
15+
* @since 1.0.0
16+
*/
17+
public record SetForegroundSessionRequest(
18+
/** The session ID to bring to the foreground. */
19+
@JsonProperty("sessionId") String sessionId) {
20+
}

‎src/test/java/com/github/copilot/sdk/DataObjectCoverageTest.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.github.copilot.sdk.json.PreToolUseHookInput;
1919
import com.github.copilot.sdk.json.PreToolUseHookOutput;
2020
import com.github.copilot.sdk.json.SectionOverride;
21+
import com.github.copilot.sdk.json.SetForegroundSessionRequest;
2122
import com.github.copilot.sdk.json.SetForegroundSessionResponse;
2223
import com.github.copilot.sdk.json.ToolBinaryResult;
2324
import com.github.copilot.sdk.json.ToolResultObject;
@@ -86,6 +87,14 @@ void getForegroundSessionResponseRecord() {
8687
assertEquals("/home/user/project", response.workspacePath());
8788
}
8889

90+
// ===== SetForegroundSessionRequest record =====
91+
92+
@Test
93+
void setForegroundSessionRequestRecord() {
94+
var request = new SetForegroundSessionRequest("session-123");
95+
assertEquals("session-123", request.sessionId());
96+
}
97+
8998
// ===== SetForegroundSessionResponse record =====
9099

91100
@Test

‎src/test/java/com/github/copilot/sdk/E2ETestContext.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ public List<Map<String, Object>> getExchanges() throws IOException, InterruptedE
249249
public Map<String, String> getEnvironment() {
250250
Map<String, String> env = new HashMap<>(System.getenv());
251251
env.put("COPILOT_API_URL", proxyUrl);
252+
env.put("COPILOT_HOME", homeDir.toString());
252253
env.put("XDG_CONFIG_HOME", homeDir.toString());
253254
env.put("XDG_STATE_HOME", homeDir.toString());
254255
return env;

0 commit comments

Comments
 (0)