-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathagent_and_compact_rpc.test.ts
More file actions
149 lines (121 loc) · 5.13 KB
/
Copy pathagent_and_compact_rpc.test.ts
File metadata and controls
149 lines (121 loc) · 5.13 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
import { describe, expect, it } from "vitest";
import { approveAll } from "../../src/index.js";
import type { CustomAgentConfig } from "../../src/index.js";
import { createSdkTestContext } from "./harness/sdkTestContext.js";
describe("Agent Selection RPC", async () => {
const { copilotClient: client } = await createSdkTestContext();
it("should list available custom agents", async () => {
const customAgents: CustomAgentConfig[] = [
{
name: "test-agent",
displayName: "Test Agent",
description: "A test agent",
prompt: "You are a test agent.",
},
{
name: "another-agent",
displayName: "Another Agent",
description: "Another test agent",
prompt: "You are another agent.",
},
];
const session = await client.createSession({
onPermissionRequest: approveAll,
customAgents,
});
const result = await session.rpc.agent.list();
expect(result.agents).toBeDefined();
expect(Array.isArray(result.agents)).toBe(true);
expect(result.agents.length).toBe(2);
expect(result.agents[0].name).toBe("test-agent");
expect(result.agents[0].displayName).toBe("Test Agent");
expect(result.agents[0].description).toBe("A test agent");
expect(result.agents[1].name).toBe("another-agent");
await session.destroy();
});
it("should return null when no agent is selected", async () => {
const customAgents: CustomAgentConfig[] = [
{
name: "test-agent",
displayName: "Test Agent",
description: "A test agent",
prompt: "You are a test agent.",
},
];
const session = await client.createSession({
onPermissionRequest: approveAll,
customAgents,
});
const result = await session.rpc.agent.getCurrent();
expect(result.agent).toBeNull();
await session.destroy();
});
it("should select and get current agent", async () => {
const customAgents: CustomAgentConfig[] = [
{
name: "test-agent",
displayName: "Test Agent",
description: "A test agent",
prompt: "You are a test agent.",
},
];
const session = await client.createSession({
onPermissionRequest: approveAll,
customAgents,
});
// Select the agent
const selectResult = await session.rpc.agent.select({ name: "test-agent" });
expect(selectResult.agent).toBeDefined();
expect(selectResult.agent.name).toBe("test-agent");
expect(selectResult.agent.displayName).toBe("Test Agent");
// Verify getCurrent returns the selected agent
const currentResult = await session.rpc.agent.getCurrent();
expect(currentResult.agent).not.toBeNull();
expect(currentResult.agent!.name).toBe("test-agent");
await session.destroy();
});
it("should deselect current agent", async () => {
const customAgents: CustomAgentConfig[] = [
{
name: "test-agent",
displayName: "Test Agent",
description: "A test agent",
prompt: "You are a test agent.",
},
];
const session = await client.createSession({
onPermissionRequest: approveAll,
customAgents,
});
// Select then deselect
await session.rpc.agent.select({ name: "test-agent" });
await session.rpc.agent.deselect();
// Verify no agent is selected
const currentResult = await session.rpc.agent.getCurrent();
expect(currentResult.agent).toBeNull();
await session.destroy();
});
it("should return empty list when no custom agents configured", async () => {
const session = await client.createSession({ onPermissionRequest: approveAll });
const result = await session.rpc.agent.list();
expect(result.agents).toEqual([]);
await session.destroy();
});
});
describe("Session Compact RPC", async () => {
const { copilotClient: client } = await createSdkTestContext();
it("should compact session history after messages", async () => {
const session = await client.createSession({ onPermissionRequest: approveAll });
// Send a message to create some history
await session.sendAndWait({ prompt: "What is 2+2?" });
// Compact the session
const result = await session.rpc.compaction.compact();
expect(typeof result.success).toBe("boolean");
expect(typeof result.tokensRemoved).toBe("number");
expect(typeof result.messagesRemoved).toBe("number");
await session.destroy();
}, 60000);
});