Skip to content

Commit 6d9db14

Browse files
Copilotedburns
andauthored
Address review feedback: use generated ConnectParams/ConnectResult, allow null copilotHome, strengthen permission test assertion, add instructionDirectories unit tests
Agent-Logs-Url: https://github.com/github/copilot-sdk-java/sessions/bf21fd78-4e30-40e7-8e6b-536294818f16 Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
1 parent 79accd3 commit 6d9db14

4 files changed

Lines changed: 41 additions & 14 deletions

File tree

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.github.copilot.sdk.json.CopilotClientOptions;
2323
import com.github.copilot.sdk.json.CreateSessionResponse;
24+
import com.github.copilot.sdk.generated.rpc.ConnectParams;
2425
import com.github.copilot.sdk.generated.rpc.ServerRpc;
2526
import com.github.copilot.sdk.json.DeleteSessionResponse;
2627
import com.github.copilot.sdk.json.GetAuthStatusResponse;
@@ -230,11 +231,13 @@ private void verifyProtocolVersion(Connection connection) throws Exception {
230231

231232
try {
232233
// Try the new 'connect' RPC which supports connection tokens
233-
var connectParams = new HashMap<String, Object>();
234-
connectParams.put("token", effectiveConnectionToken);
235-
var connectResponse = connection.rpc.invoke("connect", connectParams, ConnectResult.class).get(30,
236-
TimeUnit.SECONDS);
237-
serverVersion = connectResponse.protocolVersion();
234+
var connectParams = new ConnectParams(effectiveConnectionToken);
235+
var connectResponse = connection.rpc
236+
.invoke("connect", connectParams, com.github.copilot.sdk.generated.rpc.ConnectResult.class)
237+
.get(30, TimeUnit.SECONDS);
238+
serverVersion = connectResponse.protocolVersion() != null
239+
? connectResponse.protocolVersion().intValue()
240+
: null;
238241
} catch (Exception e) {
239242
// Unwrap CompletionException/ExecutionException to check inner cause
240243
Throwable cause = e;
@@ -267,12 +270,6 @@ private void verifyProtocolVersion(Connection connection) throws Exception {
267270
}
268271
}
269272

270-
/**
271-
* Internal record for the 'connect' RPC response.
272-
*/
273-
record ConnectResult(Integer protocolVersion) {
274-
}
275-
276273
/**
277274
* Disconnects from the Copilot server and closes all active sessions.
278275
* <p>

src/main/java/com/github/copilot/sdk/json/CopilotClientOptions.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,17 +207,20 @@ public String getCopilotHome() {
207207
* Sets the base directory for Copilot data (session state, config, etc.).
208208
* <p>
209209
* Sets the {@code COPILOT_HOME} environment variable on the spawned CLI
210-
* process. When {@code null}, the CLI defaults to {@code ~/.copilot}.
210+
* process. When {@code null}, the {@code COPILOT_HOME} env var is not set on
211+
* the spawned process, so the CLI falls back to its default
212+
* ({@code ~/.copilot}).
211213
* <p>
212214
* This option is only used when the SDK spawns the CLI process; it is ignored
213215
* when connecting to an external server via {@link #setCliUrl(String)}.
214216
*
215217
* @param copilotHome
216-
* the Copilot home directory path (must not be {@code null})
218+
* the Copilot home directory path, or {@code null} to use the CLI
219+
* default
217220
* @return this options instance for method chaining
218221
*/
219222
public CopilotClientOptions setCopilotHome(String copilotHome) {
220-
this.copilotHome = Objects.requireNonNull(copilotHome, "copilotHome must not be null");
223+
this.copilotHome = copilotHome;
221224
return this;
222225
}
223226

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,6 +2276,9 @@ void testParsePermissionCompletedEvent() throws Exception {
22762276
assertEquals("permission.completed", event.getType());
22772277
assertEquals("perm-req-456", event.getData().requestId());
22782278
assertNotNull(event.getData().result());
2279+
@SuppressWarnings("unchecked")
2280+
var result = (java.util.Map<String, Object>) event.getData().result();
2281+
assertEquals("approved", result.get("kind"));
22792282
}
22802283

22812284
@Test

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,4 +441,28 @@ void testBuildResumeRequestWithGitHubToken() {
441441

442442
assertEquals("ghp_per_session_token", request.getGitHubToken());
443443
}
444+
445+
// =========================================================================
446+
// instructionDirectories propagation
447+
// =========================================================================
448+
449+
@Test
450+
void testBuildCreateRequestPropagatesInstructionDirectories() {
451+
var dirs = List.of("/path/to/instructions", "/another/path");
452+
var config = new SessionConfig().setInstructionDirectories(dirs);
453+
454+
CreateSessionRequest request = SessionRequestBuilder.buildCreateRequest(config);
455+
456+
assertEquals(dirs, request.getInstructionDirectories());
457+
}
458+
459+
@Test
460+
void testBuildResumeRequestPropagatesInstructionDirectories() {
461+
var dirs = List.of("/resume/instructions", "/other/dir");
462+
var config = new ResumeSessionConfig().setInstructionDirectories(dirs);
463+
464+
ResumeSessionRequest request = SessionRequestBuilder.buildResumeRequest("sid-inst", config);
465+
466+
assertEquals(dirs, request.getInstructionDirectories());
467+
}
444468
}

0 commit comments

Comments
 (0)