-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathToolSetTests.cs
More file actions
119 lines (106 loc) · 3.6 KB
/
ToolSetTests.cs
File metadata and controls
119 lines (106 loc) · 3.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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
using Xunit;
namespace GitHub.Copilot.Test.Unit;
public class ToolSetTests
{
private static readonly string[] BashAndView = ["bash", "view"];
private static readonly string[] ExpectedBashAndView = ["builtin:bash", "builtin:view"];
private static readonly string[] AllWildcards = ["builtin:*", "custom:*", "mcp:*"];
private static readonly string[] BannedTools = ["bash", "powershell", "edit", "grep", "web_fetch"];
private static readonly string[] ExpectedIsolatedTools = ["ask_user", "task_complete"];
[Fact]
public void ToolSet_Emits_Source_Qualified_Strings()
{
var items = new ToolSet()
.AddBuiltIn("bash")
.AddBuiltIn("*")
.AddCustom("my_tool")
.AddCustom("*")
.AddMcp("github-list_issues")
.AddMcp("*")
.ToList();
Assert.Equal(
[
"builtin:bash",
"builtin:*",
"custom:my_tool",
"custom:*",
"mcp:github-list_issues",
"mcp:*",
], items);
}
[Fact]
public void ToolSet_AddBuiltIn_Accepts_Enumerable()
{
var items = new ToolSet().AddBuiltIn(BashAndView).ToList();
Assert.Equal(ExpectedBashAndView, items);
}
[Theory]
[InlineData("has:colon")]
[InlineData("has space")]
[InlineData("")]
public void ToolSet_Rejects_Invalid_Names(string bad)
{
Assert.Throws<ArgumentException>(() => new ToolSet().AddBuiltIn(bad));
Assert.Throws<ArgumentException>(() => new ToolSet().AddCustom(bad));
Assert.Throws<ArgumentException>(() => new ToolSet().AddMcp(bad));
}
[Fact]
public void ToolSet_Accepts_Wildcard()
{
var items = new ToolSet().AddBuiltIn("*").AddCustom("*").AddMcp("*").ToList();
Assert.Equal(AllWildcards, items);
}
[Fact]
public void BuiltInTools_Isolated_Does_Not_Contain_Banned_Tools()
{
foreach (var banned in BannedTools)
{
Assert.DoesNotContain(banned, BuiltInTools.Isolated);
}
}
[Fact]
public void BuiltInTools_Isolated_Contains_Expected_Tools()
{
foreach (var expected in ExpectedIsolatedTools)
{
Assert.Contains(expected, BuiltInTools.Isolated);
}
}
[Fact]
public void CopilotClient_Mode_Empty_Throws_Without_Base_Directory()
{
var ex = Assert.Throws<ArgumentException>(() => new CopilotClient(new CopilotClientOptions
{
Mode = CopilotClientMode.Empty,
}));
Assert.Contains("Empty", ex.Message, StringComparison.OrdinalIgnoreCase);
}
[Fact]
public void CopilotClient_Mode_Empty_Accepts_Base_Directory()
{
var dir = Path.Combine(Path.GetTempPath(), "copilot-empty-mode-test-" + Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(dir);
try
{
using var client = new CopilotClient(new CopilotClientOptions
{
Mode = CopilotClientMode.Empty,
BaseDirectory = dir,
});
Assert.NotNull(client);
}
finally
{
Directory.Delete(dir, recursive: true);
}
}
[Fact]
public void CopilotClient_Default_Mode_Is_CopilotCli()
{
using var client = new CopilotClient(new CopilotClientOptions());
Assert.NotNull(client);
}
}