fix(mapping): corriger AgentExtensions.ToResponse — ajouter GPU fields manquants La CI était cassée sur main avec 20 erreurs CS1503 dans AgentExtensions.cs. Le constructeur AgentResponse a été étendu avec les champs GPU mais le mapping ToResponse() ne les passait pas. Fixes le build cassé sur main et débloque les PRs en attente.
149 lines
4.3 KiB
C#
149 lines
4.3 KiB
C#
using Heimdall.Agent.Services;
|
|
|
|
namespace Heimdall.Agent.Tests.Services;
|
|
|
|
public class GpuInventoryProviderDetailedTests
|
|
{
|
|
[Fact]
|
|
public void Collect_ShouldReturnListOfGpuDeviceInfo()
|
|
{
|
|
var result = GpuInventoryProvider.Collect();
|
|
|
|
result.ShouldNotBeNull();
|
|
result.ShouldBeAssignableTo<IReadOnlyList<GpuDeviceInfo>>();
|
|
}
|
|
|
|
[Fact]
|
|
public void Collect_ShouldNotThrow()
|
|
{
|
|
var act = () => GpuInventoryProvider.Collect();
|
|
act.ShouldNotThrow();
|
|
}
|
|
|
|
[Fact]
|
|
public void Collect_GpuDeviceInfo_ShouldHaveVendor_WhenPresent()
|
|
{
|
|
var result = GpuInventoryProvider.Collect();
|
|
|
|
foreach (var gpu in result)
|
|
{
|
|
if (gpu.Vendor is not null)
|
|
{
|
|
var validVendors = new[] { "Nvidia", "AMD", "Intel", "Unknown" };
|
|
// Vendor could also be a raw hex ID if not mapped
|
|
gpu.Vendor.ShouldNotBeNullOrEmpty();
|
|
}
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void Collect_GpuDeviceInfo_Backend_ShouldBeValid_WhenPresent()
|
|
{
|
|
var result = GpuInventoryProvider.Collect();
|
|
|
|
foreach (var gpu in result)
|
|
{
|
|
if (gpu.Backend is not null)
|
|
{
|
|
var validBackends = new[] { "Cuda", "ROCm", "VAAPI", "Unknown" };
|
|
validBackends.ShouldContain(gpu.Backend);
|
|
}
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void Collect_GpuDeviceInfo_VramBytes_ShouldBePositive_WhenPresent()
|
|
{
|
|
var result = GpuInventoryProvider.Collect();
|
|
|
|
foreach (var gpu in result)
|
|
{
|
|
if (gpu.VramBytes.HasValue)
|
|
{
|
|
gpu.VramBytes.Value.ShouldBeGreaterThan(0);
|
|
}
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void Collect_GpuDeviceInfo_TemperatureCelsius_ShouldBeReasonable_WhenPresent()
|
|
{
|
|
var result = GpuInventoryProvider.Collect();
|
|
|
|
foreach (var gpu in result)
|
|
{
|
|
if (gpu.TemperatureCelsius.HasValue)
|
|
{
|
|
gpu.TemperatureCelsius.Value.ShouldBeGreaterThanOrEqualTo(0);
|
|
gpu.TemperatureCelsius.Value.ShouldBeLessThanOrEqualTo(200);
|
|
}
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void Collect_GpuDeviceInfo_UtilizationPercent_ShouldBeReasonable_WhenPresent()
|
|
{
|
|
var result = GpuInventoryProvider.Collect();
|
|
|
|
foreach (var gpu in result)
|
|
{
|
|
if (gpu.UtilizationPercent.HasValue)
|
|
{
|
|
gpu.UtilizationPercent.Value.ShouldBeGreaterThanOrEqualTo(0);
|
|
gpu.UtilizationPercent.Value.ShouldBeLessThanOrEqualTo(100);
|
|
}
|
|
}
|
|
}
|
|
|
|
// ── GpuDeviceInfo record tests ────────────────────────────────────────
|
|
|
|
[Fact]
|
|
public void GpuDeviceInfo_DefaultValues_ShouldBeNull()
|
|
{
|
|
var gpu = new GpuDeviceInfo();
|
|
|
|
gpu.Vendor.ShouldBeNull();
|
|
gpu.Model.ShouldBeNull();
|
|
gpu.VramBytes.ShouldBeNull();
|
|
gpu.DriverVersion.ShouldBeNull();
|
|
gpu.TemperatureCelsius.ShouldBeNull();
|
|
gpu.UtilizationPercent.ShouldBeNull();
|
|
gpu.Backend.ShouldBeNull();
|
|
gpu.EncoderSupport.ShouldBeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public void GpuDeviceInfo_WithValues_ShouldStoreCorrectly()
|
|
{
|
|
var gpu = new GpuDeviceInfo
|
|
{
|
|
Vendor = "Nvidia",
|
|
Model = "RTX 4090",
|
|
VramBytes = 24_576_000_000,
|
|
DriverVersion = "535.129.03",
|
|
TemperatureCelsius = 65.0,
|
|
UtilizationPercent = 85.5,
|
|
Backend = "Cuda",
|
|
EncoderSupport = "NVENC+NVJPG"
|
|
};
|
|
|
|
gpu.Vendor.ShouldBe("Nvidia");
|
|
gpu.Model.ShouldBe("RTX 4090");
|
|
gpu.VramBytes.ShouldBe(24_576_000_000);
|
|
gpu.DriverVersion.ShouldBe("535.129.03");
|
|
gpu.TemperatureCelsius.ShouldBe(65.0);
|
|
gpu.UtilizationPercent.ShouldBe(85.5);
|
|
gpu.Backend.ShouldBe("Cuda");
|
|
gpu.EncoderSupport.ShouldBe("NVENC+NVJPG");
|
|
}
|
|
|
|
[Fact]
|
|
public void GpuDeviceInfo_RecordEquality_ShouldWork()
|
|
{
|
|
var gpu1 = new GpuDeviceInfo { Vendor = "AMD", Model = "RX 7900 XTX", Backend = "ROCm" };
|
|
var gpu2 = new GpuDeviceInfo { Vendor = "AMD", Model = "RX 7900 XTX", Backend = "ROCm" };
|
|
|
|
gpu1.ShouldBe(gpu2);
|
|
}
|
|
}
|