-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Java: Add InProcess FFI transport E2E test (task 4.8) #2238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
edburns
merged 6 commits into
edburns/1917-java-embed-rust-cli-runtime-dd-3039924-agentic-run-02
from
copilot/edburns1917-java-embed-rust-cli-runtime-dd-3039924
Aug 4, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5939d31
Initial plan
Copilot d49df45
Add InProcess FFI transport E2E test (task 4.8)
Copilot ce80659
Skip InProcessTransportIT unless -Pinprocess profile is active
Copilot ce60e9f
Apply spotless formatting to RequireInProcess.java
Copilot 9d99e48
Address Copilot review: fix InProcessEnvGuard to use native getenv, s…
edburns eb72430
Scope -Pinprocess Failsafe includes to InProcessTransportIT only
edburns File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
java/sdk/src/test/java/com/github/copilot/e2e/InProcessTransportIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| package com.github.copilot.e2e; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| import org.junit.jupiter.api.AfterAll; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import com.github.copilot.AllowCopilotExperimental; | ||
| import com.github.copilot.CopilotClient; | ||
| import com.github.copilot.E2ETestContext; | ||
| import com.github.copilot.ffi.InProcessEnvGuard; | ||
| import com.github.copilot.rpc.CopilotClientOptions; | ||
| import com.github.copilot.rpc.PingResponse; | ||
| import com.github.copilot.rpc.RuntimeConnection; | ||
|
|
||
| /** | ||
| * Failsafe integration test for the in-process (FFI) transport. | ||
| * | ||
| * <p> | ||
| * Loads the real {@code runtime.node} native library into this test process via | ||
| * {@link com.github.copilot.ffi.FfiRuntimeHost}, performs a purely local | ||
| * {@code ping} round-trip through the runtime, and stops cleanly. {@code ping} | ||
| * is answered by the runtime itself, so no auth or replay proxy is involved — | ||
| * this mirrors {@code nodejs/test/e2e/inprocess_ffi.e2e.test.ts}, | ||
| * {@code go/internal/e2e/inprocess_ffi_e2e_test.go}, and | ||
| * {@code python/e2e/test_inprocess_ffi_e2e.py}. | ||
| * | ||
| * <p> | ||
| * {@link InProcessEnvGuard} demonstrates how the harness redirects the native | ||
| * runtime's HTTP traffic to the replay proxy (via {@code COPILOT_API_URL}) for | ||
| * tests that need session/message round trips over the in-process transport: | ||
| * the native library reads environment variables from the live OS process | ||
| * environment block, not from the JVM's {@code System.getenv()} snapshot, so | ||
| * only a JNA-backed native call can make it visible to code already loaded | ||
| * in-process. | ||
| * | ||
| * <p> | ||
| * Run with {@code mvn verify -Pinprocess} from the {@code java} reactor root, | ||
| * which builds the {@code copilot-sdk-java-runtime} artifact and sets | ||
| * {@code COPILOT_CLI_PATH} to the pinned CLI whose sibling {@code runtime.node} | ||
| * this test loads, and forces {@code forkCount=1} because the FFI host and env | ||
| * guard mutate process-global state. | ||
| * | ||
| * <p> | ||
| * {@link RequireInProcess} disables this test unless the {@code -Pinprocess} | ||
| * profile is active: without it, the {@code copilot-sdk-java-runtime} | ||
| * classifier JAR providing {@code runtime.node} is not on the classpath, so the | ||
| * test would fail with a {@code FileNotFoundException} rather than being | ||
| * skipped. | ||
| */ | ||
| @AllowCopilotExperimental | ||
| @RequireInProcess | ||
| class InProcessTransportIT { | ||
|
|
||
| private static E2ETestContext ctx; | ||
|
|
||
| @BeforeAll | ||
| static void setup() throws Exception { | ||
| ctx = E2ETestContext.create(); | ||
| } | ||
|
|
||
| @AfterAll | ||
| static void teardown() throws Exception { | ||
| if (ctx != null) { | ||
| ctx.close(); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void shouldStartPingAndStopOverInProcessFfi() throws Exception { | ||
| // Route the native runtime's HTTP traffic (should it make any) at the | ||
| // replay proxy, mirroring how a session-level in-process test would | ||
| // redirect COPILOT_API_URL. `ping` never reaches the network, but this | ||
| // demonstrates the guard's intended usage for future in-process tests. | ||
| // COPILOT_CLI_PATH is intentionally NOT set here: NativeRuntimeLoader and | ||
| // CopilotClient.resolveInProcessEntrypoint() read it via | ||
| // System.getenv(), which is a JVM-startup-time snapshot that native | ||
| // setenv() calls made after the JVM starts cannot update — it must be | ||
| // set before the JVM starts (see the -Pinprocess Maven profile). | ||
| try (InProcessEnvGuard envGuard = new InProcessEnvGuard(Map.of("COPILOT_API_URL", ctx.getProxyUrl()))) { | ||
| CopilotClientOptions options = new CopilotClientOptions().setConnection(RuntimeConnection.forInProcess()); | ||
| try (CopilotClient client = new CopilotClient(options)) { | ||
| client.start().get(); | ||
|
|
||
| PingResponse pong = client.ping("ffi message").get(); | ||
| assertEquals("pong: ffi message", pong.message()); | ||
| assertNotNull(pong.timestamp()); | ||
|
|
||
| client.stop().get(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
64 changes: 64 additions & 0 deletions
64
java/sdk/src/test/java/com/github/copilot/e2e/RequireInProcess.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| package com.github.copilot.e2e; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
|
|
||
| /** | ||
| * Enables an annotated test class or method only when the E2E suite runs under | ||
| * the in-process (FFI) transport, i.e. when | ||
| * {@code COPILOT_SDK_DEFAULT_CONNECTION} is set to {@code inprocess}. | ||
| * | ||
| * <p> | ||
| * Use this for tests that require the real {@code runtime.node} native library | ||
| * to be present on the classpath, which only the {@code -Pinprocess} Maven | ||
| * profile guarantees (see {@link InProcessTransportIT}). Without this profile, | ||
| * standard {@code mvn verify} runs would fail with a | ||
| * {@code FileNotFoundException} because the classifier JAR providing | ||
| * {@code runtime.node} is not on the classpath. | ||
| * </p> | ||
| * | ||
| * <p> | ||
| * The inverse of {@link SkipInProcess}. | ||
| * </p> | ||
| */ | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Target({ElementType.TYPE, ElementType.METHOD}) | ||
| @ExtendWith(RequireInProcess.Condition.class) | ||
| public @interface RequireInProcess { | ||
|
|
||
| /** | ||
| * Explains why the annotated test requires the in-process transport. | ||
| * | ||
| * @return the skip reason used when the in-process transport is not active | ||
| */ | ||
| String value() default "Requires the -Pinprocess Maven profile"; | ||
|
|
||
| /** | ||
| * JUnit 5 execution condition backing {@link RequireInProcess}. | ||
| */ | ||
| final class Condition implements org.junit.jupiter.api.extension.ExecutionCondition { | ||
|
|
||
| private static final String DEFAULT_CONNECTION_ENV_VAR = "COPILOT_SDK_DEFAULT_CONNECTION"; | ||
|
|
||
| @Override | ||
| public org.junit.jupiter.api.extension.ConditionEvaluationResult evaluateExecutionCondition( | ||
| org.junit.jupiter.api.extension.ExtensionContext context) { | ||
| String envValue = System.getenv(DEFAULT_CONNECTION_ENV_VAR); | ||
| if ("inprocess".equalsIgnoreCase(envValue)) { | ||
| return org.junit.jupiter.api.extension.ConditionEvaluationResult | ||
| .enabled("Running under the in-process transport"); | ||
| } | ||
| String reason = context.getElement().map(element -> element.getAnnotation(RequireInProcess.class)) | ||
| .map(RequireInProcess::value).orElse("Requires the -Pinprocess Maven profile"); | ||
| return org.junit.jupiter.api.extension.ConditionEvaluationResult.disabled(reason); | ||
| } | ||
| } | ||
| } |
64 changes: 64 additions & 0 deletions
64
java/sdk/src/test/java/com/github/copilot/e2e/SkipInProcess.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| package com.github.copilot.e2e; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
|
|
||
| /** | ||
| * Disables an annotated test class or method when the E2E suite runs under the | ||
| * in-process (FFI) transport, i.e. when {@code COPILOT_SDK_DEFAULT_CONNECTION} | ||
| * is set to {@code inprocess}. | ||
| * | ||
| * <p> | ||
| * Use this for tests that rely on per-client process settings the in-process | ||
| * transport cannot honor — for example per-client environment variables, since | ||
| * the in-process runtime shares the host process's single environment (see | ||
| * {@link com.github.copilot.rpc.InProcessRuntimeConnection} and | ||
| * <a href="https://github.com/github/copilot-sdk/issues/1934">issue #1934</a>). | ||
| * </p> | ||
| * | ||
| * <p> | ||
| * Mirrors {@code skip_inprocess(reason)} in the Rust E2E harness. | ||
| * </p> | ||
| */ | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Target({ElementType.TYPE, ElementType.METHOD}) | ||
| @ExtendWith(SkipInProcess.Condition.class) | ||
| public @interface SkipInProcess { | ||
|
|
||
| /** | ||
| * Explains why the annotated test is incompatible with the in-process | ||
| * transport. | ||
| * | ||
| * @return the skip reason | ||
| */ | ||
| String value() default "Not supported under the in-process (FFI) transport"; | ||
|
|
||
| /** | ||
| * JUnit 5 execution condition backing {@link SkipInProcess}. | ||
| */ | ||
| final class Condition implements org.junit.jupiter.api.extension.ExecutionCondition { | ||
|
|
||
| private static final String DEFAULT_CONNECTION_ENV_VAR = "COPILOT_SDK_DEFAULT_CONNECTION"; | ||
|
|
||
| @Override | ||
| public org.junit.jupiter.api.extension.ConditionEvaluationResult evaluateExecutionCondition( | ||
| org.junit.jupiter.api.extension.ExtensionContext context) { | ||
| String envValue = System.getenv(DEFAULT_CONNECTION_ENV_VAR); | ||
| if (!"inprocess".equalsIgnoreCase(envValue)) { | ||
| return org.junit.jupiter.api.extension.ConditionEvaluationResult | ||
| .enabled("Not running under the in-process transport"); | ||
| } | ||
| String reason = context.getElement().map(element -> element.getAnnotation(SkipInProcess.class)) | ||
| .map(SkipInProcess::value).orElse("Not supported under the in-process (FFI) transport"); | ||
| return org.junit.jupiter.api.extension.ConditionEvaluationResult.disabled(reason); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.