Repository navigation
Expand file tree
/
Copy pathRpcAgentE2ETests.cs
More file actions
158 lines (130 loc) · 5.9 KB
/
Copy pathRpcAgentE2ETests.cs
File metadata and controls
158 lines (130 loc) · 5.9 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
150
151
152
153
154
155
156
157
158
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
using GitHub.Copilot.Rpc;
using GitHub.Copilot.Test.Harness;
using Xunit;
using Xunit.Abstractions;
namespace GitHub.Copilot.Test.E2E;
public class RpcAgentE2ETests(E2ETestFixture fixture, ITestOutputHelper output)
: E2ETestBase(fixture, "rpc_agents", output)
{
[Fact]
public async Task Should_List_Available_Custom_Agents()
{
var session = await CreateSessionAsync(new SessionConfig { CustomAgents = CreateCustomAgents() });
var result = await session.Rpc.Agent.ListAsync();
Assert.Equal(2, result.Agents.Count);
Assert.Equal("test-agent", result.Agents[0].Name);
Assert.Equal("Test Agent", result.Agents[0].DisplayName);
Assert.Equal("A test agent", result.Agents[0].Description);
Assert.Equal("another-agent", result.Agents[1].Name);
}
[Fact]
public async Task Should_Return_Null_When_No_Agent_Is_Selected()
{
var session = await CreateSessionAsync(new SessionConfig { CustomAgents = [CreateCustomAgents()[0]] });
var result = await session.Rpc.Agent.GetCurrentAsync();
Assert.Null(result.Agent);
}
[Fact]
public async Task Should_Select_And_Get_Current_Agent()
{
var session = await CreateSessionAsync(new SessionConfig { CustomAgents = [CreateCustomAgents()[0]] });
var selectResult = await session.Rpc.Agent.SelectAsync("test-agent");
Assert.NotNull(selectResult.Agent);
Assert.Equal("test-agent", selectResult.Agent.Name);
Assert.Equal("Test Agent", selectResult.Agent.DisplayName);
var currentResult = await session.Rpc.Agent.GetCurrentAsync();
Assert.NotNull(currentResult.Agent);
Assert.Equal("test-agent", currentResult.Agent.Name);
}
[Fact]
public async Task Should_Emit_Subagent_Selected_And_Deselected_Events()
{
var session = await CreateSessionAsync(new SessionConfig { CustomAgents = [CreateCustomAgents()[0]] });
var selectedEventTask = TestHelper.GetNextEventOfTypeAsync<SubagentSelectedEvent>(
session,
static _ => true,
timeout: TimeSpan.FromSeconds(30),
timeoutDescription: "subagent.selected event");
var selectResult = await session.Rpc.Agent.SelectAsync("test-agent");
var selectedEvent = await selectedEventTask;
Assert.NotNull(selectResult.Agent);
Assert.Equal("test-agent", selectedEvent.Data.AgentName);
Assert.Equal("Test Agent", selectedEvent.Data.AgentDisplayName);
var deselectedEventTask = TestHelper.GetNextEventOfTypeAsync<SubagentDeselectedEvent>(
session,
static _ => true,
timeout: TimeSpan.FromSeconds(30),
timeoutDescription: "subagent.deselected event");
await session.Rpc.Agent.DeselectAsync();
await deselectedEventTask;
var currentResult = await session.Rpc.Agent.GetCurrentAsync();
Assert.Null(currentResult.Agent);
}
[Fact]
public async Task Should_Deselect_Current_Agent()
{
var session = await CreateSessionAsync(new SessionConfig { CustomAgents = [CreateCustomAgents()[0]] });
await session.Rpc.Agent.SelectAsync("test-agent");
await session.Rpc.Agent.DeselectAsync();
var currentResult = await session.Rpc.Agent.GetCurrentAsync();
Assert.Null(currentResult.Agent);
}
[Fact]
public async Task Should_Return_Empty_List_When_No_Custom_Agents_Configured()
{
var session = await CreateSessionAsync();
var result = await session.Rpc.Agent.ListAsync();
Assert.Empty(result.Agents);
}
[Fact]
public async Task Should_Call_Agent_Reload()
{
var reloadAgent = CreateReloadAgent($"reload-test-agent-{Guid.NewGuid():N}");
var session = await CreateSessionAsync(new SessionConfig { CustomAgents = [reloadAgent] });
var before = await session.Rpc.Agent.ListAsync();
AssertReloadAgent(before.Agents, reloadAgent);
var result = await session.Rpc.Agent.ReloadAsync();
var current = await session.Rpc.Agent.ListAsync();
Assert.NotNull(result.Agents);
Assert.Equal(
result.Agents.Select(agent => agent.Name).OrderBy(name => name, StringComparer.Ordinal),
current.Agents.Select(agent => agent.Name).OrderBy(name => name, StringComparer.Ordinal));
Assert.Equal(
result.Agents.Select(agent => agent.DisplayName).OrderBy(name => name, StringComparer.Ordinal),
current.Agents.Select(agent => agent.DisplayName).OrderBy(name => name, StringComparer.Ordinal));
}
private static void AssertReloadAgent(IEnumerable<AgentInfo> agents, CustomAgentConfig expected)
{
var agent = Assert.Single(agents, agent => string.Equals(agent.Name, expected.Name, StringComparison.Ordinal));
Assert.Equal(expected.DisplayName, agent.DisplayName);
Assert.Equal(expected.Description, agent.Description);
}
private static List<CustomAgentConfig> CreateCustomAgents() =>
[
new()
{
Name = "test-agent",
DisplayName = "Test Agent",
Description = "A test agent",
Prompt = "You are a test agent."
},
new()
{
Name = "another-agent",
DisplayName = "Another Agent",
Description = "Another test agent",
Prompt = "You are another agent."
}
];
private static CustomAgentConfig CreateReloadAgent(string name) =>
new()
{
Name = name,
DisplayName = "Reload Test Agent",
Description = "Used by the agent reload RPC test.",
Prompt = "You are a reload test agent.",
};
}