Skip to content

Commit 59dc1b6

Browse files
Update TypeScript tests
1 parent f2f9373 commit 59dc1b6

14 files changed

Lines changed: 86 additions & 47 deletions

nodejs/test/e2e/ask_user.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import { describe, expect, it } from "vitest";
66
import type { UserInputRequest, UserInputResponse } from "../../src/index.js";
7+
import { approveAll } from "../../src/index.js";
78
import { createSdkTestContext } from "./harness/sdkTestContext.js";
89

910
describe("User input (ask_user)", async () => {
@@ -13,6 +14,7 @@ describe("User input (ask_user)", async () => {
1314
const userInputRequests: UserInputRequest[] = [];
1415

1516
const session = await client.createSession({
17+
onPermissionRequest: approveAll,
1618
onUserInputRequest: async (request, invocation) => {
1719
userInputRequests.push(request);
1820
expect(invocation.sessionId).toBe(session.sessionId);
@@ -43,6 +45,7 @@ describe("User input (ask_user)", async () => {
4345
const userInputRequests: UserInputRequest[] = [];
4446

4547
const session = await client.createSession({
48+
onPermissionRequest: approveAll,
4649
onUserInputRequest: async (request) => {
4750
userInputRequests.push(request);
4851
// Pick the first choice
@@ -74,6 +77,7 @@ describe("User input (ask_user)", async () => {
7477
const freeformAnswer = "This is my custom freeform answer that was not in the choices";
7578

7679
const session = await client.createSession({
80+
onPermissionRequest: approveAll,
7781
onUserInputRequest: async (request) => {
7882
userInputRequests.push(request);
7983
// Return a freeform answer (not from choices)

nodejs/test/e2e/client.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ChildProcess } from "child_process";
22
import { describe, expect, it, onTestFinished } from "vitest";
3-
import { CopilotClient } from "../../src/index.js";
3+
import { CopilotClient, approveAll } from "../../src/index.js";
44

55
function onTestFinishedForceStop(client: CopilotClient) {
66
onTestFinished(async () => {
@@ -51,9 +51,9 @@ describe("Client", () => {
5151
// the process has exited.
5252
const client = new CopilotClient({ useStdio: false });
5353

54-
await client.createSession();
54+
await client.createSession({ onPermissionRequest: approveAll });
5555

56-
// Kill the server process to force cleanup to fail
56+
// Kill the server processto force cleanup to fail
5757
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5858
const cliProcess = (client as any).cliProcess as ChildProcess;
5959
expect(cliProcess).toBeDefined();
@@ -69,7 +69,7 @@ describe("Client", () => {
6969
const client = new CopilotClient({});
7070
onTestFinishedForceStop(client);
7171

72-
await client.createSession();
72+
await client.createSession({ onPermissionRequest: approveAll });
7373
await client.forceStop();
7474
expect(client.getState()).toBe("disconnected");
7575
});
@@ -152,7 +152,7 @@ describe("Client", () => {
152152

153153
// Verify subsequent calls also fail (don't hang)
154154
try {
155-
const session = await client.createSession();
155+
const session = await client.createSession({ onPermissionRequest: approveAll });
156156
await session.send("test");
157157
expect.fail("Expected send() to throw an error after CLI exit");
158158
} catch (error) {

nodejs/test/e2e/compaction.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from "vitest";
2-
import { SessionEvent } from "../../src/index.js";
2+
import { SessionEvent, approveAll } from "../../src/index.js";
33
import { createSdkTestContext } from "./harness/sdkTestContext.js";
44

55
describe("Compaction", async () => {
@@ -8,6 +8,7 @@ describe("Compaction", async () => {
88
it("should trigger compaction with low threshold and emit events", async () => {
99
// Create session with very low compaction thresholds to trigger compaction quickly
1010
const session = await client.createSession({
11+
onPermissionRequest: approveAll,
1112
infiniteSessions: {
1213
enabled: true,
1314
// Trigger background compaction at 0.5% context usage (~1000 tokens)
@@ -63,6 +64,7 @@ describe("Compaction", async () => {
6364

6465
it("should not emit compaction events when infinite sessions disabled", async () => {
6566
const session = await client.createSession({
67+
onPermissionRequest: approveAll,
6668
infiniteSessions: {
6769
enabled: false,
6870
},

nodejs/test/e2e/hooks.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ describe("Session hooks", async () => {
120120
const preToolUseInputs: PreToolUseHookInput[] = [];
121121

122122
const session = await client.createSession({
123+
onPermissionRequest: approveAll,
123124
hooks: {
124125
onPreToolUse: async (input) => {
125126
preToolUseInputs.push(input);

nodejs/test/e2e/mcp_and_agents.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ describe("MCP Servers and Custom Agents", async () => {
2828
};
2929

3030
const session = await client.createSession({
31+
onPermissionRequest: approveAll,
3132
mcpServers,
3233
});
3334

@@ -44,7 +45,7 @@ describe("MCP Servers and Custom Agents", async () => {
4445

4546
it("should accept MCP server configuration on session resume", async () => {
4647
// Create a session first
47-
const session1 = await client.createSession();
48+
const session1 = await client.createSession({ onPermissionRequest: approveAll });
4849
const sessionId = session1.sessionId;
4950
await session1.sendAndWait({ prompt: "What is 1+1?" });
5051

@@ -59,6 +60,7 @@ describe("MCP Servers and Custom Agents", async () => {
5960
};
6061

6162
const session2 = await client.resumeSession(sessionId, {
63+
onPermissionRequest: approveAll,
6264
mcpServers,
6365
});
6466

@@ -89,6 +91,7 @@ describe("MCP Servers and Custom Agents", async () => {
8991
};
9092

9193
const session = await client.createSession({
94+
onPermissionRequest: approveAll,
9295
mcpServers,
9396
});
9497

@@ -136,6 +139,7 @@ describe("MCP Servers and Custom Agents", async () => {
136139
];
137140

138141
const session = await client.createSession({
142+
onPermissionRequest: approveAll,
139143
customAgents,
140144
});
141145

@@ -152,7 +156,7 @@ describe("MCP Servers and Custom Agents", async () => {
152156

153157
it("should accept custom agent configuration on session resume", async () => {
154158
// Create a session first
155-
const session1 = await client.createSession();
159+
const session1 = await client.createSession({ onPermissionRequest: approveAll });
156160
const sessionId = session1.sessionId;
157161
await session1.sendAndWait({ prompt: "What is 1+1?" });
158162

@@ -167,6 +171,7 @@ describe("MCP Servers and Custom Agents", async () => {
167171
];
168172

169173
const session2 = await client.resumeSession(sessionId, {
174+
onPermissionRequest: approveAll,
170175
customAgents,
171176
});
172177

@@ -193,6 +198,7 @@ describe("MCP Servers and Custom Agents", async () => {
193198
];
194199

195200
const session = await client.createSession({
201+
onPermissionRequest: approveAll,
196202
customAgents,
197203
});
198204

@@ -219,6 +225,7 @@ describe("MCP Servers and Custom Agents", async () => {
219225
];
220226

221227
const session = await client.createSession({
228+
onPermissionRequest: approveAll,
222229
customAgents,
223230
});
224231

@@ -244,6 +251,7 @@ describe("MCP Servers and Custom Agents", async () => {
244251
];
245252

246253
const session = await client.createSession({
254+
onPermissionRequest: approveAll,
247255
customAgents,
248256
});
249257

@@ -273,6 +281,7 @@ describe("MCP Servers and Custom Agents", async () => {
273281
];
274282

275283
const session = await client.createSession({
284+
onPermissionRequest: approveAll,
276285
mcpServers,
277286
customAgents,
278287
});

nodejs/test/e2e/permissions.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe("Permission callbacks", async () => {
6767
it("should deny tool operations by default when no handler is provided", async () => {
6868
let permissionDenied = false;
6969

70-
const session = await client.createSession();
70+
const session = await client.createSession({ onPermissionRequest: approveAll });
7171
session.on((event) => {
7272
if (
7373
event.type === "tool.execution_complete" &&
@@ -90,7 +90,7 @@ describe("Permission callbacks", async () => {
9090
const sessionId = session1.sessionId;
9191
await session1.sendAndWait({ prompt: "What is 1+1?" });
9292

93-
const session2 = await client.resumeSession(sessionId);
93+
const session2 = await client.resumeSession(sessionId, { onPermissionRequest: approveAll });
9494
let permissionDenied = false;
9595
session2.on((event) => {
9696
if (
@@ -111,7 +111,7 @@ describe("Permission callbacks", async () => {
111111

112112
it("should work without permission handler (default behavior)", async () => {
113113
// Create session without onPermissionRequest handler
114-
const session = await client.createSession();
114+
const session = await client.createSession({ onPermissionRequest: approveAll });
115115

116116
const message = await session.sendAndWait({
117117
prompt: "What is 2+2?",
@@ -148,7 +148,7 @@ describe("Permission callbacks", async () => {
148148
const permissionRequests: PermissionRequest[] = [];
149149

150150
// Create session without permission handler
151-
const session1 = await client.createSession();
151+
const session1 = await client.createSession({ onPermissionRequest: approveAll });
152152
const sessionId = session1.sessionId;
153153
await session1.sendAndWait({ prompt: "What is 1+1?" });
154154

nodejs/test/e2e/rpc.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it, onTestFinished } from "vitest";
2-
import { CopilotClient } from "../../src/index.js";
2+
import { CopilotClient, approveAll } from "../../src/index.js";
33
import { createSdkTestContext } from "./harness/sdkTestContext.js";
44

55
function onTestFinishedForceStop(client: CopilotClient) {
@@ -71,7 +71,7 @@ describe("Session RPC", async () => {
7171

7272
// session.model.getCurrent is defined in schema but not yet implemented in CLI
7373
it.skip("should call session.rpc.model.getCurrent", async () => {
74-
const session = await client.createSession({ model: "claude-sonnet-4.5" });
74+
const session = await client.createSession({ onPermissionRequest: approveAll, model: "claude-sonnet-4.5" });
7575

7676
const result = await session.rpc.model.getCurrent();
7777
expect(result.modelId).toBeDefined();
@@ -80,7 +80,7 @@ describe("Session RPC", async () => {
8080

8181
// session.model.switchTo is defined in schema but not yet implemented in CLI
8282
it.skip("should call session.rpc.model.switchTo", async () => {
83-
const session = await client.createSession({ model: "claude-sonnet-4.5" });
83+
const session = await client.createSession({ onPermissionRequest: approveAll, model: "claude-sonnet-4.5" });
8484

8585
// Get initial model
8686
const before = await session.rpc.model.getCurrent();
@@ -96,7 +96,7 @@ describe("Session RPC", async () => {
9696
});
9797

9898
it("should get and set session mode", async () => {
99-
const session = await client.createSession();
99+
const session = await client.createSession({ onPermissionRequest: approveAll });
100100

101101
// Get initial mode (default should be interactive)
102102
const initial = await session.rpc.mode.get();
@@ -116,7 +116,7 @@ describe("Session RPC", async () => {
116116
});
117117

118118
it("should read, update, and delete plan", async () => {
119-
const session = await client.createSession();
119+
const session = await client.createSession({ onPermissionRequest: approveAll });
120120

121121
// Initially plan should not exist
122122
const initial = await session.rpc.plan.read();
@@ -142,7 +142,7 @@ describe("Session RPC", async () => {
142142
});
143143

144144
it("should create, list, and read workspace files", async () => {
145-
const session = await client.createSession();
145+
const session = await client.createSession({ onPermissionRequest: approveAll });
146146

147147
// Initially no files
148148
const initialFiles = await session.rpc.workspace.listFiles();

0 commit comments

Comments
 (0)