| 1 | using CascadeIDE.Cockpit.ComputingUnits; |
| 2 | using CascadeIDE.Cockpit.ComputingUnits.Launch; |
| 3 | using CascadeIDE.Features.Launch.DataAcquisition; |
| 4 | using Xunit; |
| 5 | |
| 6 | namespace CascadeIDE.Tests; |
| 7 | |
| 8 | public sealed class LaunchPreResolvePipelineUnitTests |
| 9 | { |
| 10 | [Fact] |
| 11 | public void Compose_returns_profile_readiness_when_profile_project_exists() |
| 12 | { |
| 13 | var root = Path.Combine(Path.GetTempPath(), "cide-lprp-" + Guid.NewGuid().ToString("n")); |
| 14 | Directory.CreateDirectory(root); |
| 15 | try |
| 16 | { |
| 17 | var sln = Path.Combine(root, "App.sln"); |
| 18 | File.WriteAllText(sln, ""); |
| 19 | |
| 20 | var projDir = Path.Combine(root, "src", "Web"); |
| 21 | Directory.CreateDirectory(projDir); |
| 22 | var csproj = Path.Combine(projDir, "Web.csproj"); |
| 23 | File.WriteAllText(csproj, "<Project />"); |
| 24 | |
| 25 | var launchTomlPath = LaunchProfilesStore.GetStorePath(sln); |
| 26 | Directory.CreateDirectory(Path.GetDirectoryName(launchTomlPath)!); |
| 27 | File.WriteAllText( |
| 28 | launchTomlPath, |
| 29 | """ |
| 30 | version = 1 |
| 31 | active_profile = "Web" |
| 32 | |
| 33 | [profiles.Web] |
| 34 | project = "src/Web/Web.csproj" |
| 35 | configuration = "Debug" |
| 36 | """); |
| 37 | |
| 38 | var snap = LaunchPreResolvePipelineUnit.Default.Compose( |
| 39 | sln, |
| 40 | explicitProfileName: null, |
| 41 | solutionDirectory: root, |
| 42 | startupProjectFullPath: null); |
| 43 | |
| 44 | Assert.NotNull(snap.Profile); |
| 45 | Assert.Equal(LaunchReadinessSource.Profile, snap.Readiness.Source); |
| 46 | Assert.True(snap.Readiness.CanAttemptResolve); |
| 47 | Assert.Null(snap.McpResolveError); |
| 48 | Assert.Equal(CanonicalFilePath.Normalize(csproj), snap.ProfileProjectCsprojFullPath); |
| 49 | } |
| 50 | finally |
| 51 | { |
| 52 | try { Directory.Delete(root, true); } catch { } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | [Fact] |
| 57 | public void Compose_produces_mcp_error_when_explicit_profile_not_found() |
| 58 | { |
| 59 | var root = Path.Combine(Path.GetTempPath(), "cide-lprp-" + Guid.NewGuid().ToString("n")); |
| 60 | Directory.CreateDirectory(root); |
| 61 | try |
| 62 | { |
| 63 | var sln = Path.Combine(root, "App.sln"); |
| 64 | File.WriteAllText(sln, ""); |
| 65 | |
| 66 | var snap = LaunchPreResolvePipelineUnit.Default.Compose( |
| 67 | sln, |
| 68 | explicitProfileName: "Missing", |
| 69 | solutionDirectory: root, |
| 70 | startupProjectFullPath: null); |
| 71 | |
| 72 | Assert.False(snap.Readiness.CanAttemptResolve); |
| 73 | Assert.Equal("# Error: profile_not_found: Missing", snap.McpResolveError); |
| 74 | } |
| 75 | finally |
| 76 | { |
| 77 | try { Directory.Delete(root, true); } catch { } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | [Fact] |
| 82 | public void LaunchPreResolvePipelineUnit_default_and_snapshot_implement_ccu_contracts() |
| 83 | { |
| 84 | ICockpitComputeUnit unit = LaunchPreResolvePipelineUnit.Default; |
| 85 | Assert.NotNull(unit); |
| 86 | |
| 87 | ICockpitComputeUnitPayload payload = new LaunchPreResolvePipelineSnapshot( |
| 88 | Profile: null, |
| 89 | ProfileProjectCsprojFullPath: null, |
| 90 | Readiness: LaunchReadinessSnapshot.NotReady("x"), |
| 91 | McpResolveError: "# Error: x"); |
| 92 | Assert.NotNull(payload); |
| 93 | } |
| 94 | } |
| 95 | |