Files
Alphaeus Mote 2e64046e33 feat(agent): report Windows PE as its own OS phase
Detect Windows PE via the HKLM\SYSTEM\CurrentControlSet\Control\MiniNT key
(injectable WindowsPhase probe) and report the OS as "Windows PE" with the
real build version in inventory and at enrollment. Enrollment now sends the
same OS reading inventory does, so the device row no longer flips between
"Microsoft Windows NT ..." and "Windows 11". WMI failures beyond
ManagementException (no WinPE-WMI) are caught with a clear log message.
Hardware identity is unchanged, so a device keeps its client id from WinPE
into the installed OS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 12:25:10 -04:00

68 lines
1.9 KiB
C#

using Agent.Inventory;
using Agent.Platform;
using Xunit;
namespace Agent.Tests;
public class WindowsPhaseTests
{
private static readonly WindowsPhase WinPe = new(() => true);
private static readonly WindowsPhase FullOs = new(() => false);
[Fact]
public void MiniNtKeyMeansWindowsPe()
{
Assert.True(WinPe.IsWinPe);
Assert.False(FullOs.IsWinPe);
Assert.Equal(@"SYSTEM\CurrentControlSet\Control\MiniNT", WindowsPhase.MiniNtKeyPath);
}
[Fact]
public void ProbeRunsOnce()
{
var probes = 0;
var phase = new WindowsPhase(() => ++probes > 0);
_ = phase.IsWinPe;
_ = phase.IsWinPe;
Assert.Equal(1, probes);
}
[Fact]
public void WindowsPeReportsAsWindowsPeWithoutEdition()
{
Assert.Equal(("Windows PE", (string?)null), WinPe.Describe("Windows 11", "Enterprise"));
Assert.Equal(("Windows PE", (string?)null), WinPe.Describe(null, null));
}
[Fact]
public void FullOsReportsUnchanged()
{
Assert.Equal(("Windows 11", (string?)"Enterprise"), FullOs.Describe("Windows 11", "Enterprise"));
}
[Fact]
public void ThisMachineIsNotWindowsPe()
{
// Tests never run in Windows PE; the real probe must read false here.
Assert.False(WindowsPhase.Current.IsWinPe);
}
[Fact]
public void InventoryOsHonorsTheInjectedPhase()
{
var identity = PlatformServices.CreateIdentitySource();
var winPeOs = new InventoryCollector(identity, WinPe).CollectOs();
var fullOs = new InventoryCollector(identity, FullOs).CollectOs();
Assert.Equal("Windows PE", winPeOs.Caption);
Assert.Null(winPeOs.Edition);
Assert.NotEqual("Windows PE", fullOs.Caption);
// The real build version is kept in Windows PE.
Assert.Equal(fullOs.Version, winPeOs.Version);
Assert.Equal(fullOs.Build, winPeOs.Build);
}
}