| 1 | using CascadeIDE.Features.Chat; |
| 2 | using CascadeIDE.Services; |
| 3 | using Xunit; |
| 4 | |
| 5 | namespace CascadeIDE.Tests; |
| 6 | |
| 7 | public sealed class ChatSlashCommandRunnerTests |
| 8 | { |
| 9 | [Fact] |
| 10 | public async Task TryRun_Overview_SucceedsWithoutOkText() |
| 11 | { |
| 12 | var runner = new ChatSlashCommandRunner((_, _, _) => Task.FromResult("{\"ok\":true}")); |
| 13 | var result = await runner.TryRunAsync("/intercom overview"); |
| 14 | |
| 15 | Assert.True(result.Handled); |
| 16 | Assert.True(result.Success); |
| 17 | Assert.Equal("/intercom overview", result.SlashPath); |
| 18 | Assert.Null(result.DetailText); |
| 19 | } |
| 20 | |
| 21 | [Fact] |
| 22 | public async Task TryRun_Unknown_FailsWithDetail() |
| 23 | { |
| 24 | var runner = new ChatSlashCommandRunner((_, _, _) => Task.FromResult("{}")); |
| 25 | var result = await runner.TryRunAsync("/not-a-real-command-xyz"); |
| 26 | |
| 27 | Assert.True(result.Handled); |
| 28 | Assert.False(result.Success); |
| 29 | Assert.NotNull(result.DetailText); |
| 30 | } |
| 31 | |
| 32 | [Fact] |
| 33 | public async Task TryRun_FileOpen_normalizes_path() |
| 34 | { |
| 35 | string? capturedPath = null; |
| 36 | var runner = new ChatSlashCommandRunner( |
| 37 | (id, args, _) => |
| 38 | { |
| 39 | if (id == IdeCommands.OpenFile && args is not null && args.TryGetValue("path", out var p)) |
| 40 | capturedPath = p.GetString(); |
| 41 | return Task.FromResult(""); |
| 42 | }, |
| 43 | getWorkspaceRoot: () => @"D:\ws"); |
| 44 | |
| 45 | var tempFile = Path.Combine(Path.GetTempPath(), "cide-slash-open-" + Guid.NewGuid().ToString("N") + ".txt"); |
| 46 | await File.WriteAllTextAsync(tempFile, "x"); |
| 47 | try |
| 48 | { |
| 49 | var result = await runner.TryRunAsync($"/file open \"{tempFile}\""); |
| 50 | Assert.True(result.Success); |
| 51 | Assert.Equal(Path.GetFullPath(tempFile), Path.GetFullPath(capturedPath!)); |
| 52 | } |
| 53 | finally |
| 54 | { |
| 55 | File.Delete(tempFile); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | [Fact] |
| 60 | public async Task TryRun_BuildRun_PreservesArgsTail() |
| 61 | { |
| 62 | var runner = new ChatSlashCommandRunner((id, _, _) => |
| 63 | { |
| 64 | Assert.Equal(IdeCommands.Build, id); |
| 65 | return Task.FromResult(""); |
| 66 | }); |
| 67 | |
| 68 | var result = await runner.TryRunAsync("/build run"); |
| 69 | Assert.True(result.Success); |
| 70 | Assert.Equal("/build run", result.SlashPath); |
| 71 | } |
| 72 | } |
| 73 | |