| 1 | using CascadeIDE.Services; |
| 2 | using Xunit; |
| 3 | |
| 4 | namespace CascadeIDE.Tests; |
| 5 | |
| 6 | public sealed class IdeMcpToolNamingTests |
| 7 | { |
| 8 | [Theory] |
| 9 | [InlineData("intercom.reveal_attachment", "ide_intercom_reveal_attachment")] |
| 10 | [InlineData("cockpit.open_command_line", "ide_cockpit_open_command_line")] |
| 11 | [InlineData("editor.select_code", "ide_editor_select_code")] |
| 12 | public void ToToolName_replaces_dots_with_underscores(string commandId, string expectedTool) |
| 13 | { |
| 14 | Assert.Equal(expectedTool, IdeMcpToolNaming.ToToolName(commandId)); |
| 15 | Assert.True(expectedTool.Length <= IdeMcpToolNaming.MaxToolNameLength); |
| 16 | Assert.DoesNotContain('.', IdeMcpToolNaming.ToToolName(commandId)); |
| 17 | } |
| 18 | |
| 19 | [Fact] |
| 20 | public void ToToolName_chat_toggle_spine_uses_short_alias() |
| 21 | { |
| 22 | var tool = IdeMcpToolNaming.ToToolName(IdeCommands.ChatToggleProductSpineInAgentContext); |
| 23 | Assert.Equal("ide_chat_toggle_spine_ctx", tool); |
| 24 | Assert.True(tool.Length <= IdeMcpToolNaming.MaxToolNameLength); |
| 25 | } |
| 26 | |
| 27 | [Theory] |
| 28 | [InlineData("ide_intercom_reveal_attachment", "intercom.reveal_attachment")] |
| 29 | [InlineData("ide_chat_toggle_spine_ctx", "chat_toggle_product_spine_in_agent_context")] |
| 30 | public void TryToCommandId_roundtrips(string toolName, string commandId) |
| 31 | { |
| 32 | Assert.True(IdeMcpToolNaming.TryToCommandId(toolName, out var resolved)); |
| 33 | Assert.Equal(commandId, resolved); |
| 34 | } |
| 35 | |
| 36 | [Fact] |
| 37 | public void BuildGeneratedProxyTools_skips_dotted_duplicate_when_rich_tool_exists() |
| 38 | { |
| 39 | var existing = new HashSet<string>(StringComparer.Ordinal) { "ide_intercom_reveal_attachment" }; |
| 40 | var proxies = IdeMcpToolCatalog.BuildGeneratedProxyTools(existing).ToList(); |
| 41 | Assert.DoesNotContain(proxies, t => t.Name.Contains('.', StringComparison.Ordinal)); |
| 42 | Assert.DoesNotContain(proxies, t => t.Name == "ide_intercom.reveal_attachment"); |
| 43 | } |
| 44 | } |
| 45 | |