| 1 | using System.Collections.ObjectModel; |
| 2 | using CascadeIDE.Cockpit; |
| 3 | using CascadeIDE.Cockpit.Channels.WorkspaceHealth; |
| 4 | using CascadeIDE.Cockpit.ComputingUnits.IdeHealth; |
| 5 | using CascadeIDE.Cockpit.Composition.WorkspaceHealth; |
| 6 | using Xunit; |
| 7 | |
| 8 | namespace CascadeIDE.Tests; |
| 9 | |
| 10 | public sealed class WorkspaceHealthSurfaceCompositorTests |
| 11 | { |
| 12 | private static readonly IIdeHealthSurfaceCompositor SurfaceCompositor = new IdeHealthSurfaceCompositor(); |
| 13 | |
| 14 | [Fact] |
| 15 | public void Rebuild_fills_four_segments_in_order_build_tests_debug_git() |
| 16 | { |
| 17 | var col = new ObservableCollection<IdeHealthSegment>(); |
| 18 | SurfaceCompositor.Compose( |
| 19 | col, |
| 20 | payload: IdeHealthInputSnapshot.FromFlat( |
| 21 | new IdeHealthSegmentInput("Build: idle", "READY", IsBuildRunning: false, Stratum: IdeHealthStratum.Solution), |
| 22 | new IdeHealthSegmentInput("Tests: x", "imp 0", Stratum: IdeHealthStratum.Solution), |
| 23 | new IdeHealthSegmentInput("Debug: idle", "DBG · —", Stratum: IdeHealthStratum.Solution), |
| 24 | new IdeHealthSegmentInput("Git: 0 staged", "main · Δ0", Stratum: IdeHealthStratum.Workspace)), |
| 25 | decision: new IdeHealthSurfaceDecision(Enabled: true)); |
| 26 | |
| 27 | Assert.Equal(4, col.Count); |
| 28 | Assert.Equal(IdeHealthSource.Build, col[0].Source); |
| 29 | Assert.Equal("Build: idle", col[0].LineText); |
| 30 | Assert.False(col[0].IsBuildRunning); |
| 31 | |
| 32 | Assert.Equal(IdeHealthSource.Tests, col[1].Source); |
| 33 | Assert.Equal(IdeHealthSource.Debug, col[2].Source); |
| 34 | Assert.Equal(IdeHealthSource.Git, col[3].Source); |
| 35 | Assert.Equal(IdeHealthStratum.Solution, col[0].Stratum); |
| 36 | Assert.Equal(IdeHealthStratum.Solution, col[1].Stratum); |
| 37 | Assert.Equal(IdeHealthStratum.Solution, col[2].Stratum); |
| 38 | Assert.Equal(IdeHealthStratum.Workspace, col[3].Stratum); |
| 39 | Assert.Equal(IdeHealthScope.Solution, col[0].Scope); |
| 40 | Assert.Equal(IdeHealthScope.Solution, col[1].Scope); |
| 41 | Assert.Equal(IdeHealthScope.Solution, col[2].Scope); |
| 42 | Assert.Equal(IdeHealthScope.Solution, col[3].Scope); |
| 43 | Assert.Null(col[2].ProjectPath); |
| 44 | } |
| 45 | |
| 46 | [Fact] |
| 47 | public void Instrument_deck_descriptor_matches_compositor_segment_order() |
| 48 | { |
| 49 | var deck = IdeHealthInstrumentDeck.Default; |
| 50 | Assert.Equal(IdeHealthInstrumentDeck.DeckId, deck.DeckId); |
| 51 | Assert.Equal(IdeHealthInstrumentDeck.SemanticAnchorId, deck.SemanticAnchorId); |
| 52 | Assert.Equal(InstrumentDeckLayoutPattern.Grid, deck.LayoutPattern); |
| 53 | Assert.Equal(4, deck.OrderedInstrumentIds.Count); |
| 54 | Assert.Equal(IdeHealthSegmentIds.Build, deck.OrderedInstrumentIds[0]); |
| 55 | Assert.Equal(IdeHealthSegmentIds.Tests, deck.OrderedInstrumentIds[1]); |
| 56 | Assert.Equal(IdeHealthSegmentIds.Debug, deck.OrderedInstrumentIds[2]); |
| 57 | Assert.Equal(IdeHealthSegmentIds.Git, deck.OrderedInstrumentIds[3]); |
| 58 | Assert.Same(IdeHealthInstrumentDeck.OrderedSegmentIds, deck.OrderedInstrumentIds); |
| 59 | } |
| 60 | |
| 61 | [Fact] |
| 62 | public void Rebuild_sets_IsBuildRunning_on_build_segment() |
| 63 | { |
| 64 | var col = new ObservableCollection<IdeHealthSegment>(); |
| 65 | SurfaceCompositor.Compose( |
| 66 | col, |
| 67 | payload: IdeHealthInputSnapshot.FromFlat( |
| 68 | new IdeHealthSegmentInput("Build: running…", "BUILD…", IsBuildRunning: true, Stratum: IdeHealthStratum.Solution), |
| 69 | new IdeHealthSegmentInput("Tests: a", "a"), |
| 70 | new IdeHealthSegmentInput("Debug: idle", "—", Stratum: IdeHealthStratum.Solution), |
| 71 | new IdeHealthSegmentInput("Git: a", "a", Stratum: IdeHealthStratum.Workspace)), |
| 72 | decision: new IdeHealthSurfaceDecision(Enabled: true)); |
| 73 | |
| 74 | Assert.True(col[0].IsBuildRunning); |
| 75 | Assert.True(col[0].IsBuildSource); |
| 76 | Assert.False(col[1].IsBuildSource); |
| 77 | } |
| 78 | |
| 79 | [Fact] |
| 80 | public void Rebuild_ignores_IsBuildRunning_on_non_build_segments() |
| 81 | { |
| 82 | var col = new ObservableCollection<IdeHealthSegment>(); |
| 83 | SurfaceCompositor.Compose( |
| 84 | col, |
| 85 | payload: IdeHealthInputSnapshot.FromFlat( |
| 86 | new IdeHealthSegmentInput("Build: idle", "READY", IsBuildRunning: false, Stratum: IdeHealthStratum.Solution), |
| 87 | new IdeHealthSegmentInput("Tests: x", "t", IsBuildRunning: true), |
| 88 | new IdeHealthSegmentInput("Debug: idle", "d", Stratum: IdeHealthStratum.Solution), |
| 89 | new IdeHealthSegmentInput("Git: a", "g", Stratum: IdeHealthStratum.Workspace)), |
| 90 | decision: new IdeHealthSurfaceDecision(Enabled: true)); |
| 91 | |
| 92 | Assert.False(col[1].IsBuildRunning); |
| 93 | Assert.False(col[2].IsBuildRunning); |
| 94 | Assert.False(col[3].IsBuildRunning); |
| 95 | } |
| 96 | |
| 97 | [Fact] |
| 98 | public void Rebuild_keeps_project_scope_and_project_path() |
| 99 | { |
| 100 | var col = new ObservableCollection<IdeHealthSegment>(); |
| 101 | SurfaceCompositor.Compose( |
| 102 | col, |
| 103 | payload: IdeHealthInputSnapshot.FromFlat( |
| 104 | IdeHealthFormattingUnit.Default.ProjectBuildSegment("src/App/App.csproj", isBuilding: false), |
| 105 | new IdeHealthSegmentInput("Tests: x", "t"), |
| 106 | new IdeHealthSegmentInput("Debug: idle", "d"), |
| 107 | new IdeHealthSegmentInput("Git: a", "g", Stratum: IdeHealthStratum.Workspace)), |
| 108 | decision: new IdeHealthSurfaceDecision(Enabled: true)); |
| 109 | |
| 110 | Assert.Equal(IdeHealthScope.Project, col[0].Scope); |
| 111 | Assert.Equal("src/App/App.csproj", col[0].ProjectPath); |
| 112 | Assert.Equal(IdeHealthScope.Solution, col[1].Scope); |
| 113 | Assert.Null(col[1].ProjectPath); |
| 114 | } |
| 115 | } |
| 116 | |