| 1 | #nullable enable |
| 2 | |
| 3 | using CascadeIDE.Cockpit.DataBus; |
| 4 | using CascadeIDE.Features.SolutionWarmup.Application; |
| 5 | using CascadeIDE.Models; |
| 6 | using Xunit; |
| 7 | |
| 8 | namespace CascadeIDE.Tests; |
| 9 | |
| 10 | public sealed class SolutionWarmupOrchestratorTests |
| 11 | { |
| 12 | [Fact] |
| 13 | public void OnSolutionScopeChanged_CancelsPreviousRun() |
| 14 | { |
| 15 | var bus = new InMemoryDataBus(asynchronousDispatch: false); |
| 16 | var events = new List<SolutionWarmupLifecycle>(); |
| 17 | using var sub = bus.Subscribe<SolutionWarmupStateChanged>(e => events.Add(e.Lifecycle)); |
| 18 | |
| 19 | var gate = new ManualResetEventSlim(false); |
| 20 | var host = new SolutionWarmupHostCallbacks |
| 21 | { |
| 22 | GetWarmupSettings = () => new SolutionWarmupSettings { Enabled = true }, |
| 23 | GetActiveCsFilePath = () => |
| 24 | { |
| 25 | gate.Wait(TimeSpan.FromSeconds(5)); |
| 26 | return null; |
| 27 | }, |
| 28 | }; |
| 29 | |
| 30 | using var orchestrator = new SolutionWarmupOrchestrator(bus, host); |
| 31 | orchestrator.OnSolutionScopeChanged(@"C:\ws1", @"C:\ws1\a.sln"); |
| 32 | orchestrator.OnSolutionScopeChanged(@"C:\ws2", @"C:\ws2\b.sln"); |
| 33 | gate.Set(); |
| 34 | |
| 35 | Assert.Contains(SolutionWarmupLifecycle.Cancelled, events); |
| 36 | Assert.Contains(SolutionWarmupLifecycle.Running, events); |
| 37 | } |
| 38 | |
| 39 | [Fact] |
| 40 | public void WarmIndex_BuildsBracketCache() |
| 41 | { |
| 42 | var dir = Path.Combine(Path.GetTempPath(), "cide-warmup-" + Guid.NewGuid().ToString("N")); |
| 43 | Directory.CreateDirectory(dir); |
| 44 | var file = Path.Combine(dir, "Sample.cs"); |
| 45 | try |
| 46 | { |
| 47 | File.WriteAllText( |
| 48 | file, |
| 49 | """ |
| 50 | public class Sample |
| 51 | { |
| 52 | public void Run() { } |
| 53 | } |
| 54 | """); |
| 55 | |
| 56 | Features.Chat.BracketMemberCompletionProvider.WarmIndex(file, dir); |
| 57 | var matches = Features.Chat.BracketMemberCompletionProvider.GetMatches(file, dir, "R", 10); |
| 58 | Assert.Contains(matches, m => m.Name == "Run"); |
| 59 | } |
| 60 | finally |
| 61 | { |
| 62 | try { Directory.Delete(dir, recursive: true); } catch { /* best-effort */ } |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |