| 1 | using CascadeIDE.Features.HybridIndex.Application; |
| 2 | using CascadeIDE.Features.IdeMcp.Application; |
| 3 | using Xunit; |
| 4 | |
| 5 | namespace CascadeIDE.Tests; |
| 6 | |
| 7 | public sealed class HybridIndexScopeAndIdeMcpScopeTests |
| 8 | { |
| 9 | [Fact] |
| 10 | public void HybridIndexScopeResolver_workspace_mode_nulls_solution() |
| 11 | { |
| 12 | var (w, s) = HybridIndexScopeResolver.ApplyScopeMode("workspace", @"C:\repo", @"C:\repo\s.sln"); |
| 13 | Assert.Equal(@"C:\repo", w); |
| 14 | Assert.Null(s); |
| 15 | } |
| 16 | |
| 17 | [Fact] |
| 18 | public void HybridIndexScopeResolver_non_workspace_keeps_solution() |
| 19 | { |
| 20 | var (w, s) = HybridIndexScopeResolver.ApplyScopeMode("workspace+solution", @"C:\repo", @"C:\repo\s.sln"); |
| 21 | Assert.Equal(@"C:\repo", w); |
| 22 | Assert.Equal(@"C:\repo\s.sln", s); |
| 23 | } |
| 24 | |
| 25 | [Fact] |
| 26 | public void IdeMcpHybridIndexScope_no_args_uses_solution_and_workspace_resolver() |
| 27 | { |
| 28 | var ok = IdeMcpHybridIndexScope.TryResolveForCodebaseIndexCommand( |
| 29 | argWorkspacePath: null, |
| 30 | argSolutionPath: null, |
| 31 | hybridIndexScopeMode: "workspace", |
| 32 | currentSolutionPath: @"C:\p\a.sln", |
| 33 | static sln => sln == @"C:\p\a.sln" ? @"C:\p" : null, |
| 34 | out var ws, |
| 35 | out var sln, |
| 36 | out var err); |
| 37 | Assert.True(ok); |
| 38 | Assert.Equal(@"C:\p", ws); |
| 39 | Assert.Null(sln); |
| 40 | Assert.Null(err); |
| 41 | } |
| 42 | |
| 43 | [Fact] |
| 44 | public void IdeMcpHybridIndexScope_no_workspace_returns_error_json() |
| 45 | { |
| 46 | var ok = IdeMcpHybridIndexScope.TryResolveForCodebaseIndexCommand( |
| 47 | null, |
| 48 | null, |
| 49 | "workspace", |
| 50 | @"C:\p\a.sln", |
| 51 | static _ => "", |
| 52 | out _, |
| 53 | out _, |
| 54 | out var err); |
| 55 | Assert.False(ok); |
| 56 | Assert.Contains("no_workspace", err!, StringComparison.Ordinal); |
| 57 | } |
| 58 | |
| 59 | [Fact] |
| 60 | public void IdeMcpHybridIndexScope_explicit_workspace_full_paths() |
| 61 | { |
| 62 | var ok = IdeMcpHybridIndexScope.TryResolveForCodebaseIndexCommand( |
| 63 | @"D:\ws", |
| 64 | null, |
| 65 | "workspace+solution", |
| 66 | currentSolutionPath: null, |
| 67 | static _ => null, |
| 68 | out var wsRoot, |
| 69 | out var sln, |
| 70 | out var err); |
| 71 | |
| 72 | Assert.True(ok); |
| 73 | Assert.False(string.IsNullOrWhiteSpace(wsRoot)); |
| 74 | Assert.Null(sln); |
| 75 | Assert.Null(err); |
| 76 | } |
| 77 | } |
| 78 | |