|
24 | 24 | import com.github.copilot.sdk.json.PreToolUseHookInput; |
25 | 25 | import com.github.copilot.sdk.json.PreToolUseHookOutput; |
26 | 26 | import com.github.copilot.sdk.json.SessionConfig; |
27 | | -import com.github.copilot.sdk.json.SessionEndHookInput; |
28 | 27 | import com.github.copilot.sdk.json.SessionHooks; |
29 | | -import com.github.copilot.sdk.json.SessionStartHookInput; |
30 | | -import com.github.copilot.sdk.json.UserPromptSubmittedHookInput; |
31 | 28 |
|
32 | 29 | /** |
33 | | - * Tests for hooks functionality (pre-tool-use, post-tool-use, |
34 | | - * user-prompt-submitted, session-start, and session-end hooks). |
| 30 | + * Tests for hooks functionality (pre-tool-use and post-tool-use hooks). |
35 | 31 | * |
36 | 32 | * <p> |
37 | 33 | * These tests use the shared CapiProxy infrastructure for deterministic API |
38 | 34 | * response replay. Snapshots are stored in test/snapshots/hooks/. |
39 | 35 | * </p> |
| 36 | + * |
| 37 | + * <p> |
| 38 | + * Note: Tests for userPromptSubmitted, sessionStart, and sessionEnd hooks are |
| 39 | + * not included as they are not tested in the upstream .NET or Node.js SDKs and |
| 40 | + * require test harness updates to properly invoke these hooks. |
| 41 | + * </p> |
40 | 42 | */ |
41 | 43 | public class HooksTest { |
42 | 44 |
|
@@ -197,89 +199,4 @@ void testDenyToolExecutionWhenPreToolUseReturnsDeny() throws Exception { |
197 | 199 | assertNotNull(response, "Response should not be null"); |
198 | 200 | } |
199 | 201 | } |
200 | | - |
201 | | - @Test |
202 | | - @org.junit.jupiter.api.Disabled("Requires test harness update to support userPromptSubmitted hook invocation") |
203 | | - void testUserPromptSubmittedHookInvokedWhenUserSendsMessage() throws Exception { |
204 | | - ctx.configureForTest("hooks", "invoke_user_prompt_submitted_hook"); |
205 | | - |
206 | | - List<UserPromptSubmittedHookInput> promptInputs = new ArrayList<>(); |
207 | | - final String[] sessionIdHolder = new String[1]; |
208 | | - |
209 | | - SessionConfig config = new SessionConfig() |
210 | | - .setHooks(new SessionHooks().setOnUserPromptSubmitted((input, invocation) -> { |
211 | | - promptInputs.add(input); |
212 | | - assertEquals(sessionIdHolder[0], invocation.getSessionId()); |
213 | | - return CompletableFuture.completedFuture(null); |
214 | | - })); |
215 | | - |
216 | | - try (CopilotClient client = ctx.createClient()) { |
217 | | - CopilotSession session = client.createSession(config).get(); |
218 | | - sessionIdHolder[0] = session.getSessionId(); |
219 | | - |
220 | | - session.sendAndWait(new MessageOptions().setPrompt("Hello, Copilot!")).get(60, TimeUnit.SECONDS); |
221 | | - |
222 | | - // Should have received at least one userPromptSubmitted hook call |
223 | | - assertFalse(promptInputs.isEmpty(), "Should have received userPromptSubmitted hook calls"); |
224 | | - |
225 | | - // Should have received the prompt |
226 | | - assertTrue(promptInputs.stream().anyMatch(i -> i.getPrompt() != null && !i.getPrompt().isEmpty()), |
227 | | - "Should have received prompt in userPromptSubmitted hook"); |
228 | | - } |
229 | | - } |
230 | | - |
231 | | - @Test |
232 | | - @org.junit.jupiter.api.Disabled("Requires test harness update to support sessionStart hook invocation") |
233 | | - void testSessionStartHookInvokedWhenSessionCreated() throws Exception { |
234 | | - ctx.configureForTest("hooks", "invoke_session_start_hook"); |
235 | | - |
236 | | - List<SessionStartHookInput> startInputs = new ArrayList<>(); |
237 | | - |
238 | | - SessionConfig config = new SessionConfig() |
239 | | - .setHooks(new SessionHooks().setOnSessionStart((input, invocation) -> { |
240 | | - startInputs.add(input); |
241 | | - return CompletableFuture.completedFuture(null); |
242 | | - })); |
243 | | - |
244 | | - try (CopilotClient client = ctx.createClient()) { |
245 | | - CopilotSession session = client.createSession(config).get(); |
246 | | - |
247 | | - // Send a message to trigger the session lifecycle |
248 | | - session.sendAndWait(new MessageOptions().setPrompt("Hello")).get(60, TimeUnit.SECONDS); |
249 | | - |
250 | | - // Should have received at least one sessionStart hook call |
251 | | - assertFalse(startInputs.isEmpty(), "Should have received sessionStart hook calls"); |
252 | | - |
253 | | - // Should have received the source |
254 | | - assertTrue(startInputs.stream().anyMatch(i -> i.getSource() != null), |
255 | | - "Should have received source in sessionStart hook"); |
256 | | - } |
257 | | - } |
258 | | - |
259 | | - @Test |
260 | | - @org.junit.jupiter.api.Disabled("Requires test harness update to support sessionEnd hook invocation") |
261 | | - void testSessionEndHookInvokedWhenSessionEnds() throws Exception { |
262 | | - ctx.configureForTest("hooks", "invoke_session_end_hook"); |
263 | | - |
264 | | - List<SessionEndHookInput> endInputs = new ArrayList<>(); |
265 | | - |
266 | | - SessionConfig config = new SessionConfig().setHooks(new SessionHooks().setOnSessionEnd((input, invocation) -> { |
267 | | - endInputs.add(input); |
268 | | - return CompletableFuture.completedFuture(null); |
269 | | - })); |
270 | | - |
271 | | - try (CopilotClient client = ctx.createClient()) { |
272 | | - CopilotSession session = client.createSession(config).get(); |
273 | | - |
274 | | - // Send a message and wait for completion |
275 | | - session.sendAndWait(new MessageOptions().setPrompt("Say hello")).get(60, TimeUnit.SECONDS); |
276 | | - |
277 | | - // Should have received at least one sessionEnd hook call |
278 | | - assertFalse(endInputs.isEmpty(), "Should have received sessionEnd hook calls"); |
279 | | - |
280 | | - // Should have received the reason |
281 | | - assertTrue(endInputs.stream().anyMatch(i -> i.getReason() != null), |
282 | | - "Should have received reason in sessionEnd hook"); |
283 | | - } |
284 | | - } |
285 | 202 | } |
0 commit comments