| 1 | using CascadeIDE.Cockpit.ComputingUnits; |
| 2 | using CascadeIDE.Cockpit.ComputingUnits.IdeHealth; |
| 3 | using Xunit; |
| 4 | |
| 5 | namespace CascadeIDE.Tests; |
| 6 | |
| 7 | public sealed class IdeHealthFormattingUnitTests |
| 8 | { |
| 9 | [Fact] |
| 10 | public void BuildSegment_idle_and_running() |
| 11 | { |
| 12 | var idle = IdeHealthFormattingUnit.Default.BuildSegment(isBuilding: false); |
| 13 | Assert.Equal("Build: idle", idle.LineText); |
| 14 | Assert.Equal("READY", idle.CockpitShort); |
| 15 | Assert.False(idle.IsBuildRunning); |
| 16 | Assert.Equal(IdeHealthStratum.Solution, idle.Stratum); |
| 17 | Assert.Equal(IdeHealthScope.Solution, idle.Scope); |
| 18 | Assert.Null(idle.ProjectPath); |
| 19 | |
| 20 | var run = IdeHealthFormattingUnit.Default.BuildSegment(isBuilding: true); |
| 21 | Assert.Equal("Build: running…", run.LineText); |
| 22 | Assert.Equal("BUILD…", run.CockpitShort); |
| 23 | Assert.True(run.IsBuildRunning); |
| 24 | Assert.Equal(IdeHealthStratum.Solution, run.Stratum); |
| 25 | Assert.Equal(IdeHealthScope.Solution, run.Scope); |
| 26 | Assert.Null(run.ProjectPath); |
| 27 | } |
| 28 | |
| 29 | [Fact] |
| 30 | public void TestsSegment_uses_summary_or_impacted() |
| 31 | { |
| 32 | var withSummary = IdeHealthFormattingUnit.Default.TestsSegment("ok 3 passed", 0); |
| 33 | Assert.Equal("Tests: ok 3 passed", withSummary.LineText); |
| 34 | Assert.Equal("ok 3 passed", withSummary.CockpitShort); |
| 35 | Assert.Equal(IdeHealthStratum.Solution, withSummary.Stratum); |
| 36 | Assert.Equal(IdeHealthScope.Solution, withSummary.Scope); |
| 37 | Assert.Null(withSummary.ProjectPath); |
| 38 | |
| 39 | var impacted = IdeHealthFormattingUnit.Default.TestsSegment(null, 5); |
| 40 | Assert.Equal("Tests: impacted 5", impacted.LineText); |
| 41 | Assert.Equal("imp 5", impacted.CockpitShort); |
| 42 | Assert.Equal(IdeHealthStratum.Solution, impacted.Stratum); |
| 43 | Assert.Equal(IdeHealthScope.Solution, impacted.Scope); |
| 44 | Assert.Null(impacted.ProjectPath); |
| 45 | } |
| 46 | |
| 47 | [Fact] |
| 48 | public void TestsSegment_truncates_long_summary_in_cockpit() |
| 49 | { |
| 50 | var longText = new string('a', 40); |
| 51 | var s = IdeHealthFormattingUnit.Default.TestsSegment(longText, 0); |
| 52 | Assert.Equal(34, s.CockpitShort.Length); |
| 53 | Assert.EndsWith("…", s.CockpitShort); |
| 54 | } |
| 55 | |
| 56 | [Fact] |
| 57 | public void DebugSegment_idle_paused_running() |
| 58 | { |
| 59 | var idle = IdeHealthFormattingUnit.Default.DebugSegment(false, false, 0, 0); |
| 60 | Assert.Equal("Debug: idle", idle.LineText); |
| 61 | Assert.Equal("DBG · —", idle.CockpitShort); |
| 62 | Assert.Equal(IdeHealthStratum.Solution, idle.Stratum); |
| 63 | Assert.Equal(IdeHealthScope.Solution, idle.Scope); |
| 64 | |
| 65 | var paused = IdeHealthFormattingUnit.Default.DebugSegment(true, true, 2, 4); |
| 66 | Assert.Contains("frames 2", paused.LineText); |
| 67 | Assert.Contains("vars 4", paused.LineText); |
| 68 | Assert.Equal("DBG · pause · 2fr", paused.CockpitShort); |
| 69 | Assert.Equal(IdeHealthStratum.Solution, paused.Stratum); |
| 70 | Assert.Equal(IdeHealthScope.Solution, paused.Scope); |
| 71 | |
| 72 | var running = IdeHealthFormattingUnit.Default.DebugSegment(true, false, 0, 0); |
| 73 | Assert.Equal("Debug: running…", running.LineText); |
| 74 | Assert.Equal("DBG · run", running.CockpitShort); |
| 75 | Assert.Equal(IdeHealthStratum.Solution, running.Stratum); |
| 76 | Assert.Equal(IdeHealthScope.Solution, running.Scope); |
| 77 | } |
| 78 | |
| 79 | [Fact] |
| 80 | public void Compose_fills_all_four_segments() |
| 81 | { |
| 82 | var snap = IdeHealthFormattingUnit.Default.Compose( |
| 83 | buildState: BuildStateSnapshot.Empty, |
| 84 | lastTestSummary: "", |
| 85 | impactedTestsBadge: 1, |
| 86 | hasDebugSession: false, |
| 87 | debugExecutionStopped: false, |
| 88 | debugStackFrameCount: 0, |
| 89 | debugVariableCount: 0, |
| 90 | gitLine: "Git: 0 staged", |
| 91 | gitCockpitShort: "main · Δ0"); |
| 92 | |
| 93 | Assert.Equal("Build: idle", snap.Solution.Build.LineText); |
| 94 | Assert.Equal("Tests: impacted 1", snap.Solution.Tests.LineText); |
| 95 | Assert.Equal("Debug: idle", snap.Solution.Debug.LineText); |
| 96 | Assert.Equal("Git: 0 staged", snap.Workspace.Git.LineText); |
| 97 | Assert.Equal("main · Δ0", snap.Workspace.Git.CockpitShort); |
| 98 | Assert.Equal(IdeHealthStratum.Solution, snap.Solution.Build.Stratum); |
| 99 | Assert.Equal(IdeHealthStratum.Solution, snap.Solution.Tests.Stratum); |
| 100 | Assert.Equal(IdeHealthStratum.Solution, snap.Solution.Debug.Stratum); |
| 101 | Assert.Equal(IdeHealthStratum.Workspace, snap.Workspace.Git.Stratum); |
| 102 | Assert.Equal(IdeHealthScope.Solution, snap.Solution.Build.Scope); |
| 103 | Assert.Equal(IdeHealthScope.Solution, snap.Solution.Tests.Scope); |
| 104 | Assert.Equal(IdeHealthScope.Solution, snap.Solution.Debug.Scope); |
| 105 | Assert.Equal(IdeHealthScope.Solution, snap.Workspace.Git.Scope); |
| 106 | Assert.Equal(default(IdeHealthIdeHostInput), snap.IdeHost); |
| 107 | Assert.Null(snap.IdeHost.LspStatusHint); |
| 108 | Assert.Equal(snap, IdeHealthStrataComposer.Compose(snap.Workspace, snap.Solution, snap.IdeHost)); |
| 109 | } |
| 110 | |
| 111 | [Fact] |
| 112 | public void IdeHealthFormattingUnit_Default_implements_ICockpitComputeUnit() |
| 113 | { |
| 114 | ICockpitComputeUnit unit = IdeHealthFormattingUnit.Default; |
| 115 | Assert.NotNull(unit); |
| 116 | } |
| 117 | |
| 118 | [Fact] |
| 119 | public void Composed_snapshot_implements_ICockpitComputeUnitPayload() |
| 120 | { |
| 121 | var snap = IdeHealthFormattingUnit.Default.Compose( |
| 122 | buildState: BuildStateSnapshot.Empty, |
| 123 | lastTestSummary: null, |
| 124 | impactedTestsBadge: 0, |
| 125 | hasDebugSession: false, |
| 126 | debugExecutionStopped: false, |
| 127 | debugStackFrameCount: 0, |
| 128 | debugVariableCount: 0, |
| 129 | gitLine: "g", |
| 130 | gitCockpitShort: "c"); |
| 131 | ICockpitComputeUnitPayload payload = snap; |
| 132 | Assert.NotNull(payload); |
| 133 | } |
| 134 | |
| 135 | [Fact] |
| 136 | public void Project_segments_are_marked_as_project_scope() |
| 137 | { |
| 138 | var build = IdeHealthFormattingUnit.Default.ProjectBuildSegment("src/App/App.csproj", isBuilding: true); |
| 139 | var tests = IdeHealthFormattingUnit.Default.ProjectTestsSegment("src/App/App.csproj", "failed 3", impactedTestsBadge: 0); |
| 140 | var debug = IdeHealthFormattingUnit.Default.ProjectDebugSegment("src/App/App.csproj", "paused"); |
| 141 | |
| 142 | Assert.Equal(IdeHealthScope.Project, build.Scope); |
| 143 | Assert.Equal(IdeHealthScope.Project, tests.Scope); |
| 144 | Assert.Equal(IdeHealthScope.Project, debug.Scope); |
| 145 | Assert.Equal("src/App/App.csproj", build.ProjectPath); |
| 146 | Assert.Equal("src/App/App.csproj", tests.ProjectPath); |
| 147 | Assert.Equal("src/App/App.csproj", debug.ProjectPath); |
| 148 | Assert.Equal(IdeHealthStratum.Solution, build.Stratum); |
| 149 | Assert.Equal(IdeHealthStratum.Solution, tests.Stratum); |
| 150 | Assert.Equal(IdeHealthStratum.Solution, debug.Stratum); |
| 151 | } |
| 152 | |
| 153 | [Fact] |
| 154 | public void Project_tests_segment_falls_back_to_impacted_when_summary_empty() |
| 155 | { |
| 156 | var tests = IdeHealthFormattingUnit.Default.ProjectTestsSegment("src/App/App.csproj", summary: "", impactedTestsBadge: 2); |
| 157 | Assert.Contains("impacted 2", tests.LineText); |
| 158 | Assert.Contains("impacted 2", tests.CockpitShort); |
| 159 | Assert.Equal(IdeHealthScope.Project, tests.Scope); |
| 160 | Assert.Equal("src/App/App.csproj", tests.ProjectPath); |
| 161 | } |
| 162 | } |
| 163 | |