Skip to content

Commit f51bcb4

Browse files
committed
On branch copilot/add-classical-code-gen-workflow-ready-for-review
modified: scripts/codegen/java.ts - Put `visible = true` on `SessionEventEvent`. - Add `type` property. on `UnknownSessionEvent`. modified: src/generated/java/com/github/copilot/sdk/generated/SessionEvent.java modified: src/generated/java/com/github/copilot/sdk/generated/UnknownSessionEvent.java - Regenerated. modified: src/main/java/com/github/copilot/sdk/CopilotSession.java - Use Double Check Locked to fix Big Risk #2 2. Lazy `SessionRpc` initialization is not thread-safe (HIGH) modified: src/test/java/com/github/copilot/sdk/ForwardCompatibilityTest.java modified: src/test/java/com/github/copilot/sdk/SessionEventDeserializationTest.java - Refine tests based on changes. Signed-off-by: Ed Burns <edburns@microsoft.com>
1 parent 11da06a commit f51bcb4

File tree

6 files changed

+32
-10
lines changed

6 files changed

+32
-10
lines changed

scripts/codegen/java.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ async function generateSessionEventBaseClass(
302302
lines.push(` */`);
303303
lines.push(`@JsonIgnoreProperties(ignoreUnknown = true)`);
304304
lines.push(`@JsonInclude(JsonInclude.Include.NON_NULL)`);
305-
lines.push(`@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", defaultImpl = UnknownSessionEvent.class)`);
305+
lines.push(`@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", visible = true, defaultImpl = UnknownSessionEvent.class)`);
306306
lines.push(`@JsonSubTypes({`);
307307
for (let i = 0; i < variants.length; i++) {
308308
const v = variants[i];
@@ -373,19 +373,26 @@ async function generateUnknownEventClass(packageName: string, packageDir: string
373373
lines.push(`package ${packageName};`);
374374
lines.push("");
375375
lines.push(`import com.fasterxml.jackson.annotation.JsonIgnoreProperties;`);
376+
lines.push(`import com.fasterxml.jackson.annotation.JsonProperty;`);
376377
lines.push(`import javax.annotation.processing.Generated;`);
377378
lines.push("");
378379
lines.push(`/**`);
379380
lines.push(` * Fallback for event types not yet known to this SDK version.`);
381+
lines.push(` * <p>`);
382+
lines.push(` * {@link #getType()} returns the original type string from the JSON payload,`);
383+
lines.push(` * preserving forward compatibility with event types introduced by newer CLI versions.`);
380384
lines.push(` *`);
381385
lines.push(` * @since 1.0.0`);
382386
lines.push(` */`);
383387
lines.push(`@JsonIgnoreProperties(ignoreUnknown = true)`);
384388
lines.push(GENERATED_ANNOTATION);
385389
lines.push(`public final class UnknownSessionEvent extends SessionEvent {`);
386390
lines.push("");
391+
lines.push(` @JsonProperty("type")`);
392+
lines.push(` private String type = "unknown";`);
393+
lines.push("");
387394
lines.push(` @Override`);
388-
lines.push(` public String getType() { return "unknown"; }`);
395+
lines.push(` public String getType() { return type; }`);
389396
lines.push(`}`);
390397
lines.push("");
391398

src/generated/java/com/github/copilot/sdk/generated/SessionEvent.java

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/generated/java/com/github/copilot/sdk/generated/UnknownSessionEvent.java

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,16 +294,23 @@ public SessionUiApi getUi() {
294294
* var agents = session.getRpc().agent.list().get();
295295
* }</pre>
296296
*
297-
* @return the session-scoped typed RPC client
297+
* @return the session-scoped typed RPC client (never {@code null})
298+
* @throws IllegalStateException
299+
* if the session is not connected
298300
* @since 1.0.0
299301
*/
300302
public SessionRpc getRpc() {
301303
if (rpc == null) {
302-
return null;
304+
throw new IllegalStateException("Session is not connected — RPC client is unavailable");
303305
}
304306
SessionRpc current = sessionRpc;
305307
if (current == null) {
306-
sessionRpc = current = new SessionRpc(rpc::invoke, sessionId);
308+
synchronized (this) {
309+
current = sessionRpc;
310+
if (current == null) {
311+
sessionRpc = current = new SessionRpc(rpc::invoke, sessionId);
312+
}
313+
}
307314
}
308315
return current;
309316
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void parse_unknownEventType_returnsUnknownSessionEvent() throws Exception {
5353
SessionEvent result = MAPPER.readValue(json, SessionEvent.class);
5454

5555
assertInstanceOf(UnknownSessionEvent.class, result);
56-
assertEquals("unknown", result.getType());
56+
assertEquals("future.feature_from_server", result.getType());
5757
}
5858

5959
@Test
@@ -69,7 +69,7 @@ void parse_unknownEventType_preservesOriginalType() throws Exception {
6969
SessionEvent result = MAPPER.readValue(json, SessionEvent.class);
7070

7171
assertInstanceOf(UnknownSessionEvent.class, result);
72-
assertEquals("unknown", result.getType());
72+
assertEquals("future.feature_from_server", result.getType());
7373
}
7474

7575
@Test

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,8 @@ void testParseUnknownEventType() throws Exception {
844844
assertNotNull(event, "Unknown event types should return an UnknownSessionEvent");
845845
assertInstanceOf(com.github.copilot.sdk.generated.UnknownSessionEvent.class, event,
846846
"Unknown event types should return UnknownSessionEvent for forward compatibility");
847-
assertEquals("unknown", event.getType());
847+
assertEquals("unknown.event.type", event.getType(),
848+
"UnknownSessionEvent should preserve the original type from JSON");
848849
}
849850

850851
@Test

0 commit comments

Comments
 (0)