Skip to content

Commit 1590463

Browse files
committed
Refactor HooksTest to remove disabled tests for userPromptSubmitted, sessionStart, and sessionEnd hooks
1 parent 9a8410f commit 1590463

1 file changed

Lines changed: 7 additions & 90 deletions

File tree

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

Lines changed: 7 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,21 @@
2424
import com.github.copilot.sdk.json.PreToolUseHookInput;
2525
import com.github.copilot.sdk.json.PreToolUseHookOutput;
2626
import com.github.copilot.sdk.json.SessionConfig;
27-
import com.github.copilot.sdk.json.SessionEndHookInput;
2827
import com.github.copilot.sdk.json.SessionHooks;
29-
import com.github.copilot.sdk.json.SessionStartHookInput;
30-
import com.github.copilot.sdk.json.UserPromptSubmittedHookInput;
3128

3229
/**
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).
3531
*
3632
* <p>
3733
* These tests use the shared CapiProxy infrastructure for deterministic API
3834
* response replay. Snapshots are stored in test/snapshots/hooks/.
3935
* </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>
4042
*/
4143
public class HooksTest {
4244

@@ -197,89 +199,4 @@ void testDenyToolExecutionWhenPreToolUseReturnsDeny() throws Exception {
197199
assertNotNull(response, "Response should not be null");
198200
}
199201
}
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-
}
285202
}

0 commit comments

Comments
 (0)