|
4 | 4 |
|
5 | 5 | using Microsoft.Extensions.AI; |
6 | 6 | using System.ComponentModel; |
| 7 | +using System.Text.Json; |
7 | 8 | using Xunit; |
8 | 9 |
|
9 | 10 | namespace GitHub.Copilot.SDK.Test; |
10 | 11 |
|
11 | | -public class MergeExcludedToolsTests |
| 12 | +public class OverridesBuiltInToolTests |
12 | 13 | { |
13 | 14 | [Fact] |
14 | | - public void Tool_Names_Are_Added_To_ExcludedTools() |
| 15 | + public void ToolDefinition_FromAIFunction_Sets_OverridesBuiltInTool() |
15 | 16 | { |
16 | | - var tools = new List<AIFunction> |
17 | | - { |
18 | | - AIFunctionFactory.Create(Noop, "my_tool"), |
19 | | - }; |
| 17 | + var fn = AIFunctionFactory.Create(Noop, "grep"); |
| 18 | + var def = CopilotClient.ToolDefinition.FromAIFunction(fn, overridesBuiltInTool: true); |
20 | 19 |
|
21 | | - var result = CopilotClient.MergeExcludedTools(null, tools); |
22 | | - |
23 | | - Assert.NotNull(result); |
24 | | - Assert.Contains("my_tool", result!); |
| 20 | + Assert.Equal("grep", def.Name); |
| 21 | + Assert.True(def.OverridesBuiltInTool); |
25 | 22 | } |
26 | 23 |
|
27 | 24 | [Fact] |
28 | | - public void Merges_With_Existing_ExcludedTools_And_Deduplicates() |
| 25 | + public void ToolDefinition_FromAIFunction_Omits_OverridesBuiltInTool_When_False() |
29 | 26 | { |
30 | | - var existing = new List<string> { "view", "my_tool" }; |
31 | | - var tools = new List<AIFunction> |
32 | | - { |
33 | | - AIFunctionFactory.Create(Noop, "my_tool"), |
34 | | - AIFunctionFactory.Create(Noop, "another_tool"), |
35 | | - }; |
36 | | - |
37 | | - var result = CopilotClient.MergeExcludedTools(existing, tools); |
| 27 | + var fn = AIFunctionFactory.Create(Noop, "custom_tool"); |
| 28 | + var def = CopilotClient.ToolDefinition.FromAIFunction(fn, overridesBuiltInTool: false); |
38 | 29 |
|
39 | | - Assert.NotNull(result); |
40 | | - Assert.Equal(3, result!.Count); |
41 | | - Assert.Contains("view", result); |
42 | | - Assert.Contains("my_tool", result); |
43 | | - Assert.Contains("another_tool", result); |
| 30 | + Assert.Equal("custom_tool", def.Name); |
| 31 | + Assert.Null(def.OverridesBuiltInTool); |
44 | 32 | } |
45 | 33 |
|
46 | 34 | [Fact] |
47 | | - public void Returns_Null_When_No_Tools_Provided() |
| 35 | + public void SessionConfig_BuiltInToolOverrides_Is_Used() |
48 | 36 | { |
49 | | - var result = CopilotClient.MergeExcludedTools(null, null); |
50 | | - Assert.Null(result); |
51 | | - } |
52 | | - |
53 | | - [Fact] |
54 | | - public void Returns_ExcludedTools_Unchanged_When_Tools_Empty() |
55 | | - { |
56 | | - var existing = new List<string> { "view" }; |
57 | | - var result = CopilotClient.MergeExcludedTools(existing, new List<AIFunction>()); |
| 37 | + var config = new SessionConfig |
| 38 | + { |
| 39 | + Tools = new List<AIFunction> { AIFunctionFactory.Create(Noop, "grep") }, |
| 40 | + BuiltInToolOverrides = new HashSet<string> { "grep" }, |
| 41 | + }; |
58 | 42 |
|
59 | | - Assert.Same(existing, result); |
| 43 | + Assert.Contains("grep", config.BuiltInToolOverrides); |
60 | 44 | } |
61 | 45 |
|
62 | 46 | [Fact] |
63 | | - public void Returns_Tool_Names_When_ExcludedTools_Null() |
| 47 | + public void ResumeSessionConfig_BuiltInToolOverrides_Is_Used() |
64 | 48 | { |
65 | | - var tools = new List<AIFunction> |
| 49 | + var config = new ResumeSessionConfig |
66 | 50 | { |
67 | | - AIFunctionFactory.Create(Noop, "my_tool"), |
| 51 | + Tools = new List<AIFunction> { AIFunctionFactory.Create(Noop, "grep") }, |
| 52 | + BuiltInToolOverrides = new HashSet<string> { "grep" }, |
68 | 53 | }; |
69 | 54 |
|
70 | | - var result = CopilotClient.MergeExcludedTools(null, tools); |
71 | | - |
72 | | - Assert.NotNull(result); |
73 | | - Assert.Single(result!); |
74 | | - Assert.Equal("my_tool", result[0]); |
| 55 | + Assert.NotNull(config.BuiltInToolOverrides); |
| 56 | + Assert.Contains("grep", config.BuiltInToolOverrides!); |
75 | 57 | } |
76 | 58 |
|
77 | 59 | [Description("No-op")] |
|
0 commit comments