| 1 | using CascadeIDE.Cockpit.Composition.EnvironmentReadiness; |
| 2 | using CascadeIDE.Cockpit.DataBus; |
| 3 | using CascadeIDE.Models; |
| 4 | using CascadeIDE.Services; |
| 5 | using CascadeIDE.Services.Lsp; |
| 6 | using Xunit; |
| 7 | using TestContext = Xunit.TestContext; |
| 8 | |
| 9 | namespace CascadeIDE.Tests; |
| 10 | |
| 11 | public sealed class EnvironmentReadinessSnapshotBuilderTests |
| 12 | { |
| 13 | [Fact] |
| 14 | public void BuildLspRows_ParseOnly_NoHost_IsInfo() |
| 15 | { |
| 16 | var settings = new CascadeIdeSettings |
| 17 | { |
| 18 | Languages = new LanguagesSettings |
| 19 | { |
| 20 | CSharp = new CSharpLanguageServerSettings { Mode = CSharpLspProviderIds.ParseOnly } |
| 21 | } |
| 22 | }; |
| 23 | var rows = EnvironmentReadinessSnapshotBuilder.BuildLspRows( |
| 24 | settings, |
| 25 | solutionPath: null, |
| 26 | lsp: default); |
| 27 | |
| 28 | Assert.Contains(rows, r => r.Title == "C# LSP" && r.Level == AnnunciatorLampLevel.Advisory); |
| 29 | } |
| 30 | |
| 31 | [Fact] |
| 32 | public void BuildLspRows_MarkdownOff_IsInfo() |
| 33 | { |
| 34 | var settings = new CascadeIdeSettings |
| 35 | { |
| 36 | Languages = new LanguagesSettings |
| 37 | { |
| 38 | CSharp = new CSharpLanguageServerSettings { Mode = CSharpLspProviderIds.ParseOnly }, |
| 39 | Markdown = new MarkdownLanguageServerSettings { Mode = MarkdownLspProviderIds.Off } |
| 40 | } |
| 41 | }; |
| 42 | var rows = EnvironmentReadinessSnapshotBuilder.BuildLspRows(settings, null, default); |
| 43 | |
| 44 | Assert.Contains(rows, r => r.Title == "Markdown LSP" && r.Level == AnnunciatorLampLevel.Advisory); |
| 45 | } |
| 46 | |
| 47 | [Fact] |
| 48 | public void BuildLspRows_CSharpProcess_NoSolution_IsWarning() |
| 49 | { |
| 50 | var settings = new CascadeIdeSettings |
| 51 | { |
| 52 | Languages = new LanguagesSettings |
| 53 | { |
| 54 | CSharp = new CSharpLanguageServerSettings { Mode = CSharpLspProviderIds.CSharpLs } |
| 55 | } |
| 56 | }; |
| 57 | var rows = EnvironmentReadinessSnapshotBuilder.BuildLspRows(settings, null, default); |
| 58 | |
| 59 | var row = Assert.Single(rows, r => r.Title == "C# LSP"); |
| 60 | Assert.Equal(AnnunciatorLampLevel.Caution, row.Level); |
| 61 | } |
| 62 | |
| 63 | [Fact] |
| 64 | public async Task BuildAllRowsAsync_cell_order_matches_environment_readiness_instrument_deck() |
| 65 | { |
| 66 | var settings = new CascadeIdeSettings |
| 67 | { |
| 68 | Languages = new LanguagesSettings |
| 69 | { |
| 70 | CSharp = new CSharpLanguageServerSettings { Mode = CSharpLspProviderIds.ParseOnly }, |
| 71 | Markdown = new MarkdownLanguageServerSettings { Mode = MarkdownLspProviderIds.Off } |
| 72 | } |
| 73 | }; |
| 74 | |
| 75 | var rows = await EnvironmentReadinessSnapshotBuilder.BuildAllRowsAsync( |
| 76 | settings, null, default, cancellationToken: TestContext.Current.CancellationToken); |
| 77 | |
| 78 | Assert.Equal(EnvironmentReadinessInstrumentDeck.OrderedCellIds.Count, rows.Count); |
| 79 | for (var i = 0; i < rows.Count; i++) |
| 80 | Assert.Equal(EnvironmentReadinessInstrumentDeck.OrderedCellIds[i], rows[i].Id); |
| 81 | |
| 82 | Assert.Equal(EnvironmentReadinessCellIds.DevToolsSection, rows[0].Id); |
| 83 | Assert.Equal("DEV", rows[0].LampShortLabel); |
| 84 | Assert.Equal(AnnunciatorLampLevel.Caution, rows[0].Level); |
| 85 | |
| 86 | Assert.Equal(EnvironmentReadinessCellIds.Agent, rows[1].Id); |
| 87 | Assert.Equal("Off", rows[1].LampShortLabel); |
| 88 | Assert.Equal(AnnunciatorLampLevel.Caution, rows[1].Level); |
| 89 | |
| 90 | Assert.Equal(EnvironmentReadinessCellIds.CSharpLsp, rows[2].Id); |
| 91 | Assert.Equal("C#", rows[2].LampShortLabel); |
| 92 | Assert.Equal(AnnunciatorLampLevel.Advisory, rows[2].Level); |
| 93 | |
| 94 | Assert.Equal(EnvironmentReadinessCellIds.EnvSection, rows[5].Id); |
| 95 | Assert.Equal("ENV", rows[5].LampShortLabel); |
| 96 | } |
| 97 | |
| 98 | [Fact] |
| 99 | public void AggregateEnvBlockLevel_only_ok_and_advisory_yields_ok_for_section_lamp() |
| 100 | { |
| 101 | Assert.Equal( |
| 102 | AnnunciatorLampLevel.Ok, |
| 103 | EnvironmentReadinessSnapshotBuilder.AggregateEnvBlockLevel( |
| 104 | AnnunciatorLampLevel.Ok, |
| 105 | AnnunciatorLampLevel.Advisory, |
| 106 | AnnunciatorLampLevel.Advisory)); |
| 107 | } |
| 108 | |
| 109 | [Fact] |
| 110 | public void AggregateEnvBlockLevel_critical_dominates() |
| 111 | { |
| 112 | Assert.Equal( |
| 113 | AnnunciatorLampLevel.Critical, |
| 114 | EnvironmentReadinessSnapshotBuilder.AggregateEnvBlockLevel( |
| 115 | AnnunciatorLampLevel.Advisory, |
| 116 | AnnunciatorLampLevel.Critical, |
| 117 | AnnunciatorLampLevel.Ok)); |
| 118 | } |
| 119 | |
| 120 | [Fact] |
| 121 | public void BuildEnvSectionRow_matches_aggregate_and_labels() |
| 122 | { |
| 123 | var rows = new[] |
| 124 | { |
| 125 | new AnnunciatorLampItem(EnvironmentReadinessCellIds.AgentNotesFile, "a", "", AnnunciatorLampLevel.Ok, "Notes"), |
| 126 | new AnnunciatorLampItem(EnvironmentReadinessCellIds.AgentNotesCanonPath, "b", "", AnnunciatorLampLevel.Advisory, "KB"), |
| 127 | new AnnunciatorLampItem(EnvironmentReadinessCellIds.NetcoreDbgPath, "c", "", AnnunciatorLampLevel.Advisory, "Dbg"), |
| 128 | }; |
| 129 | var section = EnvironmentReadinessSnapshotBuilder.BuildEnvSectionRow(rows); |
| 130 | Assert.Equal(EnvironmentReadinessCellIds.EnvSection, section.Id); |
| 131 | Assert.Equal(AnnunciatorLampLevel.Ok, section.Level); |
| 132 | Assert.Equal("Переменные окружения", section.Title); |
| 133 | Assert.Equal("ENV", section.LampShortLabel); |
| 134 | Assert.Empty(section.Detail); |
| 135 | } |
| 136 | |
| 137 | [Fact] |
| 138 | public void BuildDevToolsSectionRow_mcp_advisory_yields_ok_lamp() |
| 139 | { |
| 140 | var agent = new AnnunciatorLampItem( |
| 141 | EnvironmentReadinessCellIds.Agent, |
| 142 | "Агент (MCP)", |
| 143 | "", |
| 144 | AnnunciatorLampLevel.Advisory, |
| 145 | "MCP"); |
| 146 | var section = EnvironmentReadinessSnapshotBuilder.BuildDevToolsSectionRow([agent]); |
| 147 | Assert.Equal(EnvironmentReadinessCellIds.DevToolsSection, section.Id); |
| 148 | Assert.Equal(AnnunciatorLampLevel.Ok, section.Level); |
| 149 | Assert.Equal("Dev Tools", section.Title); |
| 150 | Assert.Equal("DEV", section.LampShortLabel); |
| 151 | Assert.Empty(section.Detail); |
| 152 | } |
| 153 | |
| 154 | [Fact] |
| 155 | public void BuildDevToolsSectionRow_no_bridge_caution_preserved() |
| 156 | { |
| 157 | var agent = new AnnunciatorLampItem( |
| 158 | EnvironmentReadinessCellIds.Agent, |
| 159 | "Агент (нет моста)", |
| 160 | "", |
| 161 | AnnunciatorLampLevel.Caution, |
| 162 | "Off"); |
| 163 | var section = EnvironmentReadinessSnapshotBuilder.BuildDevToolsSectionRow([agent]); |
| 164 | Assert.Equal(AnnunciatorLampLevel.Caution, section.Level); |
| 165 | Assert.NotEmpty(section.Detail); |
| 166 | } |
| 167 | |
| 168 | [Fact] |
| 169 | public async Task BuildAllRowsAsync_agent_row_mcp_stdio_is_advisory() |
| 170 | { |
| 171 | var settings = new CascadeIdeSettings |
| 172 | { |
| 173 | Languages = new LanguagesSettings |
| 174 | { |
| 175 | CSharp = new CSharpLanguageServerSettings { Mode = CSharpLspProviderIds.ParseOnly }, |
| 176 | Markdown = new MarkdownLanguageServerSettings { Mode = MarkdownLspProviderIds.Off } |
| 177 | } |
| 178 | }; |
| 179 | |
| 180 | var rows = await EnvironmentReadinessSnapshotBuilder.BuildAllRowsAsync( |
| 181 | settings, null, default, |
| 182 | isMcpStdioHost: true, activeAiProvider: "Ollama", |
| 183 | cancellationToken: TestContext.Current.CancellationToken); |
| 184 | |
| 185 | Assert.Equal("DEV", rows[0].LampShortLabel); |
| 186 | Assert.Equal(AnnunciatorLampLevel.Ok, rows[0].Level); |
| 187 | Assert.Equal("MCP", rows[1].LampShortLabel); |
| 188 | Assert.Equal(AnnunciatorLampLevel.Advisory, rows[1].Level); |
| 189 | } |
| 190 | |
| 191 | [Fact] |
| 192 | public async Task BuildAllRowsAsync_agent_row_cursor_acp_is_advisory() |
| 193 | { |
| 194 | var settings = new CascadeIdeSettings |
| 195 | { |
| 196 | Languages = new LanguagesSettings |
| 197 | { |
| 198 | CSharp = new CSharpLanguageServerSettings { Mode = CSharpLspProviderIds.ParseOnly }, |
| 199 | Markdown = new MarkdownLanguageServerSettings { Mode = MarkdownLspProviderIds.Off } |
| 200 | } |
| 201 | }; |
| 202 | |
| 203 | var rows = await EnvironmentReadinessSnapshotBuilder.BuildAllRowsAsync( |
| 204 | settings, null, default, |
| 205 | isMcpStdioHost: false, activeAiProvider: "CursorACP", |
| 206 | cancellationToken: TestContext.Current.CancellationToken); |
| 207 | |
| 208 | Assert.Equal("DEV", rows[0].LampShortLabel); |
| 209 | Assert.Equal(AnnunciatorLampLevel.Ok, rows[0].Level); |
| 210 | Assert.Equal("ACP", rows[1].LampShortLabel); |
| 211 | Assert.Equal(AnnunciatorLampLevel.Advisory, rows[1].Level); |
| 212 | } |
| 213 | } |
| 214 | |