forked from github/copilot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrpc.test.ts
More file actions
97 lines (75 loc) · 3.28 KB
/
Copy pathrpc.test.ts
File metadata and controls
97 lines (75 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { describe, expect, it, onTestFinished } from "vitest";
import { CopilotClient } from "../../src/index.js";
import { createSdkTestContext } from "./harness/sdkTestContext.js";
function onTestFinishedForceStop(client: CopilotClient) {
onTestFinished(async () => {
try {
await client.forceStop();
} catch {
// Ignore cleanup errors - process may already be stopped
}
});
}
describe("RPC", () => {
it("should call rpc.ping with typed params and result", async () => {
const client = new CopilotClient({ useStdio: true });
onTestFinishedForceStop(client);
await client.start();
const result = await client.rpc.ping({ message: "typed rpc test" });
expect(result.message).toBe("pong: typed rpc test");
expect(typeof result.timestamp).toBe("number");
await client.stop();
});
it("should call rpc.models.list with typed result", async () => {
const client = new CopilotClient({ useStdio: true });
onTestFinishedForceStop(client);
await client.start();
const authStatus = await client.getAuthStatus();
if (!authStatus.isAuthenticated) {
await client.stop();
return;
}
const result = await client.rpc.models.list();
expect(result.models).toBeDefined();
expect(Array.isArray(result.models)).toBe(true);
await client.stop();
});
// account.getQuota is defined in schema but not yet implemented in CLI
it.skip("should call rpc.account.getQuota when authenticated", async () => {
const client = new CopilotClient({ useStdio: true });
onTestFinishedForceStop(client);
await client.start();
const authStatus = await client.getAuthStatus();
if (!authStatus.isAuthenticated) {
await client.stop();
return;
}
const result = await client.rpc.account.getQuota();
expect(result.quotaSnapshots).toBeDefined();
expect(typeof result.quotaSnapshots).toBe("object");
await client.stop();
});
});
describe("Session RPC", async () => {
const { copilotClient: client } = await createSdkTestContext();
// session.model.getCurrent is defined in schema but not yet implemented in CLI
it.skip("should call session.rpc.model.getCurrent", async () => {
const session = await client.createSession({ model: "claude-sonnet-4.5" });
const result = await session.rpc.model.getCurrent();
expect(result.modelId).toBeDefined();
expect(typeof result.modelId).toBe("string");
});
// session.model.switchTo is defined in schema but not yet implemented in CLI
it.skip("should call session.rpc.model.switchTo", async () => {
const session = await client.createSession({ model: "claude-sonnet-4.5" });
// Get initial model
const before = await session.rpc.model.getCurrent();
expect(before.modelId).toBeDefined();
// Switch to a different model
const result = await session.rpc.model.switchTo({ modelId: "gpt-4.1" });
expect(result.modelId).toBe("gpt-4.1");
// Verify the switch persisted
const after = await session.rpc.model.getCurrent();
expect(after.modelId).toBe("gpt-4.1");
});
});