refactor(launcher): add DI, IUpdateEngine facade, and architecture tests

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
lincube
2026-05-28 11:13:14 +08:00
parent a26b6faace
commit 1ef47c780b
31 changed files with 167 additions and 1511 deletions

View File

@@ -1,5 +1,4 @@
using LanMountainDesktop.Launcher;
using LanMountainDesktop.Launcher.Services;
using Xunit;
namespace LanMountainDesktop.Tests;

View File

@@ -1,4 +1,3 @@
using LanMountainDesktop.Launcher.Services;
using Xunit;
namespace LanMountainDesktop.Tests;
@@ -192,7 +191,7 @@ public sealed class DotNetRuntimeProbeTests : IDisposable
SearchedPaths = [hostPath]
};
var result = LauncherFlowCoordinator.ValidateDotNetRuntimePrerequisite(
var result = HostLaunchService.ValidateDotNetRuntimePrerequisite(
plan,
resolution,
CreateOptions(DotNetRuntimeArchitecture.X64));

View File

@@ -1,4 +1,3 @@
using LanMountainDesktop.Launcher.Services;
using LanMountainDesktop.Shared.Contracts.Launcher;
using Xunit;

View File

@@ -1,5 +1,4 @@
using LanMountainDesktop.Launcher;
using LanMountainDesktop.Launcher.Services;
using LanMountainDesktop.Shared.Contracts.Launcher;
using Xunit;

View File

@@ -0,0 +1,41 @@
using System.Reflection;
using Xunit;
namespace LanMountainDesktop.Tests;
public sealed class LauncherArchitectureTests
{
private static readonly string LauncherAssemblyName = "LanMountainDesktop.Launcher";
[Fact]
public void Deployment_Update_Startup_Infrastructure_DoNotReferenceAvalonia()
{
var forbidden = new[] { "Deployment", "Update", "Startup", "Infrastructure" };
foreach (var nsSuffix in forbidden)
{
var types = GetLauncherTypes($"LanMountainDesktop.Launcher.{nsSuffix}");
var assembly = types.First().Assembly;
Assert.DoesNotContain(
assembly.GetReferencedAssemblies(),
a => string.Equals(a.Name, "Avalonia", StringComparison.OrdinalIgnoreCase));
}
}
[Fact]
public void LauncherFlowCoordinator_TypeDoesNotExist()
{
var coordinator = typeof(LanMountainDesktop.Launcher.Shell.LauncherOrchestrator).Assembly
.GetType("LanMountainDesktop.Launcher.Services.LauncherFlowCoordinator", throwOnError: false);
Assert.Null(coordinator);
}
private static IEnumerable<Type> GetLauncherTypes(string namespacePrefix)
{
var assembly = AppDomain.CurrentDomain.GetAssemblies()
.FirstOrDefault(a => string.Equals(a.GetName().Name, LauncherAssemblyName, StringComparison.OrdinalIgnoreCase))
?? throw new InvalidOperationException("Launcher assembly not loaded.");
return assembly.GetTypes()
.Where(t => t.Namespace is not null && t.Namespace.StartsWith(namespacePrefix, StringComparison.Ordinal));
}
}

View File

@@ -1,6 +1,5 @@
using System.Text.Json.Nodes;
using LanMountainDesktop.Launcher.Models;
using LanMountainDesktop.Launcher.Services;
using LanMountainDesktop.Shared.Contracts.Launcher;
using Xunit;

View File

@@ -1,4 +1,3 @@
using LanMountainDesktop.Launcher.Services;
using Xunit;
namespace LanMountainDesktop.Tests;

View File

@@ -1,7 +1,6 @@
using System.Text.Json;
using LanMountainDesktop.Launcher;
using LanMountainDesktop.Launcher.Models;
using LanMountainDesktop.Launcher.Services;
using Xunit;
namespace LanMountainDesktop.Tests;

View File

@@ -5,7 +5,6 @@ using System.Text.Json;
using LanMountainDesktop;
using LanMountainDesktop.Launcher;
using LanMountainDesktop.Launcher.Models;
using LanMountainDesktop.Launcher.Services;
using LanMountainDesktop.Services;
using LanMountainDesktop.Services.Update;
using LanMountainDesktop.Shared.Contracts.Update;
@@ -25,7 +24,7 @@ public sealed class UpdateEngineRollbackRegressionTests : IDisposable
_directory.StagePlondsUpdate("1.0.0", "1.1.0", newState, Sha256Hex(newState));
var service = new UpdateEngineService(new DeploymentLocator(_directory.AppRoot));
var service = new UpdateEngineFacade(new DeploymentLocator(_directory.AppRoot));
var result = await service.ApplyPendingUpdateAsync();
Assert.True(result.Success, result.ErrorMessage);
@@ -49,7 +48,7 @@ public sealed class UpdateEngineRollbackRegressionTests : IDisposable
_directory.StagePlondsUpdate("1.0.0", "1.1.0", newState, new string('0', 64));
var service = new UpdateEngineService(new DeploymentLocator(_directory.AppRoot));
var service = new UpdateEngineFacade(new DeploymentLocator(_directory.AppRoot));
var result = await service.ApplyPendingUpdateAsync();
Assert.False(result.Success);
@@ -71,7 +70,7 @@ public sealed class UpdateEngineRollbackRegressionTests : IDisposable
targetVersion: "1.1.0",
targetDirectory: Path.Combine(_directory.AppRoot, "app-1.1.0-0"));
var service = new UpdateEngineService(new DeploymentLocator(_directory.AppRoot));
var service = new UpdateEngineFacade(new DeploymentLocator(_directory.AppRoot));
var result = service.RollbackLatest();
Assert.False(result.Success);
@@ -87,7 +86,7 @@ public sealed class UpdateEngineRollbackRegressionTests : IDisposable
_directory.StagePlondsUpdate("1.0.0", "1.1.0", newState, Sha256Hex(newState));
_directory.WriteStaleInstallCheckpoint("9.9.9", "1.1.0");
var service = new UpdateEngineService(new DeploymentLocator(_directory.AppRoot));
var service = new UpdateEngineFacade(new DeploymentLocator(_directory.AppRoot));
var result = await service.ApplyPendingUpdateAsync();
Assert.False(result.Success);
@@ -101,7 +100,7 @@ public sealed class UpdateEngineRollbackRegressionTests : IDisposable
_directory.StageLegacyUpdate("1.0.0", "1.1.0", "new-state");
_directory.WriteStaleInstallCheckpoint("9.9.9", "1.1.0");
var service = new UpdateEngineService(new DeploymentLocator(_directory.AppRoot));
var service = new UpdateEngineFacade(new DeploymentLocator(_directory.AppRoot));
var result = await service.ApplyPendingUpdateAsync();
Assert.False(result.Success);
@@ -116,7 +115,7 @@ public sealed class UpdateEngineRollbackRegressionTests : IDisposable
_directory.StagePlondsUpdate("1.0.0", "1.1.0", newState, Sha256Hex(newState));
_directory.WriteValidPlondsResumeCheckpoint("1.0.0", "1.1.0");
var service = new UpdateEngineService(new DeploymentLocator(_directory.AppRoot));
var service = new UpdateEngineFacade(new DeploymentLocator(_directory.AppRoot));
var result = await service.ApplyPendingUpdateAsync();
Assert.True(result.Success, result.ErrorMessage);
@@ -135,7 +134,7 @@ public sealed class UpdateEngineRollbackRegressionTests : IDisposable
_directory.StageLegacyUpdate("1.0.0", "1.1.0", "new-state");
_directory.WriteValidLegacyResumeCheckpoint("1.0.0", "1.1.0");
var service = new UpdateEngineService(new DeploymentLocator(_directory.AppRoot));
var service = new UpdateEngineFacade(new DeploymentLocator(_directory.AppRoot));
var result = await service.ApplyPendingUpdateAsync();
Assert.True(result.Success, result.ErrorMessage);