| 1 | using CascadeIDE.Features.Intercom.Admin; |
| 2 | using CascadeIDE.Models; |
| 3 | using Xunit; |
| 4 | |
| 5 | namespace CascadeIDE.Tests; |
| 6 | |
| 7 | public sealed class IntercomServerHostServiceTests |
| 8 | { |
| 9 | [Fact] |
| 10 | public void TryResolveServiceProjectPath_finds_host_project_in_repo() |
| 11 | { |
| 12 | var path = IntercomServerHostService.TryResolveServiceProjectPath(); |
| 13 | Assert.NotNull(path); |
| 14 | Assert.EndsWith("IntercomService.csproj", path, StringComparison.OrdinalIgnoreCase); |
| 15 | Assert.True(File.Exists(path)); |
| 16 | } |
| 17 | |
| 18 | [Fact] |
| 19 | public void Default_transport_paths_and_url_match_bundled_defaults() |
| 20 | { |
| 21 | var transport = new IntercomTransportSettings(); |
| 22 | Assert.Equal("http://127.0.0.1:5080", IntercomTransportSettings.DefaultBaseUrl); |
| 23 | Assert.Equal(IntercomTransportSettings.DefaultBaseUrl, transport.BaseUrl); |
| 24 | Assert.Equal( |
| 25 | "tools/intercom-service/IntercomService.exe", |
| 26 | IntercomTransportSettings.DefaultLocalServerRelativePath); |
| 27 | Assert.Equal(IntercomTransportSettings.DefaultLocalServerRelativePath, transport.LocalServerPath); |
| 28 | } |
| 29 | |
| 30 | [Fact] |
| 31 | public void TryResolveLaunch_uses_default_relative_path_when_config_empty() |
| 32 | { |
| 33 | var plan = IntercomServerHostService.TryResolveLaunch(""); |
| 34 | if (plan is null) |
| 35 | { |
| 36 | // dev tree without publish: dotnet run fallback is acceptable |
| 37 | Assert.NotNull(IntercomServerHostService.TryResolveServiceProjectPath()); |
| 38 | return; |
| 39 | } |
| 40 | |
| 41 | var isPublished = plan.FileName.Contains("IntercomService", StringComparison.OrdinalIgnoreCase); |
| 42 | var isDotnetRun = string.Equals(plan.FileName, "dotnet", StringComparison.OrdinalIgnoreCase); |
| 43 | Assert.True(isPublished || isDotnetRun); |
| 44 | } |
| 45 | |
| 46 | [Fact] |
| 47 | public void EnumerateFallbackExecutableCandidates_includes_artifacts_in_repo() |
| 48 | { |
| 49 | var candidates = IntercomServerHostService.EnumerateFallbackExecutableCandidates().ToList(); |
| 50 | Assert.Contains(candidates, c => c.Contains("artifacts", StringComparison.OrdinalIgnoreCase)); |
| 51 | } |
| 52 | } |
| 53 | |