|
8 | 8 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
9 | 9 |
|
10 | 10 | import java.util.Map; |
| 11 | +import java.util.concurrent.CompletableFuture; |
| 12 | +import java.util.concurrent.TimeUnit; |
11 | 13 |
|
12 | 14 | import org.junit.jupiter.api.AfterAll; |
13 | 15 | import org.junit.jupiter.api.BeforeAll; |
14 | 16 | import org.junit.jupiter.api.Test; |
15 | 17 |
|
16 | 18 | import com.github.copilot.AllowCopilotExperimental; |
17 | 19 | import com.github.copilot.CopilotClient; |
| 20 | +import com.github.copilot.CopilotSession; |
18 | 21 | import com.github.copilot.E2ETestContext; |
19 | 22 | import com.github.copilot.ffi.InProcessEnvGuard; |
| 23 | +import com.github.copilot.generated.AssistantMessageEvent; |
| 24 | +import com.github.copilot.generated.SessionIdleEvent; |
20 | 25 | import com.github.copilot.rpc.CopilotClientOptions; |
| 26 | +import com.github.copilot.rpc.MessageOptions; |
| 27 | +import com.github.copilot.rpc.PermissionHandler; |
21 | 28 | import com.github.copilot.rpc.PingResponse; |
22 | 29 | import com.github.copilot.rpc.RuntimeConnection; |
| 30 | +import com.github.copilot.rpc.SessionConfig; |
23 | 31 |
|
24 | 32 | /** |
25 | 33 | * Failsafe integration test for the in-process (FFI) transport. |
26 | 34 | * |
27 | 35 | * <p> |
28 | 36 | * Loads the real {@code runtime.node} native library into this test process via |
29 | | - * {@link com.github.copilot.ffi.FfiRuntimeHost}, performs a purely local |
30 | | - * {@code ping} round-trip through the runtime, and stops cleanly. {@code ping} |
31 | | - * is answered by the runtime itself, so no auth or replay proxy is involved — |
32 | | - * this mirrors {@code nodejs/test/e2e/inprocess_ffi.e2e.test.ts}, |
33 | | - * {@code go/internal/e2e/inprocess_ffi_e2e_test.go}, and |
34 | | - * {@code python/e2e/test_inprocess_ffi_e2e.py}. |
| 37 | + * {@link com.github.copilot.ffi.FfiRuntimeHost}. Coverage includes both a |
| 38 | + * purely local {@code ping} round-trip and a replay-backed session turn that |
| 39 | + * exercises authentication, tool initialization, model traffic, and |
| 40 | + * asynchronous session event delivery over the FFI transport. |
35 | 41 | * |
36 | 42 | * <p> |
37 | 43 | * {@link InProcessEnvGuard} demonstrates how the harness redirects the native |
@@ -98,4 +104,24 @@ void shouldStartPingAndStopOverInProcessFfi() throws Exception { |
98 | 104 | } |
99 | 105 | } |
100 | 106 | } |
| 107 | + |
| 108 | + @Test |
| 109 | + void shouldCreateSessionAndCompleteTurnOverInProcessFfi() throws Exception { |
| 110 | + ctx.configureForTest("session", "should_receive_session_events"); |
| 111 | + |
| 112 | + try (CopilotClient client = ctx.createClient(); |
| 113 | + CopilotSession session = client |
| 114 | + .createSession(new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL)) |
| 115 | + .get(30, TimeUnit.SECONDS)) { |
| 116 | + var idleReceived = new CompletableFuture<SessionIdleEvent>(); |
| 117 | + session.on(SessionIdleEvent.class, idleReceived::complete); |
| 118 | + |
| 119 | + AssistantMessageEvent response = session.sendAndWait(new MessageOptions().setPrompt("What is 100+200?")) |
| 120 | + .get(60, TimeUnit.SECONDS); |
| 121 | + |
| 122 | + assertNotNull(response); |
| 123 | + assertEquals("100 + 200 = 300", response.getData().content()); |
| 124 | + assertNotNull(idleReceived.get(5, TimeUnit.SECONDS)); |
| 125 | + } |
| 126 | + } |
101 | 127 | } |
0 commit comments