Adds 40 rarely-used and Windows-version-specific commands across 9 existing categories: 5 Windows 10-only (maxOsBuild 19045 — the first use of maxOsBuild gating in the catalog), 11 Windows 11-only (minOsBuild 22000+, incl. 3 for 24H2/26100), and 24 rare cross-version diagnostics/info/security/dev commands. Each command is wired with Cmd_<id>_Title/_Desc keys in all five resource cultures (en, vi, ja, zh-Hans, es); reg-based HKCU tweaks include affectedRegistryValues and confirmBeforeRun for Caution entries. Also fixes TPM Status (info.tpm) and Defender Exclusions (sec.defender.exclusions): both now require admin so their queries (Get-CimInstance on MicrosoftTpm / Get-MpPreference) return data instead of appearing blank — they run in-process without elevation today. Adds CommandDefinitionTests coverage for maxOsBuild gating (Win10-only commands hidden on Windows 11, visible on Windows 10). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
99 lines
3.9 KiB
C#
99 lines
3.9 KiB
C#
using CommandForge.Domain;
|
|
using CommandForge.Infrastructure.Catalog;
|
|
|
|
namespace CommandForge.Tests;
|
|
|
|
/// <summary>Verifies the OS-build applicability predicate and the embedded catalog's version gating.</summary>
|
|
public sealed class CommandDefinitionTests
|
|
{
|
|
private static CommandDefinition Command(int? min = null, int? max = null) => new()
|
|
{
|
|
Id = "t",
|
|
CategoryId = "c",
|
|
TitleKey = "T",
|
|
DescriptionKey = "D",
|
|
Executable = "cmd",
|
|
MinOsBuild = min,
|
|
MaxOsBuild = max,
|
|
};
|
|
|
|
[Theory]
|
|
[InlineData(19045, true)] // no bounds -> always applies
|
|
[InlineData(22631, true)]
|
|
public void AppliesToOsBuild_NoBounds_AlwaysTrue(int build, bool expected)
|
|
=> Assert.Equal(expected, Command().AppliesToOsBuild(build));
|
|
|
|
[Theory]
|
|
[InlineData(19045, false)] // Windows 10 excluded by min 22000
|
|
[InlineData(21999, false)]
|
|
[InlineData(22000, true)] // inclusive lower bound
|
|
[InlineData(26100, true)]
|
|
public void AppliesToOsBuild_MinOnly_GatesBelow(int build, bool expected)
|
|
=> Assert.Equal(expected, Command(min: 22000).AppliesToOsBuild(build));
|
|
|
|
[Theory]
|
|
[InlineData(19045, true)] // inclusive upper bound (Windows 10 only)
|
|
[InlineData(22000, false)] // Windows 11 excluded by max 19045
|
|
public void AppliesToOsBuild_MaxOnly_GatesAbove(int build, bool expected)
|
|
=> Assert.Equal(expected, Command(max: 19045).AppliesToOsBuild(build));
|
|
|
|
[Theory]
|
|
[InlineData(21999, false)]
|
|
[InlineData(22000, true)]
|
|
[InlineData(22621, true)]
|
|
[InlineData(22622, false)]
|
|
public void AppliesToOsBuild_Range_GatesBothEnds(int build, bool expected)
|
|
=> Assert.Equal(expected, Command(min: 22000, max: 22621).AppliesToOsBuild(build));
|
|
|
|
[Theory]
|
|
[InlineData("tweak.win11.classicmenu", 22000)]
|
|
[InlineData("tweak.win11.modernmenu", 22000)]
|
|
[InlineData("tweak.win11.taskbarleft", 22000)]
|
|
[InlineData("tweak.win11.taskbarcenter", 22000)]
|
|
[InlineData("tweak.clockseconds.on", 22621)]
|
|
[InlineData("tweak.clockseconds.off", 22621)]
|
|
[InlineData("tweak.win11.widgets.hide", 22000)]
|
|
[InlineData("tweak.win11.endtask.on", 22631)]
|
|
public void EmbeddedCatalog_Win11Commands_AreGated(string id, int expectedMinBuild)
|
|
{
|
|
var catalog = CatalogLoader.LoadEmbedded();
|
|
var command = catalog.Commands.Single(c => c.Id == id);
|
|
Assert.Equal(expectedMinBuild, command.MinOsBuild);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("tweak.win10.meetnow.hide", 19045)]
|
|
[InlineData("tweak.win10.newsinterests.hide", 19045)]
|
|
[InlineData("tweak.win10.livetiles.off", 19045)]
|
|
public void EmbeddedCatalog_Win10OnlyCommands_AreCappedByMaxBuild(string id, int expectedMaxBuild)
|
|
{
|
|
var catalog = CatalogLoader.LoadEmbedded();
|
|
var command = catalog.Commands.Single(c => c.Id == id);
|
|
Assert.Equal(expectedMaxBuild, command.MaxOsBuild);
|
|
}
|
|
|
|
[Fact]
|
|
public void EmbeddedCatalog_Win11Tweaks_HiddenOnWindows10()
|
|
{
|
|
const int windows10Build = 19045;
|
|
var catalog = CatalogLoader.LoadEmbedded();
|
|
var hiddenOnWin10 = catalog.Commands.Where(c => !c.AppliesToOsBuild(windows10Build)).Select(c => c.Id).ToHashSet();
|
|
|
|
Assert.Contains("tweak.win11.taskbarleft", hiddenOnWin10);
|
|
Assert.Contains("tweak.clockseconds.on", hiddenOnWin10);
|
|
Assert.DoesNotContain("dism.checkhealth", hiddenOnWin10); // ungated commands stay visible
|
|
}
|
|
|
|
[Fact]
|
|
public void EmbeddedCatalog_Win10OnlyTweaks_HiddenOnWindows11()
|
|
{
|
|
const int windows11Build = 22000;
|
|
const int windows10Build = 19045;
|
|
var catalog = CatalogLoader.LoadEmbedded();
|
|
|
|
var meetNow = catalog.Commands.Single(c => c.Id == "tweak.win10.meetnow.hide");
|
|
Assert.False(meetNow.AppliesToOsBuild(windows11Build)); // capped by maxOsBuild -> hidden on Windows 11
|
|
Assert.True(meetNow.AppliesToOsBuild(windows10Build)); // visible on Windows 10 22H2
|
|
}
|
|
}
|