Repository navigation
Expand file tree
/
Copy pathRpcServerE2ETests.cs
More file actions
608 lines (513 loc) · 23.7 KB
/
Copy pathRpcServerE2ETests.cs
File metadata and controls
608 lines (513 loc) · 23.7 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
using GitHub.Copilot.Test.Harness;
using Xunit;
using Xunit.Abstractions;
using RpcSessionFsSetProviderCapabilities = GitHub.Copilot.Rpc.SessionFsSetProviderCapabilities;
using RpcSessionFsSetProviderConventions = GitHub.Copilot.Rpc.SessionFsSetProviderConventions;
using RpcSessionContext = GitHub.Copilot.Rpc.SessionContext;
using RpcSessionListFilter = GitHub.Copilot.Rpc.SessionListFilter;
using RpcLocalSessionMetadataValue = GitHub.Copilot.Rpc.LocalSessionMetadataValue;
using RpcSessionListEntry = GitHub.Copilot.Rpc.SessionListEntry;
namespace GitHub.Copilot.Test.E2E;
public class RpcServerE2ETests(E2ETestFixture fixture, ITestOutputHelper output)
: E2ETestBase(fixture, "rpc_server", output)
{
private static readonly TimeSpan SessionPersistenceTimeout = TimeSpan.FromSeconds(30);
private static async Task<Exception> AssertImplementedFailureAsync(Func<Task> action, string method)
{
var ex = await Assert.ThrowsAnyAsync<Exception>(action);
var text = ex.ToString();
Assert.DoesNotContain($"Unhandled method {method}", text, StringComparison.OrdinalIgnoreCase);
Assert.Contains("session", text, StringComparison.OrdinalIgnoreCase);
return ex;
}
private CopilotClient CreateAuthenticatedClient(string token)
{
var env = new Dictionary<string, string>(Ctx.GetEnvironment())
{
["COPILOT_DEBUG_GITHUB_API_URL"] = Ctx.ProxyUrl,
};
return Ctx.CreateClient(options: new CopilotClientOptions
{
GitHubToken = token,
}, environment: env);
}
private async Task ConfigureAuthenticatedUserAsync(
string token,
IReadOnlyDictionary<string, CopilotUserQuotaSnapshot>? quotaSnapshots = null)
{
await Ctx.SetCopilotUserByTokenAsync(token, new CopilotUserConfig(
Login: "rpc-user",
CopilotPlan: "individual_pro",
Endpoints: new CopilotUserEndpoints(Api: Ctx.ProxyUrl, Telemetry: "https://localhost:1/telemetry"),
AnalyticsTrackingId: "rpc-user-tracking-id",
QuotaSnapshots: quotaSnapshots));
}
private string CreateUniqueWorkDirectory(string prefix)
{
var directory = Path.Join(Ctx.WorkDir, $"{prefix}-{Guid.NewGuid():N}");
Directory.CreateDirectory(directory);
return directory;
}
private static bool PathEquals(string? expected, string? actual)
{
if (expected is null || actual is null)
{
return expected is null && actual is null;
}
var comparison = OperatingSystem.IsWindows() ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
var normalizedExpected = Path.GetFullPath(expected).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
var normalizedActual = Path.GetFullPath(actual).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
return string.Equals(normalizedExpected, normalizedActual, comparison);
}
private async Task SaveSessionAsync(string sessionId)
=> await SaveSessionAsync(Client, sessionId);
private static async Task SaveSessionAsync(CopilotClient client, string sessionId)
{
var saveResult = await client.Rpc.Sessions.SaveAsync(sessionId);
Assert.NotNull(saveResult);
}
private static async Task PersistSessionAsync(CopilotClient client, CopilotSession session, string marker)
{
await session.LogAsync(marker);
await SaveSessionAsync(client, session.SessionId);
}
private async Task<RpcSessionListEntry> WaitForListedSessionAsync(
string sessionId,
RpcSessionListFilter? filter = null,
long? metadataLimit = null)
=> await WaitForListedSessionAsync(Client, sessionId, filter, metadataLimit);
private static async Task<RpcSessionListEntry> WaitForListedSessionAsync(
CopilotClient client,
string sessionId,
RpcSessionListFilter? filter = null,
long? metadataLimit = null)
{
RpcSessionListEntry? metadata = null;
await TestHelper.WaitForConditionAsync(
async () =>
{
var list = await client.Rpc.Sessions.ListAsync(metadataLimit: metadataLimit, filter: filter);
metadata = list.Sessions.FirstOrDefault(session => string.Equals(session.SessionId, sessionId, StringComparison.Ordinal));
return metadata is not null;
},
timeout: SessionPersistenceTimeout,
timeoutMessage: $"Timed out waiting for session '{sessionId}' to appear in sessions.list.");
return metadata!;
}
[Fact]
public async Task Should_Call_Rpc_Ping_With_Typed_Params_And_Result()
{
await Client.StartAsync();
var result = await Client.Rpc.PingAsync(message: "typed rpc test");
Assert.Equal("pong: typed rpc test", result.Message);
Assert.NotEqual(default, result.Timestamp);
}
[Fact]
[Trait(E2ETestTraits.Backend, E2ETestTraits.CapiOnly)]
public async Task Should_Clear_The_Managed_Settings_Cache()
{
await Client.StartAsync();
await Client.Rpc.ManagedSettings.ClearCacheAsync();
}
[Fact]
public async Task Should_Reject_Llm_Inference_Response_Frames_For_Missing_Request()
{
await Client.StartAsync();
var start = await Client.Rpc.LlmInference.HttpResponseStartAsync(
requestId: "missing-llm-inference-request",
status: 200,
headers: new Dictionary<string, IList<string>>
{
["content-type"] = ["text/event-stream"],
},
statusText: "OK");
Assert.False(start.Accepted);
var chunk = await Client.Rpc.LlmInference.HttpResponseChunkAsync(
requestId: "missing-llm-inference-request",
data: "data: {}\n\n",
binary: false,
end: false);
Assert.False(chunk.Accepted);
var error = await Client.Rpc.LlmInference.HttpResponseChunkAsync(
requestId: "missing-llm-inference-request",
data: string.Empty,
end: true,
error: new GitHub.Copilot.Rpc.LlmInferenceHttpResponseChunkError
{
Code = "missing_request",
Message = "No pending LLM inference request.",
});
Assert.False(error.Accepted);
}
[Fact]
[Trait(E2ETestTraits.Backend, E2ETestTraits.CapiOnly)]
public async Task Should_Call_Rpc_Models_List_With_Typed_Result()
{
const string token = "rpc-models-token";
await ConfigureAuthenticatedUserAsync(token);
await using var client = CreateAuthenticatedClient(token);
await client.StartAsync();
var result = await client.Rpc.Models.ListAsync();
Assert.NotNull(result.Models);
Assert.Contains(result.Models, model => model.Id == "claude-sonnet-5");
Assert.All(result.Models, model => Assert.False(string.IsNullOrWhiteSpace(model.Name)));
}
[Fact]
[Trait(E2ETestTraits.Backend, E2ETestTraits.CapiOnly)]
public async Task Should_Call_Rpc_Account_GetQuota_When_Authenticated()
{
const string token = "rpc-quota-token";
await ConfigureAuthenticatedUserAsync(
token,
new Dictionary<string, CopilotUserQuotaSnapshot>
{
["chat"] = new(
Entitlement: 100,
OverageCount: 2,
OveragePermitted: true,
PercentRemaining: 75,
TimestampUtc: "2026-04-30T00:00:00Z"),
});
await using var client = CreateAuthenticatedClient(token);
await client.StartAsync();
var result = await client.Rpc.Account.GetQuotaAsync(gitHubToken: token);
var chatQuota = Assert.Contains("chat", result.QuotaSnapshots);
Assert.Equal(100, chatQuota.EntitlementRequests);
Assert.Equal(25, chatQuota.UsedRequests);
Assert.Equal(75, chatQuota.RemainingPercentage);
Assert.Equal(2, chatQuota.Overage);
Assert.True(chatQuota.UsageAllowedWithExhaustedQuota);
Assert.True(chatQuota.OverageAllowedWithExhaustedQuota);
Assert.Equal(DateTimeOffset.Parse("2026-04-30T00:00:00Z"), chatQuota.ResetDate);
}
[Fact]
public async Task Should_Call_Rpc_Tools_List_With_Typed_Result()
{
await Client.StartAsync();
var result = await Client.Rpc.Tools.ListAsync();
Assert.NotNull(result.Tools);
Assert.NotEmpty(result.Tools);
Assert.All(result.Tools, tool => Assert.False(string.IsNullOrWhiteSpace(tool.Name)));
}
[Fact]
public async Task Should_Call_Rpc_SessionFs_SetProvider_With_Typed_Result()
{
await using var client = Ctx.CreateClient();
await client.StartAsync();
var result = await client.Rpc.SessionFs.SetProviderAsync(
initialCwd: "/",
sessionStatePath: "/session-state",
conventions: RpcSessionFsSetProviderConventions.Posix,
capabilities: new RpcSessionFsSetProviderCapabilities { Sqlite = true });
Assert.True(result.Success);
}
[Fact]
public async Task Should_Add_Secret_Filter_Values()
{
var environment = Ctx.GetEnvironment();
environment["COPILOT_ENABLE_SECRET_FILTERING"] = "true";
await using var client = Ctx.CreateClient(environment: environment);
await client.StartAsync();
var secret = $"rpc-secret-{Guid.NewGuid():N}";
var result = await client.Rpc.Secrets.AddFilterValuesAsync([secret]);
Assert.True(result.Ok);
}
[Fact]
public async Task Should_List_Find_And_Inspect_Persisted_Session_State()
{
var token = $"rpc-server-list-token-{Guid.NewGuid():N}";
await ConfigureAuthenticatedUserAsync(token);
await using var client = CreateAuthenticatedClient(token);
var sessionId = Guid.NewGuid().ToString();
var workingDirectory = CreateUniqueWorkDirectory("server-rpc-list");
var missingTaskId = $"missing-task-{Guid.NewGuid():N}";
var missingSessionId = Guid.NewGuid().ToString();
var session = await Ctx.CreateSessionAsync(client, new SessionConfig
{
SessionId = sessionId,
WorkingDirectory = workingDirectory,
OnPermissionRequest = PermissionHandler.ApproveAll,
});
try
{
await SaveSessionAsync(client, sessionId);
var listed = await client.Rpc.Sessions.ListAsync(
metadataLimit: 0,
filter: new RpcSessionListFilter { Cwd = workingDirectory });
Assert.NotNull(listed.Sessions);
Assert.DoesNotContain(listed.Sessions, session => !PathEquals(workingDirectory, session.Context?.Cwd));
var prefix = sessionId[..8];
var byPrefix = await client.Rpc.Sessions.FindByPrefixAsync(prefix);
Assert.Null(byPrefix.SessionId);
var byTaskId = await client.Rpc.Sessions.FindByTaskIdAsync(missingTaskId);
Assert.Null(byTaskId.SessionId);
var lastForContext = await client.Rpc.Sessions.GetLastForContextAsync(new RpcSessionContext { Cwd = workingDirectory });
Assert.Null(lastForContext.SessionId);
var sizes = await client.Rpc.Sessions.GetSizesAsync();
Assert.NotNull(sizes.Sizes);
if (sizes.Sizes.TryGetValue(sessionId, out var size))
{
Assert.True(size >= 0);
}
var inUse = await client.Rpc.Sessions.CheckInUseAsync([sessionId, missingSessionId]);
Assert.DoesNotContain(missingSessionId, inUse.InUse);
}
finally
{
await session.DisposeAsync();
}
}
[Fact]
public async Task Should_Enrich_Basic_Session_Metadata()
{
var token = $"rpc-server-enrich-token-{Guid.NewGuid():N}";
await ConfigureAuthenticatedUserAsync(token);
await using var client = CreateAuthenticatedClient(token);
var sessionId = Guid.NewGuid().ToString();
var workingDirectory = CreateUniqueWorkDirectory("server-rpc-enrich");
var session = await Ctx.CreateSessionAsync(client, new SessionConfig
{
SessionId = sessionId,
WorkingDirectory = workingDirectory,
OnPermissionRequest = PermissionHandler.ApproveAll,
});
try
{
await SaveSessionAsync(client, sessionId);
var basic = new RpcLocalSessionMetadataValue
{
SessionId = sessionId,
StartTime = DateTimeOffset.UtcNow.ToString("O"),
ModifiedTime = DateTimeOffset.UtcNow.ToString("O"),
IsRemote = false,
Name = "Basic metadata",
Context = new RpcSessionContext { Cwd = workingDirectory },
};
var result = await client.Rpc.Sessions.EnrichMetadataAsync([
basic,
]);
var enriched = Assert.Single(result.Sessions);
Assert.Equal(sessionId, enriched.SessionId);
Assert.True(PathEquals(workingDirectory, enriched.Context?.Cwd),
$"Expected enriched session cwd '{workingDirectory}', actual '{enriched.Context?.Cwd}'.");
Assert.False(enriched.IsRemote);
}
finally
{
await session.DisposeAsync();
}
}
[Fact]
public async Task Should_Close_Active_Session_And_Release_Lock()
{
var token = $"rpc-server-close-token-{Guid.NewGuid():N}";
await ConfigureAuthenticatedUserAsync(token);
await using var client = CreateAuthenticatedClient(token);
var sessionId = Guid.NewGuid().ToString();
var workingDirectory = CreateUniqueWorkDirectory("server-rpc-close");
var session = await Ctx.CreateSessionAsync(client, new SessionConfig
{
SessionId = sessionId,
WorkingDirectory = workingDirectory,
OnPermissionRequest = PermissionHandler.ApproveAll,
});
await PersistSessionAsync(client, session, "SERVER_RPC_CLOSE_READY");
var closeResult = await client.Rpc.Sessions.CloseAsync(sessionId);
Assert.NotNull(closeResult);
var releaseResult = await client.Rpc.Sessions.ReleaseLockAsync(sessionId);
Assert.NotNull(releaseResult);
var inUse = await client.Rpc.Sessions.CheckInUseAsync([sessionId]);
Assert.DoesNotContain(sessionId, inUse.InUse);
}
[Fact]
public async Task Should_Check_In_Use_Session_From_Another_Runtime_And_Release_Lock()
{
var sessionId = Guid.NewGuid().ToString();
var workingDirectory = CreateUniqueWorkDirectory("server-rpc-in-use");
await using var otherClient = Ctx.CreateClient(options: new CopilotClientOptions { Connection = RuntimeConnection.ForStdio() });
await using var otherSession = await Ctx.CreateSessionAsync(otherClient, new SessionConfig
{
SessionId = sessionId,
WorkingDirectory = workingDirectory,
OnPermissionRequest = PermissionHandler.ApproveAll,
});
await Client.StartAsync();
await TestHelper.WaitForConditionAsync(
async () =>
{
var result = await Client.Rpc.Sessions.CheckInUseAsync([sessionId]);
return result.InUse.Contains(sessionId);
},
timeout: SessionPersistenceTimeout,
timeoutMessage: $"Timed out waiting for sessions.checkInUse to report '{sessionId}' as held by another runtime.");
var releaseResult = await otherClient.Rpc.Sessions.ReleaseLockAsync(sessionId);
Assert.NotNull(releaseResult);
await TestHelper.WaitForConditionAsync(
async () =>
{
var result = await Client.Rpc.Sessions.CheckInUseAsync([sessionId]);
return !result.InUse.Contains(sessionId);
},
timeout: SessionPersistenceTimeout,
timeoutMessage: $"Timed out waiting for sessions.releaseLock to release '{sessionId}'.");
}
[Fact]
public async Task Should_Prune_DryRun_And_BulkDelete_Persisted_Session()
{
var token = $"rpc-server-delete-token-{Guid.NewGuid():N}";
await ConfigureAuthenticatedUserAsync(token);
await using var client = CreateAuthenticatedClient(token);
var sessionId = Guid.NewGuid().ToString();
var missingSessionId = Guid.NewGuid().ToString();
var workingDirectory = CreateUniqueWorkDirectory("server-rpc-delete");
var session = await Ctx.CreateSessionAsync(client, new SessionConfig
{
SessionId = sessionId,
WorkingDirectory = workingDirectory,
OnPermissionRequest = PermissionHandler.ApproveAll,
});
await SaveSessionAsync(client, sessionId);
await client.Rpc.Sessions.CloseAsync(sessionId);
var prune = await client.Rpc.Sessions.PruneOldAsync(
olderThanDays: 0,
dryRun: true,
includeNamed: true,
excludeSessionIds: []);
Assert.True(prune.DryRun);
Assert.DoesNotContain(missingSessionId, prune.Candidates);
Assert.DoesNotContain(sessionId, prune.Deleted);
Assert.True(prune.FreedBytes >= 0);
var delete = await client.Rpc.Sessions.BulkDeleteAsync([sessionId, missingSessionId]);
Assert.True(delete.FreedBytes.TryGetValue(sessionId, out var freedBytes), $"Expected sessions.bulkDelete to delete '{sessionId}'.");
Assert.True(freedBytes >= 0);
if (delete.FreedBytes.TryGetValue(missingSessionId, out var missingFreedBytes))
{
Assert.Equal(0, missingFreedBytes);
}
await TestHelper.WaitForConditionAsync(
async () =>
{
var list = await client.Rpc.Sessions.ListAsync();
return list.Sessions.All(s => s.SessionId != sessionId);
},
timeout: SessionPersistenceTimeout,
timeoutMessage: $"Timed out waiting for sessions.bulkDelete to remove '{sessionId}'.");
GC.KeepAlive(session);
}
[Fact]
public async Task Should_Set_Additional_Plugins_And_Reload_Deferred_Hooks()
{
await Client.StartAsync();
var clearPlugins = await Client.Rpc.Sessions.SetAdditionalPluginsAsync([]);
Assert.NotNull(clearPlugins);
var sessionId = Guid.NewGuid().ToString();
var workingDirectory = CreateUniqueWorkDirectory("server-rpc-hooks");
var session = await CreateSessionAsync(new SessionConfig
{
SessionId = sessionId,
WorkingDirectory = workingDirectory,
EnableConfigDiscovery = false,
});
try
{
var reload = await Client.Rpc.Sessions.ReloadPluginHooksAsync(sessionId, deferRepoHooks: true);
Assert.NotNull(reload);
var loaded = await Client.Rpc.Sessions.LoadDeferredRepoHooksAsync(sessionId);
Assert.NotNull(loaded.StartupPrompts);
Assert.Equal(0, loaded.HookCount);
Assert.Empty(loaded.StartupPrompts);
}
finally
{
await Client.Rpc.Sessions.SetAdditionalPluginsAsync([]);
await session.DisposeAsync();
}
}
[Fact]
public async Task Should_Report_Implemented_Error_When_Connecting_Unknown_Remote_Session()
{
await Client.StartAsync();
var remoteSessionId = $"remote-{Guid.NewGuid():N}";
var ex = await AssertImplementedFailureAsync(
() => Client.Rpc.Sessions.ConnectAsync(remoteSessionId),
"sessions.connect");
Assert.False(string.IsNullOrWhiteSpace(ex.Message));
}
[Fact]
public async Task Should_Discover_Server_Mcp_And_Skills()
{
await Client.StartAsync();
var skillName = $"server-rpc-skill-{Guid.NewGuid():N}";
var skillDirectory = CreateSkillDirectory(skillName, "Skill discovered by server-scoped RPC tests.");
var mcp = await Client.Rpc.Mcp.DiscoverAsync(workingDirectory: Ctx.WorkDir);
Assert.NotNull(mcp.Servers);
var skills = await Client.Rpc.Skills.DiscoverAsync(skillDirectories: [skillDirectory]);
var discoveredSkill = Assert.Single(skills.Skills, skill => string.Equals(skill.Name, skillName, StringComparison.Ordinal));
Assert.Equal("Skill discovered by server-scoped RPC tests.", discoveredSkill.Description);
Assert.True(discoveredSkill.Enabled);
Assert.EndsWith(Path.Join(skillName, "SKILL.md"), discoveredSkill.Path);
var skillPaths = await Client.Rpc.Skills.GetDiscoveryPathsAsync(
projectPaths: [Ctx.WorkDir],
excludeHostSkills: true);
var projectSkillPath = Assert.Single(skillPaths.Paths, path =>
PathEquals(Ctx.WorkDir, path.ProjectPath) && path.PreferredForCreation);
Assert.False(string.IsNullOrWhiteSpace(projectSkillPath.Path));
var agents = await Client.Rpc.Agents.DiscoverAsync(
projectPaths: [Ctx.WorkDir],
excludeHostAgents: true);
Assert.NotNull(agents.Agents);
Assert.All(agents.Agents, agent => Assert.False(string.IsNullOrWhiteSpace(agent.Name)));
var agentPaths = await Client.Rpc.Agents.GetDiscoveryPathsAsync(
projectPaths: [Ctx.WorkDir],
excludeHostAgents: true);
var projectAgentPath = Assert.Single(agentPaths.Paths, path =>
PathEquals(Ctx.WorkDir, path.ProjectPath) && path.PreferredForCreation);
Assert.False(string.IsNullOrWhiteSpace(projectAgentPath.Path));
var instructions = await Client.Rpc.Instructions.DiscoverAsync(
projectPaths: [Ctx.WorkDir],
excludeHostInstructions: true);
Assert.NotNull(instructions.Sources);
Assert.All(instructions.Sources, source =>
{
Assert.False(string.IsNullOrWhiteSpace(source.Id));
Assert.False(string.IsNullOrWhiteSpace(source.Label));
Assert.False(string.IsNullOrWhiteSpace(source.SourcePath));
});
var instructionPaths = await Client.Rpc.Instructions.GetDiscoveryPathsAsync(
projectPaths: [Ctx.WorkDir],
excludeHostInstructions: true);
Assert.NotEmpty(instructionPaths.Paths);
Assert.Contains(instructionPaths.Paths, path => PathEquals(Ctx.WorkDir, path.ProjectPath));
Assert.All(instructionPaths.Paths, path => Assert.False(string.IsNullOrWhiteSpace(path.Path)));
try
{
await Client.Rpc.Skills.Config.SetDisabledSkillsAsync([skillName]);
var disabledSkills = await Client.Rpc.Skills.DiscoverAsync(skillDirectories: [skillDirectory]);
var disabledSkill = Assert.Single(disabledSkills.Skills, skill => string.Equals(skill.Name, skillName, StringComparison.Ordinal));
Assert.False(disabledSkill.Enabled);
}
finally
{
await Client.Rpc.Skills.Config.SetDisabledSkillsAsync([]);
}
}
private string CreateSkillDirectory(string skillName, string description)
{
var skillsDir = Path.Join(Ctx.WorkDir, "server-rpc-skills", Guid.NewGuid().ToString("N"));
var skillSubdir = Path.Join(skillsDir, skillName);
Directory.CreateDirectory(skillSubdir);
var skillContent = $"""
---
name: {skillName}
description: {description}
---
# {skillName}
This skill is used by RPC E2E tests.
""".ReplaceLineEndings("\n");
File.WriteAllText(Path.Join(skillSubdir, "SKILL.md"), skillContent);
return skillsDir;
}
}