Skip to content

Commit 7fd2bfb

Browse files
stephentoubCopilot
andcommitted
test(java): add dedicated rpc server e2e coverage
Add a dedicated Java RpcServerE2ETest that exercises server-scoped RPC wrappers in parity with the other SDKs. Update Java RPC codegen so server-scoped session methods keep their required sessionId params while session-scoped wrappers continue to inject sessionId automatically. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 9bb66f1 commit 7fd2bfb

5 files changed

Lines changed: 638 additions & 163 deletions

File tree

java/scripts/codegen/java.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,15 +1651,16 @@ function addWrapperResultImports(resultType: string, allImports: Set<string>, pa
16511651
}
16521652

16531653
/**
1654-
* Return the params class name if the method has a params schema with properties
1655-
* other than sessionId (i.e. there are user-supplied parameters).
1654+
* Return the params class name if the method has a params schema with user-supplied properties.
1655+
* Session-scoped wrappers inject sessionId automatically, but server-scoped wrappers must let
1656+
* callers supply it explicitly.
16561657
*/
1657-
function wrapperParamsClassName(method: RpcMethodNode): string | null {
1658+
function wrapperParamsClassName(method: RpcMethodNode, isSession: boolean): string | null {
16581659
let params = method.params;
16591660
if (params?.$ref) params = resolveRef(params) as JSONSchema7;
16601661
if (!params || typeof params !== "object") return null;
16611662
const props = params.properties ?? {};
1662-
const userProps = Object.keys(props).filter((k) => k !== "sessionId");
1663+
const userProps = Object.keys(props).filter((k) => !isSession || k !== "sessionId");
16631664
if (userProps.length === 0) return null;
16641665
return rpcMethodToClassName(method.rpcMethod) + "Params";
16651666
}
@@ -1682,7 +1683,7 @@ function generateApiMethod(
16821683
sessionIdExpr: string
16831684
): { lines: string[]; needsMapper: boolean; needsExperimentalImport: boolean } {
16841685
const resultClass = wrapperResultClassName(method);
1685-
const paramsClass = wrapperParamsClassName(method);
1686+
const paramsClass = wrapperParamsClassName(method, isSession);
16861687
const hasSessionId = methodHasSessionId(method);
16871688
const hasExtraParams = paramsClass !== null;
16881689
let needsMapper = false;
@@ -1790,7 +1791,7 @@ async function generateNamespaceApiFile(
17901791
const methodLines: string[] = [];
17911792
for (const [key, method] of tree.methods) {
17921793
const resultClass = wrapperResultClassName(method);
1793-
const paramsClass = wrapperParamsClassName(method);
1794+
const paramsClass = wrapperParamsClassName(method, isSession);
17941795
addWrapperResultImports(resultClass, allImports, packageName);
17951796
if (paramsClass) allImports.add(`${packageName}.${paramsClass}`);
17961797

@@ -1910,7 +1911,7 @@ async function generateRpcRootFile(
19101911
const methodLines: string[] = [];
19111912
for (const [key, method] of tree.methods) {
19121913
const resultClass = wrapperResultClassName(method);
1913-
const paramsClass = wrapperParamsClassName(method);
1914+
const paramsClass = wrapperParamsClassName(method, isSession);
19141915
addWrapperResultImports(resultClass, allImports, packageName);
19151916
if (paramsClass) allImports.add(`${packageName}.${paramsClass}`);
19161917

java/src/generated/java/com/github/copilot/generated/rpc/ServerSessionsApi.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ public CompletableFuture<SessionsForkResult> fork(SessionsForkParams params) {
5555
* @since 1.0.0
5656
*/
5757
@CopilotExperimental
58-
public CompletableFuture<SessionsConnectResult> connect() {
59-
return caller.invoke("sessions.connect", java.util.Map.of(), SessionsConnectResult.class);
58+
public CompletableFuture<SessionsConnectResult> connect(SessionsConnectParams params) {
59+
return caller.invoke("sessions.connect", params, SessionsConnectResult.class);
6060
}
6161

6262
/**
@@ -110,8 +110,8 @@ public CompletableFuture<SessionsGetLastForContextResult> getLastForContext(Sess
110110
* @since 1.0.0
111111
*/
112112
@CopilotExperimental
113-
public CompletableFuture<SessionsGetEventFilePathResult> getEventFilePath() {
114-
return caller.invoke("sessions.getEventFilePath", java.util.Map.of(), SessionsGetEventFilePathResult.class);
113+
public CompletableFuture<SessionsGetEventFilePathResult> getEventFilePath(SessionsGetEventFilePathParams params) {
114+
return caller.invoke("sessions.getEventFilePath", params, SessionsGetEventFilePathResult.class);
115115
}
116116

117117
/**
@@ -143,8 +143,8 @@ public CompletableFuture<SessionsCheckInUseResult> checkInUse(SessionsCheckInUse
143143
* @since 1.0.0
144144
*/
145145
@CopilotExperimental
146-
public CompletableFuture<SessionsGetPersistedRemoteSteerableResult> getPersistedRemoteSteerable() {
147-
return caller.invoke("sessions.getPersistedRemoteSteerable", java.util.Map.of(), SessionsGetPersistedRemoteSteerableResult.class);
146+
public CompletableFuture<SessionsGetPersistedRemoteSteerableResult> getPersistedRemoteSteerable(SessionsGetPersistedRemoteSteerableParams params) {
147+
return caller.invoke("sessions.getPersistedRemoteSteerable", params, SessionsGetPersistedRemoteSteerableResult.class);
148148
}
149149

150150
/**
@@ -154,8 +154,8 @@ public CompletableFuture<SessionsGetPersistedRemoteSteerableResult> getPersisted
154154
* @since 1.0.0
155155
*/
156156
@CopilotExperimental
157-
public CompletableFuture<Void> close() {
158-
return caller.invoke("sessions.close", java.util.Map.of(), Void.class);
157+
public CompletableFuture<Void> close(SessionsCloseParams params) {
158+
return caller.invoke("sessions.close", params, Void.class);
159159
}
160160

161161
/**
@@ -187,8 +187,8 @@ public CompletableFuture<SessionsPruneOldResult> pruneOld(SessionsPruneOldParams
187187
* @since 1.0.0
188188
*/
189189
@CopilotExperimental
190-
public CompletableFuture<Void> save() {
191-
return caller.invoke("sessions.save", java.util.Map.of(), Void.class);
190+
public CompletableFuture<Void> save(SessionsSaveParams params) {
191+
return caller.invoke("sessions.save", params, Void.class);
192192
}
193193

194194
/**
@@ -198,8 +198,8 @@ public CompletableFuture<Void> save() {
198198
* @since 1.0.0
199199
*/
200200
@CopilotExperimental
201-
public CompletableFuture<Void> releaseLock() {
202-
return caller.invoke("sessions.releaseLock", java.util.Map.of(), Void.class);
201+
public CompletableFuture<Void> releaseLock(SessionsReleaseLockParams params) {
202+
return caller.invoke("sessions.releaseLock", params, Void.class);
203203
}
204204

205205
/**
@@ -231,8 +231,8 @@ public CompletableFuture<Void> reloadPluginHooks(SessionsReloadPluginHooksParams
231231
* @since 1.0.0
232232
*/
233233
@CopilotExperimental
234-
public CompletableFuture<SessionsLoadDeferredRepoHooksResult> loadDeferredRepoHooks() {
235-
return caller.invoke("sessions.loadDeferredRepoHooks", java.util.Map.of(), SessionsLoadDeferredRepoHooksResult.class);
234+
public CompletableFuture<SessionsLoadDeferredRepoHooksResult> loadDeferredRepoHooks(SessionsLoadDeferredRepoHooksParams params) {
235+
return caller.invoke("sessions.loadDeferredRepoHooks", params, SessionsLoadDeferredRepoHooksResult.class);
236236
}
237237

238238
/**
@@ -253,8 +253,8 @@ public CompletableFuture<Void> setAdditionalPlugins(SessionsSetAdditionalPlugins
253253
* @since 1.0.0
254254
*/
255255
@CopilotExperimental
256-
public CompletableFuture<SessionsGetBoardEntryCountResult> getBoardEntryCount() {
257-
return caller.invoke("sessions.getBoardEntryCount", java.util.Map.of(), SessionsGetBoardEntryCountResult.class);
256+
public CompletableFuture<SessionsGetBoardEntryCountResult> getBoardEntryCount(SessionsGetBoardEntryCountParams params) {
257+
return caller.invoke("sessions.getBoardEntryCount", params, SessionsGetBoardEntryCountResult.class);
258258
}
259259

260260
/**

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,24 @@ public void setCopilotUserByToken(String token, String login, String copilotPlan
381381
proxy.setCopilotUserByToken(token, login, copilotPlan, apiUrl, telemetryUrl, analyticsTrackingId);
382382
}
383383

384+
/**
385+
* Configures the proxy to return a raw Copilot user response for a given token.
386+
*
387+
* @param token
388+
* the GitHub token
389+
* @param response
390+
* the raw response object to return for the token
391+
* @throws IOException
392+
* if the request fails
393+
* @throws InterruptedException
394+
* if the request is interrupted
395+
*/
396+
public void setCopilotUserByToken(String token, Map<String, Object> response)
397+
throws IOException, InterruptedException {
398+
ensureProxyAlive();
399+
proxy.setCopilotUserByToken(token, response);
400+
}
401+
384402
/**
385403
* Initializes the proxy state without loading a snapshot.
386404
* <p>

0 commit comments

Comments
 (0)