Skip to content

Commit 712eaef

Browse files
Fix lint + clean up v2-direct-RPC tests
- `nodejs/src/session.ts` had an unused `PermissionRequestResult` import after the v2 drop. eslint flagged it (`no-unused-vars`). - `nodejs/test/client.test.ts` had a leftover test for the deleted `handlePermissionRequestV2` v2 adapter. Delete the test. - `rust/tests/session_test.rs` had two tests that drove the deleted `permission.request` direct-RPC arm (`permission_request_dispatches_to_handler`, `approve_all_handler_approves_permission`). Delete the first one and rewrite the second to exercise the broadcast-event path (`permission.requested` event + `handlePendingPermissionRequest` RPC response), which is the only remaining permission flow. - Drop unused `PermissionHandler` / `PermissionResult` imports that the deleted tests left behind. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 13f7116 commit 712eaef

3 files changed

Lines changed: 13 additions & 59 deletions

File tree

nodejs/src/session.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import type {
2828
MessageOptions,
2929
PermissionHandler,
3030
PermissionRequest,
31-
PermissionRequestResult,
3231
ReasoningEffort,
3332
ModelCapabilitiesOverride,
3433
SectionTransformFn,

nodejs/test/client.test.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,6 @@ describe("CopilotClient", () => {
1717
expect(spy).not.toHaveBeenCalled();
1818
});
1919

20-
it("throws when a v2 permission handler returns no-result", async () => {
21-
const session = new CopilotSession("session-1", {} as any);
22-
session.registerPermissionHandler(() => ({ kind: "no-result" }));
23-
const client = new CopilotClient();
24-
(client as any).sessions.set(session.sessionId, session);
25-
26-
await expect(
27-
(client as any).handlePermissionRequestV2({
28-
sessionId: session.sessionId,
29-
permissionRequest: { kind: "write" },
30-
})
31-
).rejects.toThrow(/protocol v2 server/);
32-
});
33-
3420
it("forwards clientName in session.create request", async () => {
3521
const client = new CopilotClient();
3622
await client.start();

rust/tests/session_test.rs

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ use std::time::Duration;
88
use async_trait::async_trait;
99
use github_copilot_sdk::handler::{
1010
ApproveAllHandler, AutoModeSwitchHandler, AutoModeSwitchResponse, ElicitationHandler,
11-
ExitPlanModeHandler, ExitPlanModeResult, PermissionHandler, PermissionResult, UserInputHandler,
12-
UserInputResponse,
11+
ExitPlanModeHandler, ExitPlanModeResult, UserInputHandler, UserInputResponse,
1312
};
1413
use github_copilot_sdk::types::{
1514
CommandContext, CommandDefinition, CommandHandler, DeliveryMode, ElicitationRequest,
@@ -1178,41 +1177,6 @@ async fn elicitation_returns_typed_result() {
11781177
assert_eq!(result.content.unwrap()["name"], "Octocat");
11791178
}
11801179

1181-
#[tokio::test]
1182-
async fn permission_request_dispatches_to_handler() {
1183-
struct DenyHandler;
1184-
#[async_trait]
1185-
impl PermissionHandler for DenyHandler {
1186-
async fn handle(
1187-
&self,
1188-
_session_id: SessionId,
1189-
_request_id: RequestId,
1190-
_data: PermissionRequestData,
1191-
) -> PermissionResult {
1192-
PermissionResult::reject(None)
1193-
}
1194-
}
1195-
1196-
let (_session, mut server) =
1197-
create_session_pair_with_config(|cfg| cfg.with_permission_handler(Arc::new(DenyHandler)))
1198-
.await;
1199-
server
1200-
.send_request(
1201-
200,
1202-
"permission.request",
1203-
serde_json::json!({
1204-
"sessionId": server.session_id,
1205-
"requestId": "perm-1",
1206-
"kind": "shell",
1207-
}),
1208-
)
1209-
.await;
1210-
1211-
let response = timeout(TIMEOUT, server.read_response()).await.unwrap();
1212-
assert_eq!(response["id"], 200);
1213-
assert_eq!(response["result"]["kind"], "reject");
1214-
}
1215-
12161180
#[tokio::test]
12171181
async fn user_input_request_dispatches_to_handler() {
12181182
struct InputHandler;
@@ -1455,18 +1419,23 @@ async fn approve_all_handler_approves_permission() {
14551419
.await;
14561420

14571421
server
1458-
.send_request(
1459-
500,
1460-
"permission.request",
1422+
.send_event(
1423+
"permission.requested",
14611424
serde_json::json!({
1462-
"sessionId": server.session_id,
14631425
"requestId": "perm-auto",
1464-
"kind": "shell",
1426+
"sessionId": server.session_id,
1427+
"permissionRequest": { "kind": "shell" },
14651428
}),
14661429
)
14671430
.await;
1468-
let response = timeout(TIMEOUT, server.read_response()).await.unwrap();
1469-
assert_eq!(response["result"]["kind"], "approve-once");
1431+
1432+
let request = timeout(TIMEOUT, server.read_request()).await.unwrap();
1433+
assert_eq!(
1434+
request["method"],
1435+
"session.permissions.handlePendingPermissionRequest"
1436+
);
1437+
assert_eq!(request["params"]["requestId"], "perm-auto");
1438+
assert_eq!(request["params"]["result"]["kind"], "approve-once");
14701439
}
14711440

14721441
#[tokio::test]

0 commit comments

Comments
 (0)