Skip to content

Commit f3246b5

Browse files
stephentoubCopilot
andcommitted
Mock sendRequest in session.resume unit tests
These tests verify that the correct parameters are forwarded to the RPC call, not that the CLI handles them. Mock sendRequest (like the setModel test already does) so the tests don't depend on CLI authentication, which is unavailable on fork PRs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 7331ae2 commit f3246b5

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

nodejs/test/client.test.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,13 @@ describe("CopilotClient", () => {
6868
onTestFinished(() => client.forceStop());
6969

7070
const session = await client.createSession({ onPermissionRequest: approveAll });
71-
const spy = vi.spyOn((client as any).connection!, "sendRequest");
71+
// Mock sendRequest to capture the call without hitting the runtime
72+
const spy = vi
73+
.spyOn((client as any).connection!, "sendRequest")
74+
.mockImplementation(async (method: string, params: any) => {
75+
if (method === "session.resume") return { sessionId: params.sessionId };
76+
throw new Error(`Unexpected method: ${method}`);
77+
});
7278
await client.resumeSession(session.sessionId, {
7379
clientName: "my-app",
7480
onPermissionRequest: approveAll,
@@ -78,6 +84,7 @@ describe("CopilotClient", () => {
7884
"session.resume",
7985
expect.objectContaining({ clientName: "my-app", sessionId: session.sessionId })
8086
);
87+
spy.mockRestore();
8188
});
8289

8390
it("sends session.model.switchTo RPC with correct params", async () => {
@@ -325,7 +332,13 @@ describe("CopilotClient", () => {
325332
onTestFinished(() => client.forceStop());
326333

327334
const session = await client.createSession({ onPermissionRequest: approveAll });
328-
const spy = vi.spyOn((client as any).connection!, "sendRequest");
335+
// Mock sendRequest to capture the call without hitting the runtime
336+
const spy = vi
337+
.spyOn((client as any).connection!, "sendRequest")
338+
.mockImplementation(async (method: string, params: any) => {
339+
if (method === "session.resume") return { sessionId: params.sessionId };
340+
throw new Error(`Unexpected method: ${method}`);
341+
});
329342
await client.resumeSession(session.sessionId, {
330343
onPermissionRequest: approveAll,
331344
tools: [
@@ -342,6 +355,7 @@ describe("CopilotClient", () => {
342355
expect(payload.tools).toEqual([
343356
expect.objectContaining({ name: "grep", overridesBuiltInTool: true }),
344357
]);
358+
spy.mockRestore();
345359
});
346360
});
347361
});

0 commit comments

Comments
 (0)