| 1 | using DotNetBuildTest.Core; |
| 2 | using CascadeIDE.Models; |
| 3 | |
| 4 | namespace CascadeIDE.Features.Agent.Environment; |
| 5 | |
| 6 | /// <summary>Build/test host port (ADR 0148 §5.2).</summary> |
| 7 | public interface IBuildTestHostHealth |
| 8 | { |
| 9 | bool IsHealthy { get; } |
| 10 | |
| 11 | void MarkUnhealthy(); |
| 12 | |
| 13 | void MarkHealthy(); |
| 14 | } |
| 15 | |
| 16 | /// <summary>Build/test host port (ADR 0148 §5.2). MLP: in-proc coordinator или out-of-proc worker.</summary> |
| 17 | public interface IBuildTestHost : IBuildTestHostHealth |
| 18 | { |
| 19 | string HostKind { get; } |
| 20 | |
| 21 | IEnvironmentJobBackend JobBackend { get; } |
| 22 | } |
| 23 | |
| 24 | /// <summary>In-process supervised coordinator (MLP stand-in, ADR 0148 §5.2 W2).</summary> |
| 25 | public sealed class InProcessBuildTestHost : IBuildTestHost |
| 26 | { |
| 27 | private volatile bool _healthy = true; |
| 28 | |
| 29 | public InProcessBuildTestHost(BuildTestJobCoordinator coordinator) |
| 30 | { |
| 31 | JobBackend = new InProcessEnvironmentJobBackend(coordinator); |
| 32 | } |
| 33 | |
| 34 | public string HostKind => JobBackend.HostKind; |
| 35 | |
| 36 | public IEnvironmentJobBackend JobBackend { get; } |
| 37 | |
| 38 | public bool IsHealthy => _healthy; |
| 39 | |
| 40 | public void MarkUnhealthy() => _healthy = false; |
| 41 | |
| 42 | public void MarkHealthy() => _healthy = true; |
| 43 | } |
| 44 | |
| 45 | /// <summary>Out-of-process <c>BuildVerifyWorker</c> (ADR 0148 out-of-proc MLP).</summary> |
| 46 | public sealed class WorkerProcessBuildTestHost : IBuildTestHost |
| 47 | { |
| 48 | private volatile bool _healthy = true; |
| 49 | |
| 50 | public WorkerProcessBuildTestHost(IEnvironmentJobBackend jobBackend) |
| 51 | { |
| 52 | JobBackend = jobBackend; |
| 53 | } |
| 54 | |
| 55 | public string HostKind => JobBackend.HostKind; |
| 56 | |
| 57 | public IEnvironmentJobBackend JobBackend { get; } |
| 58 | |
| 59 | public bool IsHealthy => _healthy; |
| 60 | |
| 61 | public void MarkUnhealthy() => _healthy = false; |
| 62 | |
| 63 | public void MarkHealthy() => _healthy = true; |
| 64 | } |
| 65 | |
| 66 | /// <summary>Создаёт <see cref="IBuildTestHost"/> из настроек AEE.</summary> |
| 67 | public static class BuildTestHostFactory |
| 68 | { |
| 69 | public const string InProcessHostKind = "supervised-inproc"; |
| 70 | public const string WorkerProcessHostKind = "supervised-worker-process"; |
| 71 | public const string WorkerDaemonHostKind = "supervised-worker-daemon"; |
| 72 | |
| 73 | public static IBuildTestHost Create(AgentEnvironmentSettings settings, BuildTestJobCoordinator coordinator) |
| 74 | { |
| 75 | var host = settings.BuildVerifyHost?.Trim() ?? InProcessHostKind; |
| 76 | |
| 77 | if (string.Equals(host, InProcessHostKind, StringComparison.OrdinalIgnoreCase)) |
| 78 | return new InProcessBuildTestHost(coordinator); |
| 79 | |
| 80 | BuildVerifyWorkerAssemblyLocator.TryResolve(settings.BuildVerifyWorkerAssemblyPath, out var dll); |
| 81 | |
| 82 | if (string.Equals(host, WorkerDaemonHostKind, StringComparison.OrdinalIgnoreCase)) |
| 83 | return new WorkerProcessBuildTestHost(new DaemonBuildVerifyWorkerBackend(dll)); |
| 84 | |
| 85 | if (string.Equals(host, WorkerProcessHostKind, StringComparison.OrdinalIgnoreCase)) |
| 86 | return new WorkerProcessBuildTestHost(new OutOfProcessBuildVerifyWorkerBackend(dll)); |
| 87 | |
| 88 | return new InProcessBuildTestHost(coordinator); |
| 89 | } |
| 90 | } |
| 91 | |