Repository navigation
Expand file tree
/
Copy pathScenarioTestingServerControlE2ETests.cs
More file actions
232 lines (203 loc) · 10.6 KB
/
Copy pathScenarioTestingServerControlE2ETests.cs
File metadata and controls
232 lines (203 loc) · 10.6 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
using GitHub.Copilot.Rpc;
using GitHub.Copilot.Test.Harness;
using System.Text.Json;
using Xunit;
using Xunit.Abstractions;
namespace GitHub.Copilot.Test.E2E;
public class ScenarioTestingServerControlE2ETests(E2ETestFixture fixture, ITestOutputHelper output)
: ScenarioTestingE2ETestBase(fixture, "scenario_testing_server_control", output)
{
[Theory]
[InlineData("all")]
[InlineData("mcp")]
[InlineData("skills")]
public async Task Should_Search_Server_Catalog_With_Category_Contract(string category)
{
var (cliPath, capturePath) = await ScenarioTestingTestCli.CreateAsync(Ctx);
await using var client = Ctx.CreateClient(options: CreateFakeCliOptions(cliPath, capturePath));
await client.StartAsync();
var kinds = category switch
{
"all" => new[] { CatalogCandidateKind.McpServer, CatalogCandidateKind.AiSkill },
"mcp" => [CatalogCandidateKind.McpServer],
"skills" => [CatalogCandidateKind.AiSkill],
_ => throw new ArgumentOutOfRangeException(nameof(category)),
};
var capabilities = category switch
{
"all" => new[] { "mcp-server-card", "ai-skill-discovery" },
"mcp" => ["mcp-server-card"],
"skills" => ["ai-skill-discovery"],
_ => throw new ArgumentOutOfRangeException(nameof(category)),
};
var result = await client.Rpc.Catalog.SearchAsync(
new CatalogClientContract
{
ProtocolVersion = 3,
RequiredCapabilities = capabilities,
},
query: "scenario search",
limit: 50,
kinds: kinds);
var succeeded = Assert.IsType<CatalogSearchResultSucceeded>(result);
Assert.Empty(succeeded.Candidates);
Assert.Equal("scenario-search", succeeded.SearchId);
Assert.False(succeeded.Truncated);
Assert.Equal(3, succeeded.Negotiated.RuntimeProtocolVersion);
Assert.Equal(capabilities, succeeded.Negotiated.GrantedCapabilities.Select(capability => capability.Value));
var request = Assert.Single(
await ReadRequestsAsync(capturePath, "catalog.search")).GetProperty("params");
Assert.Equal("scenario search", request.GetProperty("query").GetString());
Assert.Equal(50, request.GetProperty("limit").GetInt32());
Assert.Equal(3, request.GetProperty("contract").GetProperty("protocolVersion").GetInt32());
Assert.Equal(
capabilities,
request.GetProperty("contract").GetProperty("requiredCapabilities")
.EnumerateArray().Select(item => item.GetString()));
Assert.Equal(
kinds.Select(kind => kind.Value),
request.GetProperty("kinds").EnumerateArray().Select(item => item.GetString()));
}
[Fact]
public async Task Should_Observe_Page_And_Cancel_Factory_Run()
{
var (cliPath, capturePath) = await ScenarioTestingTestCli.CreateAsync(Ctx);
await using var client = Ctx.CreateClient(options: CreateFakeCliOptions(cliPath, capturePath));
await using var session = await Ctx.CreateSessionAsync(client, new SessionConfig());
var runs = await session.Rpc.Factory.ListRunsAsync(afterSeq: 3, beforeSeq: 20, limit: 10);
var summary = Assert.Single(runs.Runs);
Assert.Equal("factory-run-1", summary.RunId);
Assert.Equal("scenario-factory", summary.FactoryName);
Assert.Equal(FactoryRunStatus.Running, summary.Status);
Assert.Equal(7, runs.OldestSeq);
Assert.Equal(7, runs.NewestSeq);
Assert.False(runs.HasMoreNewer);
var detail = await session.Rpc.Factory.GetRunDetailAsync(summary.RunId);
Assert.Equal(summary.RunId, detail.RunId);
Assert.Equal(summary.FactoryName, detail.FactoryName);
Assert.Equal(FactoryRunStatus.Running, detail.Status);
Assert.Equal(4, detail.Revision);
var progress = await session.Rpc.Factory.GetRunProgressAsync(
summary.RunId,
phaseId: "verify",
afterSeq: 5,
beforeSeq: 20,
limit: 25);
var line = Assert.Single(progress.Records);
Assert.Equal(12, line.Seq);
Assert.Equal("verify", line.PhaseId);
Assert.Equal(FactoryLogLineKind.Log, line.Kind);
Assert.Equal("Validation complete", line.Text);
var cancelled = await session.Rpc.Factory.CancelAsync(summary.RunId);
Assert.Equal(summary.RunId, cancelled.RunId);
Assert.Equal(FactoryRunStatus.Cancelled, cancelled.Status);
Assert.Equal("cancelled by user", cancelled.Reason);
var requests = await ScenarioTestingTestCli.ReadRequestsAsync(capturePath);
var list = Assert.Single(requests, request => GetMethod(request) == "session.factory.listRuns")
.GetProperty("params");
Assert.Equal(3, list.GetProperty("afterSeq").GetInt64());
Assert.Equal(20, list.GetProperty("beforeSeq").GetInt64());
Assert.Equal(10, list.GetProperty("limit").GetInt32());
var progressRequest = Assert.Single(
requests,
request => GetMethod(request) == "session.factory.getRunProgress").GetProperty("params");
Assert.Equal("factory-run-1", progressRequest.GetProperty("runId").GetString());
Assert.Equal("verify", progressRequest.GetProperty("phaseId").GetString());
Assert.Equal(5, progressRequest.GetProperty("afterSeq").GetInt64());
Assert.Equal(20, progressRequest.GetProperty("beforeSeq").GetInt64());
Assert.Equal(25, progressRequest.GetProperty("limit").GetInt32());
}
[Theory]
[InlineData("on", true)]
[InlineData("export", false)]
public async Task Should_Read_Autopilot_State_And_Enable_Remote_Mode(
string remoteMode,
bool expectedSteerable)
{
var (cliPath, capturePath) = await ScenarioTestingTestCli.CreateAsync(Ctx);
await using var client = Ctx.CreateClient(options: CreateFakeCliOptions(cliPath, capturePath));
await using var session = await Ctx.CreateSessionAsync(client, new SessionConfig());
var objective = (await session.Rpc.AutopilotObjective.GetStateAsync()).State;
Assert.NotNull(objective);
Assert.Equal(17, objective.Id);
Assert.Equal("Ship the scenario.", objective.Objective);
Assert.Equal(AutopilotObjectiveStatus.Active, objective.Status);
Assert.Equal(3, objective.TurnCount);
Assert.Equal("1250000000", objective.CreditCountNanoAiu);
Assert.Equal(5, objective.CreditLimit!.Credits);
Assert.Equal(1.25, objective.CreditLimit.CreditsUsed);
Assert.Equal("1250000000", objective.CreditLimit.CreditsUsedNanoAiu);
var enabled = await session.Rpc.Remote.EnableAsync(new RemoteSessionMode(remoteMode));
Assert.Equal(expectedSteerable, enabled.RemoteSteerable);
Assert.Equal($"https://example.test/sessions/{session.SessionId}", enabled.Url);
var remoteRequest = Assert.Single(
await ReadRequestsAsync(capturePath, "session.remote.enable")).GetProperty("params");
Assert.Equal(session.SessionId, remoteRequest.GetProperty("sessionId").GetString());
Assert.Equal(remoteMode, remoteRequest.GetProperty("mode").GetString());
}
[Fact]
public async Task Should_Edit_Reorder_Duplicate_Remove_And_Send_Queued_Items()
{
var (cliPath, capturePath) = await ScenarioTestingTestCli.CreateAsync(Ctx);
await using var client = Ctx.CreateClient(options: CreateFakeCliOptions(cliPath, capturePath));
await using var session = await Ctx.CreateSessionAsync(client, new SessionConfig());
await session.Rpc.Queue.SetDrainPausedAsync(true);
var first = await session.Rpc.Queue.InsertAtAsync(
0,
new QueueInsertMessage
{
Prompt = "First hidden prompt",
DisplayPrompt = "First visible prompt",
AgentMode = SendAgentMode.Interactive,
});
var second = await session.Rpc.Queue.InsertAtAsync(
1,
new QueueInsertMessage
{
Prompt = "Second hidden prompt",
DisplayPrompt = "Second visible prompt",
AgentMode = SendAgentMode.Plan,
});
Assert.True(await UpdateTextAsync());
var duplicate = await session.Rpc.Queue.DuplicateAtAsync(first.Id);
Assert.NotEqual(first.Id, duplicate.Id);
Assert.True((await session.Rpc.Queue.MoveItemAsync(second.Id, 0)).Changed);
var reordered = await session.Rpc.Queue.PendingItemsAsync();
Assert.Equal([second.Id, first.Id, duplicate.Id], reordered.Items.Select(item => item.Id));
Assert.Equal("Updated visible prompt", reordered.Items[1].DisplayText);
Assert.Equal(SendAgentMode.Interactive, reordered.Items[1].AgentMode);
Assert.True((await session.Rpc.Queue.SendNowAsync(second.Id)).Steered);
Assert.True((await session.Rpc.Queue.RemoveAtAsync(duplicate.Id)).Removed);
var remaining = Assert.Single((await session.Rpc.Queue.PendingItemsAsync()).Items);
Assert.Equal(first.Id, remaining.Id);
Assert.Equal("Updated visible prompt", remaining.DisplayText);
await session.Rpc.Queue.SetDrainPausedAsync(false);
var pauseRequests = await ReadRequestsAsync(capturePath, "session.queue.setDrainPaused");
Assert.Equal([true, false], pauseRequests.Select(
request => request.GetProperty("params").GetProperty("paused").GetBoolean()));
async Task<bool> UpdateTextAsync()
{
var result = await session.Rpc.Queue.UpdateTextAsync(
first.Id,
"Updated hidden prompt",
"Updated visible prompt");
return result.Updated;
}
}
private static CopilotClientOptions CreateFakeCliOptions(string cliPath, string capturePath) => new()
{
Connection = RuntimeConnection.ForStdio(
path: cliPath,
args: ["--capture-file", capturePath, "--behavior", "control-rpcs"]),
UseLoggedInUser = false,
};
private static async Task<JsonElement[]> ReadRequestsAsync(string capturePath, string method) =>
(await ScenarioTestingTestCli.ReadRequestsAsync(capturePath))
.Where(request => GetMethod(request) == method)
.ToArray();
private static string? GetMethod(JsonElement request) =>
request.GetProperty("method").GetString();
}